xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision 75f8991d0e6969407d51501d5a0537f104075c99)
1c9b443d4STobin Davis /*
2c9b443d4STobin Davis  * HD audio interface patch for Conexant HDA audio codec
3c9b443d4STobin Davis  *
4c9b443d4STobin Davis  * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5c9b443d4STobin Davis  * 		      Takashi Iwai <tiwai@suse.de>
6c9b443d4STobin Davis  * 		      Tobin Davis  <tdavis@dsl-only.net>
7c9b443d4STobin Davis  *
8c9b443d4STobin Davis  *  This driver is free software; you can redistribute it and/or modify
9c9b443d4STobin Davis  *  it under the terms of the GNU General Public License as published by
10c9b443d4STobin Davis  *  the Free Software Foundation; either version 2 of the License, or
11c9b443d4STobin Davis  *  (at your option) any later version.
12c9b443d4STobin Davis  *
13c9b443d4STobin Davis  *  This driver is distributed in the hope that it will be useful,
14c9b443d4STobin Davis  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15c9b443d4STobin Davis  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c9b443d4STobin Davis  *  GNU General Public License for more details.
17c9b443d4STobin Davis  *
18c9b443d4STobin Davis  *  You should have received a copy of the GNU General Public License
19c9b443d4STobin Davis  *  along with this program; if not, write to the Free Software
20c9b443d4STobin Davis  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21c9b443d4STobin Davis  */
22c9b443d4STobin Davis 
23c9b443d4STobin Davis #include <linux/init.h>
24c9b443d4STobin Davis #include <linux/delay.h>
25c9b443d4STobin Davis #include <linux/slab.h>
26c9b443d4STobin Davis #include <linux/pci.h>
27c9b443d4STobin Davis #include <sound/core.h>
28bc7a166dSUlrich Dangel #include <sound/jack.h>
29bc7a166dSUlrich Dangel 
30c9b443d4STobin Davis #include "hda_codec.h"
31c9b443d4STobin Davis #include "hda_local.h"
32c0f8faf0SEinar Rünkaru #include "hda_beep.h"
33c9b443d4STobin Davis 
34c9b443d4STobin Davis #define CXT_PIN_DIR_IN              0x00
35c9b443d4STobin Davis #define CXT_PIN_DIR_OUT             0x01
36c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT           0x02
37c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
38c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39c9b443d4STobin Davis 
40c9b443d4STobin Davis #define CONEXANT_HP_EVENT	0x37
41c9b443d4STobin Davis #define CONEXANT_MIC_EVENT	0x38
42c9b443d4STobin Davis 
43bc7a166dSUlrich Dangel /* Conexant 5051 specific */
44c9b443d4STobin Davis 
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;
114254bba6aSEinar Rünkaru 	unsigned int dell_vostro;
115*75f8991dSDaniel Drake 
116*75f8991dSDaniel Drake 	unsigned int ext_mic_present;
117*75f8991dSDaniel Drake 	unsigned int recording;
118*75f8991dSDaniel Drake 	void (*capture_prepare)(struct hda_codec *codec);
119*75f8991dSDaniel Drake 	void (*capture_cleanup)(struct hda_codec *codec);
120c9b443d4STobin Davis };
121c9b443d4STobin Davis 
122c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
123c9b443d4STobin Davis 				      struct hda_codec *codec,
124c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
125c9b443d4STobin Davis {
126c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1279a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1289a08160bSTakashi Iwai 					     hinfo);
129c9b443d4STobin Davis }
130c9b443d4STobin Davis 
131c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
132c9b443d4STobin Davis 					 struct hda_codec *codec,
133c9b443d4STobin Davis 					 unsigned int stream_tag,
134c9b443d4STobin Davis 					 unsigned int format,
135c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
136c9b443d4STobin Davis {
137c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
138c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
139c9b443d4STobin Davis 						stream_tag,
140c9b443d4STobin Davis 						format, substream);
141c9b443d4STobin Davis }
142c9b443d4STobin Davis 
143c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
144c9b443d4STobin Davis 					 struct hda_codec *codec,
145c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
146c9b443d4STobin Davis {
147c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
148c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
149c9b443d4STobin Davis }
150c9b443d4STobin Davis 
151c9b443d4STobin Davis /*
152c9b443d4STobin Davis  * Digital out
153c9b443d4STobin Davis  */
154c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
155c9b443d4STobin Davis 					  struct hda_codec *codec,
156c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
157c9b443d4STobin Davis {
158c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
159c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
160c9b443d4STobin Davis }
161c9b443d4STobin Davis 
162c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
163c9b443d4STobin Davis 					 struct hda_codec *codec,
164c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
165c9b443d4STobin Davis {
166c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
167c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
168c9b443d4STobin Davis }
169c9b443d4STobin Davis 
1706b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1716b97eb45STakashi Iwai 					 struct hda_codec *codec,
1726b97eb45STakashi Iwai 					 unsigned int stream_tag,
1736b97eb45STakashi Iwai 					 unsigned int format,
1746b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
1756b97eb45STakashi Iwai {
1766b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1776b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1786b97eb45STakashi Iwai 					     stream_tag,
1796b97eb45STakashi Iwai 					     format, substream);
1806b97eb45STakashi Iwai }
1816b97eb45STakashi Iwai 
182c9b443d4STobin Davis /*
183c9b443d4STobin Davis  * Analog capture
184c9b443d4STobin Davis  */
185c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
186c9b443d4STobin Davis 				      struct hda_codec *codec,
187c9b443d4STobin Davis 				      unsigned int stream_tag,
188c9b443d4STobin Davis 				      unsigned int format,
189c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
190c9b443d4STobin Davis {
191c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
192*75f8991dSDaniel Drake 	if (spec->capture_prepare)
193*75f8991dSDaniel Drake 		spec->capture_prepare(codec);
194c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
195c9b443d4STobin Davis 				   stream_tag, 0, format);
196c9b443d4STobin Davis 	return 0;
197c9b443d4STobin Davis }
198c9b443d4STobin Davis 
199c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
200c9b443d4STobin Davis 				      struct hda_codec *codec,
201c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
202c9b443d4STobin Davis {
203c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
204888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
205*75f8991dSDaniel Drake 	if (spec->capture_cleanup)
206*75f8991dSDaniel Drake 		spec->capture_cleanup(codec);
207c9b443d4STobin Davis 	return 0;
208c9b443d4STobin Davis }
209c9b443d4STobin Davis 
210c9b443d4STobin Davis 
211c9b443d4STobin Davis 
212c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = {
213c9b443d4STobin Davis 	.substreams = 1,
214c9b443d4STobin Davis 	.channels_min = 2,
215c9b443d4STobin Davis 	.channels_max = 2,
216c9b443d4STobin Davis 	.nid = 0, /* fill later */
217c9b443d4STobin Davis 	.ops = {
218c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
219c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
220c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
221c9b443d4STobin Davis 	},
222c9b443d4STobin Davis };
223c9b443d4STobin Davis 
224c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = {
225c9b443d4STobin Davis 	.substreams = 1,
226c9b443d4STobin Davis 	.channels_min = 2,
227c9b443d4STobin Davis 	.channels_max = 2,
228c9b443d4STobin Davis 	.nid = 0, /* fill later */
229c9b443d4STobin Davis 	.ops = {
230c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
231c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
232c9b443d4STobin Davis 	},
233c9b443d4STobin Davis };
234c9b443d4STobin Davis 
235c9b443d4STobin Davis 
236c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = {
237c9b443d4STobin Davis 	.substreams = 1,
238c9b443d4STobin Davis 	.channels_min = 2,
239c9b443d4STobin Davis 	.channels_max = 2,
240c9b443d4STobin Davis 	.nid = 0, /* fill later */
241c9b443d4STobin Davis 	.ops = {
242c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2436b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2446b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
245c9b443d4STobin Davis 	},
246c9b443d4STobin Davis };
247c9b443d4STobin Davis 
248c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = {
249c9b443d4STobin Davis 	.substreams = 1,
250c9b443d4STobin Davis 	.channels_min = 2,
251c9b443d4STobin Davis 	.channels_max = 2,
252c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
253c9b443d4STobin Davis };
254c9b443d4STobin Davis 
255461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
256461e2c78STakashi Iwai 				      struct hda_codec *codec,
257461e2c78STakashi Iwai 				      unsigned int stream_tag,
258461e2c78STakashi Iwai 				      unsigned int format,
259461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
260461e2c78STakashi Iwai {
261461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
262461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
263461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
264461e2c78STakashi Iwai 	spec->cur_adc_format = format;
265461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
266461e2c78STakashi Iwai 	return 0;
267461e2c78STakashi Iwai }
268461e2c78STakashi Iwai 
269461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
270461e2c78STakashi Iwai 				      struct hda_codec *codec,
271461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
272461e2c78STakashi Iwai {
273461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
274888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
275461e2c78STakashi Iwai 	spec->cur_adc = 0;
276461e2c78STakashi Iwai 	return 0;
277461e2c78STakashi Iwai }
278461e2c78STakashi Iwai 
279461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = {
280461e2c78STakashi Iwai 	.substreams = 1,
281461e2c78STakashi Iwai 	.channels_min = 2,
282461e2c78STakashi Iwai 	.channels_max = 2,
283461e2c78STakashi Iwai 	.nid = 0, /* fill later */
284461e2c78STakashi Iwai 	.ops = {
285461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
286461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
287461e2c78STakashi Iwai 	},
288461e2c78STakashi Iwai };
289461e2c78STakashi Iwai 
290c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
291c9b443d4STobin Davis {
292c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
293c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
294c9b443d4STobin Davis 
295c9b443d4STobin Davis 	codec->num_pcms = 1;
296c9b443d4STobin Davis 	codec->pcm_info = info;
297c9b443d4STobin Davis 
298c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
299c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
300c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
301c9b443d4STobin Davis 		spec->multiout.max_channels;
302c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
303c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
304461e2c78STakashi Iwai 	if (codec->vendor_id == 0x14f15051)
305461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
306461e2c78STakashi Iwai 			cx5051_pcm_analog_capture;
307461e2c78STakashi Iwai 	else
308461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
309461e2c78STakashi Iwai 			conexant_pcm_analog_capture;
310c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
311c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
312c9b443d4STobin Davis 
313c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
314c9b443d4STobin Davis 		info++;
315c9b443d4STobin Davis 		codec->num_pcms++;
316c9b443d4STobin Davis 		info->name = "Conexant Digital";
3177ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
318c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
319c9b443d4STobin Davis 			conexant_pcm_digital_playback;
320c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
321c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
322c9b443d4STobin Davis 		if (spec->dig_in_nid) {
323c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
324c9b443d4STobin Davis 				conexant_pcm_digital_capture;
325c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
326c9b443d4STobin Davis 				spec->dig_in_nid;
327c9b443d4STobin Davis 		}
328c9b443d4STobin Davis 	}
329c9b443d4STobin Davis 
330c9b443d4STobin Davis 	return 0;
331c9b443d4STobin Davis }
332c9b443d4STobin Davis 
333c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
334c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
335c9b443d4STobin Davis {
336c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
337c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
338c9b443d4STobin Davis 
339c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
340c9b443d4STobin Davis }
341c9b443d4STobin Davis 
342c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
343c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
344c9b443d4STobin Davis {
345c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
346c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
347c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
348c9b443d4STobin Davis 
349c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
350c9b443d4STobin Davis 	return 0;
351c9b443d4STobin Davis }
352c9b443d4STobin Davis 
353c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
354c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
355c9b443d4STobin Davis {
356c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
357c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
358c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
359c9b443d4STobin Davis 
360c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
361c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
362c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
363c9b443d4STobin Davis }
364c9b443d4STobin Davis 
3658c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
36695c09099STakashi Iwai static void conexant_free_jack_priv(struct snd_jack *jack)
36795c09099STakashi Iwai {
36895c09099STakashi Iwai 	struct conexant_jack *jacks = jack->private_data;
36995c09099STakashi Iwai 	jacks->nid = 0;
37095c09099STakashi Iwai 	jacks->jack = NULL;
37195c09099STakashi Iwai }
37295c09099STakashi Iwai 
373bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec,
374bc7a166dSUlrich Dangel 		hda_nid_t nid, int type)
375bc7a166dSUlrich Dangel {
376bc7a166dSUlrich Dangel 	struct conexant_spec *spec;
377bc7a166dSUlrich Dangel 	struct conexant_jack *jack;
378bc7a166dSUlrich Dangel 	const char *name;
37995c09099STakashi Iwai 	int err;
380bc7a166dSUlrich Dangel 
381bc7a166dSUlrich Dangel 	spec = codec->spec;
382bc7a166dSUlrich Dangel 	snd_array_init(&spec->jacks, sizeof(*jack), 32);
383bc7a166dSUlrich Dangel 	jack = snd_array_new(&spec->jacks);
384bc7a166dSUlrich Dangel 	name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
385bc7a166dSUlrich Dangel 
386bc7a166dSUlrich Dangel 	if (!jack)
387bc7a166dSUlrich Dangel 		return -ENOMEM;
388bc7a166dSUlrich Dangel 
389bc7a166dSUlrich Dangel 	jack->nid = nid;
390bc7a166dSUlrich Dangel 	jack->type = type;
391bc7a166dSUlrich Dangel 
39295c09099STakashi Iwai 	err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
39395c09099STakashi Iwai 	if (err < 0)
39495c09099STakashi Iwai 		return err;
39595c09099STakashi Iwai 	jack->jack->private_data = jack;
39695c09099STakashi Iwai 	jack->jack->private_free = conexant_free_jack_priv;
39795c09099STakashi Iwai 	return 0;
398bc7a166dSUlrich Dangel }
399bc7a166dSUlrich Dangel 
400bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
401bc7a166dSUlrich Dangel {
402bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
403bc7a166dSUlrich Dangel 	struct conexant_jack *jacks = spec->jacks.list;
404bc7a166dSUlrich Dangel 
405bc7a166dSUlrich Dangel 	if (jacks) {
406bc7a166dSUlrich Dangel 		int i;
407bc7a166dSUlrich Dangel 		for (i = 0; i < spec->jacks.used; i++) {
408bc7a166dSUlrich Dangel 			if (jacks->nid == nid) {
409bc7a166dSUlrich Dangel 				unsigned int present;
410d56757abSTakashi Iwai 				present = snd_hda_jack_detect(codec, nid);
411bc7a166dSUlrich Dangel 
412bc7a166dSUlrich Dangel 				present = (present) ? jacks->type : 0 ;
413bc7a166dSUlrich Dangel 
414bc7a166dSUlrich Dangel 				snd_jack_report(jacks->jack,
415bc7a166dSUlrich Dangel 						present);
416bc7a166dSUlrich Dangel 			}
417bc7a166dSUlrich Dangel 			jacks++;
418bc7a166dSUlrich Dangel 		}
419bc7a166dSUlrich Dangel 	}
420bc7a166dSUlrich Dangel }
421bc7a166dSUlrich Dangel 
422bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec)
423bc7a166dSUlrich Dangel {
424bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
425bc7a166dSUlrich Dangel 	int i;
426bc7a166dSUlrich Dangel 
427bc7a166dSUlrich Dangel 	for (i = 0; i < spec->num_init_verbs; i++) {
428bc7a166dSUlrich Dangel 		const struct hda_verb *hv;
429bc7a166dSUlrich Dangel 
430bc7a166dSUlrich Dangel 		hv = spec->init_verbs[i];
431bc7a166dSUlrich Dangel 		while (hv->nid) {
432bc7a166dSUlrich Dangel 			int err = 0;
433bc7a166dSUlrich Dangel 			switch (hv->param ^ AC_USRSP_EN) {
434bc7a166dSUlrich Dangel 			case CONEXANT_HP_EVENT:
435bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
436bc7a166dSUlrich Dangel 						SND_JACK_HEADPHONE);
437bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
438bc7a166dSUlrich Dangel 				break;
439bc7a166dSUlrich Dangel 			case CXT5051_PORTC_EVENT:
440bc7a166dSUlrich Dangel 			case CONEXANT_MIC_EVENT:
441bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
442bc7a166dSUlrich Dangel 						SND_JACK_MICROPHONE);
443bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
444bc7a166dSUlrich Dangel 				break;
445bc7a166dSUlrich Dangel 			}
446bc7a166dSUlrich Dangel 			if (err < 0)
447bc7a166dSUlrich Dangel 				return err;
448bc7a166dSUlrich Dangel 			++hv;
449bc7a166dSUlrich Dangel 		}
450bc7a166dSUlrich Dangel 	}
451bc7a166dSUlrich Dangel 	return 0;
452bc7a166dSUlrich Dangel 
453bc7a166dSUlrich Dangel }
4545801f992STakashi Iwai #else
4555801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
4565801f992STakashi Iwai {
4575801f992STakashi Iwai }
4585801f992STakashi Iwai 
4595801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec)
4605801f992STakashi Iwai {
4615801f992STakashi Iwai 	return 0;
4625801f992STakashi Iwai }
4635801f992STakashi Iwai #endif
464bc7a166dSUlrich Dangel 
465c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
466c9b443d4STobin Davis {
467c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
468c9b443d4STobin Davis 	int i;
469c9b443d4STobin Davis 
470c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
471c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
472c9b443d4STobin Davis 	return 0;
473c9b443d4STobin Davis }
474c9b443d4STobin Davis 
475c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
476c9b443d4STobin Davis {
4778c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
478bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
479bc7a166dSUlrich Dangel 	if (spec->jacks.list) {
480bc7a166dSUlrich Dangel 		struct conexant_jack *jacks = spec->jacks.list;
481bc7a166dSUlrich Dangel 		int i;
48295c09099STakashi Iwai 		for (i = 0; i < spec->jacks.used; i++, jacks++) {
48395c09099STakashi Iwai 			if (jacks->jack)
48495c09099STakashi Iwai 				snd_device_free(codec->bus->card, jacks->jack);
48595c09099STakashi Iwai 		}
486bc7a166dSUlrich Dangel 		snd_array_free(&spec->jacks);
487bc7a166dSUlrich Dangel 	}
488bc7a166dSUlrich Dangel #endif
489c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
490c9b443d4STobin Davis 	kfree(codec->spec);
491c9b443d4STobin Davis }
492c9b443d4STobin Davis 
493b880c74aSTakashi Iwai static struct snd_kcontrol_new cxt_capture_mixers[] = {
494b880c74aSTakashi Iwai 	{
495b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
496b880c74aSTakashi Iwai 		.name = "Capture Source",
497b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
498b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
499b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
500b880c74aSTakashi Iwai 	},
501b880c74aSTakashi Iwai 	{}
502b880c74aSTakashi Iwai };
503b880c74aSTakashi Iwai 
504dd5746a8STakashi Iwai static const char *slave_vols[] = {
505dd5746a8STakashi Iwai 	"Headphone Playback Volume",
506dd5746a8STakashi Iwai 	"Speaker Playback Volume",
507dd5746a8STakashi Iwai 	NULL
508dd5746a8STakashi Iwai };
509dd5746a8STakashi Iwai 
510dd5746a8STakashi Iwai static const char *slave_sws[] = {
511dd5746a8STakashi Iwai 	"Headphone Playback Switch",
512dd5746a8STakashi Iwai 	"Speaker Playback Switch",
513dd5746a8STakashi Iwai 	NULL
514dd5746a8STakashi Iwai };
515dd5746a8STakashi Iwai 
516c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
517c9b443d4STobin Davis {
518c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
519c9b443d4STobin Davis 	unsigned int i;
520c9b443d4STobin Davis 	int err;
521c9b443d4STobin Davis 
522c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
523c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
524c9b443d4STobin Davis 		if (err < 0)
525c9b443d4STobin Davis 			return err;
526c9b443d4STobin Davis 	}
527c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
528c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
529c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
530c9b443d4STobin Davis 		if (err < 0)
531c9b443d4STobin Davis 			return err;
5329a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
5339a08160bSTakashi Iwai 						    &spec->multiout);
5349a08160bSTakashi Iwai 		if (err < 0)
5359a08160bSTakashi Iwai 			return err;
5369a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
537c9b443d4STobin Davis 	}
538c9b443d4STobin Davis 	if (spec->dig_in_nid) {
539c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
540c9b443d4STobin Davis 		if (err < 0)
541c9b443d4STobin Davis 			return err;
542c9b443d4STobin Davis 	}
543dd5746a8STakashi Iwai 
544dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
545dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
546dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
547dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
548dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
549dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
550dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
551dd5746a8STakashi Iwai 					  vmaster_tlv, slave_vols);
552dd5746a8STakashi Iwai 		if (err < 0)
553dd5746a8STakashi Iwai 			return err;
554dd5746a8STakashi Iwai 	}
555dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
556dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
557dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
558dd5746a8STakashi Iwai 					  NULL, slave_sws);
559dd5746a8STakashi Iwai 		if (err < 0)
560dd5746a8STakashi Iwai 			return err;
561dd5746a8STakashi Iwai 	}
562dd5746a8STakashi Iwai 
563b880c74aSTakashi Iwai 	if (spec->input_mux) {
564b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
565b880c74aSTakashi Iwai 		if (err < 0)
566b880c74aSTakashi Iwai 			return err;
567b880c74aSTakashi Iwai 	}
568b880c74aSTakashi Iwai 
569c9b443d4STobin Davis 	return 0;
570c9b443d4STobin Davis }
571c9b443d4STobin Davis 
572c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
573c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
574c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
575c9b443d4STobin Davis 	.init = conexant_init,
576c9b443d4STobin Davis 	.free = conexant_free,
577c9b443d4STobin Davis };
578c9b443d4STobin Davis 
579c9b443d4STobin Davis /*
580c9b443d4STobin Davis  * EAPD control
581c9b443d4STobin Davis  * the private value = nid | (invert << 8)
582c9b443d4STobin Davis  */
583c9b443d4STobin Davis 
584a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
585c9b443d4STobin Davis 
58682f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
587c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
588c9b443d4STobin Davis {
589c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
590c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
591c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
592c9b443d4STobin Davis 	if (invert)
593c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
594c9b443d4STobin Davis 	else
595c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
596c9b443d4STobin Davis 	return 0;
59782f30040STobin Davis 
598c9b443d4STobin Davis }
599c9b443d4STobin Davis 
60082f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
601c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
602c9b443d4STobin Davis {
603c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
605c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
606c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
607c9b443d4STobin Davis 	unsigned int eapd;
60882f30040STobin Davis 
60968ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
610c9b443d4STobin Davis 	if (invert)
611c9b443d4STobin Davis 		eapd = !eapd;
61282beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
613c9b443d4STobin Davis 		return 0;
61482f30040STobin Davis 
615c9b443d4STobin Davis 	spec->cur_eapd = eapd;
61682beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
617c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
618c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
619c9b443d4STobin Davis 	return 1;
620c9b443d4STobin Davis }
621c9b443d4STobin Davis 
62286d72bdfSTakashi Iwai /* controls for test mode */
62386d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
62486d72bdfSTakashi Iwai 
62582f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
62682f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
62782f30040STobin Davis 	  .info = cxt_eapd_info, \
62882f30040STobin Davis 	  .get = cxt_eapd_get, \
62982f30040STobin Davis 	  .put = cxt_eapd_put, \
63082f30040STobin Davis 	  .private_value = nid | (mask<<16) }
63182f30040STobin Davis 
63282f30040STobin Davis 
63382f30040STobin Davis 
634c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
635c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
636c9b443d4STobin Davis {
637c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
639c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
640c9b443d4STobin Davis 				    spec->num_channel_mode);
641c9b443d4STobin Davis }
642c9b443d4STobin Davis 
643c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
644c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
645c9b443d4STobin Davis {
646c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
648c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
649c9b443d4STobin Davis 				   spec->num_channel_mode,
650c9b443d4STobin Davis 				   spec->multiout.max_channels);
651c9b443d4STobin Davis }
652c9b443d4STobin Davis 
653c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
654c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
655c9b443d4STobin Davis {
656c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
657c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
658c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
659c9b443d4STobin Davis 				      spec->num_channel_mode,
660c9b443d4STobin Davis 				      &spec->multiout.max_channels);
661c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
662c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
663c9b443d4STobin Davis 	return err;
664c9b443d4STobin Davis }
665c9b443d4STobin Davis 
666c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
667c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
668c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
669c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
670c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
671c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
672c9b443d4STobin Davis 
67386d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
67486d72bdfSTakashi Iwai 
675c9b443d4STobin Davis /* Conexant 5045 specific */
676c9b443d4STobin Davis 
677c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
678c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
679c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
680cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
681c9b443d4STobin Davis 
6825cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
6835cd57529STobin Davis 	{ 2, NULL },
6845cd57529STobin Davis };
685c9b443d4STobin Davis 
686c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
687c9b443d4STobin Davis 	.num_items = 2,
688c9b443d4STobin Davis 	.items = {
68982f30040STobin Davis 		{ "IntMic", 0x1 },
690f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
691c9b443d4STobin Davis 	}
692c9b443d4STobin Davis };
693c9b443d4STobin Davis 
6945218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = {
69522e14130SLukasz Marcinowski 	.num_items = 5,
6965218c892SJiang Zhe 	.items = {
6975218c892SJiang Zhe 		{ "IntMic", 0x1 },
6985218c892SJiang Zhe 		{ "ExtMic", 0x2 },
6995218c892SJiang Zhe 		{ "LineIn", 0x3 },
70022e14130SLukasz Marcinowski 		{ "CD",     0x4 },
70122e14130SLukasz Marcinowski 		{ "Mixer",  0x0 },
7025218c892SJiang Zhe 	}
7035218c892SJiang Zhe };
7045218c892SJiang Zhe 
7052de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = {
7062de3c232SJiang zhe 	.num_items = 2,
7072de3c232SJiang zhe 	.items = {
7082de3c232SJiang zhe 		{ "ExtMic", 0x1 },
7092de3c232SJiang zhe 		{ "IntMic", 0x2 },
7102de3c232SJiang zhe 	}
7112de3c232SJiang zhe };
7122de3c232SJiang zhe 
713c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
714c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
715c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
716c9b443d4STobin Davis {
717c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
71982f30040STobin Davis 	unsigned int bits;
720c9b443d4STobin Davis 
72182f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
722c9b443d4STobin Davis 		return 0;
723c9b443d4STobin Davis 
72482f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
72582f30040STobin Davis 	 * the headphone jack
72682f30040STobin Davis 	 */
72747fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
72847fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
72947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
7307f29673bSTobin Davis 
73147fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
73247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
73347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
734c9b443d4STobin Davis 	return 1;
735c9b443d4STobin Davis }
736c9b443d4STobin Davis 
737c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
738cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
739cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
740cca3b371STakashi Iwai 	.values = {
741cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
742cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
743cca3b371STakashi Iwai 		0
744cca3b371STakashi Iwai 	},
745cca3b371STakashi Iwai };
746c9b443d4STobin Davis 
7477f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
7487f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
7497f29673bSTobin Davis {
7507f29673bSTobin Davis 	static struct hda_verb mic_jack_on[] = {
7517f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7527f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7537f29673bSTobin Davis 		{}
7547f29673bSTobin Davis 	};
7557f29673bSTobin Davis 	static struct hda_verb mic_jack_off[] = {
7567f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7577f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7587f29673bSTobin Davis 		{}
7597f29673bSTobin Davis 	};
7607f29673bSTobin Davis 	unsigned int present;
7617f29673bSTobin Davis 
762d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x12);
7637f29673bSTobin Davis 	if (present)
7647f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
7657f29673bSTobin Davis 	else
7667f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
7677f29673bSTobin Davis }
7687f29673bSTobin Davis 
769c9b443d4STobin Davis 
770c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
771c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
772c9b443d4STobin Davis {
77382f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
774dd87da1cSTobin Davis 	unsigned int bits;
775c9b443d4STobin Davis 
776d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
777dd87da1cSTobin Davis 
77847fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
77947fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
78047fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
781c9b443d4STobin Davis }
782c9b443d4STobin Davis 
783c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
784c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
785c9b443d4STobin Davis 				   unsigned int res)
786c9b443d4STobin Davis {
787c9b443d4STobin Davis 	res >>= 26;
788c9b443d4STobin Davis 	switch (res) {
789c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
790c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
791c9b443d4STobin Davis 		break;
7927f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
7937f29673bSTobin Davis 		cxt5045_hp_automic(codec);
7947f29673bSTobin Davis 		break;
7957f29673bSTobin Davis 
796c9b443d4STobin Davis 	}
797c9b443d4STobin Davis }
798c9b443d4STobin Davis 
799c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
800c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
801c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
802c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
803c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
804c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
805c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
806c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
807c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
808c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
809c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
810cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
811c9b443d4STobin Davis 	{
812c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
813c9b443d4STobin Davis 		.name = "Master Playback Switch",
81482f30040STobin Davis 		.info = cxt_eapd_info,
81582f30040STobin Davis 		.get = cxt_eapd_get,
816c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
81782f30040STobin Davis 		.private_value = 0x10,
818c9b443d4STobin Davis 	},
819c9b443d4STobin Davis 
820c9b443d4STobin Davis 	{}
821c9b443d4STobin Davis };
822c9b443d4STobin Davis 
8235218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
82422e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
82522e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
82622e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
82722e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
82822e14130SLukasz Marcinowski 
8295218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
8305218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
8315218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
8325218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
8335218c892SJiang Zhe 
83422e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
83522e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
83622e14130SLukasz Marcinowski 
8375218c892SJiang Zhe 	{}
8385218c892SJiang Zhe };
8395218c892SJiang Zhe 
8402de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
8412de3c232SJiang zhe 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
8422de3c232SJiang zhe 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
8432de3c232SJiang zhe 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
8442de3c232SJiang zhe 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8452de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
8462de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
8472de3c232SJiang zhe 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
8482de3c232SJiang zhe 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
8492de3c232SJiang zhe 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
8502de3c232SJiang zhe 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8512de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
8522de3c232SJiang zhe 	{
8532de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8542de3c232SJiang zhe 		.name = "Master Playback Switch",
8552de3c232SJiang zhe 		.info = cxt_eapd_info,
8562de3c232SJiang zhe 		.get = cxt_eapd_get,
8572de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
8582de3c232SJiang zhe 		.private_value = 0x10,
8592de3c232SJiang zhe 	},
8602de3c232SJiang zhe 
8612de3c232SJiang zhe 	{}
8622de3c232SJiang zhe };
8632de3c232SJiang zhe 
864c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
865c9b443d4STobin Davis 	/* Line in, Mic */
8664090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8677f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
868c9b443d4STobin Davis 	/* HP, Amp  */
869c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
870c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
87182f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
872c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
873c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
874c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
875c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
876c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
877c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
87882f30040STobin Davis 	/* Record selector: Int mic */
8797f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
88082f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
881c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
882c9b443d4STobin Davis 	/* SPDIF route: PCM */
883cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
884c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
885c9b443d4STobin Davis 	/* EAPD */
88682f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
887c9b443d4STobin Davis 	{ } /* end */
888c9b443d4STobin Davis };
889c9b443d4STobin Davis 
8905218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = {
8915218c892SJiang Zhe 	/* Int Mic, Mic */
8925218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8935218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8945218c892SJiang Zhe 	/* Line In,HP, Amp  */
8955218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8965218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
8975218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8985218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
8995218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9005218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9015218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9025218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9035218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9045218c892SJiang Zhe 	/* Record selector: Int mic */
9055218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
9065218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
9075218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
9085218c892SJiang Zhe 	/* SPDIF route: PCM */
909cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9105218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
9115218c892SJiang Zhe 	/* EAPD */
9125218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
9135218c892SJiang Zhe 	{ } /* end */
9145218c892SJiang Zhe };
9157f29673bSTobin Davis 
9167f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
9177f29673bSTobin Davis 	/* pin sensing on HP jack */
9187f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
919d3091fadSTakashi Iwai 	{ } /* end */
9207f29673bSTobin Davis };
9217f29673bSTobin Davis 
9227f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
9237f29673bSTobin Davis 	/* pin sensing on HP jack */
9247f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
925d3091fadSTakashi Iwai 	{ } /* end */
9267f29673bSTobin Davis };
9277f29673bSTobin Davis 
928c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
929c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
930c9b443d4STobin Davis  * configuration.
931c9b443d4STobin Davis  */
932c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
933c9b443d4STobin Davis 	.num_items = 5,
934c9b443d4STobin Davis 	.items = {
935c9b443d4STobin Davis 		{ "MIXER", 0x0 },
936c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
937c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
938c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
939c9b443d4STobin Davis 		{ "CD pin", 0x4 },
940c9b443d4STobin Davis         },
941c9b443d4STobin Davis };
942c9b443d4STobin Davis 
943c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
944c9b443d4STobin Davis 
945c9b443d4STobin Davis 	/* Output controls */
946c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
947c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
9487f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
9497f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
9507f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
9517f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
952c9b443d4STobin Davis 
953c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
954c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
955c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
956c9b443d4STobin Davis 
95782f30040STobin Davis 	/* EAPD Switch Control */
95882f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
95982f30040STobin Davis 
960c9b443d4STobin Davis 	/* Loopback mixer controls */
961c9b443d4STobin Davis 
9627f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
9637f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
9647f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
9657f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
9667f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
9677f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
9687f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
9697f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
9707f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
9717f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
972c9b443d4STobin Davis 	{
973c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
974c9b443d4STobin Davis 		.name = "Input Source",
975c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
976c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
977c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
978c9b443d4STobin Davis 	},
979fb3409e7STobin Davis 	/* Audio input controls */
980fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
981fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
982fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
983fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
984fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
985fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
986fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
987fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
988fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
989fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
990c9b443d4STobin Davis 	{ } /* end */
991c9b443d4STobin Davis };
992c9b443d4STobin Davis 
993c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
9947f29673bSTobin Davis 	/* Set connections */
9957f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
9967f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
9977f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
998c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
999c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10007f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1001c9b443d4STobin Davis 
1002c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1003c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1004c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1005c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1006c9b443d4STobin Davis 	 * control.
1007c9b443d4STobin Davis 	 */
1008cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1009cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1010c9b443d4STobin Davis 
1011c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1012c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1013c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1014c9b443d4STobin Davis 
1015c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1016c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1017c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1018c9b443d4STobin Davis 	 * input/output buffers as needed.
1019c9b443d4STobin Davis 	 */
1020c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1021c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1022c9b443d4STobin Davis 
1023c9b443d4STobin Davis 	/* Mute capture amp left and right */
1024c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1025c9b443d4STobin Davis 
1026c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1027c9b443d4STobin Davis 	 * pin)
1028c9b443d4STobin Davis 	 */
1029c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
10307f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1031c9b443d4STobin Davis 
1032c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1033c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1034c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1035c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1036c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1037c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1038c9b443d4STobin Davis 
1039c9b443d4STobin Davis 	{ }
1040c9b443d4STobin Davis };
1041c9b443d4STobin Davis #endif
1042c9b443d4STobin Davis 
1043c9b443d4STobin Davis 
1044c9b443d4STobin Davis /* initialize jack-sensing, too */
1045c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
1046c9b443d4STobin Davis {
1047c9b443d4STobin Davis 	conexant_init(codec);
1048c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
1049c9b443d4STobin Davis 	return 0;
1050c9b443d4STobin Davis }
1051c9b443d4STobin Davis 
1052c9b443d4STobin Davis 
1053c9b443d4STobin Davis enum {
105415908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
105515908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
105615908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
10575218c892SJiang Zhe 	CXT5045_BENQ,
10582de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
1059c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1060c9b443d4STobin Davis 	CXT5045_TEST,
1061c9b443d4STobin Davis #endif
1062f5fcc13cSTakashi Iwai 	CXT5045_MODELS
1063c9b443d4STobin Davis };
1064c9b443d4STobin Davis 
1065f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = {
106615908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
106715908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
106815908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
10695218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
10702de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1071c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1072f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1073c9b443d4STobin Davis #endif
1074f5fcc13cSTakashi Iwai };
1075c9b443d4STobin Davis 
1076f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
10772de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1078dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1079dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPSENSE),
10806a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
10815218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
108215908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
108315908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
10849e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
10859e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
108615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
108715908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
108815908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1089dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1090dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
109115908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1092c9b443d4STobin Davis 	{}
1093c9b443d4STobin Davis };
1094c9b443d4STobin Davis 
1095c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1096c9b443d4STobin Davis {
1097c9b443d4STobin Davis 	struct conexant_spec *spec;
1098c9b443d4STobin Davis 	int board_config;
1099c9b443d4STobin Davis 
1100c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1101c9b443d4STobin Davis 	if (!spec)
1102c9b443d4STobin Davis 		return -ENOMEM;
1103c9b443d4STobin Davis 	codec->spec = spec;
11049421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1105c9b443d4STobin Davis 
1106c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1107c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1108c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1109c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1110c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1111c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1112c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1113c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1114c9b443d4STobin Davis 	spec->num_mixers = 1;
1115c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1116c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1117c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1118c9b443d4STobin Davis 	spec->spdif_route = 0;
11195cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
11205cd57529STobin Davis 	spec->channel_mode = cxt5045_modes,
11215cd57529STobin Davis 
1122c9b443d4STobin Davis 
1123c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1124c9b443d4STobin Davis 
1125f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1126f5fcc13cSTakashi Iwai 						  cxt5045_models,
1127f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
1128c9b443d4STobin Davis 	switch (board_config) {
112915908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
11307f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1131c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1132c9b443d4STobin Davis 		spec->num_init_verbs = 2;
11337f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11347f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
11357f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
11367f29673bSTobin Davis 		break;
113715908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
113886376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11397f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
11407f29673bSTobin Davis 		spec->num_init_verbs = 2;
11417f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1142c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1143c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1144c9b443d4STobin Davis 		break;
114515908c36SMarc Boucher 	default:
114615908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
114715908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
114815908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
114915908c36SMarc Boucher 		spec->num_init_verbs = 3;
115015908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
115115908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
115215908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
115315908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
115415908c36SMarc Boucher 		break;
11555218c892SJiang Zhe 	case CXT5045_BENQ:
11565218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11575218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
11585218c892SJiang Zhe 		spec->num_init_verbs = 1;
11595218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
11605218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
11615218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
11625218c892SJiang Zhe 		spec->num_mixers = 2;
11635218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
11645218c892SJiang Zhe 		break;
11652de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
11662de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11672de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
11682de3c232SJiang zhe 		spec->num_init_verbs = 2;
11692de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11702de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
11712de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
11722de3c232SJiang zhe 		break;
1173c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1174c9b443d4STobin Davis 	case CXT5045_TEST:
1175c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1176c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1177c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
117815908c36SMarc Boucher 		break;
117915908c36SMarc Boucher 
1180c9b443d4STobin Davis #endif
1181c9b443d4STobin Davis 	}
118248ecb7e8STakashi Iwai 
1183031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1184031005f7STakashi Iwai 	case 0x103c:
11850b587fc4SDaniel T Chen 	case 0x1734:
11860b587fc4SDaniel T Chen 		/* HP & Fujitsu-Siemens laptops have really bad sound over 0dB
11870b587fc4SDaniel T Chen 		 * on NID 0x17. Fix max PCM level to 0 dB
11880b587fc4SDaniel T Chen 		 * (originally it has 0x2b steps with 0dB offset 0x14)
118948ecb7e8STakashi Iwai 		 */
119048ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
119148ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
119248ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
119348ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
119448ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1195031005f7STakashi Iwai 		break;
1196031005f7STakashi Iwai 	}
119748ecb7e8STakashi Iwai 
1198c9b443d4STobin Davis 	return 0;
1199c9b443d4STobin Davis }
1200c9b443d4STobin Davis 
1201c9b443d4STobin Davis 
1202c9b443d4STobin Davis /* Conexant 5047 specific */
120382f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1204c9b443d4STobin Davis 
12055b3a7440STakashi Iwai static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1206c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1207c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1208c9b443d4STobin Davis 
12095cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
12105cd57529STobin Davis 	{ 2, NULL },
12115cd57529STobin Davis };
1212c9b443d4STobin Davis 
121382f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
121482f30040STobin Davis 	.num_items = 2,
121582f30040STobin Davis 	.items = {
121682f30040STobin Davis 		{ "ExtMic", 0x2 },
121782f30040STobin Davis 		{ "Line-In", 0x1 },
1218c9b443d4STobin Davis 	}
1219c9b443d4STobin Davis };
1220c9b443d4STobin Davis 
1221c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1222c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1223c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1224c9b443d4STobin Davis {
1225c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1226c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
122782f30040STobin Davis 	unsigned int bits;
1228c9b443d4STobin Davis 
122982f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1230c9b443d4STobin Davis 		return 0;
1231c9b443d4STobin Davis 
123282f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
123382f30040STobin Davis 	 * the headphone jack
123482f30040STobin Davis 	 */
123547fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
12363b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
12373b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
12383b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
12393b7523fcSTakashi Iwai 	 */
12405d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
124147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
124247fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
124347fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
124447fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1245c9b443d4STobin Davis 	return 1;
1246c9b443d4STobin Davis }
1247c9b443d4STobin Davis 
1248c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1249c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1250c9b443d4STobin Davis {
125182f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1252dd87da1cSTobin Davis 	unsigned int bits;
1253c9b443d4STobin Davis 
1254d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1255dd87da1cSTobin Davis 
125647fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
12573b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12585d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
125947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1260c9b443d4STobin Davis }
1261c9b443d4STobin Davis 
1262c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1263c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1264c9b443d4STobin Davis {
1265c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
12669f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12679f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1268c9b443d4STobin Davis 		{}
1269c9b443d4STobin Davis 	};
1270c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
12719f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12729f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1273c9b443d4STobin Davis 		{}
1274c9b443d4STobin Davis 	};
1275c9b443d4STobin Davis 	unsigned int present;
1276c9b443d4STobin Davis 
1277d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1278c9b443d4STobin Davis 	if (present)
1279c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1280c9b443d4STobin Davis 	else
1281c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1282c9b443d4STobin Davis }
1283c9b443d4STobin Davis 
1284c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1285c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1286c9b443d4STobin Davis 				  unsigned int res)
1287c9b443d4STobin Davis {
12889f113e0eSMarc Boucher 	switch (res >> 26) {
1289c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1290c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1291c9b443d4STobin Davis 		break;
1292c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1293c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1294c9b443d4STobin Davis 		break;
1295c9b443d4STobin Davis 	}
1296c9b443d4STobin Davis }
1297c9b443d4STobin Davis 
1298df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1299df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1300df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1301df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
1302c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1303c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1304c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1305c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
130682f30040STobin Davis 	{
130782f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
130882f30040STobin Davis 		.name = "Master Playback Switch",
130982f30040STobin Davis 		.info = cxt_eapd_info,
131082f30040STobin Davis 		.get = cxt_eapd_get,
1311c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1312c9b443d4STobin Davis 		.private_value = 0x13,
1313c9b443d4STobin Davis 	},
1314c9b443d4STobin Davis 
1315c9b443d4STobin Davis 	{}
1316c9b443d4STobin Davis };
1317c9b443d4STobin Davis 
1318df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
13193b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13205d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1321df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1322df481e41STakashi Iwai 	{}
1323df481e41STakashi Iwai };
1324df481e41STakashi Iwai 
1325df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1326c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1327c9b443d4STobin Davis 	{ } /* end */
1328c9b443d4STobin Davis };
1329c9b443d4STobin Davis 
1330c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1331c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1332c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1333c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1334c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
13357f29673bSTobin Davis 	/* HP, Speaker  */
1336b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
13375b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
13385b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
13397f29673bSTobin Davis 	/* Record selector: Mic */
13407f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
13417f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
13427f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
13437f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1344c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1345c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1346c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1347c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1348c9b443d4STobin Davis 	/* SPDIF route: PCM */
1349c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
135082f30040STobin Davis 	/* Enable unsolicited events */
135182f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
135282f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1353c9b443d4STobin Davis 	{ } /* end */
1354c9b443d4STobin Davis };
1355c9b443d4STobin Davis 
1356c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1357c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
13583b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1359c9b443d4STobin Davis 	{}
1360c9b443d4STobin Davis };
1361c9b443d4STobin Davis 
1362c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1363c9b443d4STobin Davis  * configuration.
1364c9b443d4STobin Davis  */
1365c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1366c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
136782f30040STobin Davis 	.num_items = 4,
1368c9b443d4STobin Davis 	.items = {
136982f30040STobin Davis 		{ "LINE1 pin", 0x0 },
137082f30040STobin Davis 		{ "MIC1 pin", 0x1 },
137182f30040STobin Davis 		{ "MIC2 pin", 0x2 },
137282f30040STobin Davis 		{ "CD pin", 0x3 },
1373c9b443d4STobin Davis         },
1374c9b443d4STobin Davis };
1375c9b443d4STobin Davis 
1376c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1377c9b443d4STobin Davis 
1378c9b443d4STobin Davis 	/* Output only controls */
137982f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
138082f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
138182f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
138282f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1383c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1384c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1385c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1386c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
138782f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
138882f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
138982f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
139082f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1391c9b443d4STobin Davis 
1392c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1393c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1394c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1395c9b443d4STobin Davis 
139682f30040STobin Davis 	/* EAPD Switch Control */
139782f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
139882f30040STobin Davis 
1399c9b443d4STobin Davis 	/* Loopback mixer controls */
140082f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
140182f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
140282f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
140382f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
140482f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
140582f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
140682f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
140782f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1408c9b443d4STobin Davis 
140982f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
141082f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
141182f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
141282f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
141382f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
141482f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
141582f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
141682f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1417c9b443d4STobin Davis 	{
1418c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1419c9b443d4STobin Davis 		.name = "Input Source",
1420c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1421c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1422c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1423c9b443d4STobin Davis 	},
1424854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
14259f113e0eSMarc Boucher 
1426c9b443d4STobin Davis 	{ } /* end */
1427c9b443d4STobin Davis };
1428c9b443d4STobin Davis 
1429c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1430c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1431c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1432c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1433c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1434c9b443d4STobin Davis 
1435c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1436c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1437c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1438c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1439c9b443d4STobin Davis 	 * control.
1440c9b443d4STobin Davis 	 */
1441c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1442c9b443d4STobin Davis 
1443c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1444c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1445c9b443d4STobin Davis 	 */
1446c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1447c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1448c9b443d4STobin Davis 
1449c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1450c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1451c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1452c9b443d4STobin Davis 
1453c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1454c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1455c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1456c9b443d4STobin Davis 	 * input/output buffers as needed.
1457c9b443d4STobin Davis 	 */
1458c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1459c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1460c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1461c9b443d4STobin Davis 
1462c9b443d4STobin Davis 	/* Mute capture amp left and right */
1463c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1464c9b443d4STobin Davis 
1465c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1466c9b443d4STobin Davis 	 * pin)
1467c9b443d4STobin Davis 	 */
1468c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1469c9b443d4STobin Davis 
1470c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1471c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1472c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1473c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1474c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1475c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1476c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1477c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1478c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1479c9b443d4STobin Davis 
1480c9b443d4STobin Davis 	{ }
1481c9b443d4STobin Davis };
1482c9b443d4STobin Davis #endif
1483c9b443d4STobin Davis 
1484c9b443d4STobin Davis 
1485c9b443d4STobin Davis /* initialize jack-sensing, too */
1486c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1487c9b443d4STobin Davis {
1488c9b443d4STobin Davis 	conexant_init(codec);
1489c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1490c9b443d4STobin Davis 	return 0;
1491c9b443d4STobin Davis }
1492c9b443d4STobin Davis 
1493c9b443d4STobin Davis 
1494c9b443d4STobin Davis enum {
1495f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1496f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1497f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1498c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1499c9b443d4STobin Davis 	CXT5047_TEST,
1500c9b443d4STobin Davis #endif
1501f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1502c9b443d4STobin Davis };
1503c9b443d4STobin Davis 
1504f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = {
1505f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1506f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1507f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1508c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1509f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1510c9b443d4STobin Davis #endif
1511f5fcc13cSTakashi Iwai };
1512c9b443d4STobin Davis 
1513f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1514ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1515dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1516dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1517f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1518c9b443d4STobin Davis 	{}
1519c9b443d4STobin Davis };
1520c9b443d4STobin Davis 
1521c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1522c9b443d4STobin Davis {
1523c9b443d4STobin Davis 	struct conexant_spec *spec;
1524c9b443d4STobin Davis 	int board_config;
1525c9b443d4STobin Davis 
1526c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1527c9b443d4STobin Davis 	if (!spec)
1528c9b443d4STobin Davis 		return -ENOMEM;
1529c9b443d4STobin Davis 	codec->spec = spec;
15309421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1531c9b443d4STobin Davis 
1532c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1533c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1534c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1535c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1536c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1537c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1538c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1539c9b443d4STobin Davis 	spec->num_mixers = 1;
1540df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1541c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1542c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1543c9b443d4STobin Davis 	spec->spdif_route = 0;
15445cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
15455cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1546c9b443d4STobin Davis 
1547c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1548c9b443d4STobin Davis 
1549f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1550f5fcc13cSTakashi Iwai 						  cxt5047_models,
1551f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1552c9b443d4STobin Davis 	switch (board_config) {
1553c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1554df481e41STakashi Iwai 		spec->num_mixers = 2;
1555df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1556df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1557c9b443d4STobin Davis 		break;
1558c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1559df481e41STakashi Iwai 		spec->num_mixers = 2;
1560df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1561fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1562c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1563c9b443d4STobin Davis 		break;
1564c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
156582f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1566df481e41STakashi Iwai 		spec->num_mixers = 2;
1567df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1568c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1569c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1570fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1571c9b443d4STobin Davis 		break;
1572c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1573c9b443d4STobin Davis 	case CXT5047_TEST:
1574c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1575c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1576c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1577fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1578c9b443d4STobin Davis #endif
1579c9b443d4STobin Davis 	}
1580dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1581c9b443d4STobin Davis 	return 0;
1582c9b443d4STobin Davis }
1583c9b443d4STobin Davis 
1584461e2c78STakashi Iwai /* Conexant 5051 specific */
1585461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1586461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1587461e2c78STakashi Iwai 
1588461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = {
1589461e2c78STakashi Iwai 	{ 2, NULL },
1590461e2c78STakashi Iwai };
1591461e2c78STakashi Iwai 
1592461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1593461e2c78STakashi Iwai {
1594461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1595461e2c78STakashi Iwai 	unsigned int pinctl;
1596461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1597461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1598461e2c78STakashi Iwai 			    pinctl);
1599461e2c78STakashi Iwai }
1600461e2c78STakashi Iwai 
1601461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1602461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1603461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1604461e2c78STakashi Iwai {
1605461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1606461e2c78STakashi Iwai 
1607461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1608461e2c78STakashi Iwai 		return 0;
1609461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1610461e2c78STakashi Iwai 	return 1;
1611461e2c78STakashi Iwai }
1612461e2c78STakashi Iwai 
1613461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1614461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1615461e2c78STakashi Iwai {
161679d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1617461e2c78STakashi Iwai 	unsigned int present;
1618461e2c78STakashi Iwai 
161979d7d533STakashi Iwai 	if (spec->no_auto_mic)
162079d7d533STakashi Iwai 		return;
1621d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1622461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1623461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1624461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1625461e2c78STakashi Iwai }
1626461e2c78STakashi Iwai 
1627461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1628461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1629461e2c78STakashi Iwai {
1630461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1631461e2c78STakashi Iwai 	unsigned int present;
1632461e2c78STakashi Iwai 	hda_nid_t new_adc;
1633461e2c78STakashi Iwai 
163479d7d533STakashi Iwai 	if (spec->no_auto_mic)
163579d7d533STakashi Iwai 		return;
1636d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1637461e2c78STakashi Iwai 	if (present)
1638461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1639461e2c78STakashi Iwai 	else
1640461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1641461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1642461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1643461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1644888afa15STakashi Iwai 		snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1645461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1646461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1647461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1648461e2c78STakashi Iwai 					   spec->cur_adc_format);
1649461e2c78STakashi Iwai 	}
1650461e2c78STakashi Iwai }
1651461e2c78STakashi Iwai 
1652461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1653461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1654461e2c78STakashi Iwai {
1655461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1656461e2c78STakashi Iwai 
1657d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1658461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1659461e2c78STakashi Iwai }
1660461e2c78STakashi Iwai 
1661461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1662461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1663461e2c78STakashi Iwai 				   unsigned int res)
1664461e2c78STakashi Iwai {
1665acf26c0cSUlrich Dangel 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1666461e2c78STakashi Iwai 	switch (res >> 26) {
1667461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1668461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1669461e2c78STakashi Iwai 		break;
1670461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1671461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1672461e2c78STakashi Iwai 		break;
1673461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1674461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1675461e2c78STakashi Iwai 		break;
1676461e2c78STakashi Iwai 	}
1677acf26c0cSUlrich Dangel 	conexant_report_jack(codec, nid);
1678461e2c78STakashi Iwai }
1679461e2c78STakashi Iwai 
1680461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_mixers[] = {
1681461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1682461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1683461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1684461e2c78STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1685461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1686461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1687461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1688461e2c78STakashi Iwai 	{
1689461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1690461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1691461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1692461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1693461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1694461e2c78STakashi Iwai 		.private_value = 0x1a,
1695461e2c78STakashi Iwai 	},
1696461e2c78STakashi Iwai 
1697461e2c78STakashi Iwai 	{}
1698461e2c78STakashi Iwai };
1699461e2c78STakashi Iwai 
1700461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1701461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1702461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1703461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1704461e2c78STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1705461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1706461e2c78STakashi Iwai 	{
1707461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1708461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1709461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1710461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1711461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1712461e2c78STakashi Iwai 		.private_value = 0x1a,
1713461e2c78STakashi Iwai 	},
1714461e2c78STakashi Iwai 
1715461e2c78STakashi Iwai 	{}
1716461e2c78STakashi Iwai };
1717461e2c78STakashi Iwai 
171879d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
171979d7d533STakashi Iwai 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
172079d7d533STakashi Iwai 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
172179d7d533STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
172279d7d533STakashi Iwai 	{
172379d7d533STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
172479d7d533STakashi Iwai 		.name = "Master Playback Switch",
172579d7d533STakashi Iwai 		.info = cxt_eapd_info,
172679d7d533STakashi Iwai 		.get = cxt_eapd_get,
172779d7d533STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
172879d7d533STakashi Iwai 		.private_value = 0x1a,
172979d7d533STakashi Iwai 	},
173079d7d533STakashi Iwai 
173179d7d533STakashi Iwai 	{}
173279d7d533STakashi Iwai };
173379d7d533STakashi Iwai 
1734cd9d95a5SKen Prox static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1735cd9d95a5SKen Prox 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1736cd9d95a5SKen Prox 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1737cd9d95a5SKen Prox 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1738cd9d95a5SKen Prox 	{
1739cd9d95a5SKen Prox 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1740cd9d95a5SKen Prox 		.name = "Master Playback Switch",
1741cd9d95a5SKen Prox 		.info = cxt_eapd_info,
1742cd9d95a5SKen Prox 		.get = cxt_eapd_get,
1743cd9d95a5SKen Prox 		.put = cxt5051_hp_master_sw_put,
1744cd9d95a5SKen Prox 		.private_value = 0x1a,
1745cd9d95a5SKen Prox 	},
1746cd9d95a5SKen Prox 
1747cd9d95a5SKen Prox 	{}
1748cd9d95a5SKen Prox };
1749cd9d95a5SKen Prox 
1750461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = {
1751461e2c78STakashi Iwai 	/* Line in, Mic */
1752461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1753461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1754461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1755461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1756461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1757461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1758461e2c78STakashi Iwai 	/* SPK  */
1759461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1760461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1761461e2c78STakashi Iwai 	/* HP, Amp  */
1762461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1763461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1764461e2c78STakashi Iwai 	/* DAC1 */
1765461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1766461e2c78STakashi Iwai 	/* Record selector: Int mic */
1767461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1768461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1769461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1770461e2c78STakashi Iwai 	/* SPDIF route: PCM */
1771461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1772461e2c78STakashi Iwai 	/* EAPD */
1773461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1774461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1775461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1776461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1777461e2c78STakashi Iwai 	{ } /* end */
1778461e2c78STakashi Iwai };
1779461e2c78STakashi Iwai 
178079d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
178179d7d533STakashi Iwai 	/* Line in, Mic */
178279d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
178379d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
178479d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
178579d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
178679d7d533STakashi Iwai 	/* SPK  */
178779d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
178879d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
178979d7d533STakashi Iwai 	/* HP, Amp  */
179079d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
179179d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
179279d7d533STakashi Iwai 	/* DAC1 */
179379d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
179479d7d533STakashi Iwai 	/* Record selector: Int mic */
179579d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
179679d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
179779d7d533STakashi Iwai 	/* SPDIF route: PCM */
179879d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
179979d7d533STakashi Iwai 	/* EAPD */
180079d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
180179d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
180279d7d533STakashi Iwai 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
180379d7d533STakashi Iwai 	{ } /* end */
180479d7d533STakashi Iwai };
180579d7d533STakashi Iwai 
180627e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
180727e08988SAristeu Sergio Rozanski Filho 	/* Line in, Mic */
180827e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
180927e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
181027e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
181127e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
181227e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
181327e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
181427e08988SAristeu Sergio Rozanski Filho 	/* SPK  */
181527e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
181627e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
181727e08988SAristeu Sergio Rozanski Filho 	/* HP, Amp  */
181827e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
181927e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
182027e08988SAristeu Sergio Rozanski Filho 	/* Docking HP */
182127e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
182227e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
182327e08988SAristeu Sergio Rozanski Filho 	/* DAC1 */
182427e08988SAristeu Sergio Rozanski Filho 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
182527e08988SAristeu Sergio Rozanski Filho 	/* Record selector: Int mic */
182627e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
182727e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
182827e08988SAristeu Sergio Rozanski Filho 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
182927e08988SAristeu Sergio Rozanski Filho 	/* SPDIF route: PCM */
183027e08988SAristeu Sergio Rozanski Filho 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
183127e08988SAristeu Sergio Rozanski Filho 	/* EAPD */
183227e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
183327e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
183427e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
183527e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
183627e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
183727e08988SAristeu Sergio Rozanski Filho 	{ } /* end */
183827e08988SAristeu Sergio Rozanski Filho };
183927e08988SAristeu Sergio Rozanski Filho 
1840cd9d95a5SKen Prox static struct hda_verb cxt5051_f700_init_verbs[] = {
1841cd9d95a5SKen Prox 	/* Line in, Mic */
1842cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x03},
1843cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1844cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1845cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1846cd9d95a5SKen Prox 	/* SPK  */
1847cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1848cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1849cd9d95a5SKen Prox 	/* HP, Amp  */
1850cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1851cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1852cd9d95a5SKen Prox 	/* DAC1 */
1853cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1854cd9d95a5SKen Prox 	/* Record selector: Int mic */
1855cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1856cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1857cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1858cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1859cd9d95a5SKen Prox 	/* EAPD */
1860cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1861cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1862cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1863cd9d95a5SKen Prox 	{ } /* end */
1864cd9d95a5SKen Prox };
1865cd9d95a5SKen Prox 
1866461e2c78STakashi Iwai /* initialize jack-sensing, too */
1867461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1868461e2c78STakashi Iwai {
1869461e2c78STakashi Iwai 	conexant_init(codec);
1870acf26c0cSUlrich Dangel 	conexant_init_jacks(codec);
1871461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1872461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1873461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1874461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1875461e2c78STakashi Iwai 	}
1876461e2c78STakashi Iwai 	return 0;
1877461e2c78STakashi Iwai }
1878461e2c78STakashi Iwai 
1879461e2c78STakashi Iwai 
1880461e2c78STakashi Iwai enum {
1881461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1882461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
188379d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
188427e08988SAristeu Sergio Rozanski Filho 	CXT5051_LENOVO_X200,	/* Lenovo X200 laptop */
1885cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
1886461e2c78STakashi Iwai 	CXT5051_MODELS
1887461e2c78STakashi Iwai };
1888461e2c78STakashi Iwai 
1889461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = {
1890461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1891461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
189279d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
189327e08988SAristeu Sergio Rozanski Filho 	[CXT5051_LENOVO_X200]	= "lenovo-x200",
1894cd9d95a5SKen Prox 	[CXT5051_F700]          = "hp 700"
1895461e2c78STakashi Iwai };
1896461e2c78STakashi Iwai 
1897461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
189879d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
18991812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1900461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1901461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1902461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
190327e08988SAristeu Sergio Rozanski Filho 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1904cd9d95a5SKen Prox 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1905461e2c78STakashi Iwai 	{}
1906461e2c78STakashi Iwai };
1907461e2c78STakashi Iwai 
1908461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1909461e2c78STakashi Iwai {
1910461e2c78STakashi Iwai 	struct conexant_spec *spec;
1911461e2c78STakashi Iwai 	int board_config;
1912461e2c78STakashi Iwai 
1913461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1914461e2c78STakashi Iwai 	if (!spec)
1915461e2c78STakashi Iwai 		return -ENOMEM;
1916461e2c78STakashi Iwai 	codec->spec = spec;
19179421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1918461e2c78STakashi Iwai 
1919461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
1920461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
1921461e2c78STakashi Iwai 
1922461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
1923461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1924461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
1925461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1926461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1927461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
1928461e2c78STakashi Iwai 	spec->num_mixers = 1;
1929461e2c78STakashi Iwai 	spec->mixers[0] = cxt5051_mixers;
1930461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
1931461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
1932461e2c78STakashi Iwai 	spec->spdif_route = 0;
1933461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1934461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
1935461e2c78STakashi Iwai 	spec->cur_adc = 0;
1936461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
1937461e2c78STakashi Iwai 
193879d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
193979d7d533STakashi Iwai 
1940461e2c78STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1941461e2c78STakashi Iwai 						  cxt5051_models,
1942461e2c78STakashi Iwai 						  cxt5051_cfg_tbl);
1943461e2c78STakashi Iwai 	switch (board_config) {
1944461e2c78STakashi Iwai 	case CXT5051_HP:
1945461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
1946461e2c78STakashi Iwai 		break;
194779d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
194879d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
194979d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
195079d7d533STakashi Iwai 		spec->no_auto_mic = 1;
195179d7d533STakashi Iwai 		break;
195227e08988SAristeu Sergio Rozanski Filho 	case CXT5051_LENOVO_X200:
195327e08988SAristeu Sergio Rozanski Filho 		spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1954461e2c78STakashi Iwai 		break;
1955cd9d95a5SKen Prox 	case CXT5051_F700:
1956cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
1957cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
1958cd9d95a5SKen Prox 		spec->no_auto_mic = 1;
1959cd9d95a5SKen Prox 		break;
1960461e2c78STakashi Iwai 	}
1961461e2c78STakashi Iwai 
1962461e2c78STakashi Iwai 	return 0;
1963461e2c78STakashi Iwai }
1964461e2c78STakashi Iwai 
19650fb67e98SDaniel Drake /* Conexant 5066 specific */
19660fb67e98SDaniel Drake 
19670fb67e98SDaniel Drake static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
19680fb67e98SDaniel Drake static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
19690fb67e98SDaniel Drake static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
19700fb67e98SDaniel Drake #define CXT5066_SPDIF_OUT	0x21
19710fb67e98SDaniel Drake 
1972dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors,
1973dbaccc0cSDaniel Drake  * therefore we use a 50% mic bias in order to center the input signal with
1974dbaccc0cSDaniel Drake  * the DC input range of the codec. */
1975dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1976dbaccc0cSDaniel Drake 
19770fb67e98SDaniel Drake static struct hda_channel_mode cxt5066_modes[1] = {
19780fb67e98SDaniel Drake 	{ 2, NULL },
19790fb67e98SDaniel Drake };
19800fb67e98SDaniel Drake 
19810fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
19820fb67e98SDaniel Drake {
19830fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
19840fb67e98SDaniel Drake 	unsigned int pinctl;
19850fb67e98SDaniel Drake 
19860fb67e98SDaniel Drake 	snd_printdd("CXT5066: update speaker, hp_present=%d\n",
19870fb67e98SDaniel Drake 		spec->hp_present);
19880fb67e98SDaniel Drake 
19890fb67e98SDaniel Drake 	/* Port A (HP) */
19900fb67e98SDaniel Drake 	pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
19910fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
19920fb67e98SDaniel Drake 			pinctl);
19930fb67e98SDaniel Drake 
19940fb67e98SDaniel Drake 	/* Port D (HP/LO) */
19950fb67e98SDaniel Drake 	pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
19960fb67e98SDaniel Drake 		? spec->port_d_mode : 0;
19970fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
19980fb67e98SDaniel Drake 			pinctl);
19990fb67e98SDaniel Drake 
20000fb67e98SDaniel Drake 	/* CLASS_D AMP */
20010fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
20020fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
20030fb67e98SDaniel Drake 			pinctl);
20040fb67e98SDaniel Drake 
20050fb67e98SDaniel Drake 	if (spec->dell_automute) {
20060fb67e98SDaniel Drake 		/* DELL AIO Port Rule: PortA > PortD > IntSpk */
20070fb67e98SDaniel Drake 		pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
20080fb67e98SDaniel Drake 			? PIN_OUT : 0;
20090fb67e98SDaniel Drake 		snd_hda_codec_write(codec, 0x1c, 0,
20100fb67e98SDaniel Drake 			AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
20110fb67e98SDaniel Drake 	}
20120fb67e98SDaniel Drake }
20130fb67e98SDaniel Drake 
20140fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
20150fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
20160fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
20170fb67e98SDaniel Drake {
20180fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
20190fb67e98SDaniel Drake 
20200fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
20210fb67e98SDaniel Drake 		return 0;
20220fb67e98SDaniel Drake 
20230fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
20240fb67e98SDaniel Drake 	return 1;
20250fb67e98SDaniel Drake }
20260fb67e98SDaniel Drake 
2027*75f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the
2028*75f8991dSDaniel Drake  * microphone LED comes on as soon as these settings are put in place. if we
2029*75f8991dSDaniel Drake  * did this before recording, it would give the false indication that recording
2030*75f8991dSDaniel Drake  * is happening when it is not. */
2031*75f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec)
20320fb67e98SDaniel Drake {
2033dbaccc0cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2034*75f8991dSDaniel Drake 	if (!spec->recording)
2035*75f8991dSDaniel Drake 		return;
20360fb67e98SDaniel Drake 
2037*75f8991dSDaniel Drake 	/* external mic, port B */
2038*75f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2039*75f8991dSDaniel Drake 		spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
20400fb67e98SDaniel Drake 
2041*75f8991dSDaniel Drake 	/* internal mic, port C */
2042*75f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2043*75f8991dSDaniel Drake 		spec->ext_mic_present ? 0 : PIN_VREF80);
2044*75f8991dSDaniel Drake }
20450fb67e98SDaniel Drake 
2046*75f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */
2047*75f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec)
2048*75f8991dSDaniel Drake {
2049*75f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
20500fb67e98SDaniel Drake 	unsigned int present;
20510fb67e98SDaniel Drake 
2052*75f8991dSDaniel Drake 	present = snd_hda_codec_read(codec, 0x1a, 0,
2053*75f8991dSDaniel Drake 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2054*75f8991dSDaniel Drake 	if (present)
20550fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone detected\n");
2056*75f8991dSDaniel Drake 	else
20570fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone absent\n");
2058*75f8991dSDaniel Drake 
2059*75f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2060*75f8991dSDaniel Drake 		present ? 0 : 1);
2061*75f8991dSDaniel Drake 	spec->ext_mic_present = !!present;
2062*75f8991dSDaniel Drake 
2063*75f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
20640fb67e98SDaniel Drake }
20650fb67e98SDaniel Drake 
206695a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
206795a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
206895a618bdSEinar Rünkaru {
206995a618bdSEinar Rünkaru 	unsigned int present;
207095a618bdSEinar Rünkaru 
207195a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
207295a618bdSEinar Rünkaru 		/* enable external mic, port B */
2073*75f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
207495a618bdSEinar Rünkaru 
207595a618bdSEinar Rünkaru 		/* switch to external mic input */
207695a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
207795a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
207895a618bdSEinar Rünkaru 
207995a618bdSEinar Rünkaru 		/* disable internal digital mic */
208095a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
208195a618bdSEinar Rünkaru 		{}
208295a618bdSEinar Rünkaru 	};
208395a618bdSEinar Rünkaru 	static struct hda_verb ext_mic_absent[] = {
208495a618bdSEinar Rünkaru 		/* enable internal mic, port C */
208595a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
208695a618bdSEinar Rünkaru 
208795a618bdSEinar Rünkaru 		/* switch to internal mic input */
208895a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
208995a618bdSEinar Rünkaru 
209095a618bdSEinar Rünkaru 		/* disable external mic, port B */
209195a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
209295a618bdSEinar Rünkaru 		{}
209395a618bdSEinar Rünkaru 	};
209495a618bdSEinar Rünkaru 
209595a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
209695a618bdSEinar Rünkaru 	if (present) {
209795a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
209895a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
209995a618bdSEinar Rünkaru 	} else {
210095a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
210195a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
210295a618bdSEinar Rünkaru 	}
210395a618bdSEinar Rünkaru }
210495a618bdSEinar Rünkaru 
21050fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
21060fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
21070fb67e98SDaniel Drake {
21080fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
21090fb67e98SDaniel Drake 	unsigned int portA, portD;
21100fb67e98SDaniel Drake 
21110fb67e98SDaniel Drake 	/* Port A */
2112d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
21130fb67e98SDaniel Drake 
21140fb67e98SDaniel Drake 	/* Port D */
2115d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
21160fb67e98SDaniel Drake 
21170fb67e98SDaniel Drake 	spec->hp_present = !!(portA | portD);
21180fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
21190fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
21200fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
21210fb67e98SDaniel Drake }
21220fb67e98SDaniel Drake 
21230fb67e98SDaniel Drake /* unsolicited event for jack sensing */
2124*75f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
21250fb67e98SDaniel Drake {
21260fb67e98SDaniel Drake 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
21270fb67e98SDaniel Drake 	switch (res >> 26) {
21280fb67e98SDaniel Drake 	case CONEXANT_HP_EVENT:
21290fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
21300fb67e98SDaniel Drake 		break;
21310fb67e98SDaniel Drake 	case CONEXANT_MIC_EVENT:
2132*75f8991dSDaniel Drake 		cxt5066_olpc_automic(codec);
21330fb67e98SDaniel Drake 		break;
21340fb67e98SDaniel Drake 	}
21350fb67e98SDaniel Drake }
21360fb67e98SDaniel Drake 
213795a618bdSEinar Rünkaru /* unsolicited event for jack sensing */
213895a618bdSEinar Rünkaru static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
213995a618bdSEinar Rünkaru {
214095a618bdSEinar Rünkaru 	snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
214195a618bdSEinar Rünkaru 	switch (res >> 26) {
214295a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
214395a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
214495a618bdSEinar Rünkaru 		break;
214595a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
214695a618bdSEinar Rünkaru 		cxt5066_vostro_automic(codec);
214795a618bdSEinar Rünkaru 		break;
214895a618bdSEinar Rünkaru 	}
214995a618bdSEinar Rünkaru }
215095a618bdSEinar Rünkaru 
21510fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
21520fb67e98SDaniel Drake 	.num_items = 5,
21530fb67e98SDaniel Drake 	.items = {
21540fb67e98SDaniel Drake 		{ "0dB",  0 },
21550fb67e98SDaniel Drake 		{ "10dB", 1 },
21560fb67e98SDaniel Drake 		{ "20dB", 2 },
21570fb67e98SDaniel Drake 		{ "30dB", 3 },
21580fb67e98SDaniel Drake 		{ "40dB", 4 },
21590fb67e98SDaniel Drake 	},
21600fb67e98SDaniel Drake };
21610fb67e98SDaniel Drake 
21620fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
21630fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
21640fb67e98SDaniel Drake {
21650fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
21660fb67e98SDaniel Drake }
21670fb67e98SDaniel Drake 
21680fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
21690fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
21700fb67e98SDaniel Drake {
21710fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
21720fb67e98SDaniel Drake 	int val;
2173254bba6aSEinar Rünkaru 	hda_nid_t nid = kcontrol->private_value & 0xff;
2174254bba6aSEinar Rünkaru 	int inout = (kcontrol->private_value & 0x100) ?
2175254bba6aSEinar Rünkaru 		AC_AMP_GET_INPUT : AC_AMP_GET_OUTPUT;
21760fb67e98SDaniel Drake 
2177254bba6aSEinar Rünkaru 	val = snd_hda_codec_read(codec, nid, 0,
2178254bba6aSEinar Rünkaru 		AC_VERB_GET_AMP_GAIN_MUTE, inout);
21790fb67e98SDaniel Drake 
21800fb67e98SDaniel Drake 	ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
21810fb67e98SDaniel Drake 	return 0;
21820fb67e98SDaniel Drake }
21830fb67e98SDaniel Drake 
21840fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
21850fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
21860fb67e98SDaniel Drake {
21870fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
21880fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
21890fb67e98SDaniel Drake 	unsigned int idx;
2190254bba6aSEinar Rünkaru 	hda_nid_t nid = kcontrol->private_value & 0xff;
2191254bba6aSEinar Rünkaru 	int inout = (kcontrol->private_value & 0x100) ?
2192254bba6aSEinar Rünkaru 		AC_AMP_SET_INPUT : AC_AMP_SET_OUTPUT;
21930fb67e98SDaniel Drake 
21940fb67e98SDaniel Drake 	if (!imux->num_items)
21950fb67e98SDaniel Drake 		return 0;
21960fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
21970fb67e98SDaniel Drake 	if (idx >= imux->num_items)
21980fb67e98SDaniel Drake 		idx = imux->num_items - 1;
21990fb67e98SDaniel Drake 
2200254bba6aSEinar Rünkaru 	snd_hda_codec_write_cache(codec, nid, 0,
22010fb67e98SDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2202254bba6aSEinar Rünkaru 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | inout |
22030fb67e98SDaniel Drake 			imux->items[idx].index);
22040fb67e98SDaniel Drake 
22050fb67e98SDaniel Drake 	return 1;
22060fb67e98SDaniel Drake }
22070fb67e98SDaniel Drake 
2208*75f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2209*75f8991dSDaniel Drake {
2210*75f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2211*75f8991dSDaniel Drake 	/* mark as recording and configure the microphone widget so that the
2212*75f8991dSDaniel Drake 	 * recording LED comes on. */
2213*75f8991dSDaniel Drake 	spec->recording = 1;
2214*75f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
2215*75f8991dSDaniel Drake }
2216*75f8991dSDaniel Drake 
2217*75f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2218*75f8991dSDaniel Drake {
2219*75f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2220*75f8991dSDaniel Drake 	const struct hda_verb disable_mics[] = {
2221*75f8991dSDaniel Drake 		/* disable external mic, port B */
2222*75f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2223*75f8991dSDaniel Drake 
2224*75f8991dSDaniel Drake 		/* disble internal mic, port C */
2225*75f8991dSDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2226*75f8991dSDaniel Drake 		{},
2227*75f8991dSDaniel Drake 	};
2228*75f8991dSDaniel Drake 
2229*75f8991dSDaniel Drake 	snd_hda_sequence_write(codec, disable_mics);
2230*75f8991dSDaniel Drake 	spec->recording = 0;
2231*75f8991dSDaniel Drake }
2232*75f8991dSDaniel Drake 
22330fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = {
22340fb67e98SDaniel Drake 	.num_items = 4,
22350fb67e98SDaniel Drake 	.items = {
22360fb67e98SDaniel Drake 		{ "Mic B", 0 },
22370fb67e98SDaniel Drake 		{ "Mic C", 1 },
22380fb67e98SDaniel Drake 		{ "Mic E", 2 },
22390fb67e98SDaniel Drake 		{ "Mic F", 3 },
22400fb67e98SDaniel Drake 	},
22410fb67e98SDaniel Drake };
22420fb67e98SDaniel Drake 
22430fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
22440fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
22450fb67e98SDaniel Drake 	.values = {
22460fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
22470fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
22480fb67e98SDaniel Drake 		0
22490fb67e98SDaniel Drake 	},
22500fb67e98SDaniel Drake };
22510fb67e98SDaniel Drake 
22520fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
22530fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
22540fb67e98SDaniel Drake 	.values = {
22550fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
22560fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
22570fb67e98SDaniel Drake 		0
22580fb67e98SDaniel Drake 	},
22590fb67e98SDaniel Drake };
22600fb67e98SDaniel Drake 
22610fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = {
22620fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
22630fb67e98SDaniel Drake 	{}
22640fb67e98SDaniel Drake };
22650fb67e98SDaniel Drake 
22660fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
22670fb67e98SDaniel Drake 	{
22680fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
22690fb67e98SDaniel Drake 		.name = "Master Playback Volume",
22700fb67e98SDaniel Drake 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
22710fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
22720fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
22735e26dfd0SJaroslav Kysela 		.subdevice = HDA_SUBDEV_AMP_FLAG,
22740fb67e98SDaniel Drake 		.info = snd_hda_mixer_amp_volume_info,
22750fb67e98SDaniel Drake 		.get = snd_hda_mixer_amp_volume_get,
22760fb67e98SDaniel Drake 		.put = snd_hda_mixer_amp_volume_put,
22770fb67e98SDaniel Drake 		.tlv = { .c = snd_hda_mixer_amp_tlv },
22780fb67e98SDaniel Drake 		/* offset by 28 volume steps to limit minimum gain to -46dB */
22790fb67e98SDaniel Drake 		.private_value =
22800fb67e98SDaniel Drake 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
22810fb67e98SDaniel Drake 	},
22820fb67e98SDaniel Drake 	{}
22830fb67e98SDaniel Drake };
22840fb67e98SDaniel Drake 
22850fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = {
22860fb67e98SDaniel Drake 	{
22870fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
22880fb67e98SDaniel Drake 		.name = "Master Playback Switch",
22890fb67e98SDaniel Drake 		.info = cxt_eapd_info,
22900fb67e98SDaniel Drake 		.get = cxt_eapd_get,
22910fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
22920fb67e98SDaniel Drake 		.private_value = 0x1d,
22930fb67e98SDaniel Drake 	},
22940fb67e98SDaniel Drake 
22950fb67e98SDaniel Drake 	{
22960fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2297254bba6aSEinar Rünkaru 		.name = "Ext Mic Boost Capture Enum",
22980fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
22990fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
23000fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
2301254bba6aSEinar Rünkaru 		.private_value = 0x17,
23020fb67e98SDaniel Drake 	},
23030fb67e98SDaniel Drake 
23040fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
23050fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
23060fb67e98SDaniel Drake 	{}
23070fb67e98SDaniel Drake };
23080fb67e98SDaniel Drake 
2309254bba6aSEinar Rünkaru static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2310254bba6aSEinar Rünkaru 	{
2311254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2312254bba6aSEinar Rünkaru 		.name = "Int Mic Boost Capture Enum",
2313254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2314254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2315254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2316254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2317254bba6aSEinar Rünkaru 	},
2318c0f8faf0SEinar Rünkaru 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
2319254bba6aSEinar Rünkaru 	{}
2320254bba6aSEinar Rünkaru };
2321254bba6aSEinar Rünkaru 
23220fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = {
23230fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
23240fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
23250fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
23260fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
23270fb67e98SDaniel Drake 
23280fb67e98SDaniel Drake 	/* Speakers  */
23290fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
23300fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
23310fb67e98SDaniel Drake 
23320fb67e98SDaniel Drake 	/* HP, Amp  */
23330fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
23340fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
23350fb67e98SDaniel Drake 
23360fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
23370fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
23380fb67e98SDaniel Drake 
23390fb67e98SDaniel Drake 	/* DAC1 */
23400fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
23410fb67e98SDaniel Drake 
23420fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
23430fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
23440fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
23450fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
23460fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
23470fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
23480fb67e98SDaniel Drake 
23490fb67e98SDaniel Drake 	/* no digital microphone support yet */
23500fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23510fb67e98SDaniel Drake 
23520fb67e98SDaniel Drake 	/* Audio input selector */
23530fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
23540fb67e98SDaniel Drake 
23550fb67e98SDaniel Drake 	/* SPDIF route: PCM */
23560fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
23570fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
23580fb67e98SDaniel Drake 
23590fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
23600fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
23610fb67e98SDaniel Drake 
23620fb67e98SDaniel Drake 	/* EAPD */
23630fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
23640fb67e98SDaniel Drake 
23650fb67e98SDaniel Drake 	/* not handling these yet */
23660fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23670fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23680fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23690fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23700fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23710fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23720fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23730fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23740fb67e98SDaniel Drake 	{ } /* end */
23750fb67e98SDaniel Drake };
23760fb67e98SDaniel Drake 
23770fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = {
23780fb67e98SDaniel Drake 	/* Port A: headphones */
23790fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
23800fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
23810fb67e98SDaniel Drake 
23820fb67e98SDaniel Drake 	/* Port B: external microphone */
2383*75f8991dSDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23840fb67e98SDaniel Drake 
23850fb67e98SDaniel Drake 	/* Port C: internal microphone */
2386*75f8991dSDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23870fb67e98SDaniel Drake 
23880fb67e98SDaniel Drake 	/* Port D: unused */
23890fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23900fb67e98SDaniel Drake 
23910fb67e98SDaniel Drake 	/* Port E: unused, but has primary EAPD */
23920fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23930fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
23940fb67e98SDaniel Drake 
23950fb67e98SDaniel Drake 	/* Port F: unused */
23960fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23970fb67e98SDaniel Drake 
23980fb67e98SDaniel Drake 	/* Port G: internal speakers */
23990fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
24000fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
24010fb67e98SDaniel Drake 
24020fb67e98SDaniel Drake 	/* DAC1 */
24030fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
24040fb67e98SDaniel Drake 
24050fb67e98SDaniel Drake 	/* DAC2: unused */
24060fb67e98SDaniel Drake 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
24070fb67e98SDaniel Drake 
24080fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
24090fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
24100fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
24110fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
24120fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
24130fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
24140fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
24150fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
24160fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
24170fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
24180fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
24190fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
24200fb67e98SDaniel Drake 
24210fb67e98SDaniel Drake 	/* Disable digital microphone port */
24220fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
24230fb67e98SDaniel Drake 
24240fb67e98SDaniel Drake 	/* Audio input selectors */
24250fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
24260fb67e98SDaniel Drake 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
24270fb67e98SDaniel Drake 
24280fb67e98SDaniel Drake 	/* Disable SPDIF */
24290fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
24300fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
24310fb67e98SDaniel Drake 
24320fb67e98SDaniel Drake 	/* enable unsolicited events for Port A and B */
24330fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
24340fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
24350fb67e98SDaniel Drake 	{ } /* end */
24360fb67e98SDaniel Drake };
24370fb67e98SDaniel Drake 
243895a618bdSEinar Rünkaru static struct hda_verb cxt5066_init_verbs_vostro[] = {
243995a618bdSEinar Rünkaru 	/* Port A: headphones */
244095a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
244195a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
244295a618bdSEinar Rünkaru 
244395a618bdSEinar Rünkaru 	/* Port B: external microphone */
244495a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
244595a618bdSEinar Rünkaru 
244695a618bdSEinar Rünkaru 	/* Port C: unused */
244795a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
244895a618bdSEinar Rünkaru 
244995a618bdSEinar Rünkaru 	/* Port D: unused */
245095a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
245195a618bdSEinar Rünkaru 
245295a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
245395a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
245495a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
245595a618bdSEinar Rünkaru 
245695a618bdSEinar Rünkaru 	/* Port F: unused */
245795a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
245895a618bdSEinar Rünkaru 
245995a618bdSEinar Rünkaru 	/* Port G: internal speakers */
246095a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
246195a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
246295a618bdSEinar Rünkaru 
246395a618bdSEinar Rünkaru 	/* DAC1 */
246495a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
246595a618bdSEinar Rünkaru 
246695a618bdSEinar Rünkaru 	/* DAC2: unused */
246795a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
246895a618bdSEinar Rünkaru 
246995a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
247095a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
247195a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
247295a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
247395a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
247495a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
247595a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
247695a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
247795a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
247895a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
247995a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
248095a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
248195a618bdSEinar Rünkaru 
248295a618bdSEinar Rünkaru 	/* Digital microphone port */
248395a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
248495a618bdSEinar Rünkaru 
248595a618bdSEinar Rünkaru 	/* Audio input selectors */
248695a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
248795a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
248895a618bdSEinar Rünkaru 
248995a618bdSEinar Rünkaru 	/* Disable SPDIF */
249095a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
249195a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
249295a618bdSEinar Rünkaru 
249395a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
249495a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
249595a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
249695a618bdSEinar Rünkaru 	{ } /* end */
249795a618bdSEinar Rünkaru };
249895a618bdSEinar Rünkaru 
24990fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
25000fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
25010fb67e98SDaniel Drake 	{ } /* end */
25020fb67e98SDaniel Drake };
25030fb67e98SDaniel Drake 
25040fb67e98SDaniel Drake /* initialize jack-sensing, too */
25050fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
25060fb67e98SDaniel Drake {
2507254bba6aSEinar Rünkaru 	struct conexant_spec *spec = codec->spec;
2508254bba6aSEinar Rünkaru 
25090fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
25100fb67e98SDaniel Drake 	conexant_init(codec);
25110fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
25120fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
2513254bba6aSEinar Rünkaru 		if (spec->dell_vostro)
2514254bba6aSEinar Rünkaru 			cxt5066_vostro_automic(codec);
25150fb67e98SDaniel Drake 	}
25160fb67e98SDaniel Drake 	return 0;
25170fb67e98SDaniel Drake }
25180fb67e98SDaniel Drake 
2519*75f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec)
2520*75f8991dSDaniel Drake {
2521*75f8991dSDaniel Drake 	snd_printdd("CXT5066: init\n");
2522*75f8991dSDaniel Drake 	conexant_init(codec);
2523*75f8991dSDaniel Drake 	cxt5066_hp_automute(codec);
2524*75f8991dSDaniel Drake 	cxt5066_olpc_automic(codec);
2525*75f8991dSDaniel Drake 	return 0;
2526*75f8991dSDaniel Drake }
2527*75f8991dSDaniel Drake 
25280fb67e98SDaniel Drake enum {
25290fb67e98SDaniel Drake 	CXT5066_LAPTOP,			/* Laptops w/ EAPD support */
25300fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
25310fb67e98SDaniel Drake 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
253295a618bdSEinar Rünkaru 	CXT5066_DELL_VOSTO,	/* Dell Vostro 1015i */
25330fb67e98SDaniel Drake 	CXT5066_MODELS
25340fb67e98SDaniel Drake };
25350fb67e98SDaniel Drake 
25360fb67e98SDaniel Drake static const char *cxt5066_models[CXT5066_MODELS] = {
25370fb67e98SDaniel Drake 	[CXT5066_LAPTOP]		= "laptop",
25380fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
25390fb67e98SDaniel Drake 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
254095a618bdSEinar Rünkaru 	[CXT5066_DELL_VOSTO]    = "dell-vostro"
25410fb67e98SDaniel Drake };
25420fb67e98SDaniel Drake 
25430fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
25440fb67e98SDaniel Drake 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
25450fb67e98SDaniel Drake 		      CXT5066_LAPTOP),
25460fb67e98SDaniel Drake 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
25470fb67e98SDaniel Drake 		      CXT5066_DELL_LAPTOP),
2548798a8a15SDaniel Drake 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
254995a618bdSEinar Rünkaru 	SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
25500fb67e98SDaniel Drake 	{}
25510fb67e98SDaniel Drake };
25520fb67e98SDaniel Drake 
25530fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
25540fb67e98SDaniel Drake {
25550fb67e98SDaniel Drake 	struct conexant_spec *spec;
25560fb67e98SDaniel Drake 	int board_config;
25570fb67e98SDaniel Drake 
25580fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
25590fb67e98SDaniel Drake 	if (!spec)
25600fb67e98SDaniel Drake 		return -ENOMEM;
25610fb67e98SDaniel Drake 	codec->spec = spec;
25620fb67e98SDaniel Drake 
25630fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
2564*75f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
25650fb67e98SDaniel Drake 
25660fb67e98SDaniel Drake 	spec->dell_automute = 0;
25670fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
25680fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
25690fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
25700fb67e98SDaniel Drake 	spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
25710fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
25720fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
25730fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
25740fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
25750fb67e98SDaniel Drake 
25760fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
25770fb67e98SDaniel Drake 
25780fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
25790fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
25800fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
25810fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
25820fb67e98SDaniel Drake 	spec->cur_adc = 0;
25830fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
25840fb67e98SDaniel Drake 
25850fb67e98SDaniel Drake 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
25860fb67e98SDaniel Drake 						  cxt5066_models, cxt5066_cfg_tbl);
25870fb67e98SDaniel Drake 	switch (board_config) {
25880fb67e98SDaniel Drake 	default:
25890fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
25900fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
25910fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
25920fb67e98SDaniel Drake 		break;
25930fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
25940fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
25950fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
25960fb67e98SDaniel Drake 
25970fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
25980fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
25990fb67e98SDaniel Drake 		spec->num_init_verbs++;
26000fb67e98SDaniel Drake 		spec->dell_automute = 1;
26010fb67e98SDaniel Drake 		break;
26020fb67e98SDaniel Drake 	case CXT5066_OLPC_XO_1_5:
2603*75f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_olpc_init;
2604*75f8991dSDaniel Drake 		codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
26050fb67e98SDaniel Drake 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
26060fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
26070fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
26080fb67e98SDaniel Drake 		spec->port_d_mode = 0;
26090fb67e98SDaniel Drake 
26100fb67e98SDaniel Drake 		/* no S/PDIF out */
26110fb67e98SDaniel Drake 		spec->multiout.dig_out_nid = 0;
26120fb67e98SDaniel Drake 
26130fb67e98SDaniel Drake 		/* input source automatically selected */
26140fb67e98SDaniel Drake 		spec->input_mux = NULL;
2615*75f8991dSDaniel Drake 
2616*75f8991dSDaniel Drake 		/* our capture hooks which allow us to turn on the microphone LED
2617*75f8991dSDaniel Drake 		 * at the right time */
2618*75f8991dSDaniel Drake 		spec->capture_prepare = cxt5066_olpc_capture_prepare;
2619*75f8991dSDaniel Drake 		spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
26200fb67e98SDaniel Drake 		break;
262195a618bdSEinar Rünkaru 	case CXT5066_DELL_VOSTO:
2622*75f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
262395a618bdSEinar Rünkaru 		codec->patch_ops.unsol_event = cxt5066_vostro_event;
262495a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
262595a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
262695a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2627254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
262895a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
2629254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
2630c0f8faf0SEinar Rünkaru 		snd_hda_attach_beep_device(codec, 0x13);
263195a618bdSEinar Rünkaru 
263295a618bdSEinar Rünkaru 		/* no S/PDIF out */
263395a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
263495a618bdSEinar Rünkaru 
263595a618bdSEinar Rünkaru 		/* input source automatically selected */
263695a618bdSEinar Rünkaru 		spec->input_mux = NULL;
263795a618bdSEinar Rünkaru 		break;
26380fb67e98SDaniel Drake 	}
26390fb67e98SDaniel Drake 
26400fb67e98SDaniel Drake 	return 0;
26410fb67e98SDaniel Drake }
2642461e2c78STakashi Iwai 
2643461e2c78STakashi Iwai /*
2644461e2c78STakashi Iwai  */
2645461e2c78STakashi Iwai 
26461289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = {
264782f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
264882f30040STobin Davis 	  .patch = patch_cxt5045 },
264982f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
265082f30040STobin Davis 	  .patch = patch_cxt5047 },
2651461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
2652461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
26530fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
26540fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
265595a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
265695a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
2657c9b443d4STobin Davis 	{} /* terminator */
2658c9b443d4STobin Davis };
26591289e9e8STakashi Iwai 
26601289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
26611289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
26621289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
26630fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
266495a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
26651289e9e8STakashi Iwai 
26661289e9e8STakashi Iwai MODULE_LICENSE("GPL");
26671289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
26681289e9e8STakashi Iwai 
26691289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
26701289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
26711289e9e8STakashi Iwai 	.owner = THIS_MODULE,
26721289e9e8STakashi Iwai };
26731289e9e8STakashi Iwai 
26741289e9e8STakashi Iwai static int __init patch_conexant_init(void)
26751289e9e8STakashi Iwai {
26761289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
26771289e9e8STakashi Iwai }
26781289e9e8STakashi Iwai 
26791289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
26801289e9e8STakashi Iwai {
26811289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
26821289e9e8STakashi Iwai }
26831289e9e8STakashi Iwai 
26841289e9e8STakashi Iwai module_init(patch_conexant_init)
26851289e9e8STakashi Iwai module_exit(patch_conexant_exit)
2686