xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision ebbd224c22a00dbbee95031a0d6d595460f6f2b3)
1c9b443d4STobin Davis /*
2c9b443d4STobin Davis  * HD audio interface patch for Conexant HDA audio codec
3c9b443d4STobin Davis  *
4c9b443d4STobin Davis  * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5c9b443d4STobin Davis  * 		      Takashi Iwai <tiwai@suse.de>
6c9b443d4STobin Davis  * 		      Tobin Davis  <tdavis@dsl-only.net>
7c9b443d4STobin Davis  *
8c9b443d4STobin Davis  *  This driver is free software; you can redistribute it and/or modify
9c9b443d4STobin Davis  *  it under the terms of the GNU General Public License as published by
10c9b443d4STobin Davis  *  the Free Software Foundation; either version 2 of the License, or
11c9b443d4STobin Davis  *  (at your option) any later version.
12c9b443d4STobin Davis  *
13c9b443d4STobin Davis  *  This driver is distributed in the hope that it will be useful,
14c9b443d4STobin Davis  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15c9b443d4STobin Davis  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c9b443d4STobin Davis  *  GNU General Public License for more details.
17c9b443d4STobin Davis  *
18c9b443d4STobin Davis  *  You should have received a copy of the GNU General Public License
19c9b443d4STobin Davis  *  along with this program; if not, write to the Free Software
20c9b443d4STobin Davis  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21c9b443d4STobin Davis  */
22c9b443d4STobin Davis 
23c9b443d4STobin Davis #include <linux/init.h>
24c9b443d4STobin Davis #include <linux/delay.h>
25c9b443d4STobin Davis #include <linux/slab.h>
26c9b443d4STobin Davis #include <linux/pci.h>
27c9b443d4STobin Davis #include <sound/core.h>
28bc7a166dSUlrich Dangel #include <sound/jack.h>
29bc7a166dSUlrich Dangel 
30c9b443d4STobin Davis #include "hda_codec.h"
31c9b443d4STobin Davis #include "hda_local.h"
32c0f8faf0SEinar Rünkaru #include "hda_beep.h"
33c9b443d4STobin Davis 
34c9b443d4STobin Davis #define CXT_PIN_DIR_IN              0x00
35c9b443d4STobin Davis #define CXT_PIN_DIR_OUT             0x01
36c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT           0x02
37c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
38c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39c9b443d4STobin Davis 
40c9b443d4STobin Davis #define CONEXANT_HP_EVENT	0x37
41c9b443d4STobin Davis #define CONEXANT_MIC_EVENT	0x38
42c9b443d4STobin Davis 
43bc7a166dSUlrich Dangel /* Conexant 5051 specific */
44c9b443d4STobin Davis 
45ecda0cffSTakashi Iwai #define CXT5051_SPDIF_OUT	0x12
46bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT	0x38
47bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT	0x39
48bc7a166dSUlrich Dangel 
49faddaa5dSTakashi Iwai #define AUTO_MIC_PORTB		(1 << 1)
50faddaa5dSTakashi Iwai #define AUTO_MIC_PORTC		(1 << 2)
51bc7a166dSUlrich Dangel 
52bc7a166dSUlrich Dangel struct conexant_jack {
53bc7a166dSUlrich Dangel 
54bc7a166dSUlrich Dangel 	hda_nid_t nid;
55bc7a166dSUlrich Dangel 	int type;
56bc7a166dSUlrich Dangel 	struct snd_jack *jack;
57bc7a166dSUlrich Dangel 
58bc7a166dSUlrich Dangel };
59c9b443d4STobin Davis 
60f2e5731dSTakashi Iwai struct pin_dac_pair {
61f2e5731dSTakashi Iwai 	hda_nid_t pin;
62f2e5731dSTakashi Iwai 	hda_nid_t dac;
63f2e5731dSTakashi Iwai 	int type;
64f2e5731dSTakashi Iwai };
65f2e5731dSTakashi Iwai 
66c9b443d4STobin Davis struct conexant_spec {
67c9b443d4STobin Davis 
68c9b443d4STobin Davis 	struct snd_kcontrol_new *mixers[5];
69c9b443d4STobin Davis 	int num_mixers;
70dd5746a8STakashi Iwai 	hda_nid_t vmaster_nid;
71c9b443d4STobin Davis 
72c9b443d4STobin Davis 	const struct hda_verb *init_verbs[5];	/* initialization verbs
73c9b443d4STobin Davis 						 * don't forget NULL
74c9b443d4STobin Davis 						 * termination!
75c9b443d4STobin Davis 						 */
76c9b443d4STobin Davis 	unsigned int num_init_verbs;
77c9b443d4STobin Davis 
78c9b443d4STobin Davis 	/* playback */
79c9b443d4STobin Davis 	struct hda_multi_out multiout;	/* playback set-up
80c9b443d4STobin Davis 					 * max_channels, dacs must be set
81c9b443d4STobin Davis 					 * dig_out_nid and hp_nid are optional
82c9b443d4STobin Davis 					 */
83c9b443d4STobin Davis 	unsigned int cur_eapd;
8482f30040STobin Davis 	unsigned int hp_present;
85faddaa5dSTakashi Iwai 	unsigned int auto_mic;
86f2e5731dSTakashi Iwai 	int auto_mic_ext;		/* autocfg.inputs[] index for ext mic */
87c9b443d4STobin Davis 	unsigned int need_dac_fix;
88f6a2491cSAndy Robinson 	hda_nid_t slave_dig_outs[2];
89c9b443d4STobin Davis 
90c9b443d4STobin Davis 	/* capture */
91c9b443d4STobin Davis 	unsigned int num_adc_nids;
92c9b443d4STobin Davis 	hda_nid_t *adc_nids;
93c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
94c9b443d4STobin Davis 
95461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
96461e2c78STakashi Iwai 	hda_nid_t cur_adc;
97461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
98461e2c78STakashi Iwai 	unsigned int cur_adc_format;
99461e2c78STakashi Iwai 
100c9b443d4STobin Davis 	/* capture source */
101c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
102c9b443d4STobin Davis 	hda_nid_t *capsrc_nids;
103c9b443d4STobin Davis 	unsigned int cur_mux[3];
104c9b443d4STobin Davis 
105c9b443d4STobin Davis 	/* channel model */
106c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
107c9b443d4STobin Davis 	int num_channel_mode;
108c9b443d4STobin Davis 
109c9b443d4STobin Davis 	/* PCM information */
110c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
111c9b443d4STobin Davis 
112c9b443d4STobin Davis 	unsigned int spdif_route;
113c9b443d4STobin Davis 
114bc7a166dSUlrich Dangel 	/* jack detection */
115bc7a166dSUlrich Dangel 	struct snd_array jacks;
116bc7a166dSUlrich Dangel 
117c9b443d4STobin Davis 	/* dynamic controls, init_verbs and input_mux */
118c9b443d4STobin Davis 	struct auto_pin_cfg autocfg;
119c9b443d4STobin Davis 	struct hda_input_mux private_imux;
12041923e44STakashi Iwai 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
121f2e5731dSTakashi Iwai 	struct pin_dac_pair dac_info[8];
122f2e5731dSTakashi Iwai 	int dac_info_filled;
123c9b443d4STobin Davis 
1240fb67e98SDaniel Drake 	unsigned int port_d_mode;
125f2e5731dSTakashi Iwai 	unsigned int auto_mute:1;	/* used in auto-parser */
126f2e5731dSTakashi Iwai 	unsigned int dell_automute:1;
127cfd3d8dcSGreg Alexander 	unsigned int dell_vostro:1;
128cfd3d8dcSGreg Alexander 	unsigned int ideapad:1;
1297b2bfdbcSJens Taprogge 	unsigned int thinkpad:1;
130048e78a5SDavid Henningsson 	unsigned int hp_laptop:1;
131a1d6906eSDavid Henningsson 	unsigned int asus:1;
13275f8991dSDaniel Drake 
13375f8991dSDaniel Drake 	unsigned int ext_mic_present;
13475f8991dSDaniel Drake 	unsigned int recording;
13575f8991dSDaniel Drake 	void (*capture_prepare)(struct hda_codec *codec);
13675f8991dSDaniel Drake 	void (*capture_cleanup)(struct hda_codec *codec);
137c4cfe66cSDaniel Drake 
138c4cfe66cSDaniel Drake 	/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
139c4cfe66cSDaniel Drake 	 * through the microphone jack.
140c4cfe66cSDaniel Drake 	 * When the user enables this through a mixer switch, both internal and
141c4cfe66cSDaniel Drake 	 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
142c4cfe66cSDaniel Drake 	 * we also allow the bias to be configured through a separate mixer
143c4cfe66cSDaniel Drake 	 * control. */
144c4cfe66cSDaniel Drake 	unsigned int dc_enable;
145c4cfe66cSDaniel Drake 	unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
146c4cfe66cSDaniel Drake 	unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
1473507e2a8STakashi Iwai 
1483507e2a8STakashi Iwai 	unsigned int beep_amp;
149c9b443d4STobin Davis };
150c9b443d4STobin Davis 
151c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
152c9b443d4STobin Davis 				      struct hda_codec *codec,
153c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
154c9b443d4STobin Davis {
155c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1569a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1579a08160bSTakashi Iwai 					     hinfo);
158c9b443d4STobin Davis }
159c9b443d4STobin Davis 
160c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
161c9b443d4STobin Davis 					 struct hda_codec *codec,
162c9b443d4STobin Davis 					 unsigned int stream_tag,
163c9b443d4STobin Davis 					 unsigned int format,
164c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
165c9b443d4STobin Davis {
166c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
167c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
168c9b443d4STobin Davis 						stream_tag,
169c9b443d4STobin Davis 						format, substream);
170c9b443d4STobin Davis }
171c9b443d4STobin Davis 
172c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
173c9b443d4STobin Davis 					 struct hda_codec *codec,
174c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
175c9b443d4STobin Davis {
176c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
177c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
178c9b443d4STobin Davis }
179c9b443d4STobin Davis 
180c9b443d4STobin Davis /*
181c9b443d4STobin Davis  * Digital out
182c9b443d4STobin Davis  */
183c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
184c9b443d4STobin Davis 					  struct hda_codec *codec,
185c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
186c9b443d4STobin Davis {
187c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
188c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
189c9b443d4STobin Davis }
190c9b443d4STobin Davis 
191c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
192c9b443d4STobin Davis 					 struct hda_codec *codec,
193c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
194c9b443d4STobin Davis {
195c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
196c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
197c9b443d4STobin Davis }
198c9b443d4STobin Davis 
1996b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2006b97eb45STakashi Iwai 					 struct hda_codec *codec,
2016b97eb45STakashi Iwai 					 unsigned int stream_tag,
2026b97eb45STakashi Iwai 					 unsigned int format,
2036b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
2046b97eb45STakashi Iwai {
2056b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
2066b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2076b97eb45STakashi Iwai 					     stream_tag,
2086b97eb45STakashi Iwai 					     format, substream);
2096b97eb45STakashi Iwai }
2106b97eb45STakashi Iwai 
211c9b443d4STobin Davis /*
212c9b443d4STobin Davis  * Analog capture
213c9b443d4STobin Davis  */
214c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
215c9b443d4STobin Davis 				      struct hda_codec *codec,
216c9b443d4STobin Davis 				      unsigned int stream_tag,
217c9b443d4STobin Davis 				      unsigned int format,
218c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
219c9b443d4STobin Davis {
220c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
22175f8991dSDaniel Drake 	if (spec->capture_prepare)
22275f8991dSDaniel Drake 		spec->capture_prepare(codec);
223c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
224c9b443d4STobin Davis 				   stream_tag, 0, format);
225c9b443d4STobin Davis 	return 0;
226c9b443d4STobin Davis }
227c9b443d4STobin Davis 
228c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
229c9b443d4STobin Davis 				      struct hda_codec *codec,
230c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
231c9b443d4STobin Davis {
232c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
233888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
23475f8991dSDaniel Drake 	if (spec->capture_cleanup)
23575f8991dSDaniel Drake 		spec->capture_cleanup(codec);
236c9b443d4STobin Davis 	return 0;
237c9b443d4STobin Davis }
238c9b443d4STobin Davis 
239c9b443d4STobin Davis 
240c9b443d4STobin Davis 
241c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = {
242c9b443d4STobin Davis 	.substreams = 1,
243c9b443d4STobin Davis 	.channels_min = 2,
244c9b443d4STobin Davis 	.channels_max = 2,
245c9b443d4STobin Davis 	.nid = 0, /* fill later */
246c9b443d4STobin Davis 	.ops = {
247c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
248c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
249c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
250c9b443d4STobin Davis 	},
251c9b443d4STobin Davis };
252c9b443d4STobin Davis 
253c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = {
254c9b443d4STobin Davis 	.substreams = 1,
255c9b443d4STobin Davis 	.channels_min = 2,
256c9b443d4STobin Davis 	.channels_max = 2,
257c9b443d4STobin Davis 	.nid = 0, /* fill later */
258c9b443d4STobin Davis 	.ops = {
259c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
260c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
261c9b443d4STobin Davis 	},
262c9b443d4STobin Davis };
263c9b443d4STobin Davis 
264c9b443d4STobin Davis 
265c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = {
266c9b443d4STobin Davis 	.substreams = 1,
267c9b443d4STobin Davis 	.channels_min = 2,
268c9b443d4STobin Davis 	.channels_max = 2,
269c9b443d4STobin Davis 	.nid = 0, /* fill later */
270c9b443d4STobin Davis 	.ops = {
271c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2726b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2736b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
274c9b443d4STobin Davis 	},
275c9b443d4STobin Davis };
276c9b443d4STobin Davis 
277c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = {
278c9b443d4STobin Davis 	.substreams = 1,
279c9b443d4STobin Davis 	.channels_min = 2,
280c9b443d4STobin Davis 	.channels_max = 2,
281c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
282c9b443d4STobin Davis };
283c9b443d4STobin Davis 
284461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
285461e2c78STakashi Iwai 				      struct hda_codec *codec,
286461e2c78STakashi Iwai 				      unsigned int stream_tag,
287461e2c78STakashi Iwai 				      unsigned int format,
288461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
289461e2c78STakashi Iwai {
290461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
291461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
292461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
293461e2c78STakashi Iwai 	spec->cur_adc_format = format;
294461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
295461e2c78STakashi Iwai 	return 0;
296461e2c78STakashi Iwai }
297461e2c78STakashi Iwai 
298461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
299461e2c78STakashi Iwai 				      struct hda_codec *codec,
300461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
301461e2c78STakashi Iwai {
302461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
303888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
304461e2c78STakashi Iwai 	spec->cur_adc = 0;
305461e2c78STakashi Iwai 	return 0;
306461e2c78STakashi Iwai }
307461e2c78STakashi Iwai 
308461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = {
309461e2c78STakashi Iwai 	.substreams = 1,
310461e2c78STakashi Iwai 	.channels_min = 2,
311461e2c78STakashi Iwai 	.channels_max = 2,
312461e2c78STakashi Iwai 	.nid = 0, /* fill later */
313461e2c78STakashi Iwai 	.ops = {
314461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
315461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
316461e2c78STakashi Iwai 	},
317461e2c78STakashi Iwai };
318461e2c78STakashi Iwai 
319c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
320c9b443d4STobin Davis {
321c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
322c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
323c9b443d4STobin Davis 
324c9b443d4STobin Davis 	codec->num_pcms = 1;
325c9b443d4STobin Davis 	codec->pcm_info = info;
326c9b443d4STobin Davis 
327c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
328c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
329c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
330c9b443d4STobin Davis 		spec->multiout.max_channels;
331c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
332c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
333461e2c78STakashi Iwai 	if (codec->vendor_id == 0x14f15051)
334461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
335461e2c78STakashi Iwai 			cx5051_pcm_analog_capture;
336461e2c78STakashi Iwai 	else
337461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
338461e2c78STakashi Iwai 			conexant_pcm_analog_capture;
339c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
340c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
341c9b443d4STobin Davis 
342c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
343c9b443d4STobin Davis 		info++;
344c9b443d4STobin Davis 		codec->num_pcms++;
345c9b443d4STobin Davis 		info->name = "Conexant Digital";
3467ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
347c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
348c9b443d4STobin Davis 			conexant_pcm_digital_playback;
349c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
350c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
351c9b443d4STobin Davis 		if (spec->dig_in_nid) {
352c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
353c9b443d4STobin Davis 				conexant_pcm_digital_capture;
354c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
355c9b443d4STobin Davis 				spec->dig_in_nid;
356c9b443d4STobin Davis 		}
357f6a2491cSAndy Robinson 		if (spec->slave_dig_outs[0])
358f6a2491cSAndy Robinson 			codec->slave_dig_outs = spec->slave_dig_outs;
359c9b443d4STobin Davis 	}
360c9b443d4STobin Davis 
361c9b443d4STobin Davis 	return 0;
362c9b443d4STobin Davis }
363c9b443d4STobin Davis 
364c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
365c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
366c9b443d4STobin Davis {
367c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
368c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
369c9b443d4STobin Davis 
370c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
371c9b443d4STobin Davis }
372c9b443d4STobin Davis 
373c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
374c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
375c9b443d4STobin Davis {
376c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
378c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
379c9b443d4STobin Davis 
380c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
381c9b443d4STobin Davis 	return 0;
382c9b443d4STobin Davis }
383c9b443d4STobin Davis 
384c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
385c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
386c9b443d4STobin Davis {
387c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
388c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
389c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
390c9b443d4STobin Davis 
391c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
392c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
393c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
394c9b443d4STobin Davis }
395c9b443d4STobin Davis 
3968c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
39795c09099STakashi Iwai static void conexant_free_jack_priv(struct snd_jack *jack)
39895c09099STakashi Iwai {
39995c09099STakashi Iwai 	struct conexant_jack *jacks = jack->private_data;
40095c09099STakashi Iwai 	jacks->nid = 0;
40195c09099STakashi Iwai 	jacks->jack = NULL;
40295c09099STakashi Iwai }
40395c09099STakashi Iwai 
404bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec,
405bc7a166dSUlrich Dangel 		hda_nid_t nid, int type)
406bc7a166dSUlrich Dangel {
407bc7a166dSUlrich Dangel 	struct conexant_spec *spec;
408bc7a166dSUlrich Dangel 	struct conexant_jack *jack;
409bc7a166dSUlrich Dangel 	const char *name;
41070f7db11STakashi Iwai 	int i, err;
411bc7a166dSUlrich Dangel 
412bc7a166dSUlrich Dangel 	spec = codec->spec;
413bc7a166dSUlrich Dangel 	snd_array_init(&spec->jacks, sizeof(*jack), 32);
41470f7db11STakashi Iwai 
41570f7db11STakashi Iwai 	jack = spec->jacks.list;
41670f7db11STakashi Iwai 	for (i = 0; i < spec->jacks.used; i++, jack++)
41770f7db11STakashi Iwai 		if (jack->nid == nid)
41870f7db11STakashi Iwai 			return 0 ; /* already present */
41970f7db11STakashi Iwai 
420bc7a166dSUlrich Dangel 	jack = snd_array_new(&spec->jacks);
421bc7a166dSUlrich Dangel 	name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
422bc7a166dSUlrich Dangel 
423bc7a166dSUlrich Dangel 	if (!jack)
424bc7a166dSUlrich Dangel 		return -ENOMEM;
425bc7a166dSUlrich Dangel 
426bc7a166dSUlrich Dangel 	jack->nid = nid;
427bc7a166dSUlrich Dangel 	jack->type = type;
428bc7a166dSUlrich Dangel 
42995c09099STakashi Iwai 	err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
43095c09099STakashi Iwai 	if (err < 0)
43195c09099STakashi Iwai 		return err;
43295c09099STakashi Iwai 	jack->jack->private_data = jack;
43395c09099STakashi Iwai 	jack->jack->private_free = conexant_free_jack_priv;
43495c09099STakashi Iwai 	return 0;
435bc7a166dSUlrich Dangel }
436bc7a166dSUlrich Dangel 
437bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
438bc7a166dSUlrich Dangel {
439bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
440bc7a166dSUlrich Dangel 	struct conexant_jack *jacks = spec->jacks.list;
441bc7a166dSUlrich Dangel 
442bc7a166dSUlrich Dangel 	if (jacks) {
443bc7a166dSUlrich Dangel 		int i;
444bc7a166dSUlrich Dangel 		for (i = 0; i < spec->jacks.used; i++) {
445bc7a166dSUlrich Dangel 			if (jacks->nid == nid) {
446bc7a166dSUlrich Dangel 				unsigned int present;
447d56757abSTakashi Iwai 				present = snd_hda_jack_detect(codec, nid);
448bc7a166dSUlrich Dangel 
449bc7a166dSUlrich Dangel 				present = (present) ? jacks->type : 0 ;
450bc7a166dSUlrich Dangel 
451bc7a166dSUlrich Dangel 				snd_jack_report(jacks->jack,
452bc7a166dSUlrich Dangel 						present);
453bc7a166dSUlrich Dangel 			}
454bc7a166dSUlrich Dangel 			jacks++;
455bc7a166dSUlrich Dangel 		}
456bc7a166dSUlrich Dangel 	}
457bc7a166dSUlrich Dangel }
458bc7a166dSUlrich Dangel 
459bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec)
460bc7a166dSUlrich Dangel {
461bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
462bc7a166dSUlrich Dangel 	int i;
463bc7a166dSUlrich Dangel 
464bc7a166dSUlrich Dangel 	for (i = 0; i < spec->num_init_verbs; i++) {
465bc7a166dSUlrich Dangel 		const struct hda_verb *hv;
466bc7a166dSUlrich Dangel 
467bc7a166dSUlrich Dangel 		hv = spec->init_verbs[i];
468bc7a166dSUlrich Dangel 		while (hv->nid) {
469bc7a166dSUlrich Dangel 			int err = 0;
470bc7a166dSUlrich Dangel 			switch (hv->param ^ AC_USRSP_EN) {
471bc7a166dSUlrich Dangel 			case CONEXANT_HP_EVENT:
472bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
473bc7a166dSUlrich Dangel 						SND_JACK_HEADPHONE);
474bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
475bc7a166dSUlrich Dangel 				break;
476bc7a166dSUlrich Dangel 			case CXT5051_PORTC_EVENT:
477bc7a166dSUlrich Dangel 			case CONEXANT_MIC_EVENT:
478bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
479bc7a166dSUlrich Dangel 						SND_JACK_MICROPHONE);
480bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
481bc7a166dSUlrich Dangel 				break;
482bc7a166dSUlrich Dangel 			}
483bc7a166dSUlrich Dangel 			if (err < 0)
484bc7a166dSUlrich Dangel 				return err;
485bc7a166dSUlrich Dangel 			++hv;
486bc7a166dSUlrich Dangel 		}
487bc7a166dSUlrich Dangel 	}
488bc7a166dSUlrich Dangel 	return 0;
489bc7a166dSUlrich Dangel 
490bc7a166dSUlrich Dangel }
4915801f992STakashi Iwai #else
4925801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
4935801f992STakashi Iwai {
4945801f992STakashi Iwai }
4955801f992STakashi Iwai 
4965801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec)
4975801f992STakashi Iwai {
4985801f992STakashi Iwai 	return 0;
4995801f992STakashi Iwai }
5005801f992STakashi Iwai #endif
501bc7a166dSUlrich Dangel 
502c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
503c9b443d4STobin Davis {
504c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
505c9b443d4STobin Davis 	int i;
506c9b443d4STobin Davis 
507c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
508c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
509c9b443d4STobin Davis 	return 0;
510c9b443d4STobin Davis }
511c9b443d4STobin Davis 
512c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
513c9b443d4STobin Davis {
5148c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
515bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
516bc7a166dSUlrich Dangel 	if (spec->jacks.list) {
517bc7a166dSUlrich Dangel 		struct conexant_jack *jacks = spec->jacks.list;
518bc7a166dSUlrich Dangel 		int i;
51995c09099STakashi Iwai 		for (i = 0; i < spec->jacks.used; i++, jacks++) {
52095c09099STakashi Iwai 			if (jacks->jack)
52195c09099STakashi Iwai 				snd_device_free(codec->bus->card, jacks->jack);
52295c09099STakashi Iwai 		}
523bc7a166dSUlrich Dangel 		snd_array_free(&spec->jacks);
524bc7a166dSUlrich Dangel 	}
525bc7a166dSUlrich Dangel #endif
526c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
527c9b443d4STobin Davis 	kfree(codec->spec);
528c9b443d4STobin Davis }
529c9b443d4STobin Davis 
530b880c74aSTakashi Iwai static struct snd_kcontrol_new cxt_capture_mixers[] = {
531b880c74aSTakashi Iwai 	{
532b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
533b880c74aSTakashi Iwai 		.name = "Capture Source",
534b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
535b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
536b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
537b880c74aSTakashi Iwai 	},
538b880c74aSTakashi Iwai 	{}
539b880c74aSTakashi Iwai };
540b880c74aSTakashi Iwai 
5413507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5423507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */
5433507e2a8STakashi Iwai static struct snd_kcontrol_new cxt_beep_mixer[] = {
5443507e2a8STakashi Iwai 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
5453507e2a8STakashi Iwai 	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
5463507e2a8STakashi Iwai 	{ } /* end */
5473507e2a8STakashi Iwai };
5483507e2a8STakashi Iwai #endif
5493507e2a8STakashi Iwai 
550ea734963STakashi Iwai static const char * const slave_vols[] = {
551dd5746a8STakashi Iwai 	"Headphone Playback Volume",
552dd5746a8STakashi Iwai 	"Speaker Playback Volume",
553dd5746a8STakashi Iwai 	NULL
554dd5746a8STakashi Iwai };
555dd5746a8STakashi Iwai 
556ea734963STakashi Iwai static const char * const slave_sws[] = {
557dd5746a8STakashi Iwai 	"Headphone Playback Switch",
558dd5746a8STakashi Iwai 	"Speaker Playback Switch",
559dd5746a8STakashi Iwai 	NULL
560dd5746a8STakashi Iwai };
561dd5746a8STakashi Iwai 
562c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
563c9b443d4STobin Davis {
564c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
565c9b443d4STobin Davis 	unsigned int i;
566c9b443d4STobin Davis 	int err;
567c9b443d4STobin Davis 
568c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
569c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
570c9b443d4STobin Davis 		if (err < 0)
571c9b443d4STobin Davis 			return err;
572c9b443d4STobin Davis 	}
573c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
574c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
575c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
576c9b443d4STobin Davis 		if (err < 0)
577c9b443d4STobin Davis 			return err;
5789a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
5799a08160bSTakashi Iwai 						    &spec->multiout);
5809a08160bSTakashi Iwai 		if (err < 0)
5819a08160bSTakashi Iwai 			return err;
5829a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
583c9b443d4STobin Davis 	}
584c9b443d4STobin Davis 	if (spec->dig_in_nid) {
585c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
586c9b443d4STobin Davis 		if (err < 0)
587c9b443d4STobin Davis 			return err;
588c9b443d4STobin Davis 	}
589dd5746a8STakashi Iwai 
590dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
591dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
592dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
593dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
594dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
595dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
596dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
597dd5746a8STakashi Iwai 					  vmaster_tlv, slave_vols);
598dd5746a8STakashi Iwai 		if (err < 0)
599dd5746a8STakashi Iwai 			return err;
600dd5746a8STakashi Iwai 	}
601dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
602dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
603dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
604dd5746a8STakashi Iwai 					  NULL, slave_sws);
605dd5746a8STakashi Iwai 		if (err < 0)
606dd5746a8STakashi Iwai 			return err;
607dd5746a8STakashi Iwai 	}
608dd5746a8STakashi Iwai 
609b880c74aSTakashi Iwai 	if (spec->input_mux) {
610b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
611b880c74aSTakashi Iwai 		if (err < 0)
612b880c74aSTakashi Iwai 			return err;
613b880c74aSTakashi Iwai 	}
614b880c74aSTakashi Iwai 
6153507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
6163507e2a8STakashi Iwai 	/* create beep controls if needed */
6173507e2a8STakashi Iwai 	if (spec->beep_amp) {
6183507e2a8STakashi Iwai 		struct snd_kcontrol_new *knew;
6193507e2a8STakashi Iwai 		for (knew = cxt_beep_mixer; knew->name; knew++) {
6203507e2a8STakashi Iwai 			struct snd_kcontrol *kctl;
6213507e2a8STakashi Iwai 			kctl = snd_ctl_new1(knew, codec);
6223507e2a8STakashi Iwai 			if (!kctl)
6233507e2a8STakashi Iwai 				return -ENOMEM;
6243507e2a8STakashi Iwai 			kctl->private_value = spec->beep_amp;
6253507e2a8STakashi Iwai 			err = snd_hda_ctl_add(codec, 0, kctl);
6263507e2a8STakashi Iwai 			if (err < 0)
6273507e2a8STakashi Iwai 				return err;
6283507e2a8STakashi Iwai 		}
6293507e2a8STakashi Iwai 	}
6303507e2a8STakashi Iwai #endif
6313507e2a8STakashi Iwai 
632c9b443d4STobin Davis 	return 0;
633c9b443d4STobin Davis }
634c9b443d4STobin Davis 
635697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
636697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
637697c373eSTakashi Iwai {
638697c373eSTakashi Iwai 	snd_hda_shutup_pins(codec);
639697c373eSTakashi Iwai 	return 0;
640697c373eSTakashi Iwai }
641697c373eSTakashi Iwai #endif
642697c373eSTakashi Iwai 
643c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
644c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
645c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
646c9b443d4STobin Davis 	.init = conexant_init,
647c9b443d4STobin Davis 	.free = conexant_free,
648697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
649697c373eSTakashi Iwai 	.suspend = conexant_suspend,
650697c373eSTakashi Iwai #endif
651697c373eSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
652c9b443d4STobin Davis };
653c9b443d4STobin Davis 
6543507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
6553507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \
6563507e2a8STakashi Iwai 	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
6573507e2a8STakashi Iwai #else
6583507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */
6593507e2a8STakashi Iwai #endif
6603507e2a8STakashi Iwai 
661c9b443d4STobin Davis /*
662c9b443d4STobin Davis  * EAPD control
663c9b443d4STobin Davis  * the private value = nid | (invert << 8)
664c9b443d4STobin Davis  */
665c9b443d4STobin Davis 
666a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
667c9b443d4STobin Davis 
66882f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
669c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
670c9b443d4STobin Davis {
671c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
672c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
673c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
674c9b443d4STobin Davis 	if (invert)
675c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
676c9b443d4STobin Davis 	else
677c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
678c9b443d4STobin Davis 	return 0;
67982f30040STobin Davis 
680c9b443d4STobin Davis }
681c9b443d4STobin Davis 
68282f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
683c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
684c9b443d4STobin Davis {
685c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
686c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
687c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
688c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
689c9b443d4STobin Davis 	unsigned int eapd;
69082f30040STobin Davis 
69168ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
692c9b443d4STobin Davis 	if (invert)
693c9b443d4STobin Davis 		eapd = !eapd;
69482beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
695c9b443d4STobin Davis 		return 0;
69682f30040STobin Davis 
697c9b443d4STobin Davis 	spec->cur_eapd = eapd;
69882beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
699c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
700c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
701c9b443d4STobin Davis 	return 1;
702c9b443d4STobin Davis }
703c9b443d4STobin Davis 
70486d72bdfSTakashi Iwai /* controls for test mode */
70586d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
70686d72bdfSTakashi Iwai 
70782f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
70882f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
70982f30040STobin Davis 	  .info = cxt_eapd_info, \
71082f30040STobin Davis 	  .get = cxt_eapd_get, \
71182f30040STobin Davis 	  .put = cxt_eapd_put, \
71282f30040STobin Davis 	  .private_value = nid | (mask<<16) }
71382f30040STobin Davis 
71482f30040STobin Davis 
71582f30040STobin Davis 
716c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
717c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
718c9b443d4STobin Davis {
719c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
720c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
721c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
722c9b443d4STobin Davis 				    spec->num_channel_mode);
723c9b443d4STobin Davis }
724c9b443d4STobin Davis 
725c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
726c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
727c9b443d4STobin Davis {
728c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
729c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
730c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
731c9b443d4STobin Davis 				   spec->num_channel_mode,
732c9b443d4STobin Davis 				   spec->multiout.max_channels);
733c9b443d4STobin Davis }
734c9b443d4STobin Davis 
735c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
736c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
737c9b443d4STobin Davis {
738c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
739c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
740c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
741c9b443d4STobin Davis 				      spec->num_channel_mode,
742c9b443d4STobin Davis 				      &spec->multiout.max_channels);
743c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
744c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
745c9b443d4STobin Davis 	return err;
746c9b443d4STobin Davis }
747c9b443d4STobin Davis 
748c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
749c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
750c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
751c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
752c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
753c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
754c9b443d4STobin Davis 
75586d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
75686d72bdfSTakashi Iwai 
757c9b443d4STobin Davis /* Conexant 5045 specific */
758c9b443d4STobin Davis 
759c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
760c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
761c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
762cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
763c9b443d4STobin Davis 
7645cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
7655cd57529STobin Davis 	{ 2, NULL },
7665cd57529STobin Davis };
767c9b443d4STobin Davis 
768c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
769c9b443d4STobin Davis 	.num_items = 2,
770c9b443d4STobin Davis 	.items = {
77182f30040STobin Davis 		{ "IntMic", 0x1 },
772f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
773c9b443d4STobin Davis 	}
774c9b443d4STobin Davis };
775c9b443d4STobin Davis 
7765218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = {
77722e14130SLukasz Marcinowski 	.num_items = 5,
7785218c892SJiang Zhe 	.items = {
7795218c892SJiang Zhe 		{ "IntMic", 0x1 },
7805218c892SJiang Zhe 		{ "ExtMic", 0x2 },
7815218c892SJiang Zhe 		{ "LineIn", 0x3 },
78222e14130SLukasz Marcinowski 		{ "CD",     0x4 },
78322e14130SLukasz Marcinowski 		{ "Mixer",  0x0 },
7845218c892SJiang Zhe 	}
7855218c892SJiang Zhe };
7865218c892SJiang Zhe 
7872de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = {
7882de3c232SJiang zhe 	.num_items = 2,
7892de3c232SJiang zhe 	.items = {
7902de3c232SJiang zhe 		{ "ExtMic", 0x1 },
7912de3c232SJiang zhe 		{ "IntMic", 0x2 },
7922de3c232SJiang zhe 	}
7932de3c232SJiang zhe };
7942de3c232SJiang zhe 
795c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
796c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
797c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
798c9b443d4STobin Davis {
799c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
800c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
80182f30040STobin Davis 	unsigned int bits;
802c9b443d4STobin Davis 
80382f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
804c9b443d4STobin Davis 		return 0;
805c9b443d4STobin Davis 
80682f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
80782f30040STobin Davis 	 * the headphone jack
80882f30040STobin Davis 	 */
80947fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
81047fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
81147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
8127f29673bSTobin Davis 
81347fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
81447fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
81547fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
816c9b443d4STobin Davis 	return 1;
817c9b443d4STobin Davis }
818c9b443d4STobin Davis 
819c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
820cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
821cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
822cca3b371STakashi Iwai 	.values = {
823cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
824cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
825cca3b371STakashi Iwai 		0
826cca3b371STakashi Iwai 	},
827cca3b371STakashi Iwai };
828c9b443d4STobin Davis 
8297f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
8307f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
8317f29673bSTobin Davis {
8327f29673bSTobin Davis 	static struct hda_verb mic_jack_on[] = {
8337f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
8347f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
8357f29673bSTobin Davis 		{}
8367f29673bSTobin Davis 	};
8377f29673bSTobin Davis 	static struct hda_verb mic_jack_off[] = {
8387f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
8397f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
8407f29673bSTobin Davis 		{}
8417f29673bSTobin Davis 	};
8427f29673bSTobin Davis 	unsigned int present;
8437f29673bSTobin Davis 
844d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x12);
8457f29673bSTobin Davis 	if (present)
8467f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
8477f29673bSTobin Davis 	else
8487f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
8497f29673bSTobin Davis }
8507f29673bSTobin Davis 
851c9b443d4STobin Davis 
852c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
853c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
854c9b443d4STobin Davis {
85582f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
856dd87da1cSTobin Davis 	unsigned int bits;
857c9b443d4STobin Davis 
858d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
859dd87da1cSTobin Davis 
86047fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
86147fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
86247fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
863c9b443d4STobin Davis }
864c9b443d4STobin Davis 
865c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
866c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
867c9b443d4STobin Davis 				   unsigned int res)
868c9b443d4STobin Davis {
869c9b443d4STobin Davis 	res >>= 26;
870c9b443d4STobin Davis 	switch (res) {
871c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
872c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
873c9b443d4STobin Davis 		break;
8747f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
8757f29673bSTobin Davis 		cxt5045_hp_automic(codec);
8767f29673bSTobin Davis 		break;
8777f29673bSTobin Davis 
878c9b443d4STobin Davis 	}
879c9b443d4STobin Davis }
880c9b443d4STobin Davis 
881c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
88228c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
88328c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8848607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
8858607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
886c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
887c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
88828c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
88928c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8908607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
8918607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
892cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
893c9b443d4STobin Davis 	{
894c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
895c9b443d4STobin Davis 		.name = "Master Playback Switch",
89682f30040STobin Davis 		.info = cxt_eapd_info,
89782f30040STobin Davis 		.get = cxt_eapd_get,
898c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
89982f30040STobin Davis 		.private_value = 0x10,
900c9b443d4STobin Davis 	},
901c9b443d4STobin Davis 
902c9b443d4STobin Davis 	{}
903c9b443d4STobin Davis };
904c9b443d4STobin Davis 
9055218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
90622e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
90722e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
90822e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
90922e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
91022e14130SLukasz Marcinowski 
9115218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
9125218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
9135218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
9145218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
9155218c892SJiang Zhe 
91622e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
91722e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
91822e14130SLukasz Marcinowski 
9195218c892SJiang Zhe 	{}
9205218c892SJiang Zhe };
9215218c892SJiang Zhe 
9222de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
92328c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
92428c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
9258607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
9268607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
9272de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
9282de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
92928c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
93028c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
9318607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
9328607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
9332de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
9342de3c232SJiang zhe 	{
9352de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9362de3c232SJiang zhe 		.name = "Master Playback Switch",
9372de3c232SJiang zhe 		.info = cxt_eapd_info,
9382de3c232SJiang zhe 		.get = cxt_eapd_get,
9392de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
9402de3c232SJiang zhe 		.private_value = 0x10,
9412de3c232SJiang zhe 	},
9422de3c232SJiang zhe 
9432de3c232SJiang zhe 	{}
9442de3c232SJiang zhe };
9452de3c232SJiang zhe 
946c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
947c9b443d4STobin Davis 	/* Line in, Mic */
9484090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9497f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
950c9b443d4STobin Davis 	/* HP, Amp  */
951c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
952c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
95382f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
954c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
955c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
956c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
957c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
958c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
959c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
96028c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
9617f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
96282f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
963c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
964c9b443d4STobin Davis 	/* SPDIF route: PCM */
965cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
966c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
967c9b443d4STobin Davis 	/* EAPD */
96882f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
969c9b443d4STobin Davis 	{ } /* end */
970c9b443d4STobin Davis };
971c9b443d4STobin Davis 
9725218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = {
97328c4edb7SDavid Henningsson 	/* Internal Mic, Mic */
9745218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9755218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9765218c892SJiang Zhe 	/* Line In,HP, Amp  */
9775218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9785218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
9795218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9805218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
9815218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9825218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9835218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9845218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9855218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
98628c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
9875218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
9885218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
9895218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
9905218c892SJiang Zhe 	/* SPDIF route: PCM */
991cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9925218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
9935218c892SJiang Zhe 	/* EAPD */
9945218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
9955218c892SJiang Zhe 	{ } /* end */
9965218c892SJiang Zhe };
9977f29673bSTobin Davis 
9987f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
9997f29673bSTobin Davis 	/* pin sensing on HP jack */
10007f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1001d3091fadSTakashi Iwai 	{ } /* end */
10027f29673bSTobin Davis };
10037f29673bSTobin Davis 
10047f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
10057f29673bSTobin Davis 	/* pin sensing on HP jack */
10067f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1007d3091fadSTakashi Iwai 	{ } /* end */
10087f29673bSTobin Davis };
10097f29673bSTobin Davis 
1010c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1011c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1012c9b443d4STobin Davis  * configuration.
1013c9b443d4STobin Davis  */
1014c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
1015c9b443d4STobin Davis 	.num_items = 5,
1016c9b443d4STobin Davis 	.items = {
1017c9b443d4STobin Davis 		{ "MIXER", 0x0 },
1018c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
1019c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
1020c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
1021c9b443d4STobin Davis 		{ "CD pin", 0x4 },
1022c9b443d4STobin Davis         },
1023c9b443d4STobin Davis };
1024c9b443d4STobin Davis 
1025c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
1026c9b443d4STobin Davis 
1027c9b443d4STobin Davis 	/* Output controls */
1028c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1029c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
10307f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
10317f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
10327f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
10337f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1034c9b443d4STobin Davis 
1035c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1036c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
1037c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
1038c9b443d4STobin Davis 
103982f30040STobin Davis 	/* EAPD Switch Control */
104082f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
104182f30040STobin Davis 
1042c9b443d4STobin Davis 	/* Loopback mixer controls */
1043c9b443d4STobin Davis 
10447f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
10457f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
10467f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
10477f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
10487f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
10497f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
10507f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
10517f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
10527f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
10537f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
1054c9b443d4STobin Davis 	{
1055c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1056c9b443d4STobin Davis 		.name = "Input Source",
1057c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1058c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1059c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1060c9b443d4STobin Davis 	},
1061fb3409e7STobin Davis 	/* Audio input controls */
1062fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1063fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1064fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1065fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1066fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1067fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1068fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1069fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1070fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1071fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1072c9b443d4STobin Davis 	{ } /* end */
1073c9b443d4STobin Davis };
1074c9b443d4STobin Davis 
1075c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
10767f29673bSTobin Davis 	/* Set connections */
10777f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
10787f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
10797f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1080c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1081c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10827f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1083c9b443d4STobin Davis 
1084c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1085c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1086c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1087c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1088c9b443d4STobin Davis 	 * control.
1089c9b443d4STobin Davis 	 */
1090cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1091cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1092c9b443d4STobin Davis 
1093c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1094c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1095c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1096c9b443d4STobin Davis 
1097c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1098c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1099c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1100c9b443d4STobin Davis 	 * input/output buffers as needed.
1101c9b443d4STobin Davis 	 */
1102c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1103c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1104c9b443d4STobin Davis 
1105c9b443d4STobin Davis 	/* Mute capture amp left and right */
1106c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1107c9b443d4STobin Davis 
1108c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1109c9b443d4STobin Davis 	 * pin)
1110c9b443d4STobin Davis 	 */
1111c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
11127f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1113c9b443d4STobin Davis 
1114c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1115c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1116c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1117c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1118c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1119c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1120c9b443d4STobin Davis 
1121c9b443d4STobin Davis 	{ }
1122c9b443d4STobin Davis };
1123c9b443d4STobin Davis #endif
1124c9b443d4STobin Davis 
1125c9b443d4STobin Davis 
1126c9b443d4STobin Davis /* initialize jack-sensing, too */
1127c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
1128c9b443d4STobin Davis {
1129c9b443d4STobin Davis 	conexant_init(codec);
1130c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
1131c9b443d4STobin Davis 	return 0;
1132c9b443d4STobin Davis }
1133c9b443d4STobin Davis 
1134c9b443d4STobin Davis 
1135c9b443d4STobin Davis enum {
113615908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
113715908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
113815908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
11395218c892SJiang Zhe 	CXT5045_BENQ,
11402de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
1141c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1142c9b443d4STobin Davis 	CXT5045_TEST,
1143c9b443d4STobin Davis #endif
1144f5fcc13cSTakashi Iwai 	CXT5045_MODELS
1145c9b443d4STobin Davis };
1146c9b443d4STobin Davis 
1147ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = {
114815908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
114915908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
115015908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
11515218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
11522de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1153c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1154f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1155c9b443d4STobin Davis #endif
1156f5fcc13cSTakashi Iwai };
1157c9b443d4STobin Davis 
1158f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
11592de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1160dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1161dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPSENSE),
11626a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
11635218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
116415908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
116515908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
11669e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
11679e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
116815908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
116915908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
117015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1171dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1172dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
117315908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1174c9b443d4STobin Davis 	{}
1175c9b443d4STobin Davis };
1176c9b443d4STobin Davis 
1177c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1178c9b443d4STobin Davis {
1179c9b443d4STobin Davis 	struct conexant_spec *spec;
1180c9b443d4STobin Davis 	int board_config;
1181c9b443d4STobin Davis 
1182c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1183c9b443d4STobin Davis 	if (!spec)
1184c9b443d4STobin Davis 		return -ENOMEM;
1185c9b443d4STobin Davis 	codec->spec = spec;
11869421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1187c9b443d4STobin Davis 
1188c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1189c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1190c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1191c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1192c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1193c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1194c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1195c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1196c9b443d4STobin Davis 	spec->num_mixers = 1;
1197c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1198c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1199c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1200c9b443d4STobin Davis 	spec->spdif_route = 0;
12013507e2a8STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
12023507e2a8STakashi Iwai 	spec->channel_mode = cxt5045_modes;
12035cd57529STobin Davis 
12043507e2a8STakashi Iwai 	set_beep_amp(spec, 0x16, 0, 1);
1205c9b443d4STobin Davis 
1206c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1207c9b443d4STobin Davis 
1208f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1209f5fcc13cSTakashi Iwai 						  cxt5045_models,
1210f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
1211c9b443d4STobin Davis 	switch (board_config) {
121215908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
12137f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1214c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1215c9b443d4STobin Davis 		spec->num_init_verbs = 2;
12167f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
12177f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
12187f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
12197f29673bSTobin Davis 		break;
122015908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
122186376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
12227f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
12237f29673bSTobin Davis 		spec->num_init_verbs = 2;
12247f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1225c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1226c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1227c9b443d4STobin Davis 		break;
122815908c36SMarc Boucher 	default:
122915908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
123015908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
123115908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
123215908c36SMarc Boucher 		spec->num_init_verbs = 3;
123315908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
123415908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
123515908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
123615908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
123715908c36SMarc Boucher 		break;
12385218c892SJiang Zhe 	case CXT5045_BENQ:
12395218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
12405218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
12415218c892SJiang Zhe 		spec->num_init_verbs = 1;
12425218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
12435218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
12445218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
12455218c892SJiang Zhe 		spec->num_mixers = 2;
12465218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
12475218c892SJiang Zhe 		break;
12482de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
12492de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
12502de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
12512de3c232SJiang zhe 		spec->num_init_verbs = 2;
12522de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
12532de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
12542de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
12552de3c232SJiang zhe 		break;
1256c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1257c9b443d4STobin Davis 	case CXT5045_TEST:
1258c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1259c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1260c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
126115908c36SMarc Boucher 		break;
126215908c36SMarc Boucher 
1263c9b443d4STobin Davis #endif
1264c9b443d4STobin Davis 	}
126548ecb7e8STakashi Iwai 
1266031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1267031005f7STakashi Iwai 	case 0x103c:
12688f0f5ff6SDaniel T Chen 	case 0x1631:
12690b587fc4SDaniel T Chen 	case 0x1734:
12700ebf9e36SDaniel T Chen 	case 0x17aa:
12710ebf9e36SDaniel T Chen 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
12720ebf9e36SDaniel T Chen 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
12730ebf9e36SDaniel T Chen 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
127448ecb7e8STakashi Iwai 		 */
127548ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
127648ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
127748ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
127848ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
127948ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1280031005f7STakashi Iwai 		break;
1281031005f7STakashi Iwai 	}
128248ecb7e8STakashi Iwai 
12833507e2a8STakashi Iwai 	if (spec->beep_amp)
12843507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
12853507e2a8STakashi Iwai 
1286c9b443d4STobin Davis 	return 0;
1287c9b443d4STobin Davis }
1288c9b443d4STobin Davis 
1289c9b443d4STobin Davis 
1290c9b443d4STobin Davis /* Conexant 5047 specific */
129182f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1292c9b443d4STobin Davis 
12935b3a7440STakashi Iwai static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1294c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1295c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1296c9b443d4STobin Davis 
12975cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
12985cd57529STobin Davis 	{ 2, NULL },
12995cd57529STobin Davis };
1300c9b443d4STobin Davis 
130182f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
130282f30040STobin Davis 	.num_items = 2,
130382f30040STobin Davis 	.items = {
130482f30040STobin Davis 		{ "ExtMic", 0x2 },
130582f30040STobin Davis 		{ "Line-In", 0x1 },
1306c9b443d4STobin Davis 	}
1307c9b443d4STobin Davis };
1308c9b443d4STobin Davis 
1309c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1310c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1311c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1312c9b443d4STobin Davis {
1313c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1314c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
131582f30040STobin Davis 	unsigned int bits;
1316c9b443d4STobin Davis 
131782f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1318c9b443d4STobin Davis 		return 0;
1319c9b443d4STobin Davis 
132082f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
132182f30040STobin Davis 	 * the headphone jack
132282f30040STobin Davis 	 */
132347fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
13243b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
13253b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
13263b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
13273b7523fcSTakashi Iwai 	 */
13285d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
132947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
133047fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
133147fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
133247fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1333c9b443d4STobin Davis 	return 1;
1334c9b443d4STobin Davis }
1335c9b443d4STobin Davis 
1336c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1337c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1338c9b443d4STobin Davis {
133982f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1340dd87da1cSTobin Davis 	unsigned int bits;
1341c9b443d4STobin Davis 
1342d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1343dd87da1cSTobin Davis 
134447fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
13453b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13465d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
134747fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1348c9b443d4STobin Davis }
1349c9b443d4STobin Davis 
1350c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1351c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1352c9b443d4STobin Davis {
1353c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
13549f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13559f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1356c9b443d4STobin Davis 		{}
1357c9b443d4STobin Davis 	};
1358c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
13599f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13609f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1361c9b443d4STobin Davis 		{}
1362c9b443d4STobin Davis 	};
1363c9b443d4STobin Davis 	unsigned int present;
1364c9b443d4STobin Davis 
1365d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1366c9b443d4STobin Davis 	if (present)
1367c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1368c9b443d4STobin Davis 	else
1369c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1370c9b443d4STobin Davis }
1371c9b443d4STobin Davis 
1372c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1373c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1374c9b443d4STobin Davis 				  unsigned int res)
1375c9b443d4STobin Davis {
13769f113e0eSMarc Boucher 	switch (res >> 26) {
1377c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1378c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1379c9b443d4STobin Davis 		break;
1380c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1381c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1382c9b443d4STobin Davis 		break;
1383c9b443d4STobin Davis 	}
1384c9b443d4STobin Davis }
1385c9b443d4STobin Davis 
1386df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1387df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1388df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
13895f99f86aSDavid Henningsson 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1390c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1391c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1392c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1393c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
139482f30040STobin Davis 	{
139582f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
139682f30040STobin Davis 		.name = "Master Playback Switch",
139782f30040STobin Davis 		.info = cxt_eapd_info,
139882f30040STobin Davis 		.get = cxt_eapd_get,
1399c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1400c9b443d4STobin Davis 		.private_value = 0x13,
1401c9b443d4STobin Davis 	},
1402c9b443d4STobin Davis 
1403c9b443d4STobin Davis 	{}
1404c9b443d4STobin Davis };
1405c9b443d4STobin Davis 
1406df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
14073b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
14085d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1409df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1410df481e41STakashi Iwai 	{}
1411df481e41STakashi Iwai };
1412df481e41STakashi Iwai 
1413df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1414c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1415c9b443d4STobin Davis 	{ } /* end */
1416c9b443d4STobin Davis };
1417c9b443d4STobin Davis 
1418c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1419c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1420c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1421c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1422c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
14237f29673bSTobin Davis 	/* HP, Speaker  */
1424b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
14255b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
14265b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
14277f29673bSTobin Davis 	/* Record selector: Mic */
14287f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
14297f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
14307f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
14317f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1432c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1433c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1434c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1435c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1436c9b443d4STobin Davis 	/* SPDIF route: PCM */
1437c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
143882f30040STobin Davis 	/* Enable unsolicited events */
143982f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
144082f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1441c9b443d4STobin Davis 	{ } /* end */
1442c9b443d4STobin Davis };
1443c9b443d4STobin Davis 
1444c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1445c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
14463b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1447c9b443d4STobin Davis 	{}
1448c9b443d4STobin Davis };
1449c9b443d4STobin Davis 
1450c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1451c9b443d4STobin Davis  * configuration.
1452c9b443d4STobin Davis  */
1453c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1454c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
145582f30040STobin Davis 	.num_items = 4,
1456c9b443d4STobin Davis 	.items = {
145782f30040STobin Davis 		{ "LINE1 pin", 0x0 },
145882f30040STobin Davis 		{ "MIC1 pin", 0x1 },
145982f30040STobin Davis 		{ "MIC2 pin", 0x2 },
146082f30040STobin Davis 		{ "CD pin", 0x3 },
1461c9b443d4STobin Davis         },
1462c9b443d4STobin Davis };
1463c9b443d4STobin Davis 
1464c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1465c9b443d4STobin Davis 
1466c9b443d4STobin Davis 	/* Output only controls */
146782f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
146882f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
146982f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
147082f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1471c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1472c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1473c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1474c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
147582f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
147682f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
147782f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
147882f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1479c9b443d4STobin Davis 
1480c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1481c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1482c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1483c9b443d4STobin Davis 
148482f30040STobin Davis 	/* EAPD Switch Control */
148582f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
148682f30040STobin Davis 
1487c9b443d4STobin Davis 	/* Loopback mixer controls */
148882f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
148982f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
149082f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
149182f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
149282f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
149382f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
149482f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
149582f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1496c9b443d4STobin Davis 
149782f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
149882f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
149982f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
150082f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
150182f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
150282f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
150382f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
150482f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1505c9b443d4STobin Davis 	{
1506c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1507c9b443d4STobin Davis 		.name = "Input Source",
1508c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1509c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1510c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1511c9b443d4STobin Davis 	},
1512854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
15139f113e0eSMarc Boucher 
1514c9b443d4STobin Davis 	{ } /* end */
1515c9b443d4STobin Davis };
1516c9b443d4STobin Davis 
1517c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1518c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1519c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1520c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1521c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1522c9b443d4STobin Davis 
1523c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1524c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1525c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1526c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1527c9b443d4STobin Davis 	 * control.
1528c9b443d4STobin Davis 	 */
1529c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1530c9b443d4STobin Davis 
1531c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1532c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1533c9b443d4STobin Davis 	 */
1534c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1535c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1536c9b443d4STobin Davis 
1537c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1538c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1539c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1540c9b443d4STobin Davis 
1541c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1542c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1543c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1544c9b443d4STobin Davis 	 * input/output buffers as needed.
1545c9b443d4STobin Davis 	 */
1546c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1547c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1548c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1549c9b443d4STobin Davis 
1550c9b443d4STobin Davis 	/* Mute capture amp left and right */
1551c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1552c9b443d4STobin Davis 
1553c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1554c9b443d4STobin Davis 	 * pin)
1555c9b443d4STobin Davis 	 */
1556c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1557c9b443d4STobin Davis 
1558c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1559c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1560c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1561c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1562c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1563c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1564c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1565c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1566c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1567c9b443d4STobin Davis 
1568c9b443d4STobin Davis 	{ }
1569c9b443d4STobin Davis };
1570c9b443d4STobin Davis #endif
1571c9b443d4STobin Davis 
1572c9b443d4STobin Davis 
1573c9b443d4STobin Davis /* initialize jack-sensing, too */
1574c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1575c9b443d4STobin Davis {
1576c9b443d4STobin Davis 	conexant_init(codec);
1577c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1578c9b443d4STobin Davis 	return 0;
1579c9b443d4STobin Davis }
1580c9b443d4STobin Davis 
1581c9b443d4STobin Davis 
1582c9b443d4STobin Davis enum {
1583f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1584f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1585f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1586c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1587c9b443d4STobin Davis 	CXT5047_TEST,
1588c9b443d4STobin Davis #endif
1589f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1590c9b443d4STobin Davis };
1591c9b443d4STobin Davis 
1592ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = {
1593f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1594f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1595f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1596c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1597f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1598c9b443d4STobin Davis #endif
1599f5fcc13cSTakashi Iwai };
1600c9b443d4STobin Davis 
1601f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1602ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1603dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1604dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1605f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1606c9b443d4STobin Davis 	{}
1607c9b443d4STobin Davis };
1608c9b443d4STobin Davis 
1609c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1610c9b443d4STobin Davis {
1611c9b443d4STobin Davis 	struct conexant_spec *spec;
1612c9b443d4STobin Davis 	int board_config;
1613c9b443d4STobin Davis 
1614c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1615c9b443d4STobin Davis 	if (!spec)
1616c9b443d4STobin Davis 		return -ENOMEM;
1617c9b443d4STobin Davis 	codec->spec = spec;
16189421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1619c9b443d4STobin Davis 
1620c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1621c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1622c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1623c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1624c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1625c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1626c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1627c9b443d4STobin Davis 	spec->num_mixers = 1;
1628df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1629c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1630c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1631c9b443d4STobin Davis 	spec->spdif_route = 0;
16325cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
16335cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1634c9b443d4STobin Davis 
1635c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1636c9b443d4STobin Davis 
1637f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1638f5fcc13cSTakashi Iwai 						  cxt5047_models,
1639f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1640c9b443d4STobin Davis 	switch (board_config) {
1641c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1642df481e41STakashi Iwai 		spec->num_mixers = 2;
1643df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1644df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1645c9b443d4STobin Davis 		break;
1646c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1647df481e41STakashi Iwai 		spec->num_mixers = 2;
1648df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1649fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1650c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1651c9b443d4STobin Davis 		break;
1652c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
165382f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1654df481e41STakashi Iwai 		spec->num_mixers = 2;
1655df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1656c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1657c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1658fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1659c9b443d4STobin Davis 		break;
1660c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1661c9b443d4STobin Davis 	case CXT5047_TEST:
1662c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1663c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1664c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1665fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1666c9b443d4STobin Davis #endif
1667c9b443d4STobin Davis 	}
1668dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1669025f206cSDaniel T Chen 
1670025f206cSDaniel T Chen 	switch (codec->subsystem_id >> 16) {
1671025f206cSDaniel T Chen 	case 0x103c:
1672025f206cSDaniel T Chen 		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1673025f206cSDaniel T Chen 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1674025f206cSDaniel T Chen 		 * with 0 dB offset 0x17)
1675025f206cSDaniel T Chen 		 */
1676025f206cSDaniel T Chen 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1677025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1678025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1679025f206cSDaniel T Chen 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1680025f206cSDaniel T Chen 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1681025f206cSDaniel T Chen 		break;
1682025f206cSDaniel T Chen 	}
1683025f206cSDaniel T Chen 
1684c9b443d4STobin Davis 	return 0;
1685c9b443d4STobin Davis }
1686c9b443d4STobin Davis 
1687461e2c78STakashi Iwai /* Conexant 5051 specific */
1688461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1689461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1690461e2c78STakashi Iwai 
1691461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = {
1692461e2c78STakashi Iwai 	{ 2, NULL },
1693461e2c78STakashi Iwai };
1694461e2c78STakashi Iwai 
1695461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1696461e2c78STakashi Iwai {
1697461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1698461e2c78STakashi Iwai 	unsigned int pinctl;
169923d2df5bSTakashi Iwai 	/* headphone pin */
170023d2df5bSTakashi Iwai 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
170123d2df5bSTakashi Iwai 	snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
170223d2df5bSTakashi Iwai 			    pinctl);
170323d2df5bSTakashi Iwai 	/* speaker pin */
1704461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1705461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1706461e2c78STakashi Iwai 			    pinctl);
1707f7154de2SHerton Ronaldo Krzesinski 	/* on ideapad there is an aditional speaker (subwoofer) to mute */
1708f7154de2SHerton Ronaldo Krzesinski 	if (spec->ideapad)
1709f7154de2SHerton Ronaldo Krzesinski 		snd_hda_codec_write(codec, 0x1b, 0,
1710f7154de2SHerton Ronaldo Krzesinski 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
1711f7154de2SHerton Ronaldo Krzesinski 				    pinctl);
1712461e2c78STakashi Iwai }
1713461e2c78STakashi Iwai 
1714461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1715461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1716461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1717461e2c78STakashi Iwai {
1718461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1719461e2c78STakashi Iwai 
1720461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1721461e2c78STakashi Iwai 		return 0;
1722461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1723461e2c78STakashi Iwai 	return 1;
1724461e2c78STakashi Iwai }
1725461e2c78STakashi Iwai 
1726461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1727461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1728461e2c78STakashi Iwai {
172979d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1730461e2c78STakashi Iwai 	unsigned int present;
1731461e2c78STakashi Iwai 
1732faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTB))
173379d7d533STakashi Iwai 		return;
1734d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1735461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1736461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1737461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1738461e2c78STakashi Iwai }
1739461e2c78STakashi Iwai 
1740461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1741461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1742461e2c78STakashi Iwai {
1743461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1744461e2c78STakashi Iwai 	unsigned int present;
1745461e2c78STakashi Iwai 	hda_nid_t new_adc;
1746461e2c78STakashi Iwai 
1747faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTC))
174879d7d533STakashi Iwai 		return;
1749d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1750461e2c78STakashi Iwai 	if (present)
1751461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1752461e2c78STakashi Iwai 	else
1753461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1754461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1755461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1756461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1757f0cea797STakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1758461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1759461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1760461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1761461e2c78STakashi Iwai 					   spec->cur_adc_format);
1762461e2c78STakashi Iwai 	}
1763461e2c78STakashi Iwai }
1764461e2c78STakashi Iwai 
1765461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1766461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1767461e2c78STakashi Iwai {
1768461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1769461e2c78STakashi Iwai 
1770d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1771461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1772461e2c78STakashi Iwai }
1773461e2c78STakashi Iwai 
1774461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1775461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1776461e2c78STakashi Iwai 				   unsigned int res)
1777461e2c78STakashi Iwai {
1778acf26c0cSUlrich Dangel 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1779461e2c78STakashi Iwai 	switch (res >> 26) {
1780461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1781461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1782461e2c78STakashi Iwai 		break;
1783461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1784461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1785461e2c78STakashi Iwai 		break;
1786461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1787461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1788461e2c78STakashi Iwai 		break;
1789461e2c78STakashi Iwai 	}
1790acf26c0cSUlrich Dangel 	conexant_report_jack(codec, nid);
1791461e2c78STakashi Iwai }
1792461e2c78STakashi Iwai 
17932c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1794461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1795461e2c78STakashi Iwai 	{
1796461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1797461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1798461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1799461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1800461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1801461e2c78STakashi Iwai 		.private_value = 0x1a,
1802461e2c78STakashi Iwai 	},
18032c7a3fb3STakashi Iwai 	{}
18042c7a3fb3STakashi Iwai };
1805461e2c78STakashi Iwai 
18062c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
18072c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
18082c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
18098607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
18108607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
18112c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
18122c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1813461e2c78STakashi Iwai 	{}
1814461e2c78STakashi Iwai };
1815461e2c78STakashi Iwai 
1816461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1817461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1818461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
18198607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
18208607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1821461e2c78STakashi Iwai 	{}
1822461e2c78STakashi Iwai };
1823461e2c78STakashi Iwai 
182479d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
18254e4ac600STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
18264e4ac600STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
182779d7d533STakashi Iwai 	{}
182879d7d533STakashi Iwai };
182979d7d533STakashi Iwai 
1830cd9d95a5SKen Prox static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
18315f6c3de6STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
18325f6c3de6STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1833cd9d95a5SKen Prox 	{}
1834cd9d95a5SKen Prox };
1835cd9d95a5SKen Prox 
1836faddaa5dSTakashi Iwai static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1837faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1838faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
18398607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
18408607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1841faddaa5dSTakashi Iwai 	{}
1842faddaa5dSTakashi Iwai };
1843faddaa5dSTakashi Iwai 
1844461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = {
1845461e2c78STakashi Iwai 	/* Line in, Mic */
1846461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1847461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1848461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1849461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1850461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1851461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1852461e2c78STakashi Iwai 	/* SPK  */
1853461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1854461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1855461e2c78STakashi Iwai 	/* HP, Amp  */
1856461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1857461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1858461e2c78STakashi Iwai 	/* DAC1 */
1859461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
186028c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1861461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1862461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1863461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1864461e2c78STakashi Iwai 	/* SPDIF route: PCM */
18651965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1866461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1867461e2c78STakashi Iwai 	/* EAPD */
1868461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1869461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1870461e2c78STakashi Iwai 	{ } /* end */
1871461e2c78STakashi Iwai };
1872461e2c78STakashi Iwai 
187379d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
187479d7d533STakashi Iwai 	/* Line in, Mic */
187579d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
187679d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
187779d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
187879d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
187979d7d533STakashi Iwai 	/* SPK  */
188079d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
188179d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
188279d7d533STakashi Iwai 	/* HP, Amp  */
188379d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
188479d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
188579d7d533STakashi Iwai 	/* DAC1 */
188679d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
188728c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
188879d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
188979d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
189079d7d533STakashi Iwai 	/* SPDIF route: PCM */
189179d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
189279d7d533STakashi Iwai 	/* EAPD */
189379d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
189479d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
189579d7d533STakashi Iwai 	{ } /* end */
189679d7d533STakashi Iwai };
189779d7d533STakashi Iwai 
189827e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
189927e08988SAristeu Sergio Rozanski Filho 	/* Line in, Mic */
190027e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
190127e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
190227e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
190327e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
190427e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
190527e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
190627e08988SAristeu Sergio Rozanski Filho 	/* SPK  */
190727e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
190827e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
190927e08988SAristeu Sergio Rozanski Filho 	/* HP, Amp  */
191027e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
191127e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
191227e08988SAristeu Sergio Rozanski Filho 	/* Docking HP */
191327e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
191427e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
191527e08988SAristeu Sergio Rozanski Filho 	/* DAC1 */
191627e08988SAristeu Sergio Rozanski Filho 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
191728c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
191827e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
191927e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
192027e08988SAristeu Sergio Rozanski Filho 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
192127e08988SAristeu Sergio Rozanski Filho 	/* SPDIF route: PCM */
19221965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
192327e08988SAristeu Sergio Rozanski Filho 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
192427e08988SAristeu Sergio Rozanski Filho 	/* EAPD */
192527e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
192627e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
192727e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
192827e08988SAristeu Sergio Rozanski Filho 	{ } /* end */
192927e08988SAristeu Sergio Rozanski Filho };
193027e08988SAristeu Sergio Rozanski Filho 
1931cd9d95a5SKen Prox static struct hda_verb cxt5051_f700_init_verbs[] = {
1932cd9d95a5SKen Prox 	/* Line in, Mic */
193330ed7ed1STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1934cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1935cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1936cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1937cd9d95a5SKen Prox 	/* SPK  */
1938cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1939cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1940cd9d95a5SKen Prox 	/* HP, Amp  */
1941cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1942cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1943cd9d95a5SKen Prox 	/* DAC1 */
1944cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
194528c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1946cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1947cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1948cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1949cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1950cd9d95a5SKen Prox 	/* EAPD */
1951cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1952cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1953cd9d95a5SKen Prox 	{ } /* end */
1954cd9d95a5SKen Prox };
1955cd9d95a5SKen Prox 
19566953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
19576953e552STakashi Iwai 				 unsigned int event)
19586953e552STakashi Iwai {
19596953e552STakashi Iwai 	snd_hda_codec_write(codec, nid, 0,
19606953e552STakashi Iwai 			    AC_VERB_SET_UNSOLICITED_ENABLE,
19616953e552STakashi Iwai 			    AC_USRSP_EN | event);
19626953e552STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
19636953e552STakashi Iwai 	conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
19646953e552STakashi Iwai 	conexant_report_jack(codec, nid);
19656953e552STakashi Iwai #endif
19666953e552STakashi Iwai }
19676953e552STakashi Iwai 
1968f7154de2SHerton Ronaldo Krzesinski static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1969f7154de2SHerton Ronaldo Krzesinski 	/* Subwoofer */
1970f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1971f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1972f7154de2SHerton Ronaldo Krzesinski 	{ } /* end */
1973f7154de2SHerton Ronaldo Krzesinski };
1974f7154de2SHerton Ronaldo Krzesinski 
1975461e2c78STakashi Iwai /* initialize jack-sensing, too */
1976461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1977461e2c78STakashi Iwai {
19786953e552STakashi Iwai 	struct conexant_spec *spec = codec->spec;
19796953e552STakashi Iwai 
1980461e2c78STakashi Iwai 	conexant_init(codec);
1981acf26c0cSUlrich Dangel 	conexant_init_jacks(codec);
19826953e552STakashi Iwai 
19836953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTB)
19846953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
19856953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTC)
19866953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
19876953e552STakashi Iwai 
1988461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1989461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1990461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1991461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1992461e2c78STakashi Iwai 	}
1993461e2c78STakashi Iwai 	return 0;
1994461e2c78STakashi Iwai }
1995461e2c78STakashi Iwai 
1996461e2c78STakashi Iwai 
1997461e2c78STakashi Iwai enum {
1998461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1999461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
200079d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
20011965c441SPierre-Louis Bossart 	CXT5051_LENOVO_X200,	/* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
2002cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
2003faddaa5dSTakashi Iwai 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
2004f7154de2SHerton Ronaldo Krzesinski 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
2005461e2c78STakashi Iwai 	CXT5051_MODELS
2006461e2c78STakashi Iwai };
2007461e2c78STakashi Iwai 
2008ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = {
2009461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
2010461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
201179d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
201227e08988SAristeu Sergio Rozanski Filho 	[CXT5051_LENOVO_X200]	= "lenovo-x200",
20135f6c3de6STakashi Iwai 	[CXT5051_F700]          = "hp-700",
2014faddaa5dSTakashi Iwai 	[CXT5051_TOSHIBA]	= "toshiba",
2015f7154de2SHerton Ronaldo Krzesinski 	[CXT5051_IDEAPAD]	= "ideapad",
2016461e2c78STakashi Iwai };
2017461e2c78STakashi Iwai 
2018461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
201979d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
20201812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
20215f6c3de6STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
2022faddaa5dSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
2023461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2024461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
2025461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
202627e08988SAristeu Sergio Rozanski Filho 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
2027f7154de2SHerton Ronaldo Krzesinski 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
2028461e2c78STakashi Iwai 	{}
2029461e2c78STakashi Iwai };
2030461e2c78STakashi Iwai 
2031461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
2032461e2c78STakashi Iwai {
2033461e2c78STakashi Iwai 	struct conexant_spec *spec;
2034461e2c78STakashi Iwai 	int board_config;
2035461e2c78STakashi Iwai 
2036461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2037461e2c78STakashi Iwai 	if (!spec)
2038461e2c78STakashi Iwai 		return -ENOMEM;
2039461e2c78STakashi Iwai 	codec->spec = spec;
20409421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
2041461e2c78STakashi Iwai 
2042461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
2043461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
2044461e2c78STakashi Iwai 
2045461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
2046461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2047461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
2048461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2049461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2050461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
20512c7a3fb3STakashi Iwai 	spec->num_mixers = 2;
20522c7a3fb3STakashi Iwai 	spec->mixers[0] = cxt5051_capture_mixers;
20532c7a3fb3STakashi Iwai 	spec->mixers[1] = cxt5051_playback_mixers;
2054461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
2055461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
2056461e2c78STakashi Iwai 	spec->spdif_route = 0;
2057461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2058461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
2059461e2c78STakashi Iwai 	spec->cur_adc = 0;
2060461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
2061461e2c78STakashi Iwai 
20623507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
20633507e2a8STakashi Iwai 
206479d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
206579d7d533STakashi Iwai 
2066461e2c78STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
2067461e2c78STakashi Iwai 						  cxt5051_models,
2068461e2c78STakashi Iwai 						  cxt5051_cfg_tbl);
2069faddaa5dSTakashi Iwai 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
2070461e2c78STakashi Iwai 	switch (board_config) {
2071461e2c78STakashi Iwai 	case CXT5051_HP:
2072461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
2073461e2c78STakashi Iwai 		break;
207479d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
207579d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
207679d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2077faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
207879d7d533STakashi Iwai 		break;
207927e08988SAristeu Sergio Rozanski Filho 	case CXT5051_LENOVO_X200:
208027e08988SAristeu Sergio Rozanski Filho 		spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
2081607bc3e4SJerone Young 		/* Thinkpad X301 does not have S/PDIF wired and no ability
2082607bc3e4SJerone Young 		   to use a docking station. */
2083607bc3e4SJerone Young 		if (codec->subsystem_id == 0x17aa211f)
2084607bc3e4SJerone Young 			spec->multiout.dig_out_nid = 0;
2085461e2c78STakashi Iwai 		break;
2086cd9d95a5SKen Prox 	case CXT5051_F700:
2087cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
2088cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
2089faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
2090faddaa5dSTakashi Iwai 		break;
2091faddaa5dSTakashi Iwai 	case CXT5051_TOSHIBA:
2092faddaa5dSTakashi Iwai 		spec->mixers[0] = cxt5051_toshiba_mixers;
2093faddaa5dSTakashi Iwai 		spec->auto_mic = AUTO_MIC_PORTB;
2094cd9d95a5SKen Prox 		break;
2095f7154de2SHerton Ronaldo Krzesinski 	case CXT5051_IDEAPAD:
2096f7154de2SHerton Ronaldo Krzesinski 		spec->init_verbs[spec->num_init_verbs++] =
2097f7154de2SHerton Ronaldo Krzesinski 			cxt5051_ideapad_init_verbs;
2098f7154de2SHerton Ronaldo Krzesinski 		spec->ideapad = 1;
2099f7154de2SHerton Ronaldo Krzesinski 		break;
2100461e2c78STakashi Iwai 	}
2101461e2c78STakashi Iwai 
21023507e2a8STakashi Iwai 	if (spec->beep_amp)
21033507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
21043507e2a8STakashi Iwai 
2105461e2c78STakashi Iwai 	return 0;
2106461e2c78STakashi Iwai }
2107461e2c78STakashi Iwai 
21080fb67e98SDaniel Drake /* Conexant 5066 specific */
21090fb67e98SDaniel Drake 
21100fb67e98SDaniel Drake static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
21110fb67e98SDaniel Drake static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
21120fb67e98SDaniel Drake static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2113f6a2491cSAndy Robinson static hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
21140fb67e98SDaniel Drake 
2115dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors,
2116dbaccc0cSDaniel Drake  * therefore we use a 50% mic bias in order to center the input signal with
2117dbaccc0cSDaniel Drake  * the DC input range of the codec. */
2118dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2119dbaccc0cSDaniel Drake 
21200fb67e98SDaniel Drake static struct hda_channel_mode cxt5066_modes[1] = {
21210fb67e98SDaniel Drake 	{ 2, NULL },
21220fb67e98SDaniel Drake };
21230fb67e98SDaniel Drake 
2124a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A	(1 << 0)
2125a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D	(1 << 1)
2126a3de8ab8STakashi Iwai #define hp_port_a_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_A)
2127a3de8ab8STakashi Iwai #define hp_port_d_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_D)
2128a3de8ab8STakashi Iwai 
21290fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
21300fb67e98SDaniel Drake {
21310fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
21320fb67e98SDaniel Drake 	unsigned int pinctl;
21330fb67e98SDaniel Drake 
21343a253445SJohn Baboval 	snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
21353a253445SJohn Baboval 		    spec->hp_present, spec->cur_eapd);
21360fb67e98SDaniel Drake 
21370fb67e98SDaniel Drake 	/* Port A (HP) */
2138a3de8ab8STakashi Iwai 	pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
21390fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21400fb67e98SDaniel Drake 			pinctl);
21410fb67e98SDaniel Drake 
21420fb67e98SDaniel Drake 	/* Port D (HP/LO) */
2143a3de8ab8STakashi Iwai 	pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2144a3de8ab8STakashi Iwai 	if (spec->dell_automute || spec->thinkpad) {
2145a3de8ab8STakashi Iwai 		/* Mute if Port A is connected */
2146a3de8ab8STakashi Iwai 		if (hp_port_a_present(spec))
21473a253445SJohn Baboval 			pinctl = 0;
21483a253445SJohn Baboval 	} else {
2149a3de8ab8STakashi Iwai 		/* Thinkpad/Dell doesn't give pin-D status */
2150a3de8ab8STakashi Iwai 		if (!hp_port_d_present(spec))
2151a3de8ab8STakashi Iwai 			pinctl = 0;
21523a253445SJohn Baboval 	}
21530fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21540fb67e98SDaniel Drake 			pinctl);
21550fb67e98SDaniel Drake 
21560fb67e98SDaniel Drake 	/* CLASS_D AMP */
21570fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
21580fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21590fb67e98SDaniel Drake 			pinctl);
21600fb67e98SDaniel Drake }
21610fb67e98SDaniel Drake 
21620fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
21630fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
21640fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
21650fb67e98SDaniel Drake {
21660fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
21670fb67e98SDaniel Drake 
21680fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
21690fb67e98SDaniel Drake 		return 0;
21700fb67e98SDaniel Drake 
21710fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
21720fb67e98SDaniel Drake 	return 1;
21730fb67e98SDaniel Drake }
21740fb67e98SDaniel Drake 
2175c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2176c4cfe66cSDaniel Drake 	.num_items = 3,
2177c4cfe66cSDaniel Drake 	.items = {
2178c4cfe66cSDaniel Drake 		{ "Off", PIN_IN },
2179c4cfe66cSDaniel Drake 		{ "50%", PIN_VREF50 },
2180c4cfe66cSDaniel Drake 		{ "80%", PIN_VREF80 },
2181c4cfe66cSDaniel Drake 	},
2182c4cfe66cSDaniel Drake };
2183c4cfe66cSDaniel Drake 
2184c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2185c4cfe66cSDaniel Drake {
2186c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2187c4cfe66cSDaniel Drake 	/* Even though port F is the DC input, the bias is controlled on port B.
2188c4cfe66cSDaniel Drake 	 * we also leave that port as an active input (but unselected) in DC mode
2189c4cfe66cSDaniel Drake 	 * just in case that is necessary to make the bias setting take effect. */
2190c4cfe66cSDaniel Drake 	return snd_hda_codec_write_cache(codec, 0x1a, 0,
2191c4cfe66cSDaniel Drake 		AC_VERB_SET_PIN_WIDGET_CONTROL,
2192c4cfe66cSDaniel Drake 		cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2193c4cfe66cSDaniel Drake }
2194c4cfe66cSDaniel Drake 
219575f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the
219675f8991dSDaniel Drake  * microphone LED comes on as soon as these settings are put in place. if we
219775f8991dSDaniel Drake  * did this before recording, it would give the false indication that recording
219875f8991dSDaniel Drake  * is happening when it is not. */
219975f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec)
22000fb67e98SDaniel Drake {
2201dbaccc0cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
220275f8991dSDaniel Drake 	if (!spec->recording)
220375f8991dSDaniel Drake 		return;
22040fb67e98SDaniel Drake 
2205c4cfe66cSDaniel Drake 	if (spec->dc_enable) {
2206c4cfe66cSDaniel Drake 		/* in DC mode we ignore presence detection and just use the jack
2207c4cfe66cSDaniel Drake 		 * through our special DC port */
2208c4cfe66cSDaniel Drake 		const struct hda_verb enable_dc_mode[] = {
2209c4cfe66cSDaniel Drake 			/* disble internal mic, port C */
2210c4cfe66cSDaniel Drake 			{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2211c4cfe66cSDaniel Drake 
2212c4cfe66cSDaniel Drake 			/* enable DC capture, port F */
2213c4cfe66cSDaniel Drake 			{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2214c4cfe66cSDaniel Drake 			{},
2215c4cfe66cSDaniel Drake 		};
2216c4cfe66cSDaniel Drake 
2217c4cfe66cSDaniel Drake 		snd_hda_sequence_write(codec, enable_dc_mode);
2218c4cfe66cSDaniel Drake 		/* port B input disabled (and bias set) through the following call */
2219c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
2220c4cfe66cSDaniel Drake 		return;
2221c4cfe66cSDaniel Drake 	}
2222c4cfe66cSDaniel Drake 
2223c4cfe66cSDaniel Drake 	/* disable DC (port F) */
2224c4cfe66cSDaniel Drake 	snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2225c4cfe66cSDaniel Drake 
222675f8991dSDaniel Drake 	/* external mic, port B */
222775f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
222875f8991dSDaniel Drake 		spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
22290fb67e98SDaniel Drake 
223075f8991dSDaniel Drake 	/* internal mic, port C */
223175f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
223275f8991dSDaniel Drake 		spec->ext_mic_present ? 0 : PIN_VREF80);
223375f8991dSDaniel Drake }
22340fb67e98SDaniel Drake 
223575f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */
223675f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec)
223775f8991dSDaniel Drake {
223875f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
22390fb67e98SDaniel Drake 	unsigned int present;
22400fb67e98SDaniel Drake 
2241c4cfe66cSDaniel Drake 	if (spec->dc_enable) /* don't do presence detection in DC mode */
2242c4cfe66cSDaniel Drake 		return;
2243c4cfe66cSDaniel Drake 
224475f8991dSDaniel Drake 	present = snd_hda_codec_read(codec, 0x1a, 0,
224575f8991dSDaniel Drake 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
224675f8991dSDaniel Drake 	if (present)
22470fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone detected\n");
224875f8991dSDaniel Drake 	else
22490fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone absent\n");
225075f8991dSDaniel Drake 
225175f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
225275f8991dSDaniel Drake 		present ? 0 : 1);
225375f8991dSDaniel Drake 	spec->ext_mic_present = !!present;
225475f8991dSDaniel Drake 
225575f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
22560fb67e98SDaniel Drake }
22570fb67e98SDaniel Drake 
225895a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
225995a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
226095a618bdSEinar Rünkaru {
226195a618bdSEinar Rünkaru 	unsigned int present;
226295a618bdSEinar Rünkaru 
226395a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
226495a618bdSEinar Rünkaru 		/* enable external mic, port B */
226575f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
226695a618bdSEinar Rünkaru 
226795a618bdSEinar Rünkaru 		/* switch to external mic input */
226895a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
226995a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
227095a618bdSEinar Rünkaru 
227195a618bdSEinar Rünkaru 		/* disable internal digital mic */
227295a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
227395a618bdSEinar Rünkaru 		{}
227495a618bdSEinar Rünkaru 	};
227595a618bdSEinar Rünkaru 	static struct hda_verb ext_mic_absent[] = {
227695a618bdSEinar Rünkaru 		/* enable internal mic, port C */
227795a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
227895a618bdSEinar Rünkaru 
227995a618bdSEinar Rünkaru 		/* switch to internal mic input */
228095a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
228195a618bdSEinar Rünkaru 
228295a618bdSEinar Rünkaru 		/* disable external mic, port B */
228395a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
228495a618bdSEinar Rünkaru 		{}
228595a618bdSEinar Rünkaru 	};
228695a618bdSEinar Rünkaru 
228795a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
228895a618bdSEinar Rünkaru 	if (present) {
228995a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
229095a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
229195a618bdSEinar Rünkaru 	} else {
229295a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
229395a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
229495a618bdSEinar Rünkaru 	}
229595a618bdSEinar Rünkaru }
229695a618bdSEinar Rünkaru 
2297cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */
2298cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec)
2299cfd3d8dcSGreg Alexander {
2300cfd3d8dcSGreg Alexander 	unsigned int present;
2301cfd3d8dcSGreg Alexander 
2302cfd3d8dcSGreg Alexander 	struct hda_verb ext_mic_present[] = {
2303cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2304cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2305cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2306cfd3d8dcSGreg Alexander 		{}
2307cfd3d8dcSGreg Alexander 	};
2308cfd3d8dcSGreg Alexander 	static struct hda_verb ext_mic_absent[] = {
2309cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2310cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2311cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2312cfd3d8dcSGreg Alexander 		{}
2313cfd3d8dcSGreg Alexander 	};
2314cfd3d8dcSGreg Alexander 
2315cfd3d8dcSGreg Alexander 	present = snd_hda_jack_detect(codec, 0x1b);
2316cfd3d8dcSGreg Alexander 	if (present) {
2317cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone detected\n");
2318cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_present);
2319cfd3d8dcSGreg Alexander 	} else {
2320cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone absent\n");
2321cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_absent);
2322cfd3d8dcSGreg Alexander 	}
2323cfd3d8dcSGreg Alexander }
2324cfd3d8dcSGreg Alexander 
2325a1d6906eSDavid Henningsson 
2326a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2327a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec)
2328a1d6906eSDavid Henningsson {
2329a1d6906eSDavid Henningsson 	unsigned int present;
2330a1d6906eSDavid Henningsson 
2331a1d6906eSDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2332a1d6906eSDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2333a1d6906eSDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2334a1d6906eSDavid Henningsson 			    present ? 1 : 0);
2335a1d6906eSDavid Henningsson }
2336a1d6906eSDavid Henningsson 
2337a1d6906eSDavid Henningsson 
2338048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2339048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2340048e78a5SDavid Henningsson {
2341048e78a5SDavid Henningsson 	unsigned int present;
2342048e78a5SDavid Henningsson 
2343048e78a5SDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2344048e78a5SDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2345048e78a5SDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2346048e78a5SDavid Henningsson 			    present ? 1 : 3);
2347048e78a5SDavid Henningsson }
2348048e78a5SDavid Henningsson 
2349048e78a5SDavid Henningsson 
23507b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately
23517b2bfdbcSJens Taprogge    order is: external mic -> dock mic -> interal mic */
23527b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec)
23537b2bfdbcSJens Taprogge {
23547b2bfdbcSJens Taprogge 	unsigned int ext_present, dock_present;
23557b2bfdbcSJens Taprogge 
23567b2bfdbcSJens Taprogge 	static struct hda_verb ext_mic_present[] = {
23577b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
23587b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
23597b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23607b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23617b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23627b2bfdbcSJens Taprogge 		{}
23637b2bfdbcSJens Taprogge 	};
23647b2bfdbcSJens Taprogge 	static struct hda_verb dock_mic_present[] = {
23657b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
23667b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
23677b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23687b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23697b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23707b2bfdbcSJens Taprogge 		{}
23717b2bfdbcSJens Taprogge 	};
23727b2bfdbcSJens Taprogge 	static struct hda_verb ext_mic_absent[] = {
23737b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
23747b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
23757b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23767b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23777b2bfdbcSJens Taprogge 		{}
23787b2bfdbcSJens Taprogge 	};
23797b2bfdbcSJens Taprogge 
23807b2bfdbcSJens Taprogge 	ext_present = snd_hda_jack_detect(codec, 0x1b);
23817b2bfdbcSJens Taprogge 	dock_present = snd_hda_jack_detect(codec, 0x1a);
23827b2bfdbcSJens Taprogge 	if (ext_present) {
23837b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone detected\n");
23847b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_present);
23857b2bfdbcSJens Taprogge 	} else if (dock_present) {
23867b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: dock microphone detected\n");
23877b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, dock_mic_present);
23887b2bfdbcSJens Taprogge 	} else {
23897b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone absent\n");
23907b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_absent);
23917b2bfdbcSJens Taprogge 	}
23927b2bfdbcSJens Taprogge }
23937b2bfdbcSJens Taprogge 
23940fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
23950fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
23960fb67e98SDaniel Drake {
23970fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
23980fb67e98SDaniel Drake 	unsigned int portA, portD;
23990fb67e98SDaniel Drake 
24000fb67e98SDaniel Drake 	/* Port A */
2401d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
24020fb67e98SDaniel Drake 
24030fb67e98SDaniel Drake 	/* Port D */
2404d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
24050fb67e98SDaniel Drake 
2406a3de8ab8STakashi Iwai 	spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2407a3de8ab8STakashi Iwai 	spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
24080fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
24090fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
24100fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
24110fb67e98SDaniel Drake }
24120fb67e98SDaniel Drake 
241302b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */
241402b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec)
241502b6b5b6SDavid Henningsson {
241602b6b5b6SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
241702b6b5b6SDavid Henningsson 
241802b6b5b6SDavid Henningsson 	if (spec->dell_vostro)
241902b6b5b6SDavid Henningsson 		cxt5066_vostro_automic(codec);
242002b6b5b6SDavid Henningsson 	else if (spec->ideapad)
242102b6b5b6SDavid Henningsson 		cxt5066_ideapad_automic(codec);
242202b6b5b6SDavid Henningsson 	else if (spec->thinkpad)
242302b6b5b6SDavid Henningsson 		cxt5066_thinkpad_automic(codec);
242402b6b5b6SDavid Henningsson 	else if (spec->hp_laptop)
242502b6b5b6SDavid Henningsson 		cxt5066_hp_laptop_automic(codec);
2426a1d6906eSDavid Henningsson 	else if (spec->asus)
2427a1d6906eSDavid Henningsson 		cxt5066_asus_automic(codec);
242802b6b5b6SDavid Henningsson }
242902b6b5b6SDavid Henningsson 
24300fb67e98SDaniel Drake /* unsolicited event for jack sensing */
243175f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
24320fb67e98SDaniel Drake {
2433c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
24340fb67e98SDaniel Drake 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
24350fb67e98SDaniel Drake 	switch (res >> 26) {
24360fb67e98SDaniel Drake 	case CONEXANT_HP_EVENT:
24370fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
24380fb67e98SDaniel Drake 		break;
24390fb67e98SDaniel Drake 	case CONEXANT_MIC_EVENT:
2440c4cfe66cSDaniel Drake 		/* ignore mic events in DC mode; we're always using the jack */
2441c4cfe66cSDaniel Drake 		if (!spec->dc_enable)
244275f8991dSDaniel Drake 			cxt5066_olpc_automic(codec);
24430fb67e98SDaniel Drake 		break;
24440fb67e98SDaniel Drake 	}
24450fb67e98SDaniel Drake }
24460fb67e98SDaniel Drake 
244795a618bdSEinar Rünkaru /* unsolicited event for jack sensing */
244802b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
244995a618bdSEinar Rünkaru {
245002b6b5b6SDavid Henningsson 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
245195a618bdSEinar Rünkaru 	switch (res >> 26) {
245295a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
245395a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
245495a618bdSEinar Rünkaru 		break;
245595a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
245602b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
245795a618bdSEinar Rünkaru 		break;
245895a618bdSEinar Rünkaru 	}
245995a618bdSEinar Rünkaru }
246095a618bdSEinar Rünkaru 
24617b2bfdbcSJens Taprogge 
24620fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
24630fb67e98SDaniel Drake 	.num_items = 5,
24640fb67e98SDaniel Drake 	.items = {
24650fb67e98SDaniel Drake 		{ "0dB",  0 },
24660fb67e98SDaniel Drake 		{ "10dB", 1 },
24670fb67e98SDaniel Drake 		{ "20dB", 2 },
24680fb67e98SDaniel Drake 		{ "30dB", 3 },
24690fb67e98SDaniel Drake 		{ "40dB", 4 },
24700fb67e98SDaniel Drake 	},
24710fb67e98SDaniel Drake };
24720fb67e98SDaniel Drake 
2473cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec)
2474c4cfe66cSDaniel Drake {
2475c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2476cfd3d8dcSGreg Alexander 	snd_hda_codec_write_cache(codec, 0x17, 0,
2477c4cfe66cSDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2478c4cfe66cSDaniel Drake 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2479c4cfe66cSDaniel Drake 			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
24807b2bfdbcSJens Taprogge 	if (spec->ideapad || spec->thinkpad) {
2481cfd3d8dcSGreg Alexander 		/* adjust the internal mic as well...it is not through 0x17 */
2482cfd3d8dcSGreg Alexander 		snd_hda_codec_write_cache(codec, 0x23, 0,
2483cfd3d8dcSGreg Alexander 			AC_VERB_SET_AMP_GAIN_MUTE,
2484cfd3d8dcSGreg Alexander 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2485cfd3d8dcSGreg Alexander 				cxt5066_analog_mic_boost.
2486cfd3d8dcSGreg Alexander 					items[spec->mic_boost].index);
2487cfd3d8dcSGreg Alexander 	}
2488c4cfe66cSDaniel Drake }
2489c4cfe66cSDaniel Drake 
24900fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
24910fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
24920fb67e98SDaniel Drake {
24930fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
24940fb67e98SDaniel Drake }
24950fb67e98SDaniel Drake 
24960fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
24970fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24980fb67e98SDaniel Drake {
24990fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2500c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2501c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->mic_boost;
25020fb67e98SDaniel Drake 	return 0;
25030fb67e98SDaniel Drake }
25040fb67e98SDaniel Drake 
25050fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
25060fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
25070fb67e98SDaniel Drake {
25080fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2509c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
25100fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
25110fb67e98SDaniel Drake 	unsigned int idx;
25120fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
25130fb67e98SDaniel Drake 	if (idx >= imux->num_items)
25140fb67e98SDaniel Drake 		idx = imux->num_items - 1;
25150fb67e98SDaniel Drake 
2516c4cfe66cSDaniel Drake 	spec->mic_boost = idx;
2517c4cfe66cSDaniel Drake 	if (!spec->dc_enable)
2518c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
2519c4cfe66cSDaniel Drake 	return 1;
2520c4cfe66cSDaniel Drake }
25210fb67e98SDaniel Drake 
2522c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec)
2523c4cfe66cSDaniel Drake {
2524c4cfe66cSDaniel Drake 	const struct hda_verb enable_dc_mode[] = {
2525c4cfe66cSDaniel Drake 		/* disable gain */
2526c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2527c4cfe66cSDaniel Drake 
2528c4cfe66cSDaniel Drake 		/* switch to DC input */
2529c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_CONNECT_SEL, 3},
2530c4cfe66cSDaniel Drake 		{}
2531c4cfe66cSDaniel Drake 	};
2532c4cfe66cSDaniel Drake 
2533c4cfe66cSDaniel Drake 	/* configure as input source */
2534c4cfe66cSDaniel Drake 	snd_hda_sequence_write(codec, enable_dc_mode);
2535c4cfe66cSDaniel Drake 	cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2536c4cfe66cSDaniel Drake }
2537c4cfe66cSDaniel Drake 
2538c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec)
2539c4cfe66cSDaniel Drake {
2540c4cfe66cSDaniel Drake 	/* reconfigure input source */
2541c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
2542c4cfe66cSDaniel Drake 	/* automic also selects the right mic if we're recording */
2543c4cfe66cSDaniel Drake 	cxt5066_olpc_automic(codec);
2544c4cfe66cSDaniel Drake }
2545c4cfe66cSDaniel Drake 
2546c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2547c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2548c4cfe66cSDaniel Drake {
2549c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2550c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2551c4cfe66cSDaniel Drake 	ucontrol->value.integer.value[0] = spec->dc_enable;
2552c4cfe66cSDaniel Drake 	return 0;
2553c4cfe66cSDaniel Drake }
2554c4cfe66cSDaniel Drake 
2555c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2556c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2557c4cfe66cSDaniel Drake {
2558c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2559c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2560c4cfe66cSDaniel Drake 	int dc_enable = !!ucontrol->value.integer.value[0];
2561c4cfe66cSDaniel Drake 
2562c4cfe66cSDaniel Drake 	if (dc_enable == spec->dc_enable)
2563c4cfe66cSDaniel Drake 		return 0;
2564c4cfe66cSDaniel Drake 
2565c4cfe66cSDaniel Drake 	spec->dc_enable = dc_enable;
2566c4cfe66cSDaniel Drake 	if (dc_enable)
2567c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2568c4cfe66cSDaniel Drake 	else
2569c4cfe66cSDaniel Drake 		cxt5066_disable_dc(codec);
2570c4cfe66cSDaniel Drake 
2571c4cfe66cSDaniel Drake 	return 1;
2572c4cfe66cSDaniel Drake }
2573c4cfe66cSDaniel Drake 
2574c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2575c4cfe66cSDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
2576c4cfe66cSDaniel Drake {
2577c4cfe66cSDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2578c4cfe66cSDaniel Drake }
2579c4cfe66cSDaniel Drake 
2580c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2581c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2582c4cfe66cSDaniel Drake {
2583c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2584c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2585c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2586c4cfe66cSDaniel Drake 	return 0;
2587c4cfe66cSDaniel Drake }
2588c4cfe66cSDaniel Drake 
2589c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2590c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2591c4cfe66cSDaniel Drake {
2592c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2593c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2594c4cfe66cSDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2595c4cfe66cSDaniel Drake 	unsigned int idx;
2596c4cfe66cSDaniel Drake 
2597c4cfe66cSDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
2598c4cfe66cSDaniel Drake 	if (idx >= imux->num_items)
2599c4cfe66cSDaniel Drake 		idx = imux->num_items - 1;
2600c4cfe66cSDaniel Drake 
2601c4cfe66cSDaniel Drake 	spec->dc_input_bias = idx;
2602c4cfe66cSDaniel Drake 	if (spec->dc_enable)
2603c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
26040fb67e98SDaniel Drake 	return 1;
26050fb67e98SDaniel Drake }
26060fb67e98SDaniel Drake 
260775f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
260875f8991dSDaniel Drake {
260975f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
261075f8991dSDaniel Drake 	/* mark as recording and configure the microphone widget so that the
261175f8991dSDaniel Drake 	 * recording LED comes on. */
261275f8991dSDaniel Drake 	spec->recording = 1;
261375f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
261475f8991dSDaniel Drake }
261575f8991dSDaniel Drake 
261675f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
261775f8991dSDaniel Drake {
261875f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
261975f8991dSDaniel Drake 	const struct hda_verb disable_mics[] = {
262075f8991dSDaniel Drake 		/* disable external mic, port B */
262175f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
262275f8991dSDaniel Drake 
262375f8991dSDaniel Drake 		/* disble internal mic, port C */
262475f8991dSDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2625c4cfe66cSDaniel Drake 
2626c4cfe66cSDaniel Drake 		/* disable DC capture, port F */
2627c4cfe66cSDaniel Drake 		{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
262875f8991dSDaniel Drake 		{},
262975f8991dSDaniel Drake 	};
263075f8991dSDaniel Drake 
263175f8991dSDaniel Drake 	snd_hda_sequence_write(codec, disable_mics);
263275f8991dSDaniel Drake 	spec->recording = 0;
263375f8991dSDaniel Drake }
263475f8991dSDaniel Drake 
2635f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec,
2636f6a2491cSAndy Robinson 				    hda_nid_t *dig_pins,
2637f6a2491cSAndy Robinson 				    int num_pins)
2638f6a2491cSAndy Robinson {
2639f6a2491cSAndy Robinson 	struct conexant_spec *spec = codec->spec;
2640f6a2491cSAndy Robinson 	hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2641f6a2491cSAndy Robinson 	int i;
2642f6a2491cSAndy Robinson 
2643f6a2491cSAndy Robinson 	for (i = 0; i < num_pins; i++, dig_pins++) {
2644f6a2491cSAndy Robinson 		unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2645f6a2491cSAndy Robinson 		if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2646f6a2491cSAndy Robinson 			continue;
2647f6a2491cSAndy Robinson 		if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2648f6a2491cSAndy Robinson 			continue;
2649f6a2491cSAndy Robinson 		if (spec->slave_dig_outs[0])
2650f6a2491cSAndy Robinson 			nid_loc++;
2651f6a2491cSAndy Robinson 		else
2652f6a2491cSAndy Robinson 			nid_loc = spec->slave_dig_outs;
2653f6a2491cSAndy Robinson 	}
2654f6a2491cSAndy Robinson }
2655f6a2491cSAndy Robinson 
26560fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = {
26570fb67e98SDaniel Drake 	.num_items = 4,
26580fb67e98SDaniel Drake 	.items = {
26590fb67e98SDaniel Drake 		{ "Mic B", 0 },
26600fb67e98SDaniel Drake 		{ "Mic C", 1 },
26610fb67e98SDaniel Drake 		{ "Mic E", 2 },
26620fb67e98SDaniel Drake 		{ "Mic F", 3 },
26630fb67e98SDaniel Drake 	},
26640fb67e98SDaniel Drake };
26650fb67e98SDaniel Drake 
26660fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
26670fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
26680fb67e98SDaniel Drake 	.values = {
26690fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26700fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26710fb67e98SDaniel Drake 		0
26720fb67e98SDaniel Drake 	},
26730fb67e98SDaniel Drake };
26740fb67e98SDaniel Drake 
26750fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
26760fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
26770fb67e98SDaniel Drake 	.values = {
26780fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26790fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26800fb67e98SDaniel Drake 		0
26810fb67e98SDaniel Drake 	},
26820fb67e98SDaniel Drake };
26830fb67e98SDaniel Drake 
26840fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = {
26850fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
26860fb67e98SDaniel Drake 	{}
26870fb67e98SDaniel Drake };
26880fb67e98SDaniel Drake 
26890fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
26900fb67e98SDaniel Drake 	{
26910fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26920fb67e98SDaniel Drake 		.name = "Master Playback Volume",
26930fb67e98SDaniel Drake 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
26940fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
26950fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
26965e26dfd0SJaroslav Kysela 		.subdevice = HDA_SUBDEV_AMP_FLAG,
26970fb67e98SDaniel Drake 		.info = snd_hda_mixer_amp_volume_info,
26980fb67e98SDaniel Drake 		.get = snd_hda_mixer_amp_volume_get,
26990fb67e98SDaniel Drake 		.put = snd_hda_mixer_amp_volume_put,
27000fb67e98SDaniel Drake 		.tlv = { .c = snd_hda_mixer_amp_tlv },
27010fb67e98SDaniel Drake 		/* offset by 28 volume steps to limit minimum gain to -46dB */
27020fb67e98SDaniel Drake 		.private_value =
27030fb67e98SDaniel Drake 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
27040fb67e98SDaniel Drake 	},
27050fb67e98SDaniel Drake 	{}
27060fb67e98SDaniel Drake };
27070fb67e98SDaniel Drake 
2708c4cfe66cSDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2709c4cfe66cSDaniel Drake 	{
2710c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2711c4cfe66cSDaniel Drake 		.name = "DC Mode Enable Switch",
2712c4cfe66cSDaniel Drake 		.info = snd_ctl_boolean_mono_info,
2713c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_get,
2714c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_put,
2715c4cfe66cSDaniel Drake 	},
2716c4cfe66cSDaniel Drake 	{
2717c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2718c4cfe66cSDaniel Drake 		.name = "DC Input Bias Enum",
2719c4cfe66cSDaniel Drake 		.info = cxt5066_olpc_dc_bias_enum_info,
2720c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_bias_enum_get,
2721c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_bias_enum_put,
2722c4cfe66cSDaniel Drake 	},
2723c4cfe66cSDaniel Drake 	{}
2724c4cfe66cSDaniel Drake };
2725c4cfe66cSDaniel Drake 
27260fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = {
27270fb67e98SDaniel Drake 	{
27280fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
27290fb67e98SDaniel Drake 		.name = "Master Playback Switch",
27300fb67e98SDaniel Drake 		.info = cxt_eapd_info,
27310fb67e98SDaniel Drake 		.get = cxt_eapd_get,
27320fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
27330fb67e98SDaniel Drake 		.private_value = 0x1d,
27340fb67e98SDaniel Drake 	},
27350fb67e98SDaniel Drake 
27360fb67e98SDaniel Drake 	{
27370fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2738c4cfe66cSDaniel Drake 		.name = "Analog Mic Boost Capture Enum",
27390fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
27400fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
27410fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
27420fb67e98SDaniel Drake 	},
27430fb67e98SDaniel Drake 
27440fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
27450fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
27460fb67e98SDaniel Drake 	{}
27470fb67e98SDaniel Drake };
27480fb67e98SDaniel Drake 
2749254bba6aSEinar Rünkaru static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2750254bba6aSEinar Rünkaru 	{
2751254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
275228c4edb7SDavid Henningsson 		.name = "Internal Mic Boost Capture Enum",
2753254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2754254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2755254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2756254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2757254bba6aSEinar Rünkaru 	},
2758254bba6aSEinar Rünkaru 	{}
2759254bba6aSEinar Rünkaru };
2760254bba6aSEinar Rünkaru 
27610fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = {
27620fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
27630fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
27640fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
27650fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
27660fb67e98SDaniel Drake 
27670fb67e98SDaniel Drake 	/* Speakers  */
27680fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27690fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27700fb67e98SDaniel Drake 
27710fb67e98SDaniel Drake 	/* HP, Amp  */
27720fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27730fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27740fb67e98SDaniel Drake 
27750fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27760fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27770fb67e98SDaniel Drake 
27780fb67e98SDaniel Drake 	/* DAC1 */
27790fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
27800fb67e98SDaniel Drake 
27810fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
27820fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
27830fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27840fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
27850fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27860fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
27870fb67e98SDaniel Drake 
27880fb67e98SDaniel Drake 	/* no digital microphone support yet */
27890fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27900fb67e98SDaniel Drake 
27910fb67e98SDaniel Drake 	/* Audio input selector */
27920fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
27930fb67e98SDaniel Drake 
27940fb67e98SDaniel Drake 	/* SPDIF route: PCM */
27950fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
27960fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
27970fb67e98SDaniel Drake 
27980fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27990fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
28000fb67e98SDaniel Drake 
28010fb67e98SDaniel Drake 	/* EAPD */
28020fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
28030fb67e98SDaniel Drake 
28040fb67e98SDaniel Drake 	/* not handling these yet */
28050fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
28060fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
28070fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
28080fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
28090fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
28100fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
28110fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
28120fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
28130fb67e98SDaniel Drake 	{ } /* end */
28140fb67e98SDaniel Drake };
28150fb67e98SDaniel Drake 
28160fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = {
28170fb67e98SDaniel Drake 	/* Port A: headphones */
28180fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
28190fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
28200fb67e98SDaniel Drake 
28210fb67e98SDaniel Drake 	/* Port B: external microphone */
282275f8991dSDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28230fb67e98SDaniel Drake 
28240fb67e98SDaniel Drake 	/* Port C: internal microphone */
282575f8991dSDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28260fb67e98SDaniel Drake 
28270fb67e98SDaniel Drake 	/* Port D: unused */
28280fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28290fb67e98SDaniel Drake 
28300fb67e98SDaniel Drake 	/* Port E: unused, but has primary EAPD */
28310fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28320fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
28330fb67e98SDaniel Drake 
2834c4cfe66cSDaniel Drake 	/* Port F: external DC input through microphone port */
28350fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28360fb67e98SDaniel Drake 
28370fb67e98SDaniel Drake 	/* Port G: internal speakers */
28380fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
28390fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
28400fb67e98SDaniel Drake 
28410fb67e98SDaniel Drake 	/* DAC1 */
28420fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
28430fb67e98SDaniel Drake 
28440fb67e98SDaniel Drake 	/* DAC2: unused */
28450fb67e98SDaniel Drake 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
28460fb67e98SDaniel Drake 
28470fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
28480fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28490fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28500fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28510fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
28520fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28530fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28540fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28550fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
28560fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28570fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28580fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28590fb67e98SDaniel Drake 
28600fb67e98SDaniel Drake 	/* Disable digital microphone port */
28610fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28620fb67e98SDaniel Drake 
28630fb67e98SDaniel Drake 	/* Audio input selectors */
28640fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
28650fb67e98SDaniel Drake 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
28660fb67e98SDaniel Drake 
28670fb67e98SDaniel Drake 	/* Disable SPDIF */
28680fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28690fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28700fb67e98SDaniel Drake 
28710fb67e98SDaniel Drake 	/* enable unsolicited events for Port A and B */
28720fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
28730fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
28740fb67e98SDaniel Drake 	{ } /* end */
28750fb67e98SDaniel Drake };
28760fb67e98SDaniel Drake 
287795a618bdSEinar Rünkaru static struct hda_verb cxt5066_init_verbs_vostro[] = {
287895a618bdSEinar Rünkaru 	/* Port A: headphones */
287995a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
288095a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
288195a618bdSEinar Rünkaru 
288295a618bdSEinar Rünkaru 	/* Port B: external microphone */
288395a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
288495a618bdSEinar Rünkaru 
288595a618bdSEinar Rünkaru 	/* Port C: unused */
288695a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
288795a618bdSEinar Rünkaru 
288895a618bdSEinar Rünkaru 	/* Port D: unused */
288995a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
289095a618bdSEinar Rünkaru 
289195a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
289295a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
289395a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
289495a618bdSEinar Rünkaru 
289595a618bdSEinar Rünkaru 	/* Port F: unused */
289695a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
289795a618bdSEinar Rünkaru 
289895a618bdSEinar Rünkaru 	/* Port G: internal speakers */
289995a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
290095a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
290195a618bdSEinar Rünkaru 
290295a618bdSEinar Rünkaru 	/* DAC1 */
290395a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
290495a618bdSEinar Rünkaru 
290595a618bdSEinar Rünkaru 	/* DAC2: unused */
290695a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
290795a618bdSEinar Rünkaru 
290895a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
290995a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
291095a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
291195a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
291295a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
291395a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
291495a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
291595a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
291695a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
291795a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
291895a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
291995a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
292095a618bdSEinar Rünkaru 
292195a618bdSEinar Rünkaru 	/* Digital microphone port */
292295a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
292395a618bdSEinar Rünkaru 
292495a618bdSEinar Rünkaru 	/* Audio input selectors */
292595a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
292695a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
292795a618bdSEinar Rünkaru 
292895a618bdSEinar Rünkaru 	/* Disable SPDIF */
292995a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
293095a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
293195a618bdSEinar Rünkaru 
293295a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
293395a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
293495a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
293595a618bdSEinar Rünkaru 	{ } /* end */
293695a618bdSEinar Rünkaru };
293795a618bdSEinar Rünkaru 
2938cfd3d8dcSGreg Alexander static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2939cfd3d8dcSGreg Alexander 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2940cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2941cfd3d8dcSGreg Alexander 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2942cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2943cfd3d8dcSGreg Alexander 
2944cfd3d8dcSGreg Alexander 	/* Speakers  */
2945cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2946cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2947cfd3d8dcSGreg Alexander 
2948cfd3d8dcSGreg Alexander 	/* HP, Amp  */
2949cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2950cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2951cfd3d8dcSGreg Alexander 
2952cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2953cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2954cfd3d8dcSGreg Alexander 
2955cfd3d8dcSGreg Alexander 	/* DAC1 */
2956cfd3d8dcSGreg Alexander 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2957cfd3d8dcSGreg Alexander 
2958cfd3d8dcSGreg Alexander 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2959cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2960cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2961cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2962cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2963cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2964cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2965cfd3d8dcSGreg Alexander 
2966cfd3d8dcSGreg Alexander 	/* Audio input selector */
2967cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2968cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2969cfd3d8dcSGreg Alexander 
2970cfd3d8dcSGreg Alexander 	/* SPDIF route: PCM */
2971cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2972cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2973cfd3d8dcSGreg Alexander 
2974cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2975cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2976cfd3d8dcSGreg Alexander 
2977cfd3d8dcSGreg Alexander 	/* internal microphone */
297828c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2979cfd3d8dcSGreg Alexander 
2980cfd3d8dcSGreg Alexander 	/* EAPD */
2981cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2982cfd3d8dcSGreg Alexander 
2983cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2984cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2985cfd3d8dcSGreg Alexander 	{ } /* end */
2986cfd3d8dcSGreg Alexander };
2987cfd3d8dcSGreg Alexander 
29887b2bfdbcSJens Taprogge static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
29897b2bfdbcSJens Taprogge 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
29907b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
29917b2bfdbcSJens Taprogge 
29927b2bfdbcSJens Taprogge 	/* Port G: internal speakers  */
29937b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29947b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29957b2bfdbcSJens Taprogge 
29967b2bfdbcSJens Taprogge 	/* Port A: HP, Amp  */
29977b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29987b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29997b2bfdbcSJens Taprogge 
30007b2bfdbcSJens Taprogge 	/* Port B: Mic Dock */
30017b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
30027b2bfdbcSJens Taprogge 
30037b2bfdbcSJens Taprogge 	/* Port C: Mic */
30047b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
30057b2bfdbcSJens Taprogge 
30067b2bfdbcSJens Taprogge 	/* Port D: HP Dock, Amp */
30077b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
30087b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
30097b2bfdbcSJens Taprogge 
30107b2bfdbcSJens Taprogge 	/* DAC1 */
30117b2bfdbcSJens Taprogge 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
30127b2bfdbcSJens Taprogge 
30137b2bfdbcSJens Taprogge 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
30147b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
30157b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
30167b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
30177b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
30187b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
30197b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
30207b2bfdbcSJens Taprogge 
30217b2bfdbcSJens Taprogge 	/* Audio input selector */
30227b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
30237b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
30247b2bfdbcSJens Taprogge 
30257b2bfdbcSJens Taprogge 	/* SPDIF route: PCM */
30267b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
30277b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
30287b2bfdbcSJens Taprogge 
30297b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
30307b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
30317b2bfdbcSJens Taprogge 
30327b2bfdbcSJens Taprogge 	/* internal microphone */
303328c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
30347b2bfdbcSJens Taprogge 
30357b2bfdbcSJens Taprogge 	/* EAPD */
30367b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
30377b2bfdbcSJens Taprogge 
30387b2bfdbcSJens Taprogge 	/* enable unsolicited events for Port A, B, C and D */
30397b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
30407b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
30417b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
30427b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
30437b2bfdbcSJens Taprogge 	{ } /* end */
30447b2bfdbcSJens Taprogge };
30457b2bfdbcSJens Taprogge 
30460fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
30470fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
30480fb67e98SDaniel Drake 	{ } /* end */
30490fb67e98SDaniel Drake };
30500fb67e98SDaniel Drake 
3051048e78a5SDavid Henningsson 
3052048e78a5SDavid Henningsson static struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
3053048e78a5SDavid Henningsson 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3054048e78a5SDavid Henningsson 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3055048e78a5SDavid Henningsson 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3056048e78a5SDavid Henningsson 	{ } /* end */
3057048e78a5SDavid Henningsson };
3058048e78a5SDavid Henningsson 
30590fb67e98SDaniel Drake /* initialize jack-sensing, too */
30600fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
30610fb67e98SDaniel Drake {
30620fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
30630fb67e98SDaniel Drake 	conexant_init(codec);
30640fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
30650fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
306602b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
30670fb67e98SDaniel Drake 	}
3068c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
30690fb67e98SDaniel Drake 	return 0;
30700fb67e98SDaniel Drake }
30710fb67e98SDaniel Drake 
307275f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec)
307375f8991dSDaniel Drake {
3074c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
307575f8991dSDaniel Drake 	snd_printdd("CXT5066: init\n");
307675f8991dSDaniel Drake 	conexant_init(codec);
307775f8991dSDaniel Drake 	cxt5066_hp_automute(codec);
3078c4cfe66cSDaniel Drake 	if (!spec->dc_enable) {
3079c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
308075f8991dSDaniel Drake 		cxt5066_olpc_automic(codec);
3081c4cfe66cSDaniel Drake 	} else {
3082c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
3083c4cfe66cSDaniel Drake 	}
308475f8991dSDaniel Drake 	return 0;
308575f8991dSDaniel Drake }
308675f8991dSDaniel Drake 
30870fb67e98SDaniel Drake enum {
30880fb67e98SDaniel Drake 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
30890fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
30900fb67e98SDaniel Drake 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
30911feba3b7SDavid Henningsson 	CXT5066_DELL_VOSTRO,	/* Dell Vostro 1015i */
3092cfd3d8dcSGreg Alexander 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
30937b2bfdbcSJens Taprogge 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
3094a1d6906eSDavid Henningsson 	CXT5066_ASUS,		/* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
3095048e78a5SDavid Henningsson 	CXT5066_HP_LAPTOP,      /* HP Laptop */
30960fb67e98SDaniel Drake 	CXT5066_MODELS
30970fb67e98SDaniel Drake };
30980fb67e98SDaniel Drake 
3099ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = {
31000fb67e98SDaniel Drake 	[CXT5066_LAPTOP]	= "laptop",
31010fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
31020fb67e98SDaniel Drake 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
31031feba3b7SDavid Henningsson 	[CXT5066_DELL_VOSTRO]	= "dell-vostro",
3104cfd3d8dcSGreg Alexander 	[CXT5066_IDEAPAD]	= "ideapad",
31057b2bfdbcSJens Taprogge 	[CXT5066_THINKPAD]	= "thinkpad",
3106a1d6906eSDavid Henningsson 	[CXT5066_ASUS]		= "asus",
3107048e78a5SDavid Henningsson 	[CXT5066_HP_LAPTOP]	= "hp-laptop",
31080fb67e98SDaniel Drake };
31090fb67e98SDaniel Drake 
31100fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
311100cd0bb7STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
31121feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
31138a96b1e0SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3114ca6cd851SDaniel T Chen 	SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
31151feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
3116231f50bcSAnisse Astier 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3117*ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3118*ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
3119048e78a5SDavid Henningsson 	SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3120f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
3121a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
3122f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
31232ca9cac9SAnisse Astier 	SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3124c5366681SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
31254442dd46SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
31265637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
31275637edb2SDavid Henningsson 		      CXT5066_LAPTOP),
31285637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
31294d155641STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3130ef61d4e6SManoj Iyer 	SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
313119593875SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
31327b2bfdbcSJens Taprogge  	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3133a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
313422f21d51SDavid Henningsson 	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
31350fb67e98SDaniel Drake 	{}
31360fb67e98SDaniel Drake };
31370fb67e98SDaniel Drake 
31380fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
31390fb67e98SDaniel Drake {
31400fb67e98SDaniel Drake 	struct conexant_spec *spec;
31410fb67e98SDaniel Drake 	int board_config;
31420fb67e98SDaniel Drake 
31430fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
31440fb67e98SDaniel Drake 	if (!spec)
31450fb67e98SDaniel Drake 		return -ENOMEM;
31460fb67e98SDaniel Drake 	codec->spec = spec;
31470fb67e98SDaniel Drake 
31480fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
314975f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
31500fb67e98SDaniel Drake 
31510fb67e98SDaniel Drake 	spec->dell_automute = 0;
31520fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
31530fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
31540fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
3155f6a2491cSAndy Robinson 	conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3156f6a2491cSAndy Robinson 	    ARRAY_SIZE(cxt5066_digout_pin_nids));
31570fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
31580fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
31590fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
31600fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
31610fb67e98SDaniel Drake 
31620fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
31630fb67e98SDaniel Drake 
31640fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
31650fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
31660fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
31670fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
31680fb67e98SDaniel Drake 	spec->cur_adc = 0;
31690fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
31700fb67e98SDaniel Drake 
31713507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
31723507e2a8STakashi Iwai 
31730fb67e98SDaniel Drake 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
31740fb67e98SDaniel Drake 						  cxt5066_models, cxt5066_cfg_tbl);
31750fb67e98SDaniel Drake 	switch (board_config) {
31760fb67e98SDaniel Drake 	default:
31770fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
31780fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31790fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31800fb67e98SDaniel Drake 		break;
31810fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
31820fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31830fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31840fb67e98SDaniel Drake 
31850fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
31860fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
31870fb67e98SDaniel Drake 		spec->num_init_verbs++;
31880fb67e98SDaniel Drake 		spec->dell_automute = 1;
31890fb67e98SDaniel Drake 		break;
3190a1d6906eSDavid Henningsson 	case CXT5066_ASUS:
3191048e78a5SDavid Henningsson 	case CXT5066_HP_LAPTOP:
3192048e78a5SDavid Henningsson 		codec->patch_ops.init = cxt5066_init;
319302b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3194048e78a5SDavid Henningsson 		spec->init_verbs[spec->num_init_verbs] =
3195048e78a5SDavid Henningsson 			cxt5066_init_verbs_hp_laptop;
3196048e78a5SDavid Henningsson 		spec->num_init_verbs++;
3197a1d6906eSDavid Henningsson 		spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3198a1d6906eSDavid Henningsson 		spec->asus = board_config == CXT5066_ASUS;
3199048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3200048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3201048e78a5SDavid Henningsson 		/* no S/PDIF out */
3202f6a2491cSAndy Robinson 		if (board_config == CXT5066_HP_LAPTOP)
3203048e78a5SDavid Henningsson 			spec->multiout.dig_out_nid = 0;
3204048e78a5SDavid Henningsson 		/* input source automatically selected */
3205048e78a5SDavid Henningsson 		spec->input_mux = NULL;
3206048e78a5SDavid Henningsson 		spec->port_d_mode = 0;
3207048e78a5SDavid Henningsson 		spec->mic_boost = 3; /* default 30dB gain */
3208048e78a5SDavid Henningsson 		break;
3209048e78a5SDavid Henningsson 
32100fb67e98SDaniel Drake 	case CXT5066_OLPC_XO_1_5:
321175f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_olpc_init;
321275f8991dSDaniel Drake 		codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
32130fb67e98SDaniel Drake 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
32140fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3215c4cfe66cSDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
32160fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
32170fb67e98SDaniel Drake 		spec->port_d_mode = 0;
3218c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
32190fb67e98SDaniel Drake 
32200fb67e98SDaniel Drake 		/* no S/PDIF out */
32210fb67e98SDaniel Drake 		spec->multiout.dig_out_nid = 0;
32220fb67e98SDaniel Drake 
32230fb67e98SDaniel Drake 		/* input source automatically selected */
32240fb67e98SDaniel Drake 		spec->input_mux = NULL;
322575f8991dSDaniel Drake 
322675f8991dSDaniel Drake 		/* our capture hooks which allow us to turn on the microphone LED
322775f8991dSDaniel Drake 		 * at the right time */
322875f8991dSDaniel Drake 		spec->capture_prepare = cxt5066_olpc_capture_prepare;
322975f8991dSDaniel Drake 		spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
32300fb67e98SDaniel Drake 		break;
32311feba3b7SDavid Henningsson 	case CXT5066_DELL_VOSTRO:
323275f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
323302b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
323495a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
323595a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
323695a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3237254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
323895a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
3239254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
3240c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
324195a618bdSEinar Rünkaru 
324295a618bdSEinar Rünkaru 		/* no S/PDIF out */
324395a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
324495a618bdSEinar Rünkaru 
324595a618bdSEinar Rünkaru 		/* input source automatically selected */
324695a618bdSEinar Rünkaru 		spec->input_mux = NULL;
324795a618bdSEinar Rünkaru 		break;
3248cfd3d8dcSGreg Alexander 	case CXT5066_IDEAPAD:
3249cfd3d8dcSGreg Alexander 		codec->patch_ops.init = cxt5066_init;
325002b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3251cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3252cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3253cfd3d8dcSGreg Alexander 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3254cfd3d8dcSGreg Alexander 		spec->port_d_mode = 0;
3255cfd3d8dcSGreg Alexander 		spec->ideapad = 1;
3256cfd3d8dcSGreg Alexander 		spec->mic_boost = 2;	/* default 20dB gain */
3257cfd3d8dcSGreg Alexander 
3258cfd3d8dcSGreg Alexander 		/* no S/PDIF out */
3259cfd3d8dcSGreg Alexander 		spec->multiout.dig_out_nid = 0;
3260cfd3d8dcSGreg Alexander 
3261cfd3d8dcSGreg Alexander 		/* input source automatically selected */
3262cfd3d8dcSGreg Alexander 		spec->input_mux = NULL;
3263cfd3d8dcSGreg Alexander 		break;
32647b2bfdbcSJens Taprogge 	case CXT5066_THINKPAD:
32657b2bfdbcSJens Taprogge 		codec->patch_ops.init = cxt5066_init;
326602b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
32677b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
32687b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
32697b2bfdbcSJens Taprogge 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
32707b2bfdbcSJens Taprogge 		spec->thinkpad = 1;
32717b2bfdbcSJens Taprogge 		spec->port_d_mode = PIN_OUT;
32727b2bfdbcSJens Taprogge 		spec->mic_boost = 2;	/* default 20dB gain */
32737b2bfdbcSJens Taprogge 
32747b2bfdbcSJens Taprogge 		/* no S/PDIF out */
32757b2bfdbcSJens Taprogge 		spec->multiout.dig_out_nid = 0;
32767b2bfdbcSJens Taprogge 
32777b2bfdbcSJens Taprogge 		/* input source automatically selected */
32787b2bfdbcSJens Taprogge 		spec->input_mux = NULL;
32797b2bfdbcSJens Taprogge 		break;
32800fb67e98SDaniel Drake 	}
32810fb67e98SDaniel Drake 
32823507e2a8STakashi Iwai 	if (spec->beep_amp)
32833507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
32843507e2a8STakashi Iwai 
32850fb67e98SDaniel Drake 	return 0;
32860fb67e98SDaniel Drake }
3287461e2c78STakashi Iwai 
3288461e2c78STakashi Iwai /*
3289f2e5731dSTakashi Iwai  * Automatic parser for CX20641 & co
3290f2e5731dSTakashi Iwai  */
3291f2e5731dSTakashi Iwai 
3292f2e5731dSTakashi Iwai static hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3293f2e5731dSTakashi Iwai 
3294f2e5731dSTakashi Iwai /* get the connection index of @nid in the widget @mux */
3295f2e5731dSTakashi Iwai static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3296f2e5731dSTakashi Iwai 				hda_nid_t nid)
3297f2e5731dSTakashi Iwai {
3298f2e5731dSTakashi Iwai 	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3299f2e5731dSTakashi Iwai 	int i, nums;
3300f2e5731dSTakashi Iwai 
3301f2e5731dSTakashi Iwai 	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3302f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++)
3303f2e5731dSTakashi Iwai 		if (conn[i] == nid)
3304f2e5731dSTakashi Iwai 			return i;
3305f2e5731dSTakashi Iwai 	return -1;
3306f2e5731dSTakashi Iwai }
3307f2e5731dSTakashi Iwai 
3308f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list.
3309f2e5731dSTakashi Iwai  * Return the nid if found and reduce the DAC list, or return zero if
3310f2e5731dSTakashi Iwai  * not found
3311f2e5731dSTakashi Iwai  */
3312f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3313f2e5731dSTakashi Iwai 				    hda_nid_t *dacs, int *num_dacs)
3314f2e5731dSTakashi Iwai {
3315f2e5731dSTakashi Iwai 	int i, nums = *num_dacs;
3316f2e5731dSTakashi Iwai 	hda_nid_t ret = 0;
3317f2e5731dSTakashi Iwai 
3318f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3319f2e5731dSTakashi Iwai 		if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3320f2e5731dSTakashi Iwai 			ret = dacs[i];
3321f2e5731dSTakashi Iwai 			break;
3322f2e5731dSTakashi Iwai 		}
3323f2e5731dSTakashi Iwai 	}
3324f2e5731dSTakashi Iwai 	if (!ret)
3325f2e5731dSTakashi Iwai 		return 0;
3326f2e5731dSTakashi Iwai 	if (--nums > 0)
3327f2e5731dSTakashi Iwai 		memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3328f2e5731dSTakashi Iwai 	*num_dacs = nums;
3329f2e5731dSTakashi Iwai 	return ret;
3330f2e5731dSTakashi Iwai }
3331f2e5731dSTakashi Iwai 
3332f2e5731dSTakashi Iwai #define MAX_AUTO_DACS	5
3333f2e5731dSTakashi Iwai 
3334f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */
3335f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3336f2e5731dSTakashi Iwai {
3337f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3338f2e5731dSTakashi Iwai 	int nums = 0;
3339f2e5731dSTakashi Iwai 
3340f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3341f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3342f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3343f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3344f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3345f2e5731dSTakashi Iwai 			dacs[nums++] = nid;
3346f2e5731dSTakashi Iwai 			if (nums >= MAX_AUTO_DACS)
3347f2e5731dSTakashi Iwai 				break;
3348f2e5731dSTakashi Iwai 		}
3349f2e5731dSTakashi Iwai 	}
3350f2e5731dSTakashi Iwai 	return nums;
3351f2e5731dSTakashi Iwai }
3352f2e5731dSTakashi Iwai 
3353f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */
3354f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3355f2e5731dSTakashi Iwai 			      int num_pins, hda_nid_t *dacs, int *rest,
3356f2e5731dSTakashi Iwai 			      struct pin_dac_pair *filled, int type)
3357f2e5731dSTakashi Iwai {
3358f2e5731dSTakashi Iwai 	int i, nums;
3359f2e5731dSTakashi Iwai 
3360f2e5731dSTakashi Iwai 	nums = 0;
3361f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3362f2e5731dSTakashi Iwai 		filled[nums].pin = pins[i];
3363f2e5731dSTakashi Iwai 		filled[nums].type = type;
3364f2e5731dSTakashi Iwai 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3365f2e5731dSTakashi Iwai 		nums++;
3366f2e5731dSTakashi Iwai 	}
3367f2e5731dSTakashi Iwai 	return nums;
3368f2e5731dSTakashi Iwai }
3369f2e5731dSTakashi Iwai 
3370f2e5731dSTakashi Iwai /* parse analog output paths */
3371f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec)
3372f2e5731dSTakashi Iwai {
3373f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3374f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3375f2e5731dSTakashi Iwai 	hda_nid_t dacs[MAX_AUTO_DACS];
3376f2e5731dSTakashi Iwai 	int i, j, nums, rest;
3377f2e5731dSTakashi Iwai 
3378f2e5731dSTakashi Iwai 	rest = fill_cx_auto_dacs(codec, dacs);
3379f2e5731dSTakashi Iwai 	/* parse all analog output pins */
3380f2e5731dSTakashi Iwai 	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3381f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info,
3382f2e5731dSTakashi Iwai 				  AUTO_PIN_LINE_OUT);
3383f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3384f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3385f2e5731dSTakashi Iwai 				  AUTO_PIN_HP_OUT);
3386f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3387f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3388f2e5731dSTakashi Iwai 				  AUTO_PIN_SPEAKER_OUT);
3389f2e5731dSTakashi Iwai 	spec->dac_info_filled = nums;
3390f2e5731dSTakashi Iwai 	/* fill multiout struct */
3391f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3392f2e5731dSTakashi Iwai 		hda_nid_t dac = spec->dac_info[i].dac;
3393f2e5731dSTakashi Iwai 		if (!dac)
3394f2e5731dSTakashi Iwai 			continue;
3395f2e5731dSTakashi Iwai 		switch (spec->dac_info[i].type) {
3396f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
3397f2e5731dSTakashi Iwai 			spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3398f2e5731dSTakashi Iwai 			spec->multiout.num_dacs++;
3399f2e5731dSTakashi Iwai 			break;
3400f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
3401f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
3402f2e5731dSTakashi Iwai 			if (!spec->multiout.hp_nid) {
3403f2e5731dSTakashi Iwai 				spec->multiout.hp_nid = dac;
3404f2e5731dSTakashi Iwai 				break;
3405f2e5731dSTakashi Iwai 			}
3406f2e5731dSTakashi Iwai 			for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3407f2e5731dSTakashi Iwai 				if (!spec->multiout.extra_out_nid[j]) {
3408f2e5731dSTakashi Iwai 					spec->multiout.extra_out_nid[j] = dac;
3409f2e5731dSTakashi Iwai 					break;
3410f2e5731dSTakashi Iwai 				}
3411f2e5731dSTakashi Iwai 			break;
3412f2e5731dSTakashi Iwai 		}
3413f2e5731dSTakashi Iwai 	}
3414f2e5731dSTakashi Iwai 	spec->multiout.dac_nids = spec->private_dac_nids;
341589724958SDavid Henningsson 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3416f2e5731dSTakashi Iwai 
3417f2e5731dSTakashi Iwai 	if (cfg->hp_outs > 0)
3418f2e5731dSTakashi Iwai 		spec->auto_mute = 1;
3419f2e5731dSTakashi Iwai 	spec->vmaster_nid = spec->private_dac_nids[0];
3420f2e5731dSTakashi Iwai }
3421f2e5731dSTakashi Iwai 
3422f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */
3423f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec)
3424f2e5731dSTakashi Iwai {
3425f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3426f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3427f2e5731dSTakashi Iwai 	int i, present;
3428f2e5731dSTakashi Iwai 
3429f2e5731dSTakashi Iwai 	if (!spec->auto_mute)
3430f2e5731dSTakashi Iwai 		return;
3431f2e5731dSTakashi Iwai 	present = 0;
3432f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++) {
3433f2e5731dSTakashi Iwai 		if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3434f2e5731dSTakashi Iwai 			present = 1;
3435f2e5731dSTakashi Iwai 			break;
3436f2e5731dSTakashi Iwai 		}
3437f2e5731dSTakashi Iwai 	}
3438f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->line_outs; i++) {
3439f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3440f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
3441f2e5731dSTakashi Iwai 				    present ? 0 : PIN_OUT);
3442f2e5731dSTakashi Iwai 	}
3443fbb5bb56STakashi Iwai 	for (i = 0; !present && i < cfg->line_outs; i++)
3444fbb5bb56STakashi Iwai 		if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3445fbb5bb56STakashi Iwai 			present = 1;
3446f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->speaker_outs; i++) {
3447f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3448f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
3449f2e5731dSTakashi Iwai 				    present ? 0 : PIN_OUT);
3450f2e5731dSTakashi Iwai 	}
3451f2e5731dSTakashi Iwai }
3452f2e5731dSTakashi Iwai 
3453f2e5731dSTakashi Iwai /* automatic switch internal and external mic */
3454f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec)
3455f2e5731dSTakashi Iwai {
3456f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3457f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3458f2e5731dSTakashi Iwai 	struct hda_input_mux *imux = &spec->private_imux;
3459f2e5731dSTakashi Iwai 	int ext_idx = spec->auto_mic_ext;
3460f2e5731dSTakashi Iwai 
3461f2e5731dSTakashi Iwai 	if (!spec->auto_mic)
3462f2e5731dSTakashi Iwai 		return;
3463f2e5731dSTakashi Iwai 	if (snd_hda_jack_detect(codec, cfg->inputs[ext_idx].pin)) {
3464f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3465f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL,
3466f2e5731dSTakashi Iwai 				    imux->items[ext_idx].index);
3467f2e5731dSTakashi Iwai 	} else {
3468f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3469f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL,
3470f2e5731dSTakashi Iwai 				    imux->items[!ext_idx].index);
3471f2e5731dSTakashi Iwai 	}
3472f2e5731dSTakashi Iwai }
3473f2e5731dSTakashi Iwai 
3474f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3475f2e5731dSTakashi Iwai {
3476f2e5731dSTakashi Iwai 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3477f2e5731dSTakashi Iwai 	switch (res >> 26) {
3478f2e5731dSTakashi Iwai 	case CONEXANT_HP_EVENT:
3479f2e5731dSTakashi Iwai 		cx_auto_hp_automute(codec);
3480f2e5731dSTakashi Iwai 		conexant_report_jack(codec, nid);
3481f2e5731dSTakashi Iwai 		break;
3482f2e5731dSTakashi Iwai 	case CONEXANT_MIC_EVENT:
3483f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
3484f2e5731dSTakashi Iwai 		conexant_report_jack(codec, nid);
3485f2e5731dSTakashi Iwai 		break;
3486f2e5731dSTakashi Iwai 	}
3487f2e5731dSTakashi Iwai }
3488f2e5731dSTakashi Iwai 
3489f2e5731dSTakashi Iwai /* return true if it's an internal-mic pin */
3490f2e5731dSTakashi Iwai static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3491f2e5731dSTakashi Iwai {
3492f2e5731dSTakashi Iwai 	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3493f2e5731dSTakashi Iwai 	return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
349499ae28beSTakashi Iwai 		snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
3495f2e5731dSTakashi Iwai }
3496f2e5731dSTakashi Iwai 
3497f2e5731dSTakashi Iwai /* return true if it's an external-mic pin */
3498f2e5731dSTakashi Iwai static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3499f2e5731dSTakashi Iwai {
3500f2e5731dSTakashi Iwai 	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3501f2e5731dSTakashi Iwai 	return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
3502f68b3b29STakashi Iwai 		snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3503f68b3b29STakashi Iwai 		(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
3504f2e5731dSTakashi Iwai }
3505f2e5731dSTakashi Iwai 
3506f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching;
3507f2e5731dSTakashi Iwai  * auto-mic is enabled only when one int-mic and one-ext mic exist
3508f2e5731dSTakashi Iwai  */
3509f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec)
3510f2e5731dSTakashi Iwai {
3511f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3512f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3513f2e5731dSTakashi Iwai 
3514f2e5731dSTakashi Iwai 	if (is_ext_mic(codec, cfg->inputs[0].pin) &&
3515f2e5731dSTakashi Iwai 	    is_int_mic(codec, cfg->inputs[1].pin)) {
3516f2e5731dSTakashi Iwai 		spec->auto_mic = 1;
3517f2e5731dSTakashi Iwai 		spec->auto_mic_ext = 1;
3518f2e5731dSTakashi Iwai 		return;
3519f2e5731dSTakashi Iwai 	}
3520f2e5731dSTakashi Iwai 	if (is_int_mic(codec, cfg->inputs[1].pin) &&
3521f2e5731dSTakashi Iwai 	    is_ext_mic(codec, cfg->inputs[0].pin)) {
3522f2e5731dSTakashi Iwai 		spec->auto_mic = 1;
3523f2e5731dSTakashi Iwai 		spec->auto_mic_ext = 0;
3524f2e5731dSTakashi Iwai 		return;
3525f2e5731dSTakashi Iwai 	}
3526f2e5731dSTakashi Iwai }
3527f2e5731dSTakashi Iwai 
3528f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec)
3529f2e5731dSTakashi Iwai {
3530f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3531f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3532f2e5731dSTakashi Iwai 	struct hda_input_mux *imux;
3533f2e5731dSTakashi Iwai 	int i;
3534f2e5731dSTakashi Iwai 
3535f2e5731dSTakashi Iwai 	imux = &spec->private_imux;
3536f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3537f2e5731dSTakashi Iwai 		int idx = get_connection_index(codec, spec->adc_nids[0],
3538f2e5731dSTakashi Iwai 					       cfg->inputs[i].pin);
3539f2e5731dSTakashi Iwai 		if (idx >= 0) {
3540f2e5731dSTakashi Iwai 			const char *label;
3541f2e5731dSTakashi Iwai 			label = hda_get_autocfg_input_label(codec, cfg, i);
3542f2e5731dSTakashi Iwai 			snd_hda_add_imux_item(imux, label, idx, NULL);
3543f2e5731dSTakashi Iwai 		}
3544f2e5731dSTakashi Iwai 	}
3545f2e5731dSTakashi Iwai 	if (imux->num_items == 2 && cfg->num_inputs == 2)
3546f2e5731dSTakashi Iwai 		cx_auto_check_auto_mic(codec);
3547f2e5731dSTakashi Iwai 	if (imux->num_items > 1 && !spec->auto_mic)
3548f2e5731dSTakashi Iwai 		spec->input_mux = imux;
3549f2e5731dSTakashi Iwai }
3550f2e5731dSTakashi Iwai 
3551f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */
3552f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3553f2e5731dSTakashi Iwai {
3554f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3555f2e5731dSTakashi Iwai 
3556f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3557f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3558f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3559f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3560f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3561f2e5731dSTakashi Iwai 			if (get_connection_index(codec, nid, pin) >= 0)
3562f2e5731dSTakashi Iwai 				return nid;
3563f2e5731dSTakashi Iwai 		}
3564f2e5731dSTakashi Iwai 	}
3565f2e5731dSTakashi Iwai 	return 0;
3566f2e5731dSTakashi Iwai }
3567f2e5731dSTakashi Iwai 
3568f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec)
3569f2e5731dSTakashi Iwai {
3570f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3571f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3572f2e5731dSTakashi Iwai 	hda_nid_t nid;
3573f2e5731dSTakashi Iwai 
3574f2e5731dSTakashi Iwai 	if (cfg->dig_outs &&
3575f2e5731dSTakashi Iwai 	    snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3576f2e5731dSTakashi Iwai 		spec->multiout.dig_out_nid = nid;
3577f2e5731dSTakashi Iwai 	if (cfg->dig_in_pin)
3578f2e5731dSTakashi Iwai 		spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3579f2e5731dSTakashi Iwai }
3580f2e5731dSTakashi Iwai 
3581f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
3582f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec)
3583f2e5731dSTakashi Iwai {
3584f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3585f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3586f2e5731dSTakashi Iwai 
3587f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3588f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++)
3589f2e5731dSTakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3590f2e5731dSTakashi Iwai 			set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3591f2e5731dSTakashi Iwai 			break;
3592f2e5731dSTakashi Iwai 		}
3593f2e5731dSTakashi Iwai }
3594f2e5731dSTakashi Iwai #else
3595f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec)
3596f2e5731dSTakashi Iwai #endif
3597f2e5731dSTakashi Iwai 
3598f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec)
3599f2e5731dSTakashi Iwai {
3600f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3601f2e5731dSTakashi Iwai 	int err;
3602f2e5731dSTakashi Iwai 
3603f2e5731dSTakashi Iwai 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3604f2e5731dSTakashi Iwai 	if (err < 0)
3605f2e5731dSTakashi Iwai 		return err;
3606f2e5731dSTakashi Iwai 
3607f2e5731dSTakashi Iwai 	cx_auto_parse_output(codec);
3608f2e5731dSTakashi Iwai 	cx_auto_parse_input(codec);
3609f2e5731dSTakashi Iwai 	cx_auto_parse_digital(codec);
3610f2e5731dSTakashi Iwai 	cx_auto_parse_beep(codec);
3611f2e5731dSTakashi Iwai 	return 0;
3612f2e5731dSTakashi Iwai }
3613f2e5731dSTakashi Iwai 
3614f2e5731dSTakashi Iwai static void cx_auto_turn_on_eapd(struct hda_codec *codec, int num_pins,
3615f2e5731dSTakashi Iwai 				 hda_nid_t *pins)
3616f2e5731dSTakashi Iwai {
3617f2e5731dSTakashi Iwai 	int i;
3618f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3619f2e5731dSTakashi Iwai 		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3620f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, pins[i], 0,
3621f2e5731dSTakashi Iwai 					    AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3622f2e5731dSTakashi Iwai 	}
3623f2e5731dSTakashi Iwai }
3624f2e5731dSTakashi Iwai 
3625f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3626f2e5731dSTakashi Iwai 			      hda_nid_t src)
3627f2e5731dSTakashi Iwai {
3628f2e5731dSTakashi Iwai 	int idx = get_connection_index(codec, pin, src);
3629f2e5731dSTakashi Iwai 	if (idx >= 0)
3630f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, pin, 0,
3631f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL, idx);
3632f2e5731dSTakashi Iwai }
3633f2e5731dSTakashi Iwai 
3634f2e5731dSTakashi Iwai static void cx_auto_init_output(struct hda_codec *codec)
3635f2e5731dSTakashi Iwai {
3636f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3637f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3638f2e5731dSTakashi Iwai 	hda_nid_t nid;
3639f2e5731dSTakashi Iwai 	int i;
3640f2e5731dSTakashi Iwai 
3641f2e5731dSTakashi Iwai 	for (i = 0; i < spec->multiout.num_dacs; i++)
3642f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
3643f2e5731dSTakashi Iwai 				    AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3644f2e5731dSTakashi Iwai 
3645f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++)
3646f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3647f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
3648f2e5731dSTakashi Iwai 	if (spec->auto_mute) {
3649f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->hp_outs; i++) {
3650f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3651f2e5731dSTakashi Iwai 				    AC_VERB_SET_UNSOLICITED_ENABLE,
3652f2e5731dSTakashi Iwai 				    AC_USRSP_EN | CONEXANT_HP_EVENT);
3653f2e5731dSTakashi Iwai 		}
3654f2e5731dSTakashi Iwai 		cx_auto_hp_automute(codec);
3655f2e5731dSTakashi Iwai 	} else {
3656f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->line_outs; i++)
3657f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3658f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3659f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->speaker_outs; i++)
3660f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3661f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3662f2e5731dSTakashi Iwai 	}
3663f2e5731dSTakashi Iwai 
3664f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
3665f2e5731dSTakashi Iwai 		nid = spec->dac_info[i].dac;
3666f2e5731dSTakashi Iwai 		if (!nid)
3667f2e5731dSTakashi Iwai 			nid = spec->multiout.dac_nids[0];
3668f2e5731dSTakashi Iwai 		select_connection(codec, spec->dac_info[i].pin, nid);
3669f2e5731dSTakashi Iwai 	}
3670f2e5731dSTakashi Iwai 
3671f2e5731dSTakashi Iwai 	/* turn on EAPD */
3672f2e5731dSTakashi Iwai 	cx_auto_turn_on_eapd(codec, cfg->line_outs, cfg->line_out_pins);
3673f2e5731dSTakashi Iwai 	cx_auto_turn_on_eapd(codec, cfg->hp_outs, cfg->hp_pins);
3674f2e5731dSTakashi Iwai 	cx_auto_turn_on_eapd(codec, cfg->speaker_outs, cfg->speaker_pins);
3675f2e5731dSTakashi Iwai }
3676f2e5731dSTakashi Iwai 
3677f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec)
3678f2e5731dSTakashi Iwai {
3679f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3680f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3681f2e5731dSTakashi Iwai 	int i;
3682f2e5731dSTakashi Iwai 
3683f2e5731dSTakashi Iwai 	for (i = 0; i < spec->num_adc_nids; i++)
3684f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3685f2e5731dSTakashi Iwai 				    AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0));
3686f2e5731dSTakashi Iwai 
3687f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3688f2e5731dSTakashi Iwai 		unsigned int type;
3689f2e5731dSTakashi Iwai 		if (cfg->inputs[i].type == AUTO_PIN_MIC)
3690f2e5731dSTakashi Iwai 			type = PIN_VREF80;
3691f2e5731dSTakashi Iwai 		else
3692f2e5731dSTakashi Iwai 			type = PIN_IN;
3693f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3694f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3695f2e5731dSTakashi Iwai 	}
3696f2e5731dSTakashi Iwai 
3697f2e5731dSTakashi Iwai 	if (spec->auto_mic) {
3698f2e5731dSTakashi Iwai 		int ext_idx = spec->auto_mic_ext;
3699f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3700f2e5731dSTakashi Iwai 				    AC_VERB_SET_UNSOLICITED_ENABLE,
3701f2e5731dSTakashi Iwai 				    AC_USRSP_EN | CONEXANT_MIC_EVENT);
3702f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
3703f2e5731dSTakashi Iwai 	} else {
3704f2e5731dSTakashi Iwai 		for (i = 0; i < spec->num_adc_nids; i++) {
3705f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3706f2e5731dSTakashi Iwai 					    AC_VERB_SET_CONNECT_SEL,
3707f2e5731dSTakashi Iwai 					    spec->private_imux.items[0].index);
3708f2e5731dSTakashi Iwai 		}
3709f2e5731dSTakashi Iwai 	}
3710f2e5731dSTakashi Iwai }
3711f2e5731dSTakashi Iwai 
3712f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec)
3713f2e5731dSTakashi Iwai {
3714f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3715f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3716f2e5731dSTakashi Iwai 
3717f2e5731dSTakashi Iwai 	if (spec->multiout.dig_out_nid)
3718f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3719f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3720f2e5731dSTakashi Iwai 	if (spec->dig_in_nid)
3721f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3722f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3723f2e5731dSTakashi Iwai }
3724f2e5731dSTakashi Iwai 
3725f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec)
3726f2e5731dSTakashi Iwai {
3727f2e5731dSTakashi Iwai 	/*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3728f2e5731dSTakashi Iwai 	cx_auto_init_output(codec);
3729f2e5731dSTakashi Iwai 	cx_auto_init_input(codec);
3730f2e5731dSTakashi Iwai 	cx_auto_init_digital(codec);
3731f2e5731dSTakashi Iwai 	return 0;
3732f2e5731dSTakashi Iwai }
3733f2e5731dSTakashi Iwai 
3734983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
3735f2e5731dSTakashi Iwai 			      const char *dir, int cidx,
3736983345e5SDavid Henningsson 			      hda_nid_t nid, int hda_dir, int amp_idx)
3737f2e5731dSTakashi Iwai {
3738f2e5731dSTakashi Iwai 	static char name[32];
3739f2e5731dSTakashi Iwai 	static struct snd_kcontrol_new knew[] = {
3740f2e5731dSTakashi Iwai 		HDA_CODEC_VOLUME(name, 0, 0, 0),
3741f2e5731dSTakashi Iwai 		HDA_CODEC_MUTE(name, 0, 0, 0),
3742f2e5731dSTakashi Iwai 	};
3743f2e5731dSTakashi Iwai 	static char *sfx[2] = { "Volume", "Switch" };
3744f2e5731dSTakashi Iwai 	int i, err;
3745f2e5731dSTakashi Iwai 
3746f2e5731dSTakashi Iwai 	for (i = 0; i < 2; i++) {
3747f2e5731dSTakashi Iwai 		struct snd_kcontrol *kctl;
3748983345e5SDavid Henningsson 		knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
3749983345e5SDavid Henningsson 							    hda_dir);
3750f2e5731dSTakashi Iwai 		knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3751f2e5731dSTakashi Iwai 		knew[i].index = cidx;
3752f2e5731dSTakashi Iwai 		snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3753f2e5731dSTakashi Iwai 		kctl = snd_ctl_new1(&knew[i], codec);
3754f2e5731dSTakashi Iwai 		if (!kctl)
3755f2e5731dSTakashi Iwai 			return -ENOMEM;
3756f2e5731dSTakashi Iwai 		err = snd_hda_ctl_add(codec, nid, kctl);
3757f2e5731dSTakashi Iwai 		if (err < 0)
3758f2e5731dSTakashi Iwai 			return err;
3759f2e5731dSTakashi Iwai 		if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3760f2e5731dSTakashi Iwai 			break;
3761f2e5731dSTakashi Iwai 	}
3762f2e5731dSTakashi Iwai 	return 0;
3763f2e5731dSTakashi Iwai }
3764f2e5731dSTakashi Iwai 
3765983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir)		\
3766983345e5SDavid Henningsson 	cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3767983345e5SDavid Henningsson 
3768f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx)			\
3769f2e5731dSTakashi Iwai 	cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3770f2e5731dSTakashi Iwai 
3771f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec)
3772f2e5731dSTakashi Iwai {
3773f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3774f2e5731dSTakashi Iwai 	int i, err;
3775f2e5731dSTakashi Iwai 	int num_line = 0, num_hp = 0, num_spk = 0;
3776ea734963STakashi Iwai 	static const char * const texts[3] = { "Front", "Surround", "CLFE" };
3777f2e5731dSTakashi Iwai 
3778f2e5731dSTakashi Iwai 	if (spec->dac_info_filled == 1)
3779f2e5731dSTakashi Iwai 		return cx_auto_add_pb_volume(codec, spec->dac_info[0].dac,
3780f2e5731dSTakashi Iwai 					     "Master", 0);
3781f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
3782f2e5731dSTakashi Iwai 		const char *label;
3783f2e5731dSTakashi Iwai 		int idx, type;
3784f2e5731dSTakashi Iwai 		if (!spec->dac_info[i].dac)
3785f2e5731dSTakashi Iwai 			continue;
3786f2e5731dSTakashi Iwai 		type = spec->dac_info[i].type;
3787f2e5731dSTakashi Iwai 		if (type == AUTO_PIN_LINE_OUT)
3788f2e5731dSTakashi Iwai 			type = spec->autocfg.line_out_type;
3789f2e5731dSTakashi Iwai 		switch (type) {
3790f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
3791f2e5731dSTakashi Iwai 		default:
3792f2e5731dSTakashi Iwai 			label = texts[num_line++];
3793f2e5731dSTakashi Iwai 			idx = 0;
3794f2e5731dSTakashi Iwai 			break;
3795f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
3796f2e5731dSTakashi Iwai 			label = "Headphone";
3797f2e5731dSTakashi Iwai 			idx = num_hp++;
3798f2e5731dSTakashi Iwai 			break;
3799f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
3800f2e5731dSTakashi Iwai 			label = "Speaker";
3801f2e5731dSTakashi Iwai 			idx = num_spk++;
3802f2e5731dSTakashi Iwai 			break;
3803f2e5731dSTakashi Iwai 		}
3804f2e5731dSTakashi Iwai 		err = cx_auto_add_pb_volume(codec, spec->dac_info[i].dac,
3805f2e5731dSTakashi Iwai 					    label, idx);
3806f2e5731dSTakashi Iwai 		if (err < 0)
3807f2e5731dSTakashi Iwai 			return err;
3808f2e5731dSTakashi Iwai 	}
3809f2e5731dSTakashi Iwai 	return 0;
3810f2e5731dSTakashi Iwai }
3811f2e5731dSTakashi Iwai 
3812f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec)
3813f2e5731dSTakashi Iwai {
3814f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3815f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3816f2e5731dSTakashi Iwai 	static const char *prev_label;
3817983345e5SDavid Henningsson 	int i, err, cidx, conn_len;
3818983345e5SDavid Henningsson 	hda_nid_t conn[HDA_MAX_CONNECTIONS];
3819f2e5731dSTakashi Iwai 
3820983345e5SDavid Henningsson 	int multi_adc_volume = 0; /* If the ADC nid has several input volumes */
3821983345e5SDavid Henningsson 	int adc_nid = spec->adc_nids[0];
3822983345e5SDavid Henningsson 
3823983345e5SDavid Henningsson 	conn_len = snd_hda_get_connections(codec, adc_nid, conn,
3824983345e5SDavid Henningsson 					   HDA_MAX_CONNECTIONS);
3825983345e5SDavid Henningsson 	if (conn_len < 0)
3826983345e5SDavid Henningsson 		return conn_len;
3827983345e5SDavid Henningsson 
3828983345e5SDavid Henningsson 	multi_adc_volume = cfg->num_inputs > 1 && conn_len > 1;
3829983345e5SDavid Henningsson 	if (!multi_adc_volume) {
3830983345e5SDavid Henningsson 		err = cx_auto_add_volume(codec, "Capture", "", 0, adc_nid,
3831f2e5731dSTakashi Iwai 					 HDA_INPUT);
3832f2e5731dSTakashi Iwai 		if (err < 0)
3833f2e5731dSTakashi Iwai 			return err;
3834983345e5SDavid Henningsson 	}
3835983345e5SDavid Henningsson 
3836f2e5731dSTakashi Iwai 	prev_label = NULL;
3837f2e5731dSTakashi Iwai 	cidx = 0;
3838f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3839f2e5731dSTakashi Iwai 		hda_nid_t nid = cfg->inputs[i].pin;
3840f2e5731dSTakashi Iwai 		const char *label;
3841983345e5SDavid Henningsson 		int j;
3842983345e5SDavid Henningsson 		int pin_amp = get_wcaps(codec, nid) & AC_WCAP_IN_AMP;
3843983345e5SDavid Henningsson 		if (!pin_amp && !multi_adc_volume)
3844f2e5731dSTakashi Iwai 			continue;
3845983345e5SDavid Henningsson 
3846f2e5731dSTakashi Iwai 		label = hda_get_autocfg_input_label(codec, cfg, i);
3847f2e5731dSTakashi Iwai 		if (label == prev_label)
3848f2e5731dSTakashi Iwai 			cidx++;
3849f2e5731dSTakashi Iwai 		else
3850f2e5731dSTakashi Iwai 			cidx = 0;
3851f2e5731dSTakashi Iwai 		prev_label = label;
3852983345e5SDavid Henningsson 
3853983345e5SDavid Henningsson 		if (pin_amp) {
3854983345e5SDavid Henningsson 			err = cx_auto_add_volume(codec, label, " Boost", cidx,
3855f2e5731dSTakashi Iwai 						 nid, HDA_INPUT);
3856f2e5731dSTakashi Iwai 			if (err < 0)
3857f2e5731dSTakashi Iwai 				return err;
3858f2e5731dSTakashi Iwai 		}
3859983345e5SDavid Henningsson 
3860983345e5SDavid Henningsson 		if (!multi_adc_volume)
3861983345e5SDavid Henningsson 			continue;
3862983345e5SDavid Henningsson 		for (j = 0; j < conn_len; j++) {
3863983345e5SDavid Henningsson 			if (conn[j] == nid) {
3864983345e5SDavid Henningsson 				err = cx_auto_add_volume_idx(codec, label,
3865983345e5SDavid Henningsson 				    " Capture", cidx, adc_nid, HDA_INPUT, j);
3866983345e5SDavid Henningsson 				if (err < 0)
3867983345e5SDavid Henningsson 					return err;
3868983345e5SDavid Henningsson 				break;
3869983345e5SDavid Henningsson 			}
3870983345e5SDavid Henningsson 		}
3871983345e5SDavid Henningsson 	}
3872f2e5731dSTakashi Iwai 	return 0;
3873f2e5731dSTakashi Iwai }
3874f2e5731dSTakashi Iwai 
3875f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec)
3876f2e5731dSTakashi Iwai {
3877f2e5731dSTakashi Iwai 	int err;
3878f2e5731dSTakashi Iwai 
3879f2e5731dSTakashi Iwai 	err = cx_auto_build_output_controls(codec);
3880f2e5731dSTakashi Iwai 	if (err < 0)
3881f2e5731dSTakashi Iwai 		return err;
3882f2e5731dSTakashi Iwai 	err = cx_auto_build_input_controls(codec);
3883f2e5731dSTakashi Iwai 	if (err < 0)
3884f2e5731dSTakashi Iwai 		return err;
3885f2e5731dSTakashi Iwai 	return conexant_build_controls(codec);
3886f2e5731dSTakashi Iwai }
3887f2e5731dSTakashi Iwai 
3888f2e5731dSTakashi Iwai static struct hda_codec_ops cx_auto_patch_ops = {
3889f2e5731dSTakashi Iwai 	.build_controls = cx_auto_build_controls,
3890f2e5731dSTakashi Iwai 	.build_pcms = conexant_build_pcms,
3891f2e5731dSTakashi Iwai 	.init = cx_auto_init,
3892f2e5731dSTakashi Iwai 	.free = conexant_free,
3893f2e5731dSTakashi Iwai 	.unsol_event = cx_auto_unsol_event,
3894f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
3895f2e5731dSTakashi Iwai 	.suspend = conexant_suspend,
3896f2e5731dSTakashi Iwai #endif
3897f2e5731dSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
3898f2e5731dSTakashi Iwai };
3899f2e5731dSTakashi Iwai 
3900f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec)
3901f2e5731dSTakashi Iwai {
3902f2e5731dSTakashi Iwai 	struct conexant_spec *spec;
3903f2e5731dSTakashi Iwai 	int err;
3904f2e5731dSTakashi Iwai 
3905f2e5731dSTakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3906f2e5731dSTakashi Iwai 	if (!spec)
3907f2e5731dSTakashi Iwai 		return -ENOMEM;
3908f2e5731dSTakashi Iwai 	codec->spec = spec;
3909f2e5731dSTakashi Iwai 	spec->adc_nids = cx_auto_adc_nids;
3910f2e5731dSTakashi Iwai 	spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids);
3911f2e5731dSTakashi Iwai 	spec->capsrc_nids = spec->adc_nids;
3912f2e5731dSTakashi Iwai 	err = cx_auto_parse_auto_config(codec);
3913f2e5731dSTakashi Iwai 	if (err < 0) {
3914f2e5731dSTakashi Iwai 		kfree(codec->spec);
3915f2e5731dSTakashi Iwai 		codec->spec = NULL;
3916f2e5731dSTakashi Iwai 		return err;
3917f2e5731dSTakashi Iwai 	}
3918f2e5731dSTakashi Iwai 	codec->patch_ops = cx_auto_patch_ops;
3919f2e5731dSTakashi Iwai 	if (spec->beep_amp)
3920f2e5731dSTakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
3921f2e5731dSTakashi Iwai 	return 0;
3922f2e5731dSTakashi Iwai }
3923f2e5731dSTakashi Iwai 
3924f2e5731dSTakashi Iwai /*
3925461e2c78STakashi Iwai  */
3926461e2c78STakashi Iwai 
39271289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = {
392882f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
392982f30040STobin Davis 	  .patch = patch_cxt5045 },
393082f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
393182f30040STobin Davis 	  .patch = patch_cxt5047 },
3932461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3933461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
39340fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
39350fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
393695a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
393795a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
3938850eab9dSTakashi Iwai 	{ .id = 0x14f15068, .name = "CX20584",
3939850eab9dSTakashi Iwai 	  .patch = patch_cxt5066 },
39407b2bfdbcSJens Taprogge 	{ .id = 0x14f15069, .name = "CX20585",
39417b2bfdbcSJens Taprogge 	  .patch = patch_cxt5066 },
39426da8b516SDavid Henningsson 	{ .id = 0x14f1506e, .name = "CX20590",
39436da8b516SDavid Henningsson 	  .patch = patch_cxt5066 },
3944f2e5731dSTakashi Iwai 	{ .id = 0x14f15097, .name = "CX20631",
3945f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3946f2e5731dSTakashi Iwai 	{ .id = 0x14f15098, .name = "CX20632",
3947f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3948f2e5731dSTakashi Iwai 	{ .id = 0x14f150a1, .name = "CX20641",
3949f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3950f2e5731dSTakashi Iwai 	{ .id = 0x14f150a2, .name = "CX20642",
3951f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3952f2e5731dSTakashi Iwai 	{ .id = 0x14f150ab, .name = "CX20651",
3953f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3954f2e5731dSTakashi Iwai 	{ .id = 0x14f150ac, .name = "CX20652",
3955f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3956f2e5731dSTakashi Iwai 	{ .id = 0x14f150b8, .name = "CX20664",
3957f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3958f2e5731dSTakashi Iwai 	{ .id = 0x14f150b9, .name = "CX20665",
3959f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3960c9b443d4STobin Davis 	{} /* terminator */
3961c9b443d4STobin Davis };
39621289e9e8STakashi Iwai 
39631289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
39641289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
39651289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
39660fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
396795a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
3968850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068");
39697b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069");
39706da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e");
3971f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097");
3972f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098");
3973f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3974f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3975f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3976f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3977f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3978f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9");
39791289e9e8STakashi Iwai 
39801289e9e8STakashi Iwai MODULE_LICENSE("GPL");
39811289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
39821289e9e8STakashi Iwai 
39831289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
39841289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
39851289e9e8STakashi Iwai 	.owner = THIS_MODULE,
39861289e9e8STakashi Iwai };
39871289e9e8STakashi Iwai 
39881289e9e8STakashi Iwai static int __init patch_conexant_init(void)
39891289e9e8STakashi Iwai {
39901289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
39911289e9e8STakashi Iwai }
39921289e9e8STakashi Iwai 
39931289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
39941289e9e8STakashi Iwai {
39951289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
39961289e9e8STakashi Iwai }
39971289e9e8STakashi Iwai 
39981289e9e8STakashi Iwai module_init(patch_conexant_init)
39991289e9e8STakashi Iwai module_exit(patch_conexant_exit)
4000