xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision a1d6906e2d2b4655e248f490ab088c27876a600a)
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;
88c9b443d4STobin Davis 
89c9b443d4STobin Davis 	/* capture */
90c9b443d4STobin Davis 	unsigned int num_adc_nids;
91c9b443d4STobin Davis 	hda_nid_t *adc_nids;
92c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
93c9b443d4STobin Davis 
94461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
95461e2c78STakashi Iwai 	hda_nid_t cur_adc;
96461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
97461e2c78STakashi Iwai 	unsigned int cur_adc_format;
98461e2c78STakashi Iwai 
99c9b443d4STobin Davis 	/* capture source */
100c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
101c9b443d4STobin Davis 	hda_nid_t *capsrc_nids;
102c9b443d4STobin Davis 	unsigned int cur_mux[3];
103c9b443d4STobin Davis 
104c9b443d4STobin Davis 	/* channel model */
105c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
106c9b443d4STobin Davis 	int num_channel_mode;
107c9b443d4STobin Davis 
108c9b443d4STobin Davis 	/* PCM information */
109c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
110c9b443d4STobin Davis 
111c9b443d4STobin Davis 	unsigned int spdif_route;
112c9b443d4STobin Davis 
113bc7a166dSUlrich Dangel 	/* jack detection */
114bc7a166dSUlrich Dangel 	struct snd_array jacks;
115bc7a166dSUlrich Dangel 
116c9b443d4STobin Davis 	/* dynamic controls, init_verbs and input_mux */
117c9b443d4STobin Davis 	struct auto_pin_cfg autocfg;
118c9b443d4STobin Davis 	struct hda_input_mux private_imux;
11941923e44STakashi Iwai 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
120f2e5731dSTakashi Iwai 	struct pin_dac_pair dac_info[8];
121f2e5731dSTakashi Iwai 	int dac_info_filled;
122c9b443d4STobin Davis 
1230fb67e98SDaniel Drake 	unsigned int port_d_mode;
124f2e5731dSTakashi Iwai 	unsigned int auto_mute:1;	/* used in auto-parser */
125f2e5731dSTakashi Iwai 	unsigned int dell_automute:1;
126cfd3d8dcSGreg Alexander 	unsigned int dell_vostro:1;
127cfd3d8dcSGreg Alexander 	unsigned int ideapad:1;
1287b2bfdbcSJens Taprogge 	unsigned int thinkpad:1;
129048e78a5SDavid Henningsson 	unsigned int hp_laptop:1;
130*a1d6906eSDavid Henningsson 	unsigned int asus:1;
13175f8991dSDaniel Drake 
13275f8991dSDaniel Drake 	unsigned int ext_mic_present;
13375f8991dSDaniel Drake 	unsigned int recording;
13475f8991dSDaniel Drake 	void (*capture_prepare)(struct hda_codec *codec);
13575f8991dSDaniel Drake 	void (*capture_cleanup)(struct hda_codec *codec);
136c4cfe66cSDaniel Drake 
137c4cfe66cSDaniel Drake 	/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
138c4cfe66cSDaniel Drake 	 * through the microphone jack.
139c4cfe66cSDaniel Drake 	 * When the user enables this through a mixer switch, both internal and
140c4cfe66cSDaniel Drake 	 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
141c4cfe66cSDaniel Drake 	 * we also allow the bias to be configured through a separate mixer
142c4cfe66cSDaniel Drake 	 * control. */
143c4cfe66cSDaniel Drake 	unsigned int dc_enable;
144c4cfe66cSDaniel Drake 	unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
145c4cfe66cSDaniel Drake 	unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
1463507e2a8STakashi Iwai 
1473507e2a8STakashi Iwai 	unsigned int beep_amp;
148c9b443d4STobin Davis };
149c9b443d4STobin Davis 
150c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
151c9b443d4STobin Davis 				      struct hda_codec *codec,
152c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
153c9b443d4STobin Davis {
154c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1559a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1569a08160bSTakashi Iwai 					     hinfo);
157c9b443d4STobin Davis }
158c9b443d4STobin Davis 
159c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
160c9b443d4STobin Davis 					 struct hda_codec *codec,
161c9b443d4STobin Davis 					 unsigned int stream_tag,
162c9b443d4STobin Davis 					 unsigned int format,
163c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
164c9b443d4STobin Davis {
165c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
166c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
167c9b443d4STobin Davis 						stream_tag,
168c9b443d4STobin Davis 						format, substream);
169c9b443d4STobin Davis }
170c9b443d4STobin Davis 
171c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
172c9b443d4STobin Davis 					 struct hda_codec *codec,
173c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
174c9b443d4STobin Davis {
175c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
176c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
177c9b443d4STobin Davis }
178c9b443d4STobin Davis 
179c9b443d4STobin Davis /*
180c9b443d4STobin Davis  * Digital out
181c9b443d4STobin Davis  */
182c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
183c9b443d4STobin Davis 					  struct hda_codec *codec,
184c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
185c9b443d4STobin Davis {
186c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
187c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
188c9b443d4STobin Davis }
189c9b443d4STobin Davis 
190c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
191c9b443d4STobin Davis 					 struct hda_codec *codec,
192c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
193c9b443d4STobin Davis {
194c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
195c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
196c9b443d4STobin Davis }
197c9b443d4STobin Davis 
1986b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1996b97eb45STakashi Iwai 					 struct hda_codec *codec,
2006b97eb45STakashi Iwai 					 unsigned int stream_tag,
2016b97eb45STakashi Iwai 					 unsigned int format,
2026b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
2036b97eb45STakashi Iwai {
2046b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
2056b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2066b97eb45STakashi Iwai 					     stream_tag,
2076b97eb45STakashi Iwai 					     format, substream);
2086b97eb45STakashi Iwai }
2096b97eb45STakashi Iwai 
210c9b443d4STobin Davis /*
211c9b443d4STobin Davis  * Analog capture
212c9b443d4STobin Davis  */
213c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
214c9b443d4STobin Davis 				      struct hda_codec *codec,
215c9b443d4STobin Davis 				      unsigned int stream_tag,
216c9b443d4STobin Davis 				      unsigned int format,
217c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
218c9b443d4STobin Davis {
219c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
22075f8991dSDaniel Drake 	if (spec->capture_prepare)
22175f8991dSDaniel Drake 		spec->capture_prepare(codec);
222c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
223c9b443d4STobin Davis 				   stream_tag, 0, format);
224c9b443d4STobin Davis 	return 0;
225c9b443d4STobin Davis }
226c9b443d4STobin Davis 
227c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
228c9b443d4STobin Davis 				      struct hda_codec *codec,
229c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
230c9b443d4STobin Davis {
231c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
232888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
23375f8991dSDaniel Drake 	if (spec->capture_cleanup)
23475f8991dSDaniel Drake 		spec->capture_cleanup(codec);
235c9b443d4STobin Davis 	return 0;
236c9b443d4STobin Davis }
237c9b443d4STobin Davis 
238c9b443d4STobin Davis 
239c9b443d4STobin Davis 
240c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = {
241c9b443d4STobin Davis 	.substreams = 1,
242c9b443d4STobin Davis 	.channels_min = 2,
243c9b443d4STobin Davis 	.channels_max = 2,
244c9b443d4STobin Davis 	.nid = 0, /* fill later */
245c9b443d4STobin Davis 	.ops = {
246c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
247c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
248c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
249c9b443d4STobin Davis 	},
250c9b443d4STobin Davis };
251c9b443d4STobin Davis 
252c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = {
253c9b443d4STobin Davis 	.substreams = 1,
254c9b443d4STobin Davis 	.channels_min = 2,
255c9b443d4STobin Davis 	.channels_max = 2,
256c9b443d4STobin Davis 	.nid = 0, /* fill later */
257c9b443d4STobin Davis 	.ops = {
258c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
259c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
260c9b443d4STobin Davis 	},
261c9b443d4STobin Davis };
262c9b443d4STobin Davis 
263c9b443d4STobin Davis 
264c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = {
265c9b443d4STobin Davis 	.substreams = 1,
266c9b443d4STobin Davis 	.channels_min = 2,
267c9b443d4STobin Davis 	.channels_max = 2,
268c9b443d4STobin Davis 	.nid = 0, /* fill later */
269c9b443d4STobin Davis 	.ops = {
270c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2716b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2726b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
273c9b443d4STobin Davis 	},
274c9b443d4STobin Davis };
275c9b443d4STobin Davis 
276c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = {
277c9b443d4STobin Davis 	.substreams = 1,
278c9b443d4STobin Davis 	.channels_min = 2,
279c9b443d4STobin Davis 	.channels_max = 2,
280c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
281c9b443d4STobin Davis };
282c9b443d4STobin Davis 
283461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
284461e2c78STakashi Iwai 				      struct hda_codec *codec,
285461e2c78STakashi Iwai 				      unsigned int stream_tag,
286461e2c78STakashi Iwai 				      unsigned int format,
287461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
288461e2c78STakashi Iwai {
289461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
290461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
291461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
292461e2c78STakashi Iwai 	spec->cur_adc_format = format;
293461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
294461e2c78STakashi Iwai 	return 0;
295461e2c78STakashi Iwai }
296461e2c78STakashi Iwai 
297461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
298461e2c78STakashi Iwai 				      struct hda_codec *codec,
299461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
300461e2c78STakashi Iwai {
301461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
302888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
303461e2c78STakashi Iwai 	spec->cur_adc = 0;
304461e2c78STakashi Iwai 	return 0;
305461e2c78STakashi Iwai }
306461e2c78STakashi Iwai 
307461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = {
308461e2c78STakashi Iwai 	.substreams = 1,
309461e2c78STakashi Iwai 	.channels_min = 2,
310461e2c78STakashi Iwai 	.channels_max = 2,
311461e2c78STakashi Iwai 	.nid = 0, /* fill later */
312461e2c78STakashi Iwai 	.ops = {
313461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
314461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
315461e2c78STakashi Iwai 	},
316461e2c78STakashi Iwai };
317461e2c78STakashi Iwai 
318c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
319c9b443d4STobin Davis {
320c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
321c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
322c9b443d4STobin Davis 
323c9b443d4STobin Davis 	codec->num_pcms = 1;
324c9b443d4STobin Davis 	codec->pcm_info = info;
325c9b443d4STobin Davis 
326c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
327c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
328c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
329c9b443d4STobin Davis 		spec->multiout.max_channels;
330c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
331c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
332461e2c78STakashi Iwai 	if (codec->vendor_id == 0x14f15051)
333461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
334461e2c78STakashi Iwai 			cx5051_pcm_analog_capture;
335461e2c78STakashi Iwai 	else
336461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
337461e2c78STakashi Iwai 			conexant_pcm_analog_capture;
338c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
339c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
340c9b443d4STobin Davis 
341c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
342c9b443d4STobin Davis 		info++;
343c9b443d4STobin Davis 		codec->num_pcms++;
344c9b443d4STobin Davis 		info->name = "Conexant Digital";
3457ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
346c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
347c9b443d4STobin Davis 			conexant_pcm_digital_playback;
348c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
349c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
350c9b443d4STobin Davis 		if (spec->dig_in_nid) {
351c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
352c9b443d4STobin Davis 				conexant_pcm_digital_capture;
353c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
354c9b443d4STobin Davis 				spec->dig_in_nid;
355c9b443d4STobin Davis 		}
356c9b443d4STobin Davis 	}
357c9b443d4STobin Davis 
358c9b443d4STobin Davis 	return 0;
359c9b443d4STobin Davis }
360c9b443d4STobin Davis 
361c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
362c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
363c9b443d4STobin Davis {
364c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
365c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
366c9b443d4STobin Davis 
367c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
368c9b443d4STobin Davis }
369c9b443d4STobin Davis 
370c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
371c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
372c9b443d4STobin Davis {
373c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
374c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
375c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
376c9b443d4STobin Davis 
377c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
378c9b443d4STobin Davis 	return 0;
379c9b443d4STobin Davis }
380c9b443d4STobin Davis 
381c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
382c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
383c9b443d4STobin Davis {
384c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
385c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
386c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
387c9b443d4STobin Davis 
388c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
389c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
390c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
391c9b443d4STobin Davis }
392c9b443d4STobin Davis 
3938c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
39495c09099STakashi Iwai static void conexant_free_jack_priv(struct snd_jack *jack)
39595c09099STakashi Iwai {
39695c09099STakashi Iwai 	struct conexant_jack *jacks = jack->private_data;
39795c09099STakashi Iwai 	jacks->nid = 0;
39895c09099STakashi Iwai 	jacks->jack = NULL;
39995c09099STakashi Iwai }
40095c09099STakashi Iwai 
401bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec,
402bc7a166dSUlrich Dangel 		hda_nid_t nid, int type)
403bc7a166dSUlrich Dangel {
404bc7a166dSUlrich Dangel 	struct conexant_spec *spec;
405bc7a166dSUlrich Dangel 	struct conexant_jack *jack;
406bc7a166dSUlrich Dangel 	const char *name;
40795c09099STakashi Iwai 	int err;
408bc7a166dSUlrich Dangel 
409bc7a166dSUlrich Dangel 	spec = codec->spec;
410bc7a166dSUlrich Dangel 	snd_array_init(&spec->jacks, sizeof(*jack), 32);
411bc7a166dSUlrich Dangel 	jack = snd_array_new(&spec->jacks);
412bc7a166dSUlrich Dangel 	name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
413bc7a166dSUlrich Dangel 
414bc7a166dSUlrich Dangel 	if (!jack)
415bc7a166dSUlrich Dangel 		return -ENOMEM;
416bc7a166dSUlrich Dangel 
417bc7a166dSUlrich Dangel 	jack->nid = nid;
418bc7a166dSUlrich Dangel 	jack->type = type;
419bc7a166dSUlrich Dangel 
42095c09099STakashi Iwai 	err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
42195c09099STakashi Iwai 	if (err < 0)
42295c09099STakashi Iwai 		return err;
42395c09099STakashi Iwai 	jack->jack->private_data = jack;
42495c09099STakashi Iwai 	jack->jack->private_free = conexant_free_jack_priv;
42595c09099STakashi Iwai 	return 0;
426bc7a166dSUlrich Dangel }
427bc7a166dSUlrich Dangel 
428bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
429bc7a166dSUlrich Dangel {
430bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
431bc7a166dSUlrich Dangel 	struct conexant_jack *jacks = spec->jacks.list;
432bc7a166dSUlrich Dangel 
433bc7a166dSUlrich Dangel 	if (jacks) {
434bc7a166dSUlrich Dangel 		int i;
435bc7a166dSUlrich Dangel 		for (i = 0; i < spec->jacks.used; i++) {
436bc7a166dSUlrich Dangel 			if (jacks->nid == nid) {
437bc7a166dSUlrich Dangel 				unsigned int present;
438d56757abSTakashi Iwai 				present = snd_hda_jack_detect(codec, nid);
439bc7a166dSUlrich Dangel 
440bc7a166dSUlrich Dangel 				present = (present) ? jacks->type : 0 ;
441bc7a166dSUlrich Dangel 
442bc7a166dSUlrich Dangel 				snd_jack_report(jacks->jack,
443bc7a166dSUlrich Dangel 						present);
444bc7a166dSUlrich Dangel 			}
445bc7a166dSUlrich Dangel 			jacks++;
446bc7a166dSUlrich Dangel 		}
447bc7a166dSUlrich Dangel 	}
448bc7a166dSUlrich Dangel }
449bc7a166dSUlrich Dangel 
450bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec)
451bc7a166dSUlrich Dangel {
452bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
453bc7a166dSUlrich Dangel 	int i;
454bc7a166dSUlrich Dangel 
455bc7a166dSUlrich Dangel 	for (i = 0; i < spec->num_init_verbs; i++) {
456bc7a166dSUlrich Dangel 		const struct hda_verb *hv;
457bc7a166dSUlrich Dangel 
458bc7a166dSUlrich Dangel 		hv = spec->init_verbs[i];
459bc7a166dSUlrich Dangel 		while (hv->nid) {
460bc7a166dSUlrich Dangel 			int err = 0;
461bc7a166dSUlrich Dangel 			switch (hv->param ^ AC_USRSP_EN) {
462bc7a166dSUlrich Dangel 			case CONEXANT_HP_EVENT:
463bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
464bc7a166dSUlrich Dangel 						SND_JACK_HEADPHONE);
465bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
466bc7a166dSUlrich Dangel 				break;
467bc7a166dSUlrich Dangel 			case CXT5051_PORTC_EVENT:
468bc7a166dSUlrich Dangel 			case CONEXANT_MIC_EVENT:
469bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
470bc7a166dSUlrich Dangel 						SND_JACK_MICROPHONE);
471bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
472bc7a166dSUlrich Dangel 				break;
473bc7a166dSUlrich Dangel 			}
474bc7a166dSUlrich Dangel 			if (err < 0)
475bc7a166dSUlrich Dangel 				return err;
476bc7a166dSUlrich Dangel 			++hv;
477bc7a166dSUlrich Dangel 		}
478bc7a166dSUlrich Dangel 	}
479bc7a166dSUlrich Dangel 	return 0;
480bc7a166dSUlrich Dangel 
481bc7a166dSUlrich Dangel }
4825801f992STakashi Iwai #else
4835801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
4845801f992STakashi Iwai {
4855801f992STakashi Iwai }
4865801f992STakashi Iwai 
4875801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec)
4885801f992STakashi Iwai {
4895801f992STakashi Iwai 	return 0;
4905801f992STakashi Iwai }
4915801f992STakashi Iwai #endif
492bc7a166dSUlrich Dangel 
493c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
494c9b443d4STobin Davis {
495c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
496c9b443d4STobin Davis 	int i;
497c9b443d4STobin Davis 
498c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
499c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
500c9b443d4STobin Davis 	return 0;
501c9b443d4STobin Davis }
502c9b443d4STobin Davis 
503c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
504c9b443d4STobin Davis {
5058c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
506bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
507bc7a166dSUlrich Dangel 	if (spec->jacks.list) {
508bc7a166dSUlrich Dangel 		struct conexant_jack *jacks = spec->jacks.list;
509bc7a166dSUlrich Dangel 		int i;
51095c09099STakashi Iwai 		for (i = 0; i < spec->jacks.used; i++, jacks++) {
51195c09099STakashi Iwai 			if (jacks->jack)
51295c09099STakashi Iwai 				snd_device_free(codec->bus->card, jacks->jack);
51395c09099STakashi Iwai 		}
514bc7a166dSUlrich Dangel 		snd_array_free(&spec->jacks);
515bc7a166dSUlrich Dangel 	}
516bc7a166dSUlrich Dangel #endif
517c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
518c9b443d4STobin Davis 	kfree(codec->spec);
519c9b443d4STobin Davis }
520c9b443d4STobin Davis 
521b880c74aSTakashi Iwai static struct snd_kcontrol_new cxt_capture_mixers[] = {
522b880c74aSTakashi Iwai 	{
523b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
524b880c74aSTakashi Iwai 		.name = "Capture Source",
525b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
526b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
527b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
528b880c74aSTakashi Iwai 	},
529b880c74aSTakashi Iwai 	{}
530b880c74aSTakashi Iwai };
531b880c74aSTakashi Iwai 
5323507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5333507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */
5343507e2a8STakashi Iwai static struct snd_kcontrol_new cxt_beep_mixer[] = {
5353507e2a8STakashi Iwai 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
5363507e2a8STakashi Iwai 	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
5373507e2a8STakashi Iwai 	{ } /* end */
5383507e2a8STakashi Iwai };
5393507e2a8STakashi Iwai #endif
5403507e2a8STakashi Iwai 
541ea734963STakashi Iwai static const char * const slave_vols[] = {
542dd5746a8STakashi Iwai 	"Headphone Playback Volume",
543dd5746a8STakashi Iwai 	"Speaker Playback Volume",
544dd5746a8STakashi Iwai 	NULL
545dd5746a8STakashi Iwai };
546dd5746a8STakashi Iwai 
547ea734963STakashi Iwai static const char * const slave_sws[] = {
548dd5746a8STakashi Iwai 	"Headphone Playback Switch",
549dd5746a8STakashi Iwai 	"Speaker Playback Switch",
550dd5746a8STakashi Iwai 	NULL
551dd5746a8STakashi Iwai };
552dd5746a8STakashi Iwai 
553c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
554c9b443d4STobin Davis {
555c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
556c9b443d4STobin Davis 	unsigned int i;
557c9b443d4STobin Davis 	int err;
558c9b443d4STobin Davis 
559c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
560c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
561c9b443d4STobin Davis 		if (err < 0)
562c9b443d4STobin Davis 			return err;
563c9b443d4STobin Davis 	}
564c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
565c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
566c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
567c9b443d4STobin Davis 		if (err < 0)
568c9b443d4STobin Davis 			return err;
5699a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
5709a08160bSTakashi Iwai 						    &spec->multiout);
5719a08160bSTakashi Iwai 		if (err < 0)
5729a08160bSTakashi Iwai 			return err;
5739a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
574c9b443d4STobin Davis 	}
575c9b443d4STobin Davis 	if (spec->dig_in_nid) {
576c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
577c9b443d4STobin Davis 		if (err < 0)
578c9b443d4STobin Davis 			return err;
579c9b443d4STobin Davis 	}
580dd5746a8STakashi Iwai 
581dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
582dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
583dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
584dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
585dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
586dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
587dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
588dd5746a8STakashi Iwai 					  vmaster_tlv, slave_vols);
589dd5746a8STakashi Iwai 		if (err < 0)
590dd5746a8STakashi Iwai 			return err;
591dd5746a8STakashi Iwai 	}
592dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
593dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
594dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
595dd5746a8STakashi Iwai 					  NULL, slave_sws);
596dd5746a8STakashi Iwai 		if (err < 0)
597dd5746a8STakashi Iwai 			return err;
598dd5746a8STakashi Iwai 	}
599dd5746a8STakashi Iwai 
600b880c74aSTakashi Iwai 	if (spec->input_mux) {
601b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
602b880c74aSTakashi Iwai 		if (err < 0)
603b880c74aSTakashi Iwai 			return err;
604b880c74aSTakashi Iwai 	}
605b880c74aSTakashi Iwai 
6063507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
6073507e2a8STakashi Iwai 	/* create beep controls if needed */
6083507e2a8STakashi Iwai 	if (spec->beep_amp) {
6093507e2a8STakashi Iwai 		struct snd_kcontrol_new *knew;
6103507e2a8STakashi Iwai 		for (knew = cxt_beep_mixer; knew->name; knew++) {
6113507e2a8STakashi Iwai 			struct snd_kcontrol *kctl;
6123507e2a8STakashi Iwai 			kctl = snd_ctl_new1(knew, codec);
6133507e2a8STakashi Iwai 			if (!kctl)
6143507e2a8STakashi Iwai 				return -ENOMEM;
6153507e2a8STakashi Iwai 			kctl->private_value = spec->beep_amp;
6163507e2a8STakashi Iwai 			err = snd_hda_ctl_add(codec, 0, kctl);
6173507e2a8STakashi Iwai 			if (err < 0)
6183507e2a8STakashi Iwai 				return err;
6193507e2a8STakashi Iwai 		}
6203507e2a8STakashi Iwai 	}
6213507e2a8STakashi Iwai #endif
6223507e2a8STakashi Iwai 
623c9b443d4STobin Davis 	return 0;
624c9b443d4STobin Davis }
625c9b443d4STobin Davis 
626697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
627697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
628697c373eSTakashi Iwai {
629697c373eSTakashi Iwai 	snd_hda_shutup_pins(codec);
630697c373eSTakashi Iwai 	return 0;
631697c373eSTakashi Iwai }
632697c373eSTakashi Iwai #endif
633697c373eSTakashi Iwai 
634c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
635c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
636c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
637c9b443d4STobin Davis 	.init = conexant_init,
638c9b443d4STobin Davis 	.free = conexant_free,
639697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
640697c373eSTakashi Iwai 	.suspend = conexant_suspend,
641697c373eSTakashi Iwai #endif
642697c373eSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
643c9b443d4STobin Davis };
644c9b443d4STobin Davis 
6453507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
6463507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \
6473507e2a8STakashi Iwai 	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
6483507e2a8STakashi Iwai #else
6493507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */
6503507e2a8STakashi Iwai #endif
6513507e2a8STakashi Iwai 
652c9b443d4STobin Davis /*
653c9b443d4STobin Davis  * EAPD control
654c9b443d4STobin Davis  * the private value = nid | (invert << 8)
655c9b443d4STobin Davis  */
656c9b443d4STobin Davis 
657a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
658c9b443d4STobin Davis 
65982f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
660c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
661c9b443d4STobin Davis {
662c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
663c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
664c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
665c9b443d4STobin Davis 	if (invert)
666c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
667c9b443d4STobin Davis 	else
668c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
669c9b443d4STobin Davis 	return 0;
67082f30040STobin Davis 
671c9b443d4STobin Davis }
672c9b443d4STobin Davis 
67382f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
674c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
675c9b443d4STobin Davis {
676c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
677c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
678c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
679c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
680c9b443d4STobin Davis 	unsigned int eapd;
68182f30040STobin Davis 
68268ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
683c9b443d4STobin Davis 	if (invert)
684c9b443d4STobin Davis 		eapd = !eapd;
68582beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
686c9b443d4STobin Davis 		return 0;
68782f30040STobin Davis 
688c9b443d4STobin Davis 	spec->cur_eapd = eapd;
68982beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
690c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
691c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
692c9b443d4STobin Davis 	return 1;
693c9b443d4STobin Davis }
694c9b443d4STobin Davis 
69586d72bdfSTakashi Iwai /* controls for test mode */
69686d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
69786d72bdfSTakashi Iwai 
69882f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
69982f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
70082f30040STobin Davis 	  .info = cxt_eapd_info, \
70182f30040STobin Davis 	  .get = cxt_eapd_get, \
70282f30040STobin Davis 	  .put = cxt_eapd_put, \
70382f30040STobin Davis 	  .private_value = nid | (mask<<16) }
70482f30040STobin Davis 
70582f30040STobin Davis 
70682f30040STobin Davis 
707c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
708c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
709c9b443d4STobin Davis {
710c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
711c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
712c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
713c9b443d4STobin Davis 				    spec->num_channel_mode);
714c9b443d4STobin Davis }
715c9b443d4STobin Davis 
716c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
717c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
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_get(codec, ucontrol, spec->channel_mode,
722c9b443d4STobin Davis 				   spec->num_channel_mode,
723c9b443d4STobin Davis 				   spec->multiout.max_channels);
724c9b443d4STobin Davis }
725c9b443d4STobin Davis 
726c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
727c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
728c9b443d4STobin Davis {
729c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
730c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
731c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
732c9b443d4STobin Davis 				      spec->num_channel_mode,
733c9b443d4STobin Davis 				      &spec->multiout.max_channels);
734c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
735c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
736c9b443d4STobin Davis 	return err;
737c9b443d4STobin Davis }
738c9b443d4STobin Davis 
739c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
740c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
741c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
742c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
743c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
744c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
745c9b443d4STobin Davis 
74686d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
74786d72bdfSTakashi Iwai 
748c9b443d4STobin Davis /* Conexant 5045 specific */
749c9b443d4STobin Davis 
750c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
751c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
752c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
753cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
754c9b443d4STobin Davis 
7555cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
7565cd57529STobin Davis 	{ 2, NULL },
7575cd57529STobin Davis };
758c9b443d4STobin Davis 
759c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
760c9b443d4STobin Davis 	.num_items = 2,
761c9b443d4STobin Davis 	.items = {
76282f30040STobin Davis 		{ "IntMic", 0x1 },
763f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
764c9b443d4STobin Davis 	}
765c9b443d4STobin Davis };
766c9b443d4STobin Davis 
7675218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = {
76822e14130SLukasz Marcinowski 	.num_items = 5,
7695218c892SJiang Zhe 	.items = {
7705218c892SJiang Zhe 		{ "IntMic", 0x1 },
7715218c892SJiang Zhe 		{ "ExtMic", 0x2 },
7725218c892SJiang Zhe 		{ "LineIn", 0x3 },
77322e14130SLukasz Marcinowski 		{ "CD",     0x4 },
77422e14130SLukasz Marcinowski 		{ "Mixer",  0x0 },
7755218c892SJiang Zhe 	}
7765218c892SJiang Zhe };
7775218c892SJiang Zhe 
7782de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = {
7792de3c232SJiang zhe 	.num_items = 2,
7802de3c232SJiang zhe 	.items = {
7812de3c232SJiang zhe 		{ "ExtMic", 0x1 },
7822de3c232SJiang zhe 		{ "IntMic", 0x2 },
7832de3c232SJiang zhe 	}
7842de3c232SJiang zhe };
7852de3c232SJiang zhe 
786c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
787c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
788c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
789c9b443d4STobin Davis {
790c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
791c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
79282f30040STobin Davis 	unsigned int bits;
793c9b443d4STobin Davis 
79482f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
795c9b443d4STobin Davis 		return 0;
796c9b443d4STobin Davis 
79782f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
79882f30040STobin Davis 	 * the headphone jack
79982f30040STobin Davis 	 */
80047fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
80147fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
80247fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
8037f29673bSTobin Davis 
80447fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
80547fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
80647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
807c9b443d4STobin Davis 	return 1;
808c9b443d4STobin Davis }
809c9b443d4STobin Davis 
810c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
811cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
812cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
813cca3b371STakashi Iwai 	.values = {
814cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
815cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
816cca3b371STakashi Iwai 		0
817cca3b371STakashi Iwai 	},
818cca3b371STakashi Iwai };
819c9b443d4STobin Davis 
8207f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
8217f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
8227f29673bSTobin Davis {
8237f29673bSTobin Davis 	static struct hda_verb mic_jack_on[] = {
8247f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
8257f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
8267f29673bSTobin Davis 		{}
8277f29673bSTobin Davis 	};
8287f29673bSTobin Davis 	static struct hda_verb mic_jack_off[] = {
8297f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
8307f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
8317f29673bSTobin Davis 		{}
8327f29673bSTobin Davis 	};
8337f29673bSTobin Davis 	unsigned int present;
8347f29673bSTobin Davis 
835d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x12);
8367f29673bSTobin Davis 	if (present)
8377f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
8387f29673bSTobin Davis 	else
8397f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
8407f29673bSTobin Davis }
8417f29673bSTobin Davis 
842c9b443d4STobin Davis 
843c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
844c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
845c9b443d4STobin Davis {
84682f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
847dd87da1cSTobin Davis 	unsigned int bits;
848c9b443d4STobin Davis 
849d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
850dd87da1cSTobin Davis 
85147fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
85247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
85347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
854c9b443d4STobin Davis }
855c9b443d4STobin Davis 
856c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
857c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
858c9b443d4STobin Davis 				   unsigned int res)
859c9b443d4STobin Davis {
860c9b443d4STobin Davis 	res >>= 26;
861c9b443d4STobin Davis 	switch (res) {
862c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
863c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
864c9b443d4STobin Davis 		break;
8657f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
8667f29673bSTobin Davis 		cxt5045_hp_automic(codec);
8677f29673bSTobin Davis 		break;
8687f29673bSTobin Davis 
869c9b443d4STobin Davis 	}
870c9b443d4STobin Davis }
871c9b443d4STobin Davis 
872c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
87328c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
87428c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8758607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
8768607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
877c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
878c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
87928c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
88028c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8818607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
8828607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
883cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
884c9b443d4STobin Davis 	{
885c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
886c9b443d4STobin Davis 		.name = "Master Playback Switch",
88782f30040STobin Davis 		.info = cxt_eapd_info,
88882f30040STobin Davis 		.get = cxt_eapd_get,
889c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
89082f30040STobin Davis 		.private_value = 0x10,
891c9b443d4STobin Davis 	},
892c9b443d4STobin Davis 
893c9b443d4STobin Davis 	{}
894c9b443d4STobin Davis };
895c9b443d4STobin Davis 
8965218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
89722e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
89822e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
89922e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
90022e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
90122e14130SLukasz Marcinowski 
9025218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
9035218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
9045218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
9055218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
9065218c892SJiang Zhe 
90722e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
90822e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
90922e14130SLukasz Marcinowski 
9105218c892SJiang Zhe 	{}
9115218c892SJiang Zhe };
9125218c892SJiang Zhe 
9132de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
91428c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
91528c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
9168607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
9178607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
9182de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
9192de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
92028c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
92128c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
9228607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
9238607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
9242de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
9252de3c232SJiang zhe 	{
9262de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9272de3c232SJiang zhe 		.name = "Master Playback Switch",
9282de3c232SJiang zhe 		.info = cxt_eapd_info,
9292de3c232SJiang zhe 		.get = cxt_eapd_get,
9302de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
9312de3c232SJiang zhe 		.private_value = 0x10,
9322de3c232SJiang zhe 	},
9332de3c232SJiang zhe 
9342de3c232SJiang zhe 	{}
9352de3c232SJiang zhe };
9362de3c232SJiang zhe 
937c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
938c9b443d4STobin Davis 	/* Line in, Mic */
9394090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9407f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
941c9b443d4STobin Davis 	/* HP, Amp  */
942c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
943c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
94482f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
945c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
946c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
947c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
948c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
949c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
950c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
95128c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
9527f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
95382f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
954c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
955c9b443d4STobin Davis 	/* SPDIF route: PCM */
956cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
957c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
958c9b443d4STobin Davis 	/* EAPD */
95982f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
960c9b443d4STobin Davis 	{ } /* end */
961c9b443d4STobin Davis };
962c9b443d4STobin Davis 
9635218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = {
96428c4edb7SDavid Henningsson 	/* Internal Mic, Mic */
9655218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9665218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9675218c892SJiang Zhe 	/* Line In,HP, Amp  */
9685218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9695218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
9705218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9715218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
9725218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9735218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9745218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9755218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9765218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
97728c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
9785218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
9795218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
9805218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
9815218c892SJiang Zhe 	/* SPDIF route: PCM */
982cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9835218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
9845218c892SJiang Zhe 	/* EAPD */
9855218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
9865218c892SJiang Zhe 	{ } /* end */
9875218c892SJiang Zhe };
9887f29673bSTobin Davis 
9897f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
9907f29673bSTobin Davis 	/* pin sensing on HP jack */
9917f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
992d3091fadSTakashi Iwai 	{ } /* end */
9937f29673bSTobin Davis };
9947f29673bSTobin Davis 
9957f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
9967f29673bSTobin Davis 	/* pin sensing on HP jack */
9977f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
998d3091fadSTakashi Iwai 	{ } /* end */
9997f29673bSTobin Davis };
10007f29673bSTobin Davis 
1001c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1002c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1003c9b443d4STobin Davis  * configuration.
1004c9b443d4STobin Davis  */
1005c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
1006c9b443d4STobin Davis 	.num_items = 5,
1007c9b443d4STobin Davis 	.items = {
1008c9b443d4STobin Davis 		{ "MIXER", 0x0 },
1009c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
1010c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
1011c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
1012c9b443d4STobin Davis 		{ "CD pin", 0x4 },
1013c9b443d4STobin Davis         },
1014c9b443d4STobin Davis };
1015c9b443d4STobin Davis 
1016c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
1017c9b443d4STobin Davis 
1018c9b443d4STobin Davis 	/* Output controls */
1019c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1020c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
10217f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
10227f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
10237f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
10247f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1025c9b443d4STobin Davis 
1026c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1027c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
1028c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
1029c9b443d4STobin Davis 
103082f30040STobin Davis 	/* EAPD Switch Control */
103182f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
103282f30040STobin Davis 
1033c9b443d4STobin Davis 	/* Loopback mixer controls */
1034c9b443d4STobin Davis 
10357f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
10367f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
10377f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
10387f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
10397f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
10407f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
10417f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
10427f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
10437f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
10447f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
1045c9b443d4STobin Davis 	{
1046c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1047c9b443d4STobin Davis 		.name = "Input Source",
1048c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1049c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1050c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1051c9b443d4STobin Davis 	},
1052fb3409e7STobin Davis 	/* Audio input controls */
1053fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1054fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1055fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1056fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1057fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1058fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1059fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1060fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1061fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1062fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1063c9b443d4STobin Davis 	{ } /* end */
1064c9b443d4STobin Davis };
1065c9b443d4STobin Davis 
1066c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
10677f29673bSTobin Davis 	/* Set connections */
10687f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
10697f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
10707f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1071c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1072c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10737f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1074c9b443d4STobin Davis 
1075c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1076c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1077c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1078c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1079c9b443d4STobin Davis 	 * control.
1080c9b443d4STobin Davis 	 */
1081cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1082cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1083c9b443d4STobin Davis 
1084c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1085c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1086c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1087c9b443d4STobin Davis 
1088c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1089c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1090c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1091c9b443d4STobin Davis 	 * input/output buffers as needed.
1092c9b443d4STobin Davis 	 */
1093c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1094c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1095c9b443d4STobin Davis 
1096c9b443d4STobin Davis 	/* Mute capture amp left and right */
1097c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1098c9b443d4STobin Davis 
1099c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1100c9b443d4STobin Davis 	 * pin)
1101c9b443d4STobin Davis 	 */
1102c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
11037f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1104c9b443d4STobin Davis 
1105c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1106c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1107c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1108c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1109c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1110c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1111c9b443d4STobin Davis 
1112c9b443d4STobin Davis 	{ }
1113c9b443d4STobin Davis };
1114c9b443d4STobin Davis #endif
1115c9b443d4STobin Davis 
1116c9b443d4STobin Davis 
1117c9b443d4STobin Davis /* initialize jack-sensing, too */
1118c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
1119c9b443d4STobin Davis {
1120c9b443d4STobin Davis 	conexant_init(codec);
1121c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
1122c9b443d4STobin Davis 	return 0;
1123c9b443d4STobin Davis }
1124c9b443d4STobin Davis 
1125c9b443d4STobin Davis 
1126c9b443d4STobin Davis enum {
112715908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
112815908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
112915908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
11305218c892SJiang Zhe 	CXT5045_BENQ,
11312de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
1132c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1133c9b443d4STobin Davis 	CXT5045_TEST,
1134c9b443d4STobin Davis #endif
1135f5fcc13cSTakashi Iwai 	CXT5045_MODELS
1136c9b443d4STobin Davis };
1137c9b443d4STobin Davis 
1138ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = {
113915908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
114015908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
114115908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
11425218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
11432de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1144c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1145f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1146c9b443d4STobin Davis #endif
1147f5fcc13cSTakashi Iwai };
1148c9b443d4STobin Davis 
1149f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
11502de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1151dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1152dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPSENSE),
11536a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
11545218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
115515908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
115615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
11579e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
11589e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
115915908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
116015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
116115908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1162dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1163dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
116415908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1165c9b443d4STobin Davis 	{}
1166c9b443d4STobin Davis };
1167c9b443d4STobin Davis 
1168c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1169c9b443d4STobin Davis {
1170c9b443d4STobin Davis 	struct conexant_spec *spec;
1171c9b443d4STobin Davis 	int board_config;
1172c9b443d4STobin Davis 
1173c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1174c9b443d4STobin Davis 	if (!spec)
1175c9b443d4STobin Davis 		return -ENOMEM;
1176c9b443d4STobin Davis 	codec->spec = spec;
11779421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1178c9b443d4STobin Davis 
1179c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1180c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1181c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1182c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1183c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1184c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1185c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1186c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1187c9b443d4STobin Davis 	spec->num_mixers = 1;
1188c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1189c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1190c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1191c9b443d4STobin Davis 	spec->spdif_route = 0;
11923507e2a8STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
11933507e2a8STakashi Iwai 	spec->channel_mode = cxt5045_modes;
11945cd57529STobin Davis 
11953507e2a8STakashi Iwai 	set_beep_amp(spec, 0x16, 0, 1);
1196c9b443d4STobin Davis 
1197c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1198c9b443d4STobin Davis 
1199f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1200f5fcc13cSTakashi Iwai 						  cxt5045_models,
1201f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
1202c9b443d4STobin Davis 	switch (board_config) {
120315908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
12047f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1205c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1206c9b443d4STobin Davis 		spec->num_init_verbs = 2;
12077f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
12087f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
12097f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
12107f29673bSTobin Davis 		break;
121115908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
121286376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
12137f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
12147f29673bSTobin Davis 		spec->num_init_verbs = 2;
12157f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1216c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1217c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1218c9b443d4STobin Davis 		break;
121915908c36SMarc Boucher 	default:
122015908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
122115908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
122215908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
122315908c36SMarc Boucher 		spec->num_init_verbs = 3;
122415908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
122515908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
122615908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
122715908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
122815908c36SMarc Boucher 		break;
12295218c892SJiang Zhe 	case CXT5045_BENQ:
12305218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
12315218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
12325218c892SJiang Zhe 		spec->num_init_verbs = 1;
12335218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
12345218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
12355218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
12365218c892SJiang Zhe 		spec->num_mixers = 2;
12375218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
12385218c892SJiang Zhe 		break;
12392de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
12402de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
12412de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
12422de3c232SJiang zhe 		spec->num_init_verbs = 2;
12432de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
12442de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
12452de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
12462de3c232SJiang zhe 		break;
1247c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1248c9b443d4STobin Davis 	case CXT5045_TEST:
1249c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1250c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1251c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
125215908c36SMarc Boucher 		break;
125315908c36SMarc Boucher 
1254c9b443d4STobin Davis #endif
1255c9b443d4STobin Davis 	}
125648ecb7e8STakashi Iwai 
1257031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1258031005f7STakashi Iwai 	case 0x103c:
12598f0f5ff6SDaniel T Chen 	case 0x1631:
12600b587fc4SDaniel T Chen 	case 0x1734:
12610ebf9e36SDaniel T Chen 	case 0x17aa:
12620ebf9e36SDaniel T Chen 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
12630ebf9e36SDaniel T Chen 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
12640ebf9e36SDaniel T Chen 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
126548ecb7e8STakashi Iwai 		 */
126648ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
126748ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
126848ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
126948ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
127048ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1271031005f7STakashi Iwai 		break;
1272031005f7STakashi Iwai 	}
127348ecb7e8STakashi Iwai 
12743507e2a8STakashi Iwai 	if (spec->beep_amp)
12753507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
12763507e2a8STakashi Iwai 
1277c9b443d4STobin Davis 	return 0;
1278c9b443d4STobin Davis }
1279c9b443d4STobin Davis 
1280c9b443d4STobin Davis 
1281c9b443d4STobin Davis /* Conexant 5047 specific */
128282f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1283c9b443d4STobin Davis 
12845b3a7440STakashi Iwai static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1285c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1286c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1287c9b443d4STobin Davis 
12885cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
12895cd57529STobin Davis 	{ 2, NULL },
12905cd57529STobin Davis };
1291c9b443d4STobin Davis 
129282f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
129382f30040STobin Davis 	.num_items = 2,
129482f30040STobin Davis 	.items = {
129582f30040STobin Davis 		{ "ExtMic", 0x2 },
129682f30040STobin Davis 		{ "Line-In", 0x1 },
1297c9b443d4STobin Davis 	}
1298c9b443d4STobin Davis };
1299c9b443d4STobin Davis 
1300c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1301c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1302c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1303c9b443d4STobin Davis {
1304c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1305c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
130682f30040STobin Davis 	unsigned int bits;
1307c9b443d4STobin Davis 
130882f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1309c9b443d4STobin Davis 		return 0;
1310c9b443d4STobin Davis 
131182f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
131282f30040STobin Davis 	 * the headphone jack
131382f30040STobin Davis 	 */
131447fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
13153b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
13163b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
13173b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
13183b7523fcSTakashi Iwai 	 */
13195d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
132047fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
132147fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
132247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
132347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1324c9b443d4STobin Davis 	return 1;
1325c9b443d4STobin Davis }
1326c9b443d4STobin Davis 
1327c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1328c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1329c9b443d4STobin Davis {
133082f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1331dd87da1cSTobin Davis 	unsigned int bits;
1332c9b443d4STobin Davis 
1333d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1334dd87da1cSTobin Davis 
133547fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
13363b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13375d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
133847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1339c9b443d4STobin Davis }
1340c9b443d4STobin Davis 
1341c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1342c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1343c9b443d4STobin Davis {
1344c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
13459f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13469f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1347c9b443d4STobin Davis 		{}
1348c9b443d4STobin Davis 	};
1349c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
13509f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13519f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1352c9b443d4STobin Davis 		{}
1353c9b443d4STobin Davis 	};
1354c9b443d4STobin Davis 	unsigned int present;
1355c9b443d4STobin Davis 
1356d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1357c9b443d4STobin Davis 	if (present)
1358c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1359c9b443d4STobin Davis 	else
1360c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1361c9b443d4STobin Davis }
1362c9b443d4STobin Davis 
1363c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1364c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1365c9b443d4STobin Davis 				  unsigned int res)
1366c9b443d4STobin Davis {
13679f113e0eSMarc Boucher 	switch (res >> 26) {
1368c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1369c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1370c9b443d4STobin Davis 		break;
1371c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1372c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1373c9b443d4STobin Davis 		break;
1374c9b443d4STobin Davis 	}
1375c9b443d4STobin Davis }
1376c9b443d4STobin Davis 
1377df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1378df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1379df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
13805f99f86aSDavid Henningsson 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1381c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1382c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1383c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1384c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
138582f30040STobin Davis 	{
138682f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
138782f30040STobin Davis 		.name = "Master Playback Switch",
138882f30040STobin Davis 		.info = cxt_eapd_info,
138982f30040STobin Davis 		.get = cxt_eapd_get,
1390c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1391c9b443d4STobin Davis 		.private_value = 0x13,
1392c9b443d4STobin Davis 	},
1393c9b443d4STobin Davis 
1394c9b443d4STobin Davis 	{}
1395c9b443d4STobin Davis };
1396c9b443d4STobin Davis 
1397df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
13983b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13995d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1400df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1401df481e41STakashi Iwai 	{}
1402df481e41STakashi Iwai };
1403df481e41STakashi Iwai 
1404df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1405c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1406c9b443d4STobin Davis 	{ } /* end */
1407c9b443d4STobin Davis };
1408c9b443d4STobin Davis 
1409c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1410c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1411c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1412c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1413c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
14147f29673bSTobin Davis 	/* HP, Speaker  */
1415b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
14165b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
14175b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
14187f29673bSTobin Davis 	/* Record selector: Mic */
14197f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
14207f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
14217f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
14227f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1423c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1424c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1425c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1426c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1427c9b443d4STobin Davis 	/* SPDIF route: PCM */
1428c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
142982f30040STobin Davis 	/* Enable unsolicited events */
143082f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
143182f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1432c9b443d4STobin Davis 	{ } /* end */
1433c9b443d4STobin Davis };
1434c9b443d4STobin Davis 
1435c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1436c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
14373b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1438c9b443d4STobin Davis 	{}
1439c9b443d4STobin Davis };
1440c9b443d4STobin Davis 
1441c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1442c9b443d4STobin Davis  * configuration.
1443c9b443d4STobin Davis  */
1444c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1445c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
144682f30040STobin Davis 	.num_items = 4,
1447c9b443d4STobin Davis 	.items = {
144882f30040STobin Davis 		{ "LINE1 pin", 0x0 },
144982f30040STobin Davis 		{ "MIC1 pin", 0x1 },
145082f30040STobin Davis 		{ "MIC2 pin", 0x2 },
145182f30040STobin Davis 		{ "CD pin", 0x3 },
1452c9b443d4STobin Davis         },
1453c9b443d4STobin Davis };
1454c9b443d4STobin Davis 
1455c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1456c9b443d4STobin Davis 
1457c9b443d4STobin Davis 	/* Output only controls */
145882f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
145982f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
146082f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
146182f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1462c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1463c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1464c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1465c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
146682f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
146782f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
146882f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
146982f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1470c9b443d4STobin Davis 
1471c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1472c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1473c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1474c9b443d4STobin Davis 
147582f30040STobin Davis 	/* EAPD Switch Control */
147682f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
147782f30040STobin Davis 
1478c9b443d4STobin Davis 	/* Loopback mixer controls */
147982f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
148082f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
148182f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
148282f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
148382f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
148482f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
148582f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
148682f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1487c9b443d4STobin Davis 
148882f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
148982f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
149082f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
149182f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
149282f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
149382f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
149482f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
149582f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1496c9b443d4STobin Davis 	{
1497c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1498c9b443d4STobin Davis 		.name = "Input Source",
1499c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1500c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1501c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1502c9b443d4STobin Davis 	},
1503854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
15049f113e0eSMarc Boucher 
1505c9b443d4STobin Davis 	{ } /* end */
1506c9b443d4STobin Davis };
1507c9b443d4STobin Davis 
1508c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1509c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1510c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1511c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1512c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1513c9b443d4STobin Davis 
1514c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1515c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1516c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1517c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1518c9b443d4STobin Davis 	 * control.
1519c9b443d4STobin Davis 	 */
1520c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1521c9b443d4STobin Davis 
1522c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1523c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1524c9b443d4STobin Davis 	 */
1525c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1526c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1527c9b443d4STobin Davis 
1528c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1529c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1530c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1531c9b443d4STobin Davis 
1532c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1533c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1534c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1535c9b443d4STobin Davis 	 * input/output buffers as needed.
1536c9b443d4STobin Davis 	 */
1537c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1538c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1539c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1540c9b443d4STobin Davis 
1541c9b443d4STobin Davis 	/* Mute capture amp left and right */
1542c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1543c9b443d4STobin Davis 
1544c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1545c9b443d4STobin Davis 	 * pin)
1546c9b443d4STobin Davis 	 */
1547c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1548c9b443d4STobin Davis 
1549c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1550c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1551c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1552c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1553c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1554c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1555c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1556c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1557c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1558c9b443d4STobin Davis 
1559c9b443d4STobin Davis 	{ }
1560c9b443d4STobin Davis };
1561c9b443d4STobin Davis #endif
1562c9b443d4STobin Davis 
1563c9b443d4STobin Davis 
1564c9b443d4STobin Davis /* initialize jack-sensing, too */
1565c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1566c9b443d4STobin Davis {
1567c9b443d4STobin Davis 	conexant_init(codec);
1568c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1569c9b443d4STobin Davis 	return 0;
1570c9b443d4STobin Davis }
1571c9b443d4STobin Davis 
1572c9b443d4STobin Davis 
1573c9b443d4STobin Davis enum {
1574f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1575f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1576f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1577c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1578c9b443d4STobin Davis 	CXT5047_TEST,
1579c9b443d4STobin Davis #endif
1580f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1581c9b443d4STobin Davis };
1582c9b443d4STobin Davis 
1583ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = {
1584f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1585f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1586f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1587c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1588f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1589c9b443d4STobin Davis #endif
1590f5fcc13cSTakashi Iwai };
1591c9b443d4STobin Davis 
1592f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1593ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1594dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1595dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1596f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1597c9b443d4STobin Davis 	{}
1598c9b443d4STobin Davis };
1599c9b443d4STobin Davis 
1600c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1601c9b443d4STobin Davis {
1602c9b443d4STobin Davis 	struct conexant_spec *spec;
1603c9b443d4STobin Davis 	int board_config;
1604c9b443d4STobin Davis 
1605c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1606c9b443d4STobin Davis 	if (!spec)
1607c9b443d4STobin Davis 		return -ENOMEM;
1608c9b443d4STobin Davis 	codec->spec = spec;
16099421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1610c9b443d4STobin Davis 
1611c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1612c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1613c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1614c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1615c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1616c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1617c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1618c9b443d4STobin Davis 	spec->num_mixers = 1;
1619df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1620c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1621c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1622c9b443d4STobin Davis 	spec->spdif_route = 0;
16235cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
16245cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1625c9b443d4STobin Davis 
1626c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1627c9b443d4STobin Davis 
1628f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1629f5fcc13cSTakashi Iwai 						  cxt5047_models,
1630f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1631c9b443d4STobin Davis 	switch (board_config) {
1632c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1633df481e41STakashi Iwai 		spec->num_mixers = 2;
1634df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1635df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1636c9b443d4STobin Davis 		break;
1637c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1638df481e41STakashi Iwai 		spec->num_mixers = 2;
1639df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1640fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1641c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1642c9b443d4STobin Davis 		break;
1643c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
164482f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1645df481e41STakashi Iwai 		spec->num_mixers = 2;
1646df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1647c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1648c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1649fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1650c9b443d4STobin Davis 		break;
1651c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1652c9b443d4STobin Davis 	case CXT5047_TEST:
1653c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1654c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1655c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1656fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1657c9b443d4STobin Davis #endif
1658c9b443d4STobin Davis 	}
1659dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1660025f206cSDaniel T Chen 
1661025f206cSDaniel T Chen 	switch (codec->subsystem_id >> 16) {
1662025f206cSDaniel T Chen 	case 0x103c:
1663025f206cSDaniel T Chen 		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1664025f206cSDaniel T Chen 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1665025f206cSDaniel T Chen 		 * with 0 dB offset 0x17)
1666025f206cSDaniel T Chen 		 */
1667025f206cSDaniel T Chen 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1668025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1669025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1670025f206cSDaniel T Chen 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1671025f206cSDaniel T Chen 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1672025f206cSDaniel T Chen 		break;
1673025f206cSDaniel T Chen 	}
1674025f206cSDaniel T Chen 
1675c9b443d4STobin Davis 	return 0;
1676c9b443d4STobin Davis }
1677c9b443d4STobin Davis 
1678461e2c78STakashi Iwai /* Conexant 5051 specific */
1679461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1680461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1681461e2c78STakashi Iwai 
1682461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = {
1683461e2c78STakashi Iwai 	{ 2, NULL },
1684461e2c78STakashi Iwai };
1685461e2c78STakashi Iwai 
1686461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1687461e2c78STakashi Iwai {
1688461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1689461e2c78STakashi Iwai 	unsigned int pinctl;
169023d2df5bSTakashi Iwai 	/* headphone pin */
169123d2df5bSTakashi Iwai 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
169223d2df5bSTakashi Iwai 	snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
169323d2df5bSTakashi Iwai 			    pinctl);
169423d2df5bSTakashi Iwai 	/* speaker pin */
1695461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1696461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1697461e2c78STakashi Iwai 			    pinctl);
1698f7154de2SHerton Ronaldo Krzesinski 	/* on ideapad there is an aditional speaker (subwoofer) to mute */
1699f7154de2SHerton Ronaldo Krzesinski 	if (spec->ideapad)
1700f7154de2SHerton Ronaldo Krzesinski 		snd_hda_codec_write(codec, 0x1b, 0,
1701f7154de2SHerton Ronaldo Krzesinski 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
1702f7154de2SHerton Ronaldo Krzesinski 				    pinctl);
1703461e2c78STakashi Iwai }
1704461e2c78STakashi Iwai 
1705461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1706461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1707461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1708461e2c78STakashi Iwai {
1709461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1710461e2c78STakashi Iwai 
1711461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1712461e2c78STakashi Iwai 		return 0;
1713461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1714461e2c78STakashi Iwai 	return 1;
1715461e2c78STakashi Iwai }
1716461e2c78STakashi Iwai 
1717461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1718461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1719461e2c78STakashi Iwai {
172079d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1721461e2c78STakashi Iwai 	unsigned int present;
1722461e2c78STakashi Iwai 
1723faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTB))
172479d7d533STakashi Iwai 		return;
1725d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1726461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1727461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1728461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1729461e2c78STakashi Iwai }
1730461e2c78STakashi Iwai 
1731461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1732461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1733461e2c78STakashi Iwai {
1734461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1735461e2c78STakashi Iwai 	unsigned int present;
1736461e2c78STakashi Iwai 	hda_nid_t new_adc;
1737461e2c78STakashi Iwai 
1738faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTC))
173979d7d533STakashi Iwai 		return;
1740d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1741461e2c78STakashi Iwai 	if (present)
1742461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1743461e2c78STakashi Iwai 	else
1744461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1745461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1746461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1747461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1748f0cea797STakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1749461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1750461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1751461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1752461e2c78STakashi Iwai 					   spec->cur_adc_format);
1753461e2c78STakashi Iwai 	}
1754461e2c78STakashi Iwai }
1755461e2c78STakashi Iwai 
1756461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1757461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1758461e2c78STakashi Iwai {
1759461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1760461e2c78STakashi Iwai 
1761d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1762461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1763461e2c78STakashi Iwai }
1764461e2c78STakashi Iwai 
1765461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1766461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1767461e2c78STakashi Iwai 				   unsigned int res)
1768461e2c78STakashi Iwai {
1769acf26c0cSUlrich Dangel 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1770461e2c78STakashi Iwai 	switch (res >> 26) {
1771461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1772461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1773461e2c78STakashi Iwai 		break;
1774461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1775461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1776461e2c78STakashi Iwai 		break;
1777461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1778461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1779461e2c78STakashi Iwai 		break;
1780461e2c78STakashi Iwai 	}
1781acf26c0cSUlrich Dangel 	conexant_report_jack(codec, nid);
1782461e2c78STakashi Iwai }
1783461e2c78STakashi Iwai 
17842c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1785461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1786461e2c78STakashi Iwai 	{
1787461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1788461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1789461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1790461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1791461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1792461e2c78STakashi Iwai 		.private_value = 0x1a,
1793461e2c78STakashi Iwai 	},
17942c7a3fb3STakashi Iwai 	{}
17952c7a3fb3STakashi Iwai };
1796461e2c78STakashi Iwai 
17972c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
17982c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
17992c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
18008607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
18018607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
18022c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
18032c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1804461e2c78STakashi Iwai 	{}
1805461e2c78STakashi Iwai };
1806461e2c78STakashi Iwai 
1807461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1808461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1809461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
18108607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
18118607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1812461e2c78STakashi Iwai 	{}
1813461e2c78STakashi Iwai };
1814461e2c78STakashi Iwai 
181579d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
18164e4ac600STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
18174e4ac600STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
181879d7d533STakashi Iwai 	{}
181979d7d533STakashi Iwai };
182079d7d533STakashi Iwai 
1821cd9d95a5SKen Prox static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
18225f6c3de6STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
18235f6c3de6STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1824cd9d95a5SKen Prox 	{}
1825cd9d95a5SKen Prox };
1826cd9d95a5SKen Prox 
1827faddaa5dSTakashi Iwai static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1828faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1829faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
18308607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
18318607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1832faddaa5dSTakashi Iwai 	{}
1833faddaa5dSTakashi Iwai };
1834faddaa5dSTakashi Iwai 
1835461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = {
1836461e2c78STakashi Iwai 	/* Line in, Mic */
1837461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1838461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1839461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1840461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1841461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1842461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1843461e2c78STakashi Iwai 	/* SPK  */
1844461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1845461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1846461e2c78STakashi Iwai 	/* HP, Amp  */
1847461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1848461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1849461e2c78STakashi Iwai 	/* DAC1 */
1850461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
185128c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1852461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1853461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1854461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1855461e2c78STakashi Iwai 	/* SPDIF route: PCM */
18561965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1857461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1858461e2c78STakashi Iwai 	/* EAPD */
1859461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1860461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1861461e2c78STakashi Iwai 	{ } /* end */
1862461e2c78STakashi Iwai };
1863461e2c78STakashi Iwai 
186479d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
186579d7d533STakashi Iwai 	/* Line in, Mic */
186679d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
186779d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
186879d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
186979d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
187079d7d533STakashi Iwai 	/* SPK  */
187179d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
187279d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
187379d7d533STakashi Iwai 	/* HP, Amp  */
187479d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
187579d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
187679d7d533STakashi Iwai 	/* DAC1 */
187779d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
187828c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
187979d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
188079d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
188179d7d533STakashi Iwai 	/* SPDIF route: PCM */
188279d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
188379d7d533STakashi Iwai 	/* EAPD */
188479d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
188579d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
188679d7d533STakashi Iwai 	{ } /* end */
188779d7d533STakashi Iwai };
188879d7d533STakashi Iwai 
188927e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
189027e08988SAristeu Sergio Rozanski Filho 	/* Line in, Mic */
189127e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
189227e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
189327e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
189427e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
189527e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
189627e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
189727e08988SAristeu Sergio Rozanski Filho 	/* SPK  */
189827e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
189927e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
190027e08988SAristeu Sergio Rozanski Filho 	/* HP, Amp  */
190127e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
190227e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
190327e08988SAristeu Sergio Rozanski Filho 	/* Docking HP */
190427e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
190527e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
190627e08988SAristeu Sergio Rozanski Filho 	/* DAC1 */
190727e08988SAristeu Sergio Rozanski Filho 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
190828c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
190927e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
191027e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
191127e08988SAristeu Sergio Rozanski Filho 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
191227e08988SAristeu Sergio Rozanski Filho 	/* SPDIF route: PCM */
19131965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
191427e08988SAristeu Sergio Rozanski Filho 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
191527e08988SAristeu Sergio Rozanski Filho 	/* EAPD */
191627e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
191727e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
191827e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
191927e08988SAristeu Sergio Rozanski Filho 	{ } /* end */
192027e08988SAristeu Sergio Rozanski Filho };
192127e08988SAristeu Sergio Rozanski Filho 
1922cd9d95a5SKen Prox static struct hda_verb cxt5051_f700_init_verbs[] = {
1923cd9d95a5SKen Prox 	/* Line in, Mic */
192430ed7ed1STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1925cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1926cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1927cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1928cd9d95a5SKen Prox 	/* SPK  */
1929cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1930cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1931cd9d95a5SKen Prox 	/* HP, Amp  */
1932cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1933cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1934cd9d95a5SKen Prox 	/* DAC1 */
1935cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
193628c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1937cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1938cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1939cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1940cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1941cd9d95a5SKen Prox 	/* EAPD */
1942cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1943cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1944cd9d95a5SKen Prox 	{ } /* end */
1945cd9d95a5SKen Prox };
1946cd9d95a5SKen Prox 
19476953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
19486953e552STakashi Iwai 				 unsigned int event)
19496953e552STakashi Iwai {
19506953e552STakashi Iwai 	snd_hda_codec_write(codec, nid, 0,
19516953e552STakashi Iwai 			    AC_VERB_SET_UNSOLICITED_ENABLE,
19526953e552STakashi Iwai 			    AC_USRSP_EN | event);
19536953e552STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
19546953e552STakashi Iwai 	conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
19556953e552STakashi Iwai 	conexant_report_jack(codec, nid);
19566953e552STakashi Iwai #endif
19576953e552STakashi Iwai }
19586953e552STakashi Iwai 
1959f7154de2SHerton Ronaldo Krzesinski static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1960f7154de2SHerton Ronaldo Krzesinski 	/* Subwoofer */
1961f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1962f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1963f7154de2SHerton Ronaldo Krzesinski 	{ } /* end */
1964f7154de2SHerton Ronaldo Krzesinski };
1965f7154de2SHerton Ronaldo Krzesinski 
1966461e2c78STakashi Iwai /* initialize jack-sensing, too */
1967461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1968461e2c78STakashi Iwai {
19696953e552STakashi Iwai 	struct conexant_spec *spec = codec->spec;
19706953e552STakashi Iwai 
1971461e2c78STakashi Iwai 	conexant_init(codec);
1972acf26c0cSUlrich Dangel 	conexant_init_jacks(codec);
19736953e552STakashi Iwai 
19746953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTB)
19756953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
19766953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTC)
19776953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
19786953e552STakashi Iwai 
1979461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1980461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1981461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1982461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1983461e2c78STakashi Iwai 	}
1984461e2c78STakashi Iwai 	return 0;
1985461e2c78STakashi Iwai }
1986461e2c78STakashi Iwai 
1987461e2c78STakashi Iwai 
1988461e2c78STakashi Iwai enum {
1989461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1990461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
199179d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
19921965c441SPierre-Louis Bossart 	CXT5051_LENOVO_X200,	/* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1993cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
1994faddaa5dSTakashi Iwai 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
1995f7154de2SHerton Ronaldo Krzesinski 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
1996461e2c78STakashi Iwai 	CXT5051_MODELS
1997461e2c78STakashi Iwai };
1998461e2c78STakashi Iwai 
1999ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = {
2000461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
2001461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
200279d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
200327e08988SAristeu Sergio Rozanski Filho 	[CXT5051_LENOVO_X200]	= "lenovo-x200",
20045f6c3de6STakashi Iwai 	[CXT5051_F700]          = "hp-700",
2005faddaa5dSTakashi Iwai 	[CXT5051_TOSHIBA]	= "toshiba",
2006f7154de2SHerton Ronaldo Krzesinski 	[CXT5051_IDEAPAD]	= "ideapad",
2007461e2c78STakashi Iwai };
2008461e2c78STakashi Iwai 
2009461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
201079d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
20111812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
20125f6c3de6STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
2013faddaa5dSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
2014461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2015461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
2016461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
201727e08988SAristeu Sergio Rozanski Filho 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
2018f7154de2SHerton Ronaldo Krzesinski 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
2019461e2c78STakashi Iwai 	{}
2020461e2c78STakashi Iwai };
2021461e2c78STakashi Iwai 
2022461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
2023461e2c78STakashi Iwai {
2024461e2c78STakashi Iwai 	struct conexant_spec *spec;
2025461e2c78STakashi Iwai 	int board_config;
2026461e2c78STakashi Iwai 
2027461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2028461e2c78STakashi Iwai 	if (!spec)
2029461e2c78STakashi Iwai 		return -ENOMEM;
2030461e2c78STakashi Iwai 	codec->spec = spec;
20319421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
2032461e2c78STakashi Iwai 
2033461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
2034461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
2035461e2c78STakashi Iwai 
2036461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
2037461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2038461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
2039461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2040461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2041461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
20422c7a3fb3STakashi Iwai 	spec->num_mixers = 2;
20432c7a3fb3STakashi Iwai 	spec->mixers[0] = cxt5051_capture_mixers;
20442c7a3fb3STakashi Iwai 	spec->mixers[1] = cxt5051_playback_mixers;
2045461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
2046461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
2047461e2c78STakashi Iwai 	spec->spdif_route = 0;
2048461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2049461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
2050461e2c78STakashi Iwai 	spec->cur_adc = 0;
2051461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
2052461e2c78STakashi Iwai 
20533507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
20543507e2a8STakashi Iwai 
205579d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
205679d7d533STakashi Iwai 
2057461e2c78STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
2058461e2c78STakashi Iwai 						  cxt5051_models,
2059461e2c78STakashi Iwai 						  cxt5051_cfg_tbl);
2060faddaa5dSTakashi Iwai 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
2061461e2c78STakashi Iwai 	switch (board_config) {
2062461e2c78STakashi Iwai 	case CXT5051_HP:
2063461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
2064461e2c78STakashi Iwai 		break;
206579d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
206679d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
206779d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2068faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
206979d7d533STakashi Iwai 		break;
207027e08988SAristeu Sergio Rozanski Filho 	case CXT5051_LENOVO_X200:
207127e08988SAristeu Sergio Rozanski Filho 		spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
2072607bc3e4SJerone Young 		/* Thinkpad X301 does not have S/PDIF wired and no ability
2073607bc3e4SJerone Young 		   to use a docking station. */
2074607bc3e4SJerone Young 		if (codec->subsystem_id == 0x17aa211f)
2075607bc3e4SJerone Young 			spec->multiout.dig_out_nid = 0;
2076461e2c78STakashi Iwai 		break;
2077cd9d95a5SKen Prox 	case CXT5051_F700:
2078cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
2079cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
2080faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
2081faddaa5dSTakashi Iwai 		break;
2082faddaa5dSTakashi Iwai 	case CXT5051_TOSHIBA:
2083faddaa5dSTakashi Iwai 		spec->mixers[0] = cxt5051_toshiba_mixers;
2084faddaa5dSTakashi Iwai 		spec->auto_mic = AUTO_MIC_PORTB;
2085cd9d95a5SKen Prox 		break;
2086f7154de2SHerton Ronaldo Krzesinski 	case CXT5051_IDEAPAD:
2087f7154de2SHerton Ronaldo Krzesinski 		spec->init_verbs[spec->num_init_verbs++] =
2088f7154de2SHerton Ronaldo Krzesinski 			cxt5051_ideapad_init_verbs;
2089f7154de2SHerton Ronaldo Krzesinski 		spec->ideapad = 1;
2090f7154de2SHerton Ronaldo Krzesinski 		break;
2091461e2c78STakashi Iwai 	}
2092461e2c78STakashi Iwai 
20933507e2a8STakashi Iwai 	if (spec->beep_amp)
20943507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
20953507e2a8STakashi Iwai 
2096461e2c78STakashi Iwai 	return 0;
2097461e2c78STakashi Iwai }
2098461e2c78STakashi Iwai 
20990fb67e98SDaniel Drake /* Conexant 5066 specific */
21000fb67e98SDaniel Drake 
21010fb67e98SDaniel Drake static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
21020fb67e98SDaniel Drake static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
21030fb67e98SDaniel Drake static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
21040fb67e98SDaniel Drake #define CXT5066_SPDIF_OUT	0x21
21050fb67e98SDaniel Drake 
2106dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors,
2107dbaccc0cSDaniel Drake  * therefore we use a 50% mic bias in order to center the input signal with
2108dbaccc0cSDaniel Drake  * the DC input range of the codec. */
2109dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2110dbaccc0cSDaniel Drake 
21110fb67e98SDaniel Drake static struct hda_channel_mode cxt5066_modes[1] = {
21120fb67e98SDaniel Drake 	{ 2, NULL },
21130fb67e98SDaniel Drake };
21140fb67e98SDaniel Drake 
2115a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A	(1 << 0)
2116a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D	(1 << 1)
2117a3de8ab8STakashi Iwai #define hp_port_a_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_A)
2118a3de8ab8STakashi Iwai #define hp_port_d_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_D)
2119a3de8ab8STakashi Iwai 
21200fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
21210fb67e98SDaniel Drake {
21220fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
21230fb67e98SDaniel Drake 	unsigned int pinctl;
21240fb67e98SDaniel Drake 
21253a253445SJohn Baboval 	snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
21263a253445SJohn Baboval 		    spec->hp_present, spec->cur_eapd);
21270fb67e98SDaniel Drake 
21280fb67e98SDaniel Drake 	/* Port A (HP) */
2129a3de8ab8STakashi Iwai 	pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
21300fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21310fb67e98SDaniel Drake 			pinctl);
21320fb67e98SDaniel Drake 
21330fb67e98SDaniel Drake 	/* Port D (HP/LO) */
2134a3de8ab8STakashi Iwai 	pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2135a3de8ab8STakashi Iwai 	if (spec->dell_automute || spec->thinkpad) {
2136a3de8ab8STakashi Iwai 		/* Mute if Port A is connected */
2137a3de8ab8STakashi Iwai 		if (hp_port_a_present(spec))
21383a253445SJohn Baboval 			pinctl = 0;
21393a253445SJohn Baboval 	} else {
2140a3de8ab8STakashi Iwai 		/* Thinkpad/Dell doesn't give pin-D status */
2141a3de8ab8STakashi Iwai 		if (!hp_port_d_present(spec))
2142a3de8ab8STakashi Iwai 			pinctl = 0;
21433a253445SJohn Baboval 	}
21440fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21450fb67e98SDaniel Drake 			pinctl);
21460fb67e98SDaniel Drake 
21470fb67e98SDaniel Drake 	/* CLASS_D AMP */
21480fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
21490fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21500fb67e98SDaniel Drake 			pinctl);
21510fb67e98SDaniel Drake }
21520fb67e98SDaniel Drake 
21530fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
21540fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
21550fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
21560fb67e98SDaniel Drake {
21570fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
21580fb67e98SDaniel Drake 
21590fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
21600fb67e98SDaniel Drake 		return 0;
21610fb67e98SDaniel Drake 
21620fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
21630fb67e98SDaniel Drake 	return 1;
21640fb67e98SDaniel Drake }
21650fb67e98SDaniel Drake 
2166c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2167c4cfe66cSDaniel Drake 	.num_items = 3,
2168c4cfe66cSDaniel Drake 	.items = {
2169c4cfe66cSDaniel Drake 		{ "Off", PIN_IN },
2170c4cfe66cSDaniel Drake 		{ "50%", PIN_VREF50 },
2171c4cfe66cSDaniel Drake 		{ "80%", PIN_VREF80 },
2172c4cfe66cSDaniel Drake 	},
2173c4cfe66cSDaniel Drake };
2174c4cfe66cSDaniel Drake 
2175c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2176c4cfe66cSDaniel Drake {
2177c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2178c4cfe66cSDaniel Drake 	/* Even though port F is the DC input, the bias is controlled on port B.
2179c4cfe66cSDaniel Drake 	 * we also leave that port as an active input (but unselected) in DC mode
2180c4cfe66cSDaniel Drake 	 * just in case that is necessary to make the bias setting take effect. */
2181c4cfe66cSDaniel Drake 	return snd_hda_codec_write_cache(codec, 0x1a, 0,
2182c4cfe66cSDaniel Drake 		AC_VERB_SET_PIN_WIDGET_CONTROL,
2183c4cfe66cSDaniel Drake 		cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2184c4cfe66cSDaniel Drake }
2185c4cfe66cSDaniel Drake 
218675f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the
218775f8991dSDaniel Drake  * microphone LED comes on as soon as these settings are put in place. if we
218875f8991dSDaniel Drake  * did this before recording, it would give the false indication that recording
218975f8991dSDaniel Drake  * is happening when it is not. */
219075f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec)
21910fb67e98SDaniel Drake {
2192dbaccc0cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
219375f8991dSDaniel Drake 	if (!spec->recording)
219475f8991dSDaniel Drake 		return;
21950fb67e98SDaniel Drake 
2196c4cfe66cSDaniel Drake 	if (spec->dc_enable) {
2197c4cfe66cSDaniel Drake 		/* in DC mode we ignore presence detection and just use the jack
2198c4cfe66cSDaniel Drake 		 * through our special DC port */
2199c4cfe66cSDaniel Drake 		const struct hda_verb enable_dc_mode[] = {
2200c4cfe66cSDaniel Drake 			/* disble internal mic, port C */
2201c4cfe66cSDaniel Drake 			{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2202c4cfe66cSDaniel Drake 
2203c4cfe66cSDaniel Drake 			/* enable DC capture, port F */
2204c4cfe66cSDaniel Drake 			{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2205c4cfe66cSDaniel Drake 			{},
2206c4cfe66cSDaniel Drake 		};
2207c4cfe66cSDaniel Drake 
2208c4cfe66cSDaniel Drake 		snd_hda_sequence_write(codec, enable_dc_mode);
2209c4cfe66cSDaniel Drake 		/* port B input disabled (and bias set) through the following call */
2210c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
2211c4cfe66cSDaniel Drake 		return;
2212c4cfe66cSDaniel Drake 	}
2213c4cfe66cSDaniel Drake 
2214c4cfe66cSDaniel Drake 	/* disable DC (port F) */
2215c4cfe66cSDaniel Drake 	snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2216c4cfe66cSDaniel Drake 
221775f8991dSDaniel Drake 	/* external mic, port B */
221875f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
221975f8991dSDaniel Drake 		spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
22200fb67e98SDaniel Drake 
222175f8991dSDaniel Drake 	/* internal mic, port C */
222275f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
222375f8991dSDaniel Drake 		spec->ext_mic_present ? 0 : PIN_VREF80);
222475f8991dSDaniel Drake }
22250fb67e98SDaniel Drake 
222675f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */
222775f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec)
222875f8991dSDaniel Drake {
222975f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
22300fb67e98SDaniel Drake 	unsigned int present;
22310fb67e98SDaniel Drake 
2232c4cfe66cSDaniel Drake 	if (spec->dc_enable) /* don't do presence detection in DC mode */
2233c4cfe66cSDaniel Drake 		return;
2234c4cfe66cSDaniel Drake 
223575f8991dSDaniel Drake 	present = snd_hda_codec_read(codec, 0x1a, 0,
223675f8991dSDaniel Drake 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
223775f8991dSDaniel Drake 	if (present)
22380fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone detected\n");
223975f8991dSDaniel Drake 	else
22400fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone absent\n");
224175f8991dSDaniel Drake 
224275f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
224375f8991dSDaniel Drake 		present ? 0 : 1);
224475f8991dSDaniel Drake 	spec->ext_mic_present = !!present;
224575f8991dSDaniel Drake 
224675f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
22470fb67e98SDaniel Drake }
22480fb67e98SDaniel Drake 
224995a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
225095a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
225195a618bdSEinar Rünkaru {
225295a618bdSEinar Rünkaru 	unsigned int present;
225395a618bdSEinar Rünkaru 
225495a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
225595a618bdSEinar Rünkaru 		/* enable external mic, port B */
225675f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
225795a618bdSEinar Rünkaru 
225895a618bdSEinar Rünkaru 		/* switch to external mic input */
225995a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
226095a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
226195a618bdSEinar Rünkaru 
226295a618bdSEinar Rünkaru 		/* disable internal digital mic */
226395a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
226495a618bdSEinar Rünkaru 		{}
226595a618bdSEinar Rünkaru 	};
226695a618bdSEinar Rünkaru 	static struct hda_verb ext_mic_absent[] = {
226795a618bdSEinar Rünkaru 		/* enable internal mic, port C */
226895a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
226995a618bdSEinar Rünkaru 
227095a618bdSEinar Rünkaru 		/* switch to internal mic input */
227195a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
227295a618bdSEinar Rünkaru 
227395a618bdSEinar Rünkaru 		/* disable external mic, port B */
227495a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
227595a618bdSEinar Rünkaru 		{}
227695a618bdSEinar Rünkaru 	};
227795a618bdSEinar Rünkaru 
227895a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
227995a618bdSEinar Rünkaru 	if (present) {
228095a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
228195a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
228295a618bdSEinar Rünkaru 	} else {
228395a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
228495a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
228595a618bdSEinar Rünkaru 	}
228695a618bdSEinar Rünkaru }
228795a618bdSEinar Rünkaru 
2288cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */
2289cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec)
2290cfd3d8dcSGreg Alexander {
2291cfd3d8dcSGreg Alexander 	unsigned int present;
2292cfd3d8dcSGreg Alexander 
2293cfd3d8dcSGreg Alexander 	struct hda_verb ext_mic_present[] = {
2294cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2295cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2296cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2297cfd3d8dcSGreg Alexander 		{}
2298cfd3d8dcSGreg Alexander 	};
2299cfd3d8dcSGreg Alexander 	static struct hda_verb ext_mic_absent[] = {
2300cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2301cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2302cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2303cfd3d8dcSGreg Alexander 		{}
2304cfd3d8dcSGreg Alexander 	};
2305cfd3d8dcSGreg Alexander 
2306cfd3d8dcSGreg Alexander 	present = snd_hda_jack_detect(codec, 0x1b);
2307cfd3d8dcSGreg Alexander 	if (present) {
2308cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone detected\n");
2309cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_present);
2310cfd3d8dcSGreg Alexander 	} else {
2311cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone absent\n");
2312cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_absent);
2313cfd3d8dcSGreg Alexander 	}
2314cfd3d8dcSGreg Alexander }
2315cfd3d8dcSGreg Alexander 
2316*a1d6906eSDavid Henningsson 
2317*a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2318*a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec)
2319*a1d6906eSDavid Henningsson {
2320*a1d6906eSDavid Henningsson 	unsigned int present;
2321*a1d6906eSDavid Henningsson 
2322*a1d6906eSDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2323*a1d6906eSDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2324*a1d6906eSDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2325*a1d6906eSDavid Henningsson 			    present ? 1 : 0);
2326*a1d6906eSDavid Henningsson }
2327*a1d6906eSDavid Henningsson 
2328*a1d6906eSDavid Henningsson 
2329048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2330048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2331048e78a5SDavid Henningsson {
2332048e78a5SDavid Henningsson 	unsigned int present;
2333048e78a5SDavid Henningsson 
2334048e78a5SDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2335048e78a5SDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2336048e78a5SDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2337048e78a5SDavid Henningsson 			    present ? 1 : 3);
2338048e78a5SDavid Henningsson }
2339048e78a5SDavid Henningsson 
2340048e78a5SDavid Henningsson 
23417b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately
23427b2bfdbcSJens Taprogge    order is: external mic -> dock mic -> interal mic */
23437b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec)
23447b2bfdbcSJens Taprogge {
23457b2bfdbcSJens Taprogge 	unsigned int ext_present, dock_present;
23467b2bfdbcSJens Taprogge 
23477b2bfdbcSJens Taprogge 	static struct hda_verb ext_mic_present[] = {
23487b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
23497b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
23507b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23517b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23527b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23537b2bfdbcSJens Taprogge 		{}
23547b2bfdbcSJens Taprogge 	};
23557b2bfdbcSJens Taprogge 	static struct hda_verb dock_mic_present[] = {
23567b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
23577b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
23587b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23597b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23607b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23617b2bfdbcSJens Taprogge 		{}
23627b2bfdbcSJens Taprogge 	};
23637b2bfdbcSJens Taprogge 	static struct hda_verb ext_mic_absent[] = {
23647b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
23657b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
23667b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23677b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23687b2bfdbcSJens Taprogge 		{}
23697b2bfdbcSJens Taprogge 	};
23707b2bfdbcSJens Taprogge 
23717b2bfdbcSJens Taprogge 	ext_present = snd_hda_jack_detect(codec, 0x1b);
23727b2bfdbcSJens Taprogge 	dock_present = snd_hda_jack_detect(codec, 0x1a);
23737b2bfdbcSJens Taprogge 	if (ext_present) {
23747b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone detected\n");
23757b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_present);
23767b2bfdbcSJens Taprogge 	} else if (dock_present) {
23777b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: dock microphone detected\n");
23787b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, dock_mic_present);
23797b2bfdbcSJens Taprogge 	} else {
23807b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone absent\n");
23817b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_absent);
23827b2bfdbcSJens Taprogge 	}
23837b2bfdbcSJens Taprogge }
23847b2bfdbcSJens Taprogge 
23850fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
23860fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
23870fb67e98SDaniel Drake {
23880fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
23890fb67e98SDaniel Drake 	unsigned int portA, portD;
23900fb67e98SDaniel Drake 
23910fb67e98SDaniel Drake 	/* Port A */
2392d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
23930fb67e98SDaniel Drake 
23940fb67e98SDaniel Drake 	/* Port D */
2395d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
23960fb67e98SDaniel Drake 
2397a3de8ab8STakashi Iwai 	spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2398a3de8ab8STakashi Iwai 	spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
23990fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
24000fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
24010fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
24020fb67e98SDaniel Drake }
24030fb67e98SDaniel Drake 
240402b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */
240502b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec)
240602b6b5b6SDavid Henningsson {
240702b6b5b6SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
240802b6b5b6SDavid Henningsson 
240902b6b5b6SDavid Henningsson 	if (spec->dell_vostro)
241002b6b5b6SDavid Henningsson 		cxt5066_vostro_automic(codec);
241102b6b5b6SDavid Henningsson 	else if (spec->ideapad)
241202b6b5b6SDavid Henningsson 		cxt5066_ideapad_automic(codec);
241302b6b5b6SDavid Henningsson 	else if (spec->thinkpad)
241402b6b5b6SDavid Henningsson 		cxt5066_thinkpad_automic(codec);
241502b6b5b6SDavid Henningsson 	else if (spec->hp_laptop)
241602b6b5b6SDavid Henningsson 		cxt5066_hp_laptop_automic(codec);
2417*a1d6906eSDavid Henningsson 	else if (spec->asus)
2418*a1d6906eSDavid Henningsson 		cxt5066_asus_automic(codec);
241902b6b5b6SDavid Henningsson }
242002b6b5b6SDavid Henningsson 
24210fb67e98SDaniel Drake /* unsolicited event for jack sensing */
242275f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
24230fb67e98SDaniel Drake {
2424c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
24250fb67e98SDaniel Drake 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
24260fb67e98SDaniel Drake 	switch (res >> 26) {
24270fb67e98SDaniel Drake 	case CONEXANT_HP_EVENT:
24280fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
24290fb67e98SDaniel Drake 		break;
24300fb67e98SDaniel Drake 	case CONEXANT_MIC_EVENT:
2431c4cfe66cSDaniel Drake 		/* ignore mic events in DC mode; we're always using the jack */
2432c4cfe66cSDaniel Drake 		if (!spec->dc_enable)
243375f8991dSDaniel Drake 			cxt5066_olpc_automic(codec);
24340fb67e98SDaniel Drake 		break;
24350fb67e98SDaniel Drake 	}
24360fb67e98SDaniel Drake }
24370fb67e98SDaniel Drake 
243895a618bdSEinar Rünkaru /* unsolicited event for jack sensing */
243902b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
244095a618bdSEinar Rünkaru {
244102b6b5b6SDavid Henningsson 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
244295a618bdSEinar Rünkaru 	switch (res >> 26) {
244395a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
244495a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
244595a618bdSEinar Rünkaru 		break;
244695a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
244702b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
244895a618bdSEinar Rünkaru 		break;
244995a618bdSEinar Rünkaru 	}
245095a618bdSEinar Rünkaru }
245195a618bdSEinar Rünkaru 
24527b2bfdbcSJens Taprogge 
24530fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
24540fb67e98SDaniel Drake 	.num_items = 5,
24550fb67e98SDaniel Drake 	.items = {
24560fb67e98SDaniel Drake 		{ "0dB",  0 },
24570fb67e98SDaniel Drake 		{ "10dB", 1 },
24580fb67e98SDaniel Drake 		{ "20dB", 2 },
24590fb67e98SDaniel Drake 		{ "30dB", 3 },
24600fb67e98SDaniel Drake 		{ "40dB", 4 },
24610fb67e98SDaniel Drake 	},
24620fb67e98SDaniel Drake };
24630fb67e98SDaniel Drake 
2464cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec)
2465c4cfe66cSDaniel Drake {
2466c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2467cfd3d8dcSGreg Alexander 	snd_hda_codec_write_cache(codec, 0x17, 0,
2468c4cfe66cSDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2469c4cfe66cSDaniel Drake 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2470c4cfe66cSDaniel Drake 			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
24717b2bfdbcSJens Taprogge 	if (spec->ideapad || spec->thinkpad) {
2472cfd3d8dcSGreg Alexander 		/* adjust the internal mic as well...it is not through 0x17 */
2473cfd3d8dcSGreg Alexander 		snd_hda_codec_write_cache(codec, 0x23, 0,
2474cfd3d8dcSGreg Alexander 			AC_VERB_SET_AMP_GAIN_MUTE,
2475cfd3d8dcSGreg Alexander 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2476cfd3d8dcSGreg Alexander 				cxt5066_analog_mic_boost.
2477cfd3d8dcSGreg Alexander 					items[spec->mic_boost].index);
2478cfd3d8dcSGreg Alexander 	}
2479c4cfe66cSDaniel Drake }
2480c4cfe66cSDaniel Drake 
24810fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
24820fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
24830fb67e98SDaniel Drake {
24840fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
24850fb67e98SDaniel Drake }
24860fb67e98SDaniel Drake 
24870fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
24880fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24890fb67e98SDaniel Drake {
24900fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2491c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2492c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->mic_boost;
24930fb67e98SDaniel Drake 	return 0;
24940fb67e98SDaniel Drake }
24950fb67e98SDaniel Drake 
24960fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(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;
25010fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
25020fb67e98SDaniel Drake 	unsigned int idx;
25030fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
25040fb67e98SDaniel Drake 	if (idx >= imux->num_items)
25050fb67e98SDaniel Drake 		idx = imux->num_items - 1;
25060fb67e98SDaniel Drake 
2507c4cfe66cSDaniel Drake 	spec->mic_boost = idx;
2508c4cfe66cSDaniel Drake 	if (!spec->dc_enable)
2509c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
2510c4cfe66cSDaniel Drake 	return 1;
2511c4cfe66cSDaniel Drake }
25120fb67e98SDaniel Drake 
2513c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec)
2514c4cfe66cSDaniel Drake {
2515c4cfe66cSDaniel Drake 	const struct hda_verb enable_dc_mode[] = {
2516c4cfe66cSDaniel Drake 		/* disable gain */
2517c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2518c4cfe66cSDaniel Drake 
2519c4cfe66cSDaniel Drake 		/* switch to DC input */
2520c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_CONNECT_SEL, 3},
2521c4cfe66cSDaniel Drake 		{}
2522c4cfe66cSDaniel Drake 	};
2523c4cfe66cSDaniel Drake 
2524c4cfe66cSDaniel Drake 	/* configure as input source */
2525c4cfe66cSDaniel Drake 	snd_hda_sequence_write(codec, enable_dc_mode);
2526c4cfe66cSDaniel Drake 	cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2527c4cfe66cSDaniel Drake }
2528c4cfe66cSDaniel Drake 
2529c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec)
2530c4cfe66cSDaniel Drake {
2531c4cfe66cSDaniel Drake 	/* reconfigure input source */
2532c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
2533c4cfe66cSDaniel Drake 	/* automic also selects the right mic if we're recording */
2534c4cfe66cSDaniel Drake 	cxt5066_olpc_automic(codec);
2535c4cfe66cSDaniel Drake }
2536c4cfe66cSDaniel Drake 
2537c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2538c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2539c4cfe66cSDaniel Drake {
2540c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2541c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2542c4cfe66cSDaniel Drake 	ucontrol->value.integer.value[0] = spec->dc_enable;
2543c4cfe66cSDaniel Drake 	return 0;
2544c4cfe66cSDaniel Drake }
2545c4cfe66cSDaniel Drake 
2546c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(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 	int dc_enable = !!ucontrol->value.integer.value[0];
2552c4cfe66cSDaniel Drake 
2553c4cfe66cSDaniel Drake 	if (dc_enable == spec->dc_enable)
2554c4cfe66cSDaniel Drake 		return 0;
2555c4cfe66cSDaniel Drake 
2556c4cfe66cSDaniel Drake 	spec->dc_enable = dc_enable;
2557c4cfe66cSDaniel Drake 	if (dc_enable)
2558c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2559c4cfe66cSDaniel Drake 	else
2560c4cfe66cSDaniel Drake 		cxt5066_disable_dc(codec);
2561c4cfe66cSDaniel Drake 
2562c4cfe66cSDaniel Drake 	return 1;
2563c4cfe66cSDaniel Drake }
2564c4cfe66cSDaniel Drake 
2565c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2566c4cfe66cSDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
2567c4cfe66cSDaniel Drake {
2568c4cfe66cSDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2569c4cfe66cSDaniel Drake }
2570c4cfe66cSDaniel Drake 
2571c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2572c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2573c4cfe66cSDaniel Drake {
2574c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2575c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2576c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2577c4cfe66cSDaniel Drake 	return 0;
2578c4cfe66cSDaniel Drake }
2579c4cfe66cSDaniel Drake 
2580c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(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 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2586c4cfe66cSDaniel Drake 	unsigned int idx;
2587c4cfe66cSDaniel Drake 
2588c4cfe66cSDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
2589c4cfe66cSDaniel Drake 	if (idx >= imux->num_items)
2590c4cfe66cSDaniel Drake 		idx = imux->num_items - 1;
2591c4cfe66cSDaniel Drake 
2592c4cfe66cSDaniel Drake 	spec->dc_input_bias = idx;
2593c4cfe66cSDaniel Drake 	if (spec->dc_enable)
2594c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
25950fb67e98SDaniel Drake 	return 1;
25960fb67e98SDaniel Drake }
25970fb67e98SDaniel Drake 
259875f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
259975f8991dSDaniel Drake {
260075f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
260175f8991dSDaniel Drake 	/* mark as recording and configure the microphone widget so that the
260275f8991dSDaniel Drake 	 * recording LED comes on. */
260375f8991dSDaniel Drake 	spec->recording = 1;
260475f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
260575f8991dSDaniel Drake }
260675f8991dSDaniel Drake 
260775f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
260875f8991dSDaniel Drake {
260975f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
261075f8991dSDaniel Drake 	const struct hda_verb disable_mics[] = {
261175f8991dSDaniel Drake 		/* disable external mic, port B */
261275f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
261375f8991dSDaniel Drake 
261475f8991dSDaniel Drake 		/* disble internal mic, port C */
261575f8991dSDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2616c4cfe66cSDaniel Drake 
2617c4cfe66cSDaniel Drake 		/* disable DC capture, port F */
2618c4cfe66cSDaniel Drake 		{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
261975f8991dSDaniel Drake 		{},
262075f8991dSDaniel Drake 	};
262175f8991dSDaniel Drake 
262275f8991dSDaniel Drake 	snd_hda_sequence_write(codec, disable_mics);
262375f8991dSDaniel Drake 	spec->recording = 0;
262475f8991dSDaniel Drake }
262575f8991dSDaniel Drake 
26260fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = {
26270fb67e98SDaniel Drake 	.num_items = 4,
26280fb67e98SDaniel Drake 	.items = {
26290fb67e98SDaniel Drake 		{ "Mic B", 0 },
26300fb67e98SDaniel Drake 		{ "Mic C", 1 },
26310fb67e98SDaniel Drake 		{ "Mic E", 2 },
26320fb67e98SDaniel Drake 		{ "Mic F", 3 },
26330fb67e98SDaniel Drake 	},
26340fb67e98SDaniel Drake };
26350fb67e98SDaniel Drake 
26360fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
26370fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
26380fb67e98SDaniel Drake 	.values = {
26390fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26400fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26410fb67e98SDaniel Drake 		0
26420fb67e98SDaniel Drake 	},
26430fb67e98SDaniel Drake };
26440fb67e98SDaniel Drake 
26450fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
26460fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
26470fb67e98SDaniel Drake 	.values = {
26480fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26490fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26500fb67e98SDaniel Drake 		0
26510fb67e98SDaniel Drake 	},
26520fb67e98SDaniel Drake };
26530fb67e98SDaniel Drake 
26540fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = {
26550fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
26560fb67e98SDaniel Drake 	{}
26570fb67e98SDaniel Drake };
26580fb67e98SDaniel Drake 
26590fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
26600fb67e98SDaniel Drake 	{
26610fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26620fb67e98SDaniel Drake 		.name = "Master Playback Volume",
26630fb67e98SDaniel Drake 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
26640fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
26650fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
26665e26dfd0SJaroslav Kysela 		.subdevice = HDA_SUBDEV_AMP_FLAG,
26670fb67e98SDaniel Drake 		.info = snd_hda_mixer_amp_volume_info,
26680fb67e98SDaniel Drake 		.get = snd_hda_mixer_amp_volume_get,
26690fb67e98SDaniel Drake 		.put = snd_hda_mixer_amp_volume_put,
26700fb67e98SDaniel Drake 		.tlv = { .c = snd_hda_mixer_amp_tlv },
26710fb67e98SDaniel Drake 		/* offset by 28 volume steps to limit minimum gain to -46dB */
26720fb67e98SDaniel Drake 		.private_value =
26730fb67e98SDaniel Drake 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
26740fb67e98SDaniel Drake 	},
26750fb67e98SDaniel Drake 	{}
26760fb67e98SDaniel Drake };
26770fb67e98SDaniel Drake 
2678c4cfe66cSDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2679c4cfe66cSDaniel Drake 	{
2680c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2681c4cfe66cSDaniel Drake 		.name = "DC Mode Enable Switch",
2682c4cfe66cSDaniel Drake 		.info = snd_ctl_boolean_mono_info,
2683c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_get,
2684c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_put,
2685c4cfe66cSDaniel Drake 	},
2686c4cfe66cSDaniel Drake 	{
2687c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2688c4cfe66cSDaniel Drake 		.name = "DC Input Bias Enum",
2689c4cfe66cSDaniel Drake 		.info = cxt5066_olpc_dc_bias_enum_info,
2690c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_bias_enum_get,
2691c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_bias_enum_put,
2692c4cfe66cSDaniel Drake 	},
2693c4cfe66cSDaniel Drake 	{}
2694c4cfe66cSDaniel Drake };
2695c4cfe66cSDaniel Drake 
26960fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = {
26970fb67e98SDaniel Drake 	{
26980fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26990fb67e98SDaniel Drake 		.name = "Master Playback Switch",
27000fb67e98SDaniel Drake 		.info = cxt_eapd_info,
27010fb67e98SDaniel Drake 		.get = cxt_eapd_get,
27020fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
27030fb67e98SDaniel Drake 		.private_value = 0x1d,
27040fb67e98SDaniel Drake 	},
27050fb67e98SDaniel Drake 
27060fb67e98SDaniel Drake 	{
27070fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2708c4cfe66cSDaniel Drake 		.name = "Analog Mic Boost Capture Enum",
27090fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
27100fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
27110fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
27120fb67e98SDaniel Drake 	},
27130fb67e98SDaniel Drake 
27140fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
27150fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
27160fb67e98SDaniel Drake 	{}
27170fb67e98SDaniel Drake };
27180fb67e98SDaniel Drake 
2719254bba6aSEinar Rünkaru static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2720254bba6aSEinar Rünkaru 	{
2721254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
272228c4edb7SDavid Henningsson 		.name = "Internal Mic Boost Capture Enum",
2723254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2724254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2725254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2726254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2727254bba6aSEinar Rünkaru 	},
2728254bba6aSEinar Rünkaru 	{}
2729254bba6aSEinar Rünkaru };
2730254bba6aSEinar Rünkaru 
27310fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = {
27320fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
27330fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
27340fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
27350fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
27360fb67e98SDaniel Drake 
27370fb67e98SDaniel Drake 	/* Speakers  */
27380fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27390fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27400fb67e98SDaniel Drake 
27410fb67e98SDaniel Drake 	/* HP, Amp  */
27420fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27430fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27440fb67e98SDaniel Drake 
27450fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27460fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27470fb67e98SDaniel Drake 
27480fb67e98SDaniel Drake 	/* DAC1 */
27490fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
27500fb67e98SDaniel Drake 
27510fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
27520fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
27530fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27540fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
27550fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27560fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
27570fb67e98SDaniel Drake 
27580fb67e98SDaniel Drake 	/* no digital microphone support yet */
27590fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27600fb67e98SDaniel Drake 
27610fb67e98SDaniel Drake 	/* Audio input selector */
27620fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
27630fb67e98SDaniel Drake 
27640fb67e98SDaniel Drake 	/* SPDIF route: PCM */
27650fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
27660fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
27670fb67e98SDaniel Drake 
27680fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27690fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27700fb67e98SDaniel Drake 
27710fb67e98SDaniel Drake 	/* EAPD */
27720fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27730fb67e98SDaniel Drake 
27740fb67e98SDaniel Drake 	/* not handling these yet */
27750fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27760fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27770fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27780fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27790fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27800fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27810fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27820fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27830fb67e98SDaniel Drake 	{ } /* end */
27840fb67e98SDaniel Drake };
27850fb67e98SDaniel Drake 
27860fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = {
27870fb67e98SDaniel Drake 	/* Port A: headphones */
27880fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27890fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27900fb67e98SDaniel Drake 
27910fb67e98SDaniel Drake 	/* Port B: external microphone */
279275f8991dSDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27930fb67e98SDaniel Drake 
27940fb67e98SDaniel Drake 	/* Port C: internal microphone */
279575f8991dSDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27960fb67e98SDaniel Drake 
27970fb67e98SDaniel Drake 	/* Port D: unused */
27980fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27990fb67e98SDaniel Drake 
28000fb67e98SDaniel Drake 	/* Port E: unused, but has primary EAPD */
28010fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28020fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
28030fb67e98SDaniel Drake 
2804c4cfe66cSDaniel Drake 	/* Port F: external DC input through microphone port */
28050fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28060fb67e98SDaniel Drake 
28070fb67e98SDaniel Drake 	/* Port G: internal speakers */
28080fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
28090fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
28100fb67e98SDaniel Drake 
28110fb67e98SDaniel Drake 	/* DAC1 */
28120fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
28130fb67e98SDaniel Drake 
28140fb67e98SDaniel Drake 	/* DAC2: unused */
28150fb67e98SDaniel Drake 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
28160fb67e98SDaniel Drake 
28170fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
28180fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28190fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28200fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28210fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
28220fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28230fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28240fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28250fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
28260fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28270fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28280fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28290fb67e98SDaniel Drake 
28300fb67e98SDaniel Drake 	/* Disable digital microphone port */
28310fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28320fb67e98SDaniel Drake 
28330fb67e98SDaniel Drake 	/* Audio input selectors */
28340fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
28350fb67e98SDaniel Drake 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
28360fb67e98SDaniel Drake 
28370fb67e98SDaniel Drake 	/* Disable SPDIF */
28380fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28390fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28400fb67e98SDaniel Drake 
28410fb67e98SDaniel Drake 	/* enable unsolicited events for Port A and B */
28420fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
28430fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
28440fb67e98SDaniel Drake 	{ } /* end */
28450fb67e98SDaniel Drake };
28460fb67e98SDaniel Drake 
284795a618bdSEinar Rünkaru static struct hda_verb cxt5066_init_verbs_vostro[] = {
284895a618bdSEinar Rünkaru 	/* Port A: headphones */
284995a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
285095a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
285195a618bdSEinar Rünkaru 
285295a618bdSEinar Rünkaru 	/* Port B: external microphone */
285395a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
285495a618bdSEinar Rünkaru 
285595a618bdSEinar Rünkaru 	/* Port C: unused */
285695a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
285795a618bdSEinar Rünkaru 
285895a618bdSEinar Rünkaru 	/* Port D: unused */
285995a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
286095a618bdSEinar Rünkaru 
286195a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
286295a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
286395a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
286495a618bdSEinar Rünkaru 
286595a618bdSEinar Rünkaru 	/* Port F: unused */
286695a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
286795a618bdSEinar Rünkaru 
286895a618bdSEinar Rünkaru 	/* Port G: internal speakers */
286995a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
287095a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
287195a618bdSEinar Rünkaru 
287295a618bdSEinar Rünkaru 	/* DAC1 */
287395a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
287495a618bdSEinar Rünkaru 
287595a618bdSEinar Rünkaru 	/* DAC2: unused */
287695a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
287795a618bdSEinar Rünkaru 
287895a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
287995a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
288095a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
288195a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
288295a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
288395a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
288495a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
288595a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
288695a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
288795a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
288895a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
288995a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
289095a618bdSEinar Rünkaru 
289195a618bdSEinar Rünkaru 	/* Digital microphone port */
289295a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
289395a618bdSEinar Rünkaru 
289495a618bdSEinar Rünkaru 	/* Audio input selectors */
289595a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
289695a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
289795a618bdSEinar Rünkaru 
289895a618bdSEinar Rünkaru 	/* Disable SPDIF */
289995a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
290095a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
290195a618bdSEinar Rünkaru 
290295a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
290395a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
290495a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
290595a618bdSEinar Rünkaru 	{ } /* end */
290695a618bdSEinar Rünkaru };
290795a618bdSEinar Rünkaru 
2908cfd3d8dcSGreg Alexander static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2909cfd3d8dcSGreg Alexander 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2910cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2911cfd3d8dcSGreg Alexander 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2912cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2913cfd3d8dcSGreg Alexander 
2914cfd3d8dcSGreg Alexander 	/* Speakers  */
2915cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2916cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2917cfd3d8dcSGreg Alexander 
2918cfd3d8dcSGreg Alexander 	/* HP, Amp  */
2919cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2920cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2921cfd3d8dcSGreg Alexander 
2922cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2923cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2924cfd3d8dcSGreg Alexander 
2925cfd3d8dcSGreg Alexander 	/* DAC1 */
2926cfd3d8dcSGreg Alexander 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2927cfd3d8dcSGreg Alexander 
2928cfd3d8dcSGreg Alexander 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2929cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2930cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2931cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2932cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2933cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2934cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2935cfd3d8dcSGreg Alexander 
2936cfd3d8dcSGreg Alexander 	/* Audio input selector */
2937cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2938cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2939cfd3d8dcSGreg Alexander 
2940cfd3d8dcSGreg Alexander 	/* SPDIF route: PCM */
2941cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2942cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2943cfd3d8dcSGreg Alexander 
2944cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2945cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2946cfd3d8dcSGreg Alexander 
2947cfd3d8dcSGreg Alexander 	/* internal microphone */
294828c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2949cfd3d8dcSGreg Alexander 
2950cfd3d8dcSGreg Alexander 	/* EAPD */
2951cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2952cfd3d8dcSGreg Alexander 
2953cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2954cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2955cfd3d8dcSGreg Alexander 	{ } /* end */
2956cfd3d8dcSGreg Alexander };
2957cfd3d8dcSGreg Alexander 
29587b2bfdbcSJens Taprogge static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
29597b2bfdbcSJens Taprogge 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
29607b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
29617b2bfdbcSJens Taprogge 
29627b2bfdbcSJens Taprogge 	/* Port G: internal speakers  */
29637b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29647b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29657b2bfdbcSJens Taprogge 
29667b2bfdbcSJens Taprogge 	/* Port A: HP, Amp  */
29677b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29687b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29697b2bfdbcSJens Taprogge 
29707b2bfdbcSJens Taprogge 	/* Port B: Mic Dock */
29717b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29727b2bfdbcSJens Taprogge 
29737b2bfdbcSJens Taprogge 	/* Port C: Mic */
29747b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29757b2bfdbcSJens Taprogge 
29767b2bfdbcSJens Taprogge 	/* Port D: HP Dock, Amp */
29777b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29787b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29797b2bfdbcSJens Taprogge 
29807b2bfdbcSJens Taprogge 	/* DAC1 */
29817b2bfdbcSJens Taprogge 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
29827b2bfdbcSJens Taprogge 
29837b2bfdbcSJens Taprogge 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
29847b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
29857b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
29867b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
29877b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
29887b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
29897b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
29907b2bfdbcSJens Taprogge 
29917b2bfdbcSJens Taprogge 	/* Audio input selector */
29927b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
29937b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
29947b2bfdbcSJens Taprogge 
29957b2bfdbcSJens Taprogge 	/* SPDIF route: PCM */
29967b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
29977b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
29987b2bfdbcSJens Taprogge 
29997b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
30007b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
30017b2bfdbcSJens Taprogge 
30027b2bfdbcSJens Taprogge 	/* internal microphone */
300328c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
30047b2bfdbcSJens Taprogge 
30057b2bfdbcSJens Taprogge 	/* EAPD */
30067b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
30077b2bfdbcSJens Taprogge 
30087b2bfdbcSJens Taprogge 	/* enable unsolicited events for Port A, B, C and D */
30097b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
30107b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
30117b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
30127b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
30137b2bfdbcSJens Taprogge 	{ } /* end */
30147b2bfdbcSJens Taprogge };
30157b2bfdbcSJens Taprogge 
30160fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
30170fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
30180fb67e98SDaniel Drake 	{ } /* end */
30190fb67e98SDaniel Drake };
30200fb67e98SDaniel Drake 
3021048e78a5SDavid Henningsson 
3022048e78a5SDavid Henningsson static struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
3023048e78a5SDavid Henningsson 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3024048e78a5SDavid Henningsson 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3025048e78a5SDavid Henningsson 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3026048e78a5SDavid Henningsson 	{ } /* end */
3027048e78a5SDavid Henningsson };
3028048e78a5SDavid Henningsson 
30290fb67e98SDaniel Drake /* initialize jack-sensing, too */
30300fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
30310fb67e98SDaniel Drake {
30320fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
30330fb67e98SDaniel Drake 	conexant_init(codec);
30340fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
30350fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
303602b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
30370fb67e98SDaniel Drake 	}
3038c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
30390fb67e98SDaniel Drake 	return 0;
30400fb67e98SDaniel Drake }
30410fb67e98SDaniel Drake 
304275f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec)
304375f8991dSDaniel Drake {
3044c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
304575f8991dSDaniel Drake 	snd_printdd("CXT5066: init\n");
304675f8991dSDaniel Drake 	conexant_init(codec);
304775f8991dSDaniel Drake 	cxt5066_hp_automute(codec);
3048c4cfe66cSDaniel Drake 	if (!spec->dc_enable) {
3049c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
305075f8991dSDaniel Drake 		cxt5066_olpc_automic(codec);
3051c4cfe66cSDaniel Drake 	} else {
3052c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
3053c4cfe66cSDaniel Drake 	}
305475f8991dSDaniel Drake 	return 0;
305575f8991dSDaniel Drake }
305675f8991dSDaniel Drake 
30570fb67e98SDaniel Drake enum {
30580fb67e98SDaniel Drake 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
30590fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
30600fb67e98SDaniel Drake 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
30611feba3b7SDavid Henningsson 	CXT5066_DELL_VOSTRO,	/* Dell Vostro 1015i */
3062cfd3d8dcSGreg Alexander 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
30637b2bfdbcSJens Taprogge 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
3064*a1d6906eSDavid Henningsson 	CXT5066_ASUS,		/* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
3065048e78a5SDavid Henningsson 	CXT5066_HP_LAPTOP,      /* HP Laptop */
30660fb67e98SDaniel Drake 	CXT5066_MODELS
30670fb67e98SDaniel Drake };
30680fb67e98SDaniel Drake 
3069ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = {
30700fb67e98SDaniel Drake 	[CXT5066_LAPTOP]	= "laptop",
30710fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
30720fb67e98SDaniel Drake 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
30731feba3b7SDavid Henningsson 	[CXT5066_DELL_VOSTRO]	= "dell-vostro",
3074cfd3d8dcSGreg Alexander 	[CXT5066_IDEAPAD]	= "ideapad",
30757b2bfdbcSJens Taprogge 	[CXT5066_THINKPAD]	= "thinkpad",
3076*a1d6906eSDavid Henningsson 	[CXT5066_ASUS]		= "asus",
3077048e78a5SDavid Henningsson 	[CXT5066_HP_LAPTOP]	= "hp-laptop",
30780fb67e98SDaniel Drake };
30790fb67e98SDaniel Drake 
30800fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
308100cd0bb7STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
30821feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
30838a96b1e0SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3084ca6cd851SDaniel T Chen 	SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
30851feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
3086231f50bcSAnisse Astier 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3087048e78a5SDavid Henningsson 	SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3088673f7a89SDaniel T Chen 	SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_HP_LAPTOP),
3089*a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
30902ca9cac9SAnisse Astier 	SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3091c5366681SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
30924442dd46SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
30935637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
30945637edb2SDavid Henningsson 		      CXT5066_LAPTOP),
30955637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
30964d155641STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3097ef61d4e6SManoj Iyer 	SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
30987b2bfdbcSJens Taprogge  	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3099*a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
310022f21d51SDavid Henningsson 	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
31010fb67e98SDaniel Drake 	{}
31020fb67e98SDaniel Drake };
31030fb67e98SDaniel Drake 
31040fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
31050fb67e98SDaniel Drake {
31060fb67e98SDaniel Drake 	struct conexant_spec *spec;
31070fb67e98SDaniel Drake 	int board_config;
31080fb67e98SDaniel Drake 
31090fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
31100fb67e98SDaniel Drake 	if (!spec)
31110fb67e98SDaniel Drake 		return -ENOMEM;
31120fb67e98SDaniel Drake 	codec->spec = spec;
31130fb67e98SDaniel Drake 
31140fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
311575f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
31160fb67e98SDaniel Drake 
31170fb67e98SDaniel Drake 	spec->dell_automute = 0;
31180fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
31190fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
31200fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
31210fb67e98SDaniel Drake 	spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
31220fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
31230fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
31240fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
31250fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
31260fb67e98SDaniel Drake 
31270fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
31280fb67e98SDaniel Drake 
31290fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
31300fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
31310fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
31320fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
31330fb67e98SDaniel Drake 	spec->cur_adc = 0;
31340fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
31350fb67e98SDaniel Drake 
31363507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
31373507e2a8STakashi Iwai 
31380fb67e98SDaniel Drake 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
31390fb67e98SDaniel Drake 						  cxt5066_models, cxt5066_cfg_tbl);
31400fb67e98SDaniel Drake 	switch (board_config) {
31410fb67e98SDaniel Drake 	default:
31420fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
31430fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31440fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31450fb67e98SDaniel Drake 		break;
31460fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
31470fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31480fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31490fb67e98SDaniel Drake 
31500fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
31510fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
31520fb67e98SDaniel Drake 		spec->num_init_verbs++;
31530fb67e98SDaniel Drake 		spec->dell_automute = 1;
31540fb67e98SDaniel Drake 		break;
3155*a1d6906eSDavid Henningsson 	case CXT5066_ASUS:
3156048e78a5SDavid Henningsson 	case CXT5066_HP_LAPTOP:
3157048e78a5SDavid Henningsson 		codec->patch_ops.init = cxt5066_init;
315802b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3159048e78a5SDavid Henningsson 		spec->init_verbs[spec->num_init_verbs] =
3160048e78a5SDavid Henningsson 			cxt5066_init_verbs_hp_laptop;
3161048e78a5SDavid Henningsson 		spec->num_init_verbs++;
3162*a1d6906eSDavid Henningsson 		spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3163*a1d6906eSDavid Henningsson 		spec->asus = board_config == CXT5066_ASUS;
3164048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3165048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3166048e78a5SDavid Henningsson 		/* no S/PDIF out */
3167048e78a5SDavid Henningsson 		spec->multiout.dig_out_nid = 0;
3168048e78a5SDavid Henningsson 		/* input source automatically selected */
3169048e78a5SDavid Henningsson 		spec->input_mux = NULL;
3170048e78a5SDavid Henningsson 		spec->port_d_mode = 0;
3171048e78a5SDavid Henningsson 		spec->mic_boost = 3; /* default 30dB gain */
3172048e78a5SDavid Henningsson 		break;
3173048e78a5SDavid Henningsson 
31740fb67e98SDaniel Drake 	case CXT5066_OLPC_XO_1_5:
317575f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_olpc_init;
317675f8991dSDaniel Drake 		codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
31770fb67e98SDaniel Drake 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
31780fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3179c4cfe66cSDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
31800fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31810fb67e98SDaniel Drake 		spec->port_d_mode = 0;
3182c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
31830fb67e98SDaniel Drake 
31840fb67e98SDaniel Drake 		/* no S/PDIF out */
31850fb67e98SDaniel Drake 		spec->multiout.dig_out_nid = 0;
31860fb67e98SDaniel Drake 
31870fb67e98SDaniel Drake 		/* input source automatically selected */
31880fb67e98SDaniel Drake 		spec->input_mux = NULL;
318975f8991dSDaniel Drake 
319075f8991dSDaniel Drake 		/* our capture hooks which allow us to turn on the microphone LED
319175f8991dSDaniel Drake 		 * at the right time */
319275f8991dSDaniel Drake 		spec->capture_prepare = cxt5066_olpc_capture_prepare;
319375f8991dSDaniel Drake 		spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
31940fb67e98SDaniel Drake 		break;
31951feba3b7SDavid Henningsson 	case CXT5066_DELL_VOSTRO:
319675f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
319702b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
319895a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
319995a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
320095a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3201254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
320295a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
3203254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
3204c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
320595a618bdSEinar Rünkaru 
320695a618bdSEinar Rünkaru 		/* no S/PDIF out */
320795a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
320895a618bdSEinar Rünkaru 
320995a618bdSEinar Rünkaru 		/* input source automatically selected */
321095a618bdSEinar Rünkaru 		spec->input_mux = NULL;
321195a618bdSEinar Rünkaru 		break;
3212cfd3d8dcSGreg Alexander 	case CXT5066_IDEAPAD:
3213cfd3d8dcSGreg Alexander 		codec->patch_ops.init = cxt5066_init;
321402b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3215cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3216cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3217cfd3d8dcSGreg Alexander 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3218cfd3d8dcSGreg Alexander 		spec->port_d_mode = 0;
3219cfd3d8dcSGreg Alexander 		spec->ideapad = 1;
3220cfd3d8dcSGreg Alexander 		spec->mic_boost = 2;	/* default 20dB gain */
3221cfd3d8dcSGreg Alexander 
3222cfd3d8dcSGreg Alexander 		/* no S/PDIF out */
3223cfd3d8dcSGreg Alexander 		spec->multiout.dig_out_nid = 0;
3224cfd3d8dcSGreg Alexander 
3225cfd3d8dcSGreg Alexander 		/* input source automatically selected */
3226cfd3d8dcSGreg Alexander 		spec->input_mux = NULL;
3227cfd3d8dcSGreg Alexander 		break;
32287b2bfdbcSJens Taprogge 	case CXT5066_THINKPAD:
32297b2bfdbcSJens Taprogge 		codec->patch_ops.init = cxt5066_init;
323002b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
32317b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
32327b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
32337b2bfdbcSJens Taprogge 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
32347b2bfdbcSJens Taprogge 		spec->thinkpad = 1;
32357b2bfdbcSJens Taprogge 		spec->port_d_mode = PIN_OUT;
32367b2bfdbcSJens Taprogge 		spec->mic_boost = 2;	/* default 20dB gain */
32377b2bfdbcSJens Taprogge 
32387b2bfdbcSJens Taprogge 		/* no S/PDIF out */
32397b2bfdbcSJens Taprogge 		spec->multiout.dig_out_nid = 0;
32407b2bfdbcSJens Taprogge 
32417b2bfdbcSJens Taprogge 		/* input source automatically selected */
32427b2bfdbcSJens Taprogge 		spec->input_mux = NULL;
32437b2bfdbcSJens Taprogge 		break;
32440fb67e98SDaniel Drake 	}
32450fb67e98SDaniel Drake 
32463507e2a8STakashi Iwai 	if (spec->beep_amp)
32473507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
32483507e2a8STakashi Iwai 
32490fb67e98SDaniel Drake 	return 0;
32500fb67e98SDaniel Drake }
3251461e2c78STakashi Iwai 
3252461e2c78STakashi Iwai /*
3253f2e5731dSTakashi Iwai  * Automatic parser for CX20641 & co
3254f2e5731dSTakashi Iwai  */
3255f2e5731dSTakashi Iwai 
3256f2e5731dSTakashi Iwai static hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3257f2e5731dSTakashi Iwai 
3258f2e5731dSTakashi Iwai /* get the connection index of @nid in the widget @mux */
3259f2e5731dSTakashi Iwai static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3260f2e5731dSTakashi Iwai 				hda_nid_t nid)
3261f2e5731dSTakashi Iwai {
3262f2e5731dSTakashi Iwai 	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3263f2e5731dSTakashi Iwai 	int i, nums;
3264f2e5731dSTakashi Iwai 
3265f2e5731dSTakashi Iwai 	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3266f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++)
3267f2e5731dSTakashi Iwai 		if (conn[i] == nid)
3268f2e5731dSTakashi Iwai 			return i;
3269f2e5731dSTakashi Iwai 	return -1;
3270f2e5731dSTakashi Iwai }
3271f2e5731dSTakashi Iwai 
3272f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list.
3273f2e5731dSTakashi Iwai  * Return the nid if found and reduce the DAC list, or return zero if
3274f2e5731dSTakashi Iwai  * not found
3275f2e5731dSTakashi Iwai  */
3276f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3277f2e5731dSTakashi Iwai 				    hda_nid_t *dacs, int *num_dacs)
3278f2e5731dSTakashi Iwai {
3279f2e5731dSTakashi Iwai 	int i, nums = *num_dacs;
3280f2e5731dSTakashi Iwai 	hda_nid_t ret = 0;
3281f2e5731dSTakashi Iwai 
3282f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3283f2e5731dSTakashi Iwai 		if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3284f2e5731dSTakashi Iwai 			ret = dacs[i];
3285f2e5731dSTakashi Iwai 			break;
3286f2e5731dSTakashi Iwai 		}
3287f2e5731dSTakashi Iwai 	}
3288f2e5731dSTakashi Iwai 	if (!ret)
3289f2e5731dSTakashi Iwai 		return 0;
3290f2e5731dSTakashi Iwai 	if (--nums > 0)
3291f2e5731dSTakashi Iwai 		memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3292f2e5731dSTakashi Iwai 	*num_dacs = nums;
3293f2e5731dSTakashi Iwai 	return ret;
3294f2e5731dSTakashi Iwai }
3295f2e5731dSTakashi Iwai 
3296f2e5731dSTakashi Iwai #define MAX_AUTO_DACS	5
3297f2e5731dSTakashi Iwai 
3298f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */
3299f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3300f2e5731dSTakashi Iwai {
3301f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3302f2e5731dSTakashi Iwai 	int nums = 0;
3303f2e5731dSTakashi Iwai 
3304f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3305f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3306f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3307f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3308f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3309f2e5731dSTakashi Iwai 			dacs[nums++] = nid;
3310f2e5731dSTakashi Iwai 			if (nums >= MAX_AUTO_DACS)
3311f2e5731dSTakashi Iwai 				break;
3312f2e5731dSTakashi Iwai 		}
3313f2e5731dSTakashi Iwai 	}
3314f2e5731dSTakashi Iwai 	return nums;
3315f2e5731dSTakashi Iwai }
3316f2e5731dSTakashi Iwai 
3317f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */
3318f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3319f2e5731dSTakashi Iwai 			      int num_pins, hda_nid_t *dacs, int *rest,
3320f2e5731dSTakashi Iwai 			      struct pin_dac_pair *filled, int type)
3321f2e5731dSTakashi Iwai {
3322f2e5731dSTakashi Iwai 	int i, nums;
3323f2e5731dSTakashi Iwai 
3324f2e5731dSTakashi Iwai 	nums = 0;
3325f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3326f2e5731dSTakashi Iwai 		filled[nums].pin = pins[i];
3327f2e5731dSTakashi Iwai 		filled[nums].type = type;
3328f2e5731dSTakashi Iwai 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3329f2e5731dSTakashi Iwai 		nums++;
3330f2e5731dSTakashi Iwai 	}
3331f2e5731dSTakashi Iwai 	return nums;
3332f2e5731dSTakashi Iwai }
3333f2e5731dSTakashi Iwai 
3334f2e5731dSTakashi Iwai /* parse analog output paths */
3335f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec)
3336f2e5731dSTakashi Iwai {
3337f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3338f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3339f2e5731dSTakashi Iwai 	hda_nid_t dacs[MAX_AUTO_DACS];
3340f2e5731dSTakashi Iwai 	int i, j, nums, rest;
3341f2e5731dSTakashi Iwai 
3342f2e5731dSTakashi Iwai 	rest = fill_cx_auto_dacs(codec, dacs);
3343f2e5731dSTakashi Iwai 	/* parse all analog output pins */
3344f2e5731dSTakashi Iwai 	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3345f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info,
3346f2e5731dSTakashi Iwai 				  AUTO_PIN_LINE_OUT);
3347f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3348f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3349f2e5731dSTakashi Iwai 				  AUTO_PIN_HP_OUT);
3350f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3351f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3352f2e5731dSTakashi Iwai 				  AUTO_PIN_SPEAKER_OUT);
3353f2e5731dSTakashi Iwai 	spec->dac_info_filled = nums;
3354f2e5731dSTakashi Iwai 	/* fill multiout struct */
3355f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3356f2e5731dSTakashi Iwai 		hda_nid_t dac = spec->dac_info[i].dac;
3357f2e5731dSTakashi Iwai 		if (!dac)
3358f2e5731dSTakashi Iwai 			continue;
3359f2e5731dSTakashi Iwai 		switch (spec->dac_info[i].type) {
3360f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
3361f2e5731dSTakashi Iwai 			spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3362f2e5731dSTakashi Iwai 			spec->multiout.num_dacs++;
3363f2e5731dSTakashi Iwai 			break;
3364f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
3365f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
3366f2e5731dSTakashi Iwai 			if (!spec->multiout.hp_nid) {
3367f2e5731dSTakashi Iwai 				spec->multiout.hp_nid = dac;
3368f2e5731dSTakashi Iwai 				break;
3369f2e5731dSTakashi Iwai 			}
3370f2e5731dSTakashi Iwai 			for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3371f2e5731dSTakashi Iwai 				if (!spec->multiout.extra_out_nid[j]) {
3372f2e5731dSTakashi Iwai 					spec->multiout.extra_out_nid[j] = dac;
3373f2e5731dSTakashi Iwai 					break;
3374f2e5731dSTakashi Iwai 				}
3375f2e5731dSTakashi Iwai 			break;
3376f2e5731dSTakashi Iwai 		}
3377f2e5731dSTakashi Iwai 	}
3378f2e5731dSTakashi Iwai 	spec->multiout.dac_nids = spec->private_dac_nids;
3379f2e5731dSTakashi Iwai 	spec->multiout.max_channels = nums * 2;
3380f2e5731dSTakashi Iwai 
3381f2e5731dSTakashi Iwai 	if (cfg->hp_outs > 0)
3382f2e5731dSTakashi Iwai 		spec->auto_mute = 1;
3383f2e5731dSTakashi Iwai 	spec->vmaster_nid = spec->private_dac_nids[0];
3384f2e5731dSTakashi Iwai }
3385f2e5731dSTakashi Iwai 
3386f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */
3387f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec)
3388f2e5731dSTakashi Iwai {
3389f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3390f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3391f2e5731dSTakashi Iwai 	int i, present;
3392f2e5731dSTakashi Iwai 
3393f2e5731dSTakashi Iwai 	if (!spec->auto_mute)
3394f2e5731dSTakashi Iwai 		return;
3395f2e5731dSTakashi Iwai 	present = 0;
3396f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++) {
3397f2e5731dSTakashi Iwai 		if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3398f2e5731dSTakashi Iwai 			present = 1;
3399f2e5731dSTakashi Iwai 			break;
3400f2e5731dSTakashi Iwai 		}
3401f2e5731dSTakashi Iwai 	}
3402f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->line_outs; i++) {
3403f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3404f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
3405f2e5731dSTakashi Iwai 				    present ? 0 : PIN_OUT);
3406f2e5731dSTakashi Iwai 	}
3407fbb5bb56STakashi Iwai 	for (i = 0; !present && i < cfg->line_outs; i++)
3408fbb5bb56STakashi Iwai 		if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3409fbb5bb56STakashi Iwai 			present = 1;
3410f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->speaker_outs; i++) {
3411f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3412f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
3413f2e5731dSTakashi Iwai 				    present ? 0 : PIN_OUT);
3414f2e5731dSTakashi Iwai 	}
3415f2e5731dSTakashi Iwai }
3416f2e5731dSTakashi Iwai 
3417f2e5731dSTakashi Iwai /* automatic switch internal and external mic */
3418f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec)
3419f2e5731dSTakashi Iwai {
3420f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3421f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3422f2e5731dSTakashi Iwai 	struct hda_input_mux *imux = &spec->private_imux;
3423f2e5731dSTakashi Iwai 	int ext_idx = spec->auto_mic_ext;
3424f2e5731dSTakashi Iwai 
3425f2e5731dSTakashi Iwai 	if (!spec->auto_mic)
3426f2e5731dSTakashi Iwai 		return;
3427f2e5731dSTakashi Iwai 	if (snd_hda_jack_detect(codec, cfg->inputs[ext_idx].pin)) {
3428f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3429f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL,
3430f2e5731dSTakashi Iwai 				    imux->items[ext_idx].index);
3431f2e5731dSTakashi Iwai 	} else {
3432f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3433f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL,
3434f2e5731dSTakashi Iwai 				    imux->items[!ext_idx].index);
3435f2e5731dSTakashi Iwai 	}
3436f2e5731dSTakashi Iwai }
3437f2e5731dSTakashi Iwai 
3438f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3439f2e5731dSTakashi Iwai {
3440f2e5731dSTakashi Iwai 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3441f2e5731dSTakashi Iwai 	switch (res >> 26) {
3442f2e5731dSTakashi Iwai 	case CONEXANT_HP_EVENT:
3443f2e5731dSTakashi Iwai 		cx_auto_hp_automute(codec);
3444f2e5731dSTakashi Iwai 		conexant_report_jack(codec, nid);
3445f2e5731dSTakashi Iwai 		break;
3446f2e5731dSTakashi Iwai 	case CONEXANT_MIC_EVENT:
3447f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
3448f2e5731dSTakashi Iwai 		conexant_report_jack(codec, nid);
3449f2e5731dSTakashi Iwai 		break;
3450f2e5731dSTakashi Iwai 	}
3451f2e5731dSTakashi Iwai }
3452f2e5731dSTakashi Iwai 
3453f2e5731dSTakashi Iwai /* return true if it's an internal-mic pin */
3454f2e5731dSTakashi Iwai static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3455f2e5731dSTakashi Iwai {
3456f2e5731dSTakashi Iwai 	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3457f2e5731dSTakashi Iwai 	return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
345899ae28beSTakashi Iwai 		snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
3459f2e5731dSTakashi Iwai }
3460f2e5731dSTakashi Iwai 
3461f2e5731dSTakashi Iwai /* return true if it's an external-mic pin */
3462f2e5731dSTakashi Iwai static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3463f2e5731dSTakashi Iwai {
3464f2e5731dSTakashi Iwai 	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3465f2e5731dSTakashi Iwai 	return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
3466f68b3b29STakashi Iwai 		snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3467f68b3b29STakashi Iwai 		(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
3468f2e5731dSTakashi Iwai }
3469f2e5731dSTakashi Iwai 
3470f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching;
3471f2e5731dSTakashi Iwai  * auto-mic is enabled only when one int-mic and one-ext mic exist
3472f2e5731dSTakashi Iwai  */
3473f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec)
3474f2e5731dSTakashi Iwai {
3475f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3476f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3477f2e5731dSTakashi Iwai 
3478f2e5731dSTakashi Iwai 	if (is_ext_mic(codec, cfg->inputs[0].pin) &&
3479f2e5731dSTakashi Iwai 	    is_int_mic(codec, cfg->inputs[1].pin)) {
3480f2e5731dSTakashi Iwai 		spec->auto_mic = 1;
3481f2e5731dSTakashi Iwai 		spec->auto_mic_ext = 1;
3482f2e5731dSTakashi Iwai 		return;
3483f2e5731dSTakashi Iwai 	}
3484f2e5731dSTakashi Iwai 	if (is_int_mic(codec, cfg->inputs[1].pin) &&
3485f2e5731dSTakashi Iwai 	    is_ext_mic(codec, cfg->inputs[0].pin)) {
3486f2e5731dSTakashi Iwai 		spec->auto_mic = 1;
3487f2e5731dSTakashi Iwai 		spec->auto_mic_ext = 0;
3488f2e5731dSTakashi Iwai 		return;
3489f2e5731dSTakashi Iwai 	}
3490f2e5731dSTakashi Iwai }
3491f2e5731dSTakashi Iwai 
3492f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec)
3493f2e5731dSTakashi Iwai {
3494f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3495f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3496f2e5731dSTakashi Iwai 	struct hda_input_mux *imux;
3497f2e5731dSTakashi Iwai 	int i;
3498f2e5731dSTakashi Iwai 
3499f2e5731dSTakashi Iwai 	imux = &spec->private_imux;
3500f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3501f2e5731dSTakashi Iwai 		int idx = get_connection_index(codec, spec->adc_nids[0],
3502f2e5731dSTakashi Iwai 					       cfg->inputs[i].pin);
3503f2e5731dSTakashi Iwai 		if (idx >= 0) {
3504f2e5731dSTakashi Iwai 			const char *label;
3505f2e5731dSTakashi Iwai 			label = hda_get_autocfg_input_label(codec, cfg, i);
3506f2e5731dSTakashi Iwai 			snd_hda_add_imux_item(imux, label, idx, NULL);
3507f2e5731dSTakashi Iwai 		}
3508f2e5731dSTakashi Iwai 	}
3509f2e5731dSTakashi Iwai 	if (imux->num_items == 2 && cfg->num_inputs == 2)
3510f2e5731dSTakashi Iwai 		cx_auto_check_auto_mic(codec);
3511f2e5731dSTakashi Iwai 	if (imux->num_items > 1 && !spec->auto_mic)
3512f2e5731dSTakashi Iwai 		spec->input_mux = imux;
3513f2e5731dSTakashi Iwai }
3514f2e5731dSTakashi Iwai 
3515f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */
3516f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3517f2e5731dSTakashi Iwai {
3518f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3519f2e5731dSTakashi Iwai 
3520f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3521f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3522f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3523f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3524f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3525f2e5731dSTakashi Iwai 			if (get_connection_index(codec, nid, pin) >= 0)
3526f2e5731dSTakashi Iwai 				return nid;
3527f2e5731dSTakashi Iwai 		}
3528f2e5731dSTakashi Iwai 	}
3529f2e5731dSTakashi Iwai 	return 0;
3530f2e5731dSTakashi Iwai }
3531f2e5731dSTakashi Iwai 
3532f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec)
3533f2e5731dSTakashi Iwai {
3534f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3535f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3536f2e5731dSTakashi Iwai 	hda_nid_t nid;
3537f2e5731dSTakashi Iwai 
3538f2e5731dSTakashi Iwai 	if (cfg->dig_outs &&
3539f2e5731dSTakashi Iwai 	    snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3540f2e5731dSTakashi Iwai 		spec->multiout.dig_out_nid = nid;
3541f2e5731dSTakashi Iwai 	if (cfg->dig_in_pin)
3542f2e5731dSTakashi Iwai 		spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3543f2e5731dSTakashi Iwai }
3544f2e5731dSTakashi Iwai 
3545f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
3546f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec)
3547f2e5731dSTakashi Iwai {
3548f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3549f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3550f2e5731dSTakashi Iwai 
3551f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3552f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++)
3553f2e5731dSTakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3554f2e5731dSTakashi Iwai 			set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3555f2e5731dSTakashi Iwai 			break;
3556f2e5731dSTakashi Iwai 		}
3557f2e5731dSTakashi Iwai }
3558f2e5731dSTakashi Iwai #else
3559f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec)
3560f2e5731dSTakashi Iwai #endif
3561f2e5731dSTakashi Iwai 
3562f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec)
3563f2e5731dSTakashi Iwai {
3564f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3565f2e5731dSTakashi Iwai 	int err;
3566f2e5731dSTakashi Iwai 
3567f2e5731dSTakashi Iwai 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3568f2e5731dSTakashi Iwai 	if (err < 0)
3569f2e5731dSTakashi Iwai 		return err;
3570f2e5731dSTakashi Iwai 
3571f2e5731dSTakashi Iwai 	cx_auto_parse_output(codec);
3572f2e5731dSTakashi Iwai 	cx_auto_parse_input(codec);
3573f2e5731dSTakashi Iwai 	cx_auto_parse_digital(codec);
3574f2e5731dSTakashi Iwai 	cx_auto_parse_beep(codec);
3575f2e5731dSTakashi Iwai 	return 0;
3576f2e5731dSTakashi Iwai }
3577f2e5731dSTakashi Iwai 
3578f2e5731dSTakashi Iwai static void cx_auto_turn_on_eapd(struct hda_codec *codec, int num_pins,
3579f2e5731dSTakashi Iwai 				 hda_nid_t *pins)
3580f2e5731dSTakashi Iwai {
3581f2e5731dSTakashi Iwai 	int i;
3582f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3583f2e5731dSTakashi Iwai 		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3584f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, pins[i], 0,
3585f2e5731dSTakashi Iwai 					    AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3586f2e5731dSTakashi Iwai 	}
3587f2e5731dSTakashi Iwai }
3588f2e5731dSTakashi Iwai 
3589f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3590f2e5731dSTakashi Iwai 			      hda_nid_t src)
3591f2e5731dSTakashi Iwai {
3592f2e5731dSTakashi Iwai 	int idx = get_connection_index(codec, pin, src);
3593f2e5731dSTakashi Iwai 	if (idx >= 0)
3594f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, pin, 0,
3595f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL, idx);
3596f2e5731dSTakashi Iwai }
3597f2e5731dSTakashi Iwai 
3598f2e5731dSTakashi Iwai static void cx_auto_init_output(struct hda_codec *codec)
3599f2e5731dSTakashi Iwai {
3600f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3601f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3602f2e5731dSTakashi Iwai 	hda_nid_t nid;
3603f2e5731dSTakashi Iwai 	int i;
3604f2e5731dSTakashi Iwai 
3605f2e5731dSTakashi Iwai 	for (i = 0; i < spec->multiout.num_dacs; i++)
3606f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
3607f2e5731dSTakashi Iwai 				    AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3608f2e5731dSTakashi Iwai 
3609f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++)
3610f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3611f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
3612f2e5731dSTakashi Iwai 	if (spec->auto_mute) {
3613f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->hp_outs; i++) {
3614f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3615f2e5731dSTakashi Iwai 				    AC_VERB_SET_UNSOLICITED_ENABLE,
3616f2e5731dSTakashi Iwai 				    AC_USRSP_EN | CONEXANT_HP_EVENT);
3617f2e5731dSTakashi Iwai 		}
3618f2e5731dSTakashi Iwai 		cx_auto_hp_automute(codec);
3619f2e5731dSTakashi Iwai 	} else {
3620f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->line_outs; i++)
3621f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3622f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3623f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->speaker_outs; i++)
3624f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3625f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3626f2e5731dSTakashi Iwai 	}
3627f2e5731dSTakashi Iwai 
3628f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
3629f2e5731dSTakashi Iwai 		nid = spec->dac_info[i].dac;
3630f2e5731dSTakashi Iwai 		if (!nid)
3631f2e5731dSTakashi Iwai 			nid = spec->multiout.dac_nids[0];
3632f2e5731dSTakashi Iwai 		select_connection(codec, spec->dac_info[i].pin, nid);
3633f2e5731dSTakashi Iwai 	}
3634f2e5731dSTakashi Iwai 
3635f2e5731dSTakashi Iwai 	/* turn on EAPD */
3636f2e5731dSTakashi Iwai 	cx_auto_turn_on_eapd(codec, cfg->line_outs, cfg->line_out_pins);
3637f2e5731dSTakashi Iwai 	cx_auto_turn_on_eapd(codec, cfg->hp_outs, cfg->hp_pins);
3638f2e5731dSTakashi Iwai 	cx_auto_turn_on_eapd(codec, cfg->speaker_outs, cfg->speaker_pins);
3639f2e5731dSTakashi Iwai }
3640f2e5731dSTakashi Iwai 
3641f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec)
3642f2e5731dSTakashi Iwai {
3643f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3644f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3645f2e5731dSTakashi Iwai 	int i;
3646f2e5731dSTakashi Iwai 
3647f2e5731dSTakashi Iwai 	for (i = 0; i < spec->num_adc_nids; i++)
3648f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3649f2e5731dSTakashi Iwai 				    AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0));
3650f2e5731dSTakashi Iwai 
3651f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3652f2e5731dSTakashi Iwai 		unsigned int type;
3653f2e5731dSTakashi Iwai 		if (cfg->inputs[i].type == AUTO_PIN_MIC)
3654f2e5731dSTakashi Iwai 			type = PIN_VREF80;
3655f2e5731dSTakashi Iwai 		else
3656f2e5731dSTakashi Iwai 			type = PIN_IN;
3657f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3658f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3659f2e5731dSTakashi Iwai 	}
3660f2e5731dSTakashi Iwai 
3661f2e5731dSTakashi Iwai 	if (spec->auto_mic) {
3662f2e5731dSTakashi Iwai 		int ext_idx = spec->auto_mic_ext;
3663f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3664f2e5731dSTakashi Iwai 				    AC_VERB_SET_UNSOLICITED_ENABLE,
3665f2e5731dSTakashi Iwai 				    AC_USRSP_EN | CONEXANT_MIC_EVENT);
3666f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
3667f2e5731dSTakashi Iwai 	} else {
3668f2e5731dSTakashi Iwai 		for (i = 0; i < spec->num_adc_nids; i++) {
3669f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3670f2e5731dSTakashi Iwai 					    AC_VERB_SET_CONNECT_SEL,
3671f2e5731dSTakashi Iwai 					    spec->private_imux.items[0].index);
3672f2e5731dSTakashi Iwai 		}
3673f2e5731dSTakashi Iwai 	}
3674f2e5731dSTakashi Iwai }
3675f2e5731dSTakashi Iwai 
3676f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec)
3677f2e5731dSTakashi Iwai {
3678f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3679f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3680f2e5731dSTakashi Iwai 
3681f2e5731dSTakashi Iwai 	if (spec->multiout.dig_out_nid)
3682f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3683f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3684f2e5731dSTakashi Iwai 	if (spec->dig_in_nid)
3685f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3686f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3687f2e5731dSTakashi Iwai }
3688f2e5731dSTakashi Iwai 
3689f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec)
3690f2e5731dSTakashi Iwai {
3691f2e5731dSTakashi Iwai 	/*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3692f2e5731dSTakashi Iwai 	cx_auto_init_output(codec);
3693f2e5731dSTakashi Iwai 	cx_auto_init_input(codec);
3694f2e5731dSTakashi Iwai 	cx_auto_init_digital(codec);
3695f2e5731dSTakashi Iwai 	return 0;
3696f2e5731dSTakashi Iwai }
3697f2e5731dSTakashi Iwai 
3698f2e5731dSTakashi Iwai static int cx_auto_add_volume(struct hda_codec *codec, const char *basename,
3699f2e5731dSTakashi Iwai 			      const char *dir, int cidx,
3700f2e5731dSTakashi Iwai 			      hda_nid_t nid, int hda_dir)
3701f2e5731dSTakashi Iwai {
3702f2e5731dSTakashi Iwai 	static char name[32];
3703f2e5731dSTakashi Iwai 	static struct snd_kcontrol_new knew[] = {
3704f2e5731dSTakashi Iwai 		HDA_CODEC_VOLUME(name, 0, 0, 0),
3705f2e5731dSTakashi Iwai 		HDA_CODEC_MUTE(name, 0, 0, 0),
3706f2e5731dSTakashi Iwai 	};
3707f2e5731dSTakashi Iwai 	static char *sfx[2] = { "Volume", "Switch" };
3708f2e5731dSTakashi Iwai 	int i, err;
3709f2e5731dSTakashi Iwai 
3710f2e5731dSTakashi Iwai 	for (i = 0; i < 2; i++) {
3711f2e5731dSTakashi Iwai 		struct snd_kcontrol *kctl;
3712f2e5731dSTakashi Iwai 		knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, hda_dir);
3713f2e5731dSTakashi Iwai 		knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3714f2e5731dSTakashi Iwai 		knew[i].index = cidx;
3715f2e5731dSTakashi Iwai 		snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3716f2e5731dSTakashi Iwai 		kctl = snd_ctl_new1(&knew[i], codec);
3717f2e5731dSTakashi Iwai 		if (!kctl)
3718f2e5731dSTakashi Iwai 			return -ENOMEM;
3719f2e5731dSTakashi Iwai 		err = snd_hda_ctl_add(codec, nid, kctl);
3720f2e5731dSTakashi Iwai 		if (err < 0)
3721f2e5731dSTakashi Iwai 			return err;
3722f2e5731dSTakashi Iwai 		if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3723f2e5731dSTakashi Iwai 			break;
3724f2e5731dSTakashi Iwai 	}
3725f2e5731dSTakashi Iwai 	return 0;
3726f2e5731dSTakashi Iwai }
3727f2e5731dSTakashi Iwai 
3728f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx)			\
3729f2e5731dSTakashi Iwai 	cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3730f2e5731dSTakashi Iwai 
3731f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec)
3732f2e5731dSTakashi Iwai {
3733f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3734f2e5731dSTakashi Iwai 	int i, err;
3735f2e5731dSTakashi Iwai 	int num_line = 0, num_hp = 0, num_spk = 0;
3736ea734963STakashi Iwai 	static const char * const texts[3] = { "Front", "Surround", "CLFE" };
3737f2e5731dSTakashi Iwai 
3738f2e5731dSTakashi Iwai 	if (spec->dac_info_filled == 1)
3739f2e5731dSTakashi Iwai 		return cx_auto_add_pb_volume(codec, spec->dac_info[0].dac,
3740f2e5731dSTakashi Iwai 					     "Master", 0);
3741f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
3742f2e5731dSTakashi Iwai 		const char *label;
3743f2e5731dSTakashi Iwai 		int idx, type;
3744f2e5731dSTakashi Iwai 		if (!spec->dac_info[i].dac)
3745f2e5731dSTakashi Iwai 			continue;
3746f2e5731dSTakashi Iwai 		type = spec->dac_info[i].type;
3747f2e5731dSTakashi Iwai 		if (type == AUTO_PIN_LINE_OUT)
3748f2e5731dSTakashi Iwai 			type = spec->autocfg.line_out_type;
3749f2e5731dSTakashi Iwai 		switch (type) {
3750f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
3751f2e5731dSTakashi Iwai 		default:
3752f2e5731dSTakashi Iwai 			label = texts[num_line++];
3753f2e5731dSTakashi Iwai 			idx = 0;
3754f2e5731dSTakashi Iwai 			break;
3755f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
3756f2e5731dSTakashi Iwai 			label = "Headphone";
3757f2e5731dSTakashi Iwai 			idx = num_hp++;
3758f2e5731dSTakashi Iwai 			break;
3759f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
3760f2e5731dSTakashi Iwai 			label = "Speaker";
3761f2e5731dSTakashi Iwai 			idx = num_spk++;
3762f2e5731dSTakashi Iwai 			break;
3763f2e5731dSTakashi Iwai 		}
3764f2e5731dSTakashi Iwai 		err = cx_auto_add_pb_volume(codec, spec->dac_info[i].dac,
3765f2e5731dSTakashi Iwai 					    label, idx);
3766f2e5731dSTakashi Iwai 		if (err < 0)
3767f2e5731dSTakashi Iwai 			return err;
3768f2e5731dSTakashi Iwai 	}
3769f2e5731dSTakashi Iwai 	return 0;
3770f2e5731dSTakashi Iwai }
3771f2e5731dSTakashi Iwai 
3772f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec)
3773f2e5731dSTakashi Iwai {
3774f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3775f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3776f2e5731dSTakashi Iwai 	static const char *prev_label;
3777f2e5731dSTakashi Iwai 	int i, err, cidx;
3778f2e5731dSTakashi Iwai 
3779f2e5731dSTakashi Iwai 	err = cx_auto_add_volume(codec, "Capture", "", 0, spec->adc_nids[0],
3780f2e5731dSTakashi Iwai 				 HDA_INPUT);
3781f2e5731dSTakashi Iwai 	if (err < 0)
3782f2e5731dSTakashi Iwai 		return err;
3783f2e5731dSTakashi Iwai 	prev_label = NULL;
3784f2e5731dSTakashi Iwai 	cidx = 0;
3785f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3786f2e5731dSTakashi Iwai 		hda_nid_t nid = cfg->inputs[i].pin;
3787f2e5731dSTakashi Iwai 		const char *label;
3788f2e5731dSTakashi Iwai 		if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3789f2e5731dSTakashi Iwai 			continue;
3790f2e5731dSTakashi Iwai 		label = hda_get_autocfg_input_label(codec, cfg, i);
3791f2e5731dSTakashi Iwai 		if (label == prev_label)
3792f2e5731dSTakashi Iwai 			cidx++;
3793f2e5731dSTakashi Iwai 		else
3794f2e5731dSTakashi Iwai 			cidx = 0;
3795f2e5731dSTakashi Iwai 		prev_label = label;
3796f2e5731dSTakashi Iwai 		err = cx_auto_add_volume(codec, label, " Capture", cidx,
3797f2e5731dSTakashi Iwai 					 nid, HDA_INPUT);
3798f2e5731dSTakashi Iwai 		if (err < 0)
3799f2e5731dSTakashi Iwai 			return err;
3800f2e5731dSTakashi Iwai 	}
3801f2e5731dSTakashi Iwai 	return 0;
3802f2e5731dSTakashi Iwai }
3803f2e5731dSTakashi Iwai 
3804f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec)
3805f2e5731dSTakashi Iwai {
3806f2e5731dSTakashi Iwai 	int err;
3807f2e5731dSTakashi Iwai 
3808f2e5731dSTakashi Iwai 	err = cx_auto_build_output_controls(codec);
3809f2e5731dSTakashi Iwai 	if (err < 0)
3810f2e5731dSTakashi Iwai 		return err;
3811f2e5731dSTakashi Iwai 	err = cx_auto_build_input_controls(codec);
3812f2e5731dSTakashi Iwai 	if (err < 0)
3813f2e5731dSTakashi Iwai 		return err;
3814f2e5731dSTakashi Iwai 	return conexant_build_controls(codec);
3815f2e5731dSTakashi Iwai }
3816f2e5731dSTakashi Iwai 
3817f2e5731dSTakashi Iwai static struct hda_codec_ops cx_auto_patch_ops = {
3818f2e5731dSTakashi Iwai 	.build_controls = cx_auto_build_controls,
3819f2e5731dSTakashi Iwai 	.build_pcms = conexant_build_pcms,
3820f2e5731dSTakashi Iwai 	.init = cx_auto_init,
3821f2e5731dSTakashi Iwai 	.free = conexant_free,
3822f2e5731dSTakashi Iwai 	.unsol_event = cx_auto_unsol_event,
3823f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
3824f2e5731dSTakashi Iwai 	.suspend = conexant_suspend,
3825f2e5731dSTakashi Iwai #endif
3826f2e5731dSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
3827f2e5731dSTakashi Iwai };
3828f2e5731dSTakashi Iwai 
3829f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec)
3830f2e5731dSTakashi Iwai {
3831f2e5731dSTakashi Iwai 	struct conexant_spec *spec;
3832f2e5731dSTakashi Iwai 	int err;
3833f2e5731dSTakashi Iwai 
3834f2e5731dSTakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3835f2e5731dSTakashi Iwai 	if (!spec)
3836f2e5731dSTakashi Iwai 		return -ENOMEM;
3837f2e5731dSTakashi Iwai 	codec->spec = spec;
3838f2e5731dSTakashi Iwai 	spec->adc_nids = cx_auto_adc_nids;
3839f2e5731dSTakashi Iwai 	spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids);
3840f2e5731dSTakashi Iwai 	spec->capsrc_nids = spec->adc_nids;
3841f2e5731dSTakashi Iwai 	err = cx_auto_parse_auto_config(codec);
3842f2e5731dSTakashi Iwai 	if (err < 0) {
3843f2e5731dSTakashi Iwai 		kfree(codec->spec);
3844f2e5731dSTakashi Iwai 		codec->spec = NULL;
3845f2e5731dSTakashi Iwai 		return err;
3846f2e5731dSTakashi Iwai 	}
3847f2e5731dSTakashi Iwai 	codec->patch_ops = cx_auto_patch_ops;
3848f2e5731dSTakashi Iwai 	if (spec->beep_amp)
3849f2e5731dSTakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
3850f2e5731dSTakashi Iwai 	return 0;
3851f2e5731dSTakashi Iwai }
3852f2e5731dSTakashi Iwai 
3853f2e5731dSTakashi Iwai /*
3854461e2c78STakashi Iwai  */
3855461e2c78STakashi Iwai 
38561289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = {
385782f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
385882f30040STobin Davis 	  .patch = patch_cxt5045 },
385982f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
386082f30040STobin Davis 	  .patch = patch_cxt5047 },
3861461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3862461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
38630fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
38640fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
386595a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
386695a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
3867850eab9dSTakashi Iwai 	{ .id = 0x14f15068, .name = "CX20584",
3868850eab9dSTakashi Iwai 	  .patch = patch_cxt5066 },
38697b2bfdbcSJens Taprogge 	{ .id = 0x14f15069, .name = "CX20585",
38707b2bfdbcSJens Taprogge 	  .patch = patch_cxt5066 },
3871f2e5731dSTakashi Iwai 	{ .id = 0x14f15097, .name = "CX20631",
3872f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3873f2e5731dSTakashi Iwai 	{ .id = 0x14f15098, .name = "CX20632",
3874f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3875f2e5731dSTakashi Iwai 	{ .id = 0x14f150a1, .name = "CX20641",
3876f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3877f2e5731dSTakashi Iwai 	{ .id = 0x14f150a2, .name = "CX20642",
3878f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3879f2e5731dSTakashi Iwai 	{ .id = 0x14f150ab, .name = "CX20651",
3880f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3881f2e5731dSTakashi Iwai 	{ .id = 0x14f150ac, .name = "CX20652",
3882f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3883f2e5731dSTakashi Iwai 	{ .id = 0x14f150b8, .name = "CX20664",
3884f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3885f2e5731dSTakashi Iwai 	{ .id = 0x14f150b9, .name = "CX20665",
3886f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3887c9b443d4STobin Davis 	{} /* terminator */
3888c9b443d4STobin Davis };
38891289e9e8STakashi Iwai 
38901289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
38911289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
38921289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
38930fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
389495a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
3895850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068");
38967b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069");
3897f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097");
3898f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098");
3899f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3900f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3901f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3902f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3903f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3904f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9");
39051289e9e8STakashi Iwai 
39061289e9e8STakashi Iwai MODULE_LICENSE("GPL");
39071289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
39081289e9e8STakashi Iwai 
39091289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
39101289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
39111289e9e8STakashi Iwai 	.owner = THIS_MODULE,
39121289e9e8STakashi Iwai };
39131289e9e8STakashi Iwai 
39141289e9e8STakashi Iwai static int __init patch_conexant_init(void)
39151289e9e8STakashi Iwai {
39161289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
39171289e9e8STakashi Iwai }
39181289e9e8STakashi Iwai 
39191289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
39201289e9e8STakashi Iwai {
39211289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
39221289e9e8STakashi Iwai }
39231289e9e8STakashi Iwai 
39241289e9e8STakashi Iwai module_init(patch_conexant_init)
39251289e9e8STakashi Iwai module_exit(patch_conexant_exit)
3926