xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision cca3b3718ca96dca51daf1129ac03003bcede751)
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 <sound/driver.h>
24c9b443d4STobin Davis #include <linux/init.h>
25c9b443d4STobin Davis #include <linux/delay.h>
26c9b443d4STobin Davis #include <linux/slab.h>
27c9b443d4STobin Davis #include <linux/pci.h>
28c9b443d4STobin Davis #include <sound/core.h>
29c9b443d4STobin Davis #include "hda_codec.h"
30c9b443d4STobin Davis #include "hda_local.h"
31c9b443d4STobin Davis 
32c9b443d4STobin Davis #define CXT_PIN_DIR_IN              0x00
33c9b443d4STobin Davis #define CXT_PIN_DIR_OUT             0x01
34c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT           0x02
35c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
36c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
37c9b443d4STobin Davis 
38c9b443d4STobin Davis #define CONEXANT_HP_EVENT	0x37
39c9b443d4STobin Davis #define CONEXANT_MIC_EVENT	0x38
40c9b443d4STobin Davis 
41c9b443d4STobin Davis 
42c9b443d4STobin Davis 
43c9b443d4STobin Davis struct conexant_spec {
44c9b443d4STobin Davis 
45c9b443d4STobin Davis 	struct snd_kcontrol_new *mixers[5];
46c9b443d4STobin Davis 	int num_mixers;
47c9b443d4STobin Davis 
48c9b443d4STobin Davis 	const struct hda_verb *init_verbs[5];	/* initialization verbs
49c9b443d4STobin Davis 						 * don't forget NULL
50c9b443d4STobin Davis 						 * termination!
51c9b443d4STobin Davis 						 */
52c9b443d4STobin Davis 	unsigned int num_init_verbs;
53c9b443d4STobin Davis 
54c9b443d4STobin Davis 	/* playback */
55c9b443d4STobin Davis 	struct hda_multi_out multiout;	/* playback set-up
56c9b443d4STobin Davis 					 * max_channels, dacs must be set
57c9b443d4STobin Davis 					 * dig_out_nid and hp_nid are optional
58c9b443d4STobin Davis 					 */
59c9b443d4STobin Davis 	unsigned int cur_eapd;
6082f30040STobin Davis 	unsigned int hp_present;
61c9b443d4STobin Davis 	unsigned int need_dac_fix;
62c9b443d4STobin Davis 
63c9b443d4STobin Davis 	/* capture */
64c9b443d4STobin Davis 	unsigned int num_adc_nids;
65c9b443d4STobin Davis 	hda_nid_t *adc_nids;
66c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
67c9b443d4STobin Davis 
68c9b443d4STobin Davis 	/* capture source */
69c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
70c9b443d4STobin Davis 	hda_nid_t *capsrc_nids;
71c9b443d4STobin Davis 	unsigned int cur_mux[3];
72c9b443d4STobin Davis 
73c9b443d4STobin Davis 	/* channel model */
74c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
75c9b443d4STobin Davis 	int num_channel_mode;
76c9b443d4STobin Davis 
77c9b443d4STobin Davis 	/* PCM information */
78c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
79c9b443d4STobin Davis 
80c9b443d4STobin Davis 	struct mutex amp_mutex;	/* PCM volume/mute control mutex */
81c9b443d4STobin Davis 	unsigned int spdif_route;
82c9b443d4STobin Davis 
83c9b443d4STobin Davis 	/* dynamic controls, init_verbs and input_mux */
84c9b443d4STobin Davis 	struct auto_pin_cfg autocfg;
85c9b443d4STobin Davis 	unsigned int num_kctl_alloc, num_kctl_used;
86c9b443d4STobin Davis 	struct snd_kcontrol_new *kctl_alloc;
87c9b443d4STobin Davis 	struct hda_input_mux private_imux;
88c9b443d4STobin Davis 	hda_nid_t private_dac_nids[4];
89c9b443d4STobin Davis 
90c9b443d4STobin Davis };
91c9b443d4STobin Davis 
92c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
93c9b443d4STobin Davis 				      struct hda_codec *codec,
94c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
95c9b443d4STobin Davis {
96c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
97c9b443d4STobin Davis 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
98c9b443d4STobin Davis }
99c9b443d4STobin Davis 
100c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
101c9b443d4STobin Davis 					 struct hda_codec *codec,
102c9b443d4STobin Davis 					 unsigned int stream_tag,
103c9b443d4STobin Davis 					 unsigned int format,
104c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
105c9b443d4STobin Davis {
106c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
107c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
108c9b443d4STobin Davis 						stream_tag,
109c9b443d4STobin Davis 						format, substream);
110c9b443d4STobin Davis }
111c9b443d4STobin Davis 
112c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
113c9b443d4STobin Davis 					 struct hda_codec *codec,
114c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
115c9b443d4STobin Davis {
116c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
117c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
118c9b443d4STobin Davis }
119c9b443d4STobin Davis 
120c9b443d4STobin Davis /*
121c9b443d4STobin Davis  * Digital out
122c9b443d4STobin Davis  */
123c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
124c9b443d4STobin Davis 					  struct hda_codec *codec,
125c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
126c9b443d4STobin Davis {
127c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
128c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
129c9b443d4STobin Davis }
130c9b443d4STobin Davis 
131c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
132c9b443d4STobin Davis 					 struct hda_codec *codec,
133c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
134c9b443d4STobin Davis {
135c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
136c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
137c9b443d4STobin Davis }
138c9b443d4STobin Davis 
1396b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1406b97eb45STakashi Iwai 					 struct hda_codec *codec,
1416b97eb45STakashi Iwai 					 unsigned int stream_tag,
1426b97eb45STakashi Iwai 					 unsigned int format,
1436b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
1446b97eb45STakashi Iwai {
1456b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1466b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1476b97eb45STakashi Iwai 					     stream_tag,
1486b97eb45STakashi Iwai 					     format, substream);
1496b97eb45STakashi Iwai }
1506b97eb45STakashi Iwai 
151c9b443d4STobin Davis /*
152c9b443d4STobin Davis  * Analog capture
153c9b443d4STobin Davis  */
154c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
155c9b443d4STobin Davis 				      struct hda_codec *codec,
156c9b443d4STobin Davis 				      unsigned int stream_tag,
157c9b443d4STobin Davis 				      unsigned int format,
158c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
159c9b443d4STobin Davis {
160c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
161c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
162c9b443d4STobin Davis 				   stream_tag, 0, format);
163c9b443d4STobin Davis 	return 0;
164c9b443d4STobin Davis }
165c9b443d4STobin Davis 
166c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
167c9b443d4STobin Davis 				      struct hda_codec *codec,
168c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
169c9b443d4STobin Davis {
170c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
171c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
172c9b443d4STobin Davis 				   0, 0, 0);
173c9b443d4STobin Davis 	return 0;
174c9b443d4STobin Davis }
175c9b443d4STobin Davis 
176c9b443d4STobin Davis 
177c9b443d4STobin Davis 
178c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = {
179c9b443d4STobin Davis 	.substreams = 1,
180c9b443d4STobin Davis 	.channels_min = 2,
181c9b443d4STobin Davis 	.channels_max = 2,
182c9b443d4STobin Davis 	.nid = 0, /* fill later */
183c9b443d4STobin Davis 	.ops = {
184c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
185c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
186c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
187c9b443d4STobin Davis 	},
188c9b443d4STobin Davis };
189c9b443d4STobin Davis 
190c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = {
191c9b443d4STobin Davis 	.substreams = 1,
192c9b443d4STobin Davis 	.channels_min = 2,
193c9b443d4STobin Davis 	.channels_max = 2,
194c9b443d4STobin Davis 	.nid = 0, /* fill later */
195c9b443d4STobin Davis 	.ops = {
196c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
197c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
198c9b443d4STobin Davis 	},
199c9b443d4STobin Davis };
200c9b443d4STobin Davis 
201c9b443d4STobin Davis 
202c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = {
203c9b443d4STobin Davis 	.substreams = 1,
204c9b443d4STobin Davis 	.channels_min = 2,
205c9b443d4STobin Davis 	.channels_max = 2,
206c9b443d4STobin Davis 	.nid = 0, /* fill later */
207c9b443d4STobin Davis 	.ops = {
208c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2096b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2106b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
211c9b443d4STobin Davis 	},
212c9b443d4STobin Davis };
213c9b443d4STobin Davis 
214c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = {
215c9b443d4STobin Davis 	.substreams = 1,
216c9b443d4STobin Davis 	.channels_min = 2,
217c9b443d4STobin Davis 	.channels_max = 2,
218c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
219c9b443d4STobin Davis };
220c9b443d4STobin Davis 
221c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
222c9b443d4STobin Davis {
223c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
224c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
225c9b443d4STobin Davis 
226c9b443d4STobin Davis 	codec->num_pcms = 1;
227c9b443d4STobin Davis 	codec->pcm_info = info;
228c9b443d4STobin Davis 
229c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
230c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
231c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
232c9b443d4STobin Davis 		spec->multiout.max_channels;
233c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
234c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
235c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture;
236c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
237c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
238c9b443d4STobin Davis 
239c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
240c9b443d4STobin Davis 		info++;
241c9b443d4STobin Davis 		codec->num_pcms++;
242c9b443d4STobin Davis 		info->name = "Conexant Digital";
243c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
244c9b443d4STobin Davis 			conexant_pcm_digital_playback;
245c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
246c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
247c9b443d4STobin Davis 		if (spec->dig_in_nid) {
248c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
249c9b443d4STobin Davis 				conexant_pcm_digital_capture;
250c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
251c9b443d4STobin Davis 				spec->dig_in_nid;
252c9b443d4STobin Davis 		}
253c9b443d4STobin Davis 	}
254c9b443d4STobin Davis 
255c9b443d4STobin Davis 	return 0;
256c9b443d4STobin Davis }
257c9b443d4STobin Davis 
258c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
259c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
260c9b443d4STobin Davis {
261c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
262c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
263c9b443d4STobin Davis 
264c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
265c9b443d4STobin Davis }
266c9b443d4STobin Davis 
267c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
268c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
269c9b443d4STobin Davis {
270c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
271c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
272c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
273c9b443d4STobin Davis 
274c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
275c9b443d4STobin Davis 	return 0;
276c9b443d4STobin Davis }
277c9b443d4STobin Davis 
278c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
279c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
280c9b443d4STobin Davis {
281c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
282c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
283c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
284c9b443d4STobin Davis 
285c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
286c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
287c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
288c9b443d4STobin Davis }
289c9b443d4STobin Davis 
290c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
291c9b443d4STobin Davis {
292c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
293c9b443d4STobin Davis 	int i;
294c9b443d4STobin Davis 
295c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
296c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
297c9b443d4STobin Davis 	return 0;
298c9b443d4STobin Davis }
299c9b443d4STobin Davis 
300c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
301c9b443d4STobin Davis {
302c9b443d4STobin Davis         struct conexant_spec *spec = codec->spec;
303c9b443d4STobin Davis         unsigned int i;
304c9b443d4STobin Davis 
305c9b443d4STobin Davis         if (spec->kctl_alloc) {
306c9b443d4STobin Davis                 for (i = 0; i < spec->num_kctl_used; i++)
307c9b443d4STobin Davis                         kfree(spec->kctl_alloc[i].name);
308c9b443d4STobin Davis                 kfree(spec->kctl_alloc);
309c9b443d4STobin Davis         }
310c9b443d4STobin Davis 
311c9b443d4STobin Davis 	kfree(codec->spec);
312c9b443d4STobin Davis }
313c9b443d4STobin Davis 
314c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
315c9b443d4STobin Davis {
316c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
317c9b443d4STobin Davis 	unsigned int i;
318c9b443d4STobin Davis 	int err;
319c9b443d4STobin Davis 
320c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
321c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
322c9b443d4STobin Davis 		if (err < 0)
323c9b443d4STobin Davis 			return err;
324c9b443d4STobin Davis 	}
325c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
326c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
327c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
328c9b443d4STobin Davis 		if (err < 0)
329c9b443d4STobin Davis 			return err;
330c9b443d4STobin Davis 	}
331c9b443d4STobin Davis 	if (spec->dig_in_nid) {
332c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
333c9b443d4STobin Davis 		if (err < 0)
334c9b443d4STobin Davis 			return err;
335c9b443d4STobin Davis 	}
336c9b443d4STobin Davis 	return 0;
337c9b443d4STobin Davis }
338c9b443d4STobin Davis 
339c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
340c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
341c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
342c9b443d4STobin Davis 	.init = conexant_init,
343c9b443d4STobin Davis 	.free = conexant_free,
344c9b443d4STobin Davis };
345c9b443d4STobin Davis 
346c9b443d4STobin Davis /*
347c9b443d4STobin Davis  * EAPD control
348c9b443d4STobin Davis  * the private value = nid | (invert << 8)
349c9b443d4STobin Davis  */
350c9b443d4STobin Davis 
351a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
352c9b443d4STobin Davis 
35382f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
354c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
355c9b443d4STobin Davis {
356c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
357c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
358c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
359c9b443d4STobin Davis 	if (invert)
360c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
361c9b443d4STobin Davis 	else
362c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
363c9b443d4STobin Davis 	return 0;
36482f30040STobin Davis 
365c9b443d4STobin Davis }
366c9b443d4STobin Davis 
36782f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
368c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
369c9b443d4STobin Davis {
370c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
371c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
372c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
373c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
374c9b443d4STobin Davis 	unsigned int eapd;
37582f30040STobin Davis 
376c9b443d4STobin Davis 	eapd = ucontrol->value.integer.value[0];
377c9b443d4STobin Davis 	if (invert)
378c9b443d4STobin Davis 		eapd = !eapd;
37982beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
380c9b443d4STobin Davis 		return 0;
38182f30040STobin Davis 
382c9b443d4STobin Davis 	spec->cur_eapd = eapd;
38382beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
384c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
385c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
386c9b443d4STobin Davis 	return 1;
387c9b443d4STobin Davis }
388c9b443d4STobin Davis 
38986d72bdfSTakashi Iwai /* controls for test mode */
39086d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
39186d72bdfSTakashi Iwai 
39282f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
39382f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
39482f30040STobin Davis 	  .info = cxt_eapd_info, \
39582f30040STobin Davis 	  .get = cxt_eapd_get, \
39682f30040STobin Davis 	  .put = cxt_eapd_put, \
39782f30040STobin Davis 	  .private_value = nid | (mask<<16) }
39882f30040STobin Davis 
39982f30040STobin Davis 
40082f30040STobin Davis 
401c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
402c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
403c9b443d4STobin Davis {
404c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
405c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
406c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
407c9b443d4STobin Davis 				    spec->num_channel_mode);
408c9b443d4STobin Davis }
409c9b443d4STobin Davis 
410c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
411c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
412c9b443d4STobin Davis {
413c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
414c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
415c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
416c9b443d4STobin Davis 				   spec->num_channel_mode,
417c9b443d4STobin Davis 				   spec->multiout.max_channels);
418c9b443d4STobin Davis }
419c9b443d4STobin Davis 
420c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
421c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
422c9b443d4STobin Davis {
423c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
424c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
425c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
426c9b443d4STobin Davis 				      spec->num_channel_mode,
427c9b443d4STobin Davis 				      &spec->multiout.max_channels);
428c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
429c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
430c9b443d4STobin Davis 	return err;
431c9b443d4STobin Davis }
432c9b443d4STobin Davis 
433c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
434c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
435c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
436c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
437c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
438c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
439c9b443d4STobin Davis 
44086d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
44186d72bdfSTakashi Iwai 
442c9b443d4STobin Davis /* Conexant 5045 specific */
443c9b443d4STobin Davis 
444c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
445c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
446c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
447c9b443d4STobin Davis #define CXT5045_SPDIF_OUT	0x13
448c9b443d4STobin Davis 
4495cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
4505cd57529STobin Davis 	{ 2, NULL },
4515cd57529STobin Davis };
452c9b443d4STobin Davis 
453c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
454c9b443d4STobin Davis 	.num_items = 2,
455c9b443d4STobin Davis 	.items = {
45682f30040STobin Davis 		{ "IntMic", 0x1 },
457c9b443d4STobin Davis 		{ "LineIn", 0x2 },
458c9b443d4STobin Davis 	}
459c9b443d4STobin Davis };
460c9b443d4STobin Davis 
461c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
462c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
463c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
464c9b443d4STobin Davis {
465c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
466c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
46782f30040STobin Davis 	unsigned int bits;
468c9b443d4STobin Davis 
46982f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
470c9b443d4STobin Davis 		return 0;
471c9b443d4STobin Davis 
47282f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
47382f30040STobin Davis 	 * the headphone jack
47482f30040STobin Davis 	 */
47547fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
47647fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
47747fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
4787f29673bSTobin Davis 
47947fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
48047fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
48147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
482c9b443d4STobin Davis 	return 1;
483c9b443d4STobin Davis }
484c9b443d4STobin Davis 
485c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
486*cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
487*cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
488*cca3b371STakashi Iwai 	.values = {
489*cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
490*cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
491*cca3b371STakashi Iwai 		0
492*cca3b371STakashi Iwai 	},
493*cca3b371STakashi Iwai };
494c9b443d4STobin Davis 
4957f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
4967f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
4977f29673bSTobin Davis {
4987f29673bSTobin Davis 	static struct hda_verb mic_jack_on[] = {
4997f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
5007f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5017f29673bSTobin Davis 		{}
5027f29673bSTobin Davis 	};
5037f29673bSTobin Davis 	static struct hda_verb mic_jack_off[] = {
5047f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
5057f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5067f29673bSTobin Davis 		{}
5077f29673bSTobin Davis 	};
5087f29673bSTobin Davis 	unsigned int present;
5097f29673bSTobin Davis 
5107f29673bSTobin Davis 	present = snd_hda_codec_read(codec, 0x12, 0,
5117f29673bSTobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5127f29673bSTobin Davis 	if (present)
5137f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
5147f29673bSTobin Davis 	else
5157f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
5167f29673bSTobin Davis }
5177f29673bSTobin Davis 
518c9b443d4STobin Davis 
519c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
520c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
521c9b443d4STobin Davis {
52282f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
523dd87da1cSTobin Davis 	unsigned int bits;
524c9b443d4STobin Davis 
52582f30040STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
526c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
527dd87da1cSTobin Davis 
52847fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
52947fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
53047fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
531c9b443d4STobin Davis }
532c9b443d4STobin Davis 
533c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
534c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
535c9b443d4STobin Davis 				   unsigned int res)
536c9b443d4STobin Davis {
537c9b443d4STobin Davis 	res >>= 26;
538c9b443d4STobin Davis 	switch (res) {
539c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
540c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
541c9b443d4STobin Davis 		break;
5427f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
5437f29673bSTobin Davis 		cxt5045_hp_automic(codec);
5447f29673bSTobin Davis 		break;
5457f29673bSTobin Davis 
546c9b443d4STobin Davis 	}
547c9b443d4STobin Davis }
548c9b443d4STobin Davis 
549c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
550c9b443d4STobin Davis 	{
551c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
552c9b443d4STobin Davis 		.name = "Capture Source",
553c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
554c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
555c9b443d4STobin Davis 		.put = conexant_mux_enum_put
556c9b443d4STobin Davis 	},
5577f29673bSTobin Davis 	HDA_CODEC_VOLUME("Int Mic Volume", 0x1a, 0x01, HDA_INPUT),
5587f29673bSTobin Davis 	HDA_CODEC_MUTE("Int Mic Switch", 0x1a, 0x01, HDA_INPUT),
5597f29673bSTobin Davis 	HDA_CODEC_VOLUME("Ext Mic Volume", 0x1a, 0x02, HDA_INPUT),
5607f29673bSTobin Davis 	HDA_CODEC_MUTE("Ext Mic Switch", 0x1a, 0x02, HDA_INPUT),
561*cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
562c9b443d4STobin Davis 	{
563c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
564c9b443d4STobin Davis 		.name = "Master Playback Switch",
56582f30040STobin Davis 		.info = cxt_eapd_info,
56682f30040STobin Davis 		.get = cxt_eapd_get,
567c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
56882f30040STobin Davis 		.private_value = 0x10,
569c9b443d4STobin Davis 	},
570c9b443d4STobin Davis 
571c9b443d4STobin Davis 	{}
572c9b443d4STobin Davis };
573c9b443d4STobin Davis 
574c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
575c9b443d4STobin Davis 	/* Line in, Mic */
576c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5777f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
578c9b443d4STobin Davis 	/* HP, Amp  */
57982f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
58082f30040STobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL,0x01},
581c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE,
58282f30040STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x01},
58382f30040STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE,
58482f30040STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x02},
58582f30040STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE,
58682f30040STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
58782f30040STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE,
58882f30040STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x04},
58982f30040STobin Davis 	/* Record selector: Int mic */
5907f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
59182f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
592c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
593c9b443d4STobin Davis 	/* SPDIF route: PCM */
594c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
595c9b443d4STobin Davis 	/* EAPD */
59682f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
597c9b443d4STobin Davis 	{ } /* end */
598c9b443d4STobin Davis };
599c9b443d4STobin Davis 
6007f29673bSTobin Davis 
6017f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
6027f29673bSTobin Davis 	/* pin sensing on HP jack */
6037f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
604d3091fadSTakashi Iwai 	{ } /* end */
6057f29673bSTobin Davis };
6067f29673bSTobin Davis 
6077f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
6087f29673bSTobin Davis 	/* pin sensing on HP jack */
6097f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
610d3091fadSTakashi Iwai 	{ } /* end */
6117f29673bSTobin Davis };
6127f29673bSTobin Davis 
613c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
614c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
615c9b443d4STobin Davis  * configuration.
616c9b443d4STobin Davis  */
617c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
618c9b443d4STobin Davis 	.num_items = 5,
619c9b443d4STobin Davis 	.items = {
620c9b443d4STobin Davis 		{ "MIXER", 0x0 },
621c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
622c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
623c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
624c9b443d4STobin Davis 		{ "CD pin", 0x4 },
625c9b443d4STobin Davis         },
626c9b443d4STobin Davis };
627c9b443d4STobin Davis 
628c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
629c9b443d4STobin Davis 
630c9b443d4STobin Davis 	/* Output controls */
631c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
632c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
6337f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
6347f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
6357f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
6367f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
637c9b443d4STobin Davis 
638c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
639c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
640c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
641c9b443d4STobin Davis 
64282f30040STobin Davis 	/* EAPD Switch Control */
64382f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
64482f30040STobin Davis 
645c9b443d4STobin Davis 	/* Loopback mixer controls */
646c9b443d4STobin Davis 
6477f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
6487f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
6497f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
6507f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
6517f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
6527f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
6537f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
6547f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
6557f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
6567f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
657c9b443d4STobin Davis 	{
658c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
659c9b443d4STobin Davis 		.name = "Input Source",
660c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
661c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
662c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
663c9b443d4STobin Davis 	},
664fb3409e7STobin Davis 	/* Audio input controls */
665fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
666fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
667fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
668fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
669fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
670fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
671fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
672fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
673fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
674fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
675c9b443d4STobin Davis 	{ } /* end */
676c9b443d4STobin Davis };
677c9b443d4STobin Davis 
678c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
6797f29673bSTobin Davis 	/* Set connections */
6807f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
6817f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
6827f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
683c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
684c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6857f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
686c9b443d4STobin Davis 
687c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
688c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
689c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
690c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
691c9b443d4STobin Davis 	 * control.
692c9b443d4STobin Davis 	 */
693c9b443d4STobin Davis 	{0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
694c9b443d4STobin Davis 
695c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
696c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
697c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
698c9b443d4STobin Davis 
699c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
700c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
701c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
702c9b443d4STobin Davis 	 * input/output buffers as needed.
703c9b443d4STobin Davis 	 */
704c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
705c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
706c9b443d4STobin Davis 
707c9b443d4STobin Davis 	/* Mute capture amp left and right */
708c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
709c9b443d4STobin Davis 
710c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
711c9b443d4STobin Davis 	 * pin)
712c9b443d4STobin Davis 	 */
713c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7147f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
715c9b443d4STobin Davis 
716c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
717c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
718c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
719c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
720c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
721c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
722c9b443d4STobin Davis 
723c9b443d4STobin Davis 	{ }
724c9b443d4STobin Davis };
725c9b443d4STobin Davis #endif
726c9b443d4STobin Davis 
727c9b443d4STobin Davis 
728c9b443d4STobin Davis /* initialize jack-sensing, too */
729c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
730c9b443d4STobin Davis {
731c9b443d4STobin Davis 	conexant_init(codec);
732c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
733c9b443d4STobin Davis 	return 0;
734c9b443d4STobin Davis }
735c9b443d4STobin Davis 
736c9b443d4STobin Davis 
737c9b443d4STobin Davis enum {
738f5fcc13cSTakashi Iwai 	CXT5045_LAPTOP,	 /* Laptops w/ EAPD support */
7397f29673bSTobin Davis 	CXT5045_FUJITSU, /* Laptops w/ EAPD support */
740c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
741c9b443d4STobin Davis 	CXT5045_TEST,
742c9b443d4STobin Davis #endif
743f5fcc13cSTakashi Iwai 	CXT5045_MODELS
744c9b443d4STobin Davis };
745c9b443d4STobin Davis 
746f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = {
747f5fcc13cSTakashi Iwai 	[CXT5045_LAPTOP]	= "laptop",
7487f29673bSTobin Davis 	[CXT5045_FUJITSU]	= "fujitsu",
749c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
750f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
751c9b443d4STobin Davis #endif
752f5fcc13cSTakashi Iwai };
753c9b443d4STobin Davis 
754f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
755f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP),
75682f30040STobin Davis 	SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP),
7574d69d756STobin Davis 	SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP),
7584d69d756STobin Davis 	SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP),
7594d69d756STobin Davis 	SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP),
7608481da5aSClaudio Matsuoka 	SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP),
7617f29673bSTobin Davis 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_FUJITSU),
762f8f794abSTobin Davis 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP),
7637f29673bSTobin Davis 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP),
764c9b443d4STobin Davis 	{}
765c9b443d4STobin Davis };
766c9b443d4STobin Davis 
767c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
768c9b443d4STobin Davis {
769c9b443d4STobin Davis 	struct conexant_spec *spec;
770c9b443d4STobin Davis 	int board_config;
771c9b443d4STobin Davis 
772c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
773c9b443d4STobin Davis 	if (!spec)
774c9b443d4STobin Davis 		return -ENOMEM;
775c9b443d4STobin Davis 	mutex_init(&spec->amp_mutex);
776c9b443d4STobin Davis 	codec->spec = spec;
777c9b443d4STobin Davis 
778c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
779c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
780c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
781c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
782c9b443d4STobin Davis 	spec->num_adc_nids = 1;
783c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
784c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
785c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
786c9b443d4STobin Davis 	spec->num_mixers = 1;
787c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
788c9b443d4STobin Davis 	spec->num_init_verbs = 1;
789c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
790c9b443d4STobin Davis 	spec->spdif_route = 0;
7915cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
7925cd57529STobin Davis 	spec->channel_mode = cxt5045_modes,
7935cd57529STobin Davis 
794c9b443d4STobin Davis 
795c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
796c9b443d4STobin Davis 
797f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
798f5fcc13cSTakashi Iwai 						  cxt5045_models,
799f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
800c9b443d4STobin Davis 	switch (board_config) {
801c9b443d4STobin Davis 	case CXT5045_LAPTOP:
8027f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
803c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
804c9b443d4STobin Davis 		spec->num_init_verbs = 2;
8057f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
8067f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
8077f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
8087f29673bSTobin Davis 		break;
8097f29673bSTobin Davis 	case CXT5045_FUJITSU:
8107f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
8117f29673bSTobin Davis 		spec->num_init_verbs = 2;
8127f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
813c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
814c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
815c9b443d4STobin Davis 		break;
816c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
817c9b443d4STobin Davis 	case CXT5045_TEST:
818c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
819c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
820c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
821c9b443d4STobin Davis #endif
822c9b443d4STobin Davis 	}
823c9b443d4STobin Davis 	return 0;
824c9b443d4STobin Davis }
825c9b443d4STobin Davis 
826c9b443d4STobin Davis 
827c9b443d4STobin Davis /* Conexant 5047 specific */
82882f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
829c9b443d4STobin Davis 
83082f30040STobin Davis static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
831c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
832c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
833c9b443d4STobin Davis 
8345cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
8355cd57529STobin Davis 	{ 2, NULL },
8365cd57529STobin Davis };
837c9b443d4STobin Davis 
838c9b443d4STobin Davis static struct hda_input_mux cxt5047_capture_source = {
8397f29673bSTobin Davis 	.num_items = 1,
840c9b443d4STobin Davis 	.items = {
8417f29673bSTobin Davis 		{ "Mic", 0x2 },
842c9b443d4STobin Davis 	}
843c9b443d4STobin Davis };
844c9b443d4STobin Davis 
845c9b443d4STobin Davis static struct hda_input_mux cxt5047_hp_capture_source = {
846c9b443d4STobin Davis 	.num_items = 1,
847c9b443d4STobin Davis 	.items = {
84882f30040STobin Davis 		{ "ExtMic", 0x2 },
84982f30040STobin Davis 	}
85082f30040STobin Davis };
85182f30040STobin Davis 
85282f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
85382f30040STobin Davis 	.num_items = 2,
85482f30040STobin Davis 	.items = {
85582f30040STobin Davis 		{ "ExtMic", 0x2 },
85682f30040STobin Davis 		{ "Line-In", 0x1 },
857c9b443d4STobin Davis 	}
858c9b443d4STobin Davis };
859c9b443d4STobin Davis 
860c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
861c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
862c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
863c9b443d4STobin Davis {
864c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
865c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
86682f30040STobin Davis 	unsigned int bits;
867c9b443d4STobin Davis 
86882f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
869c9b443d4STobin Davis 		return 0;
870c9b443d4STobin Davis 
87182f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
87282f30040STobin Davis 	 * the headphone jack
87382f30040STobin Davis 	 */
87447fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
87547fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
87647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
87747fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
87847fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
87947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
880c9b443d4STobin Davis 	return 1;
881c9b443d4STobin Davis }
882c9b443d4STobin Davis 
88382f30040STobin Davis /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
884*cca3b371STakashi Iwai static struct hda_bind_ctls cxt5047_bind_master_vol = {
885*cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
886*cca3b371STakashi Iwai 	.values = {
887*cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
888*cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
889*cca3b371STakashi Iwai 		0
890*cca3b371STakashi Iwai 	},
891*cca3b371STakashi Iwai };
892c9b443d4STobin Davis 
893c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
894c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
895c9b443d4STobin Davis {
89682f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
897dd87da1cSTobin Davis 	unsigned int bits;
898c9b443d4STobin Davis 
89982f30040STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
900c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
901dd87da1cSTobin Davis 
90247fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
90347fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
90447fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
90582f30040STobin Davis 	/* Mute/Unmute PCM 2 for good measure - some systems need this */
90647fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
90747fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
908c9b443d4STobin Davis }
909c9b443d4STobin Davis 
910fb3409e7STobin Davis /* mute internal speaker if HP is plugged */
911fb3409e7STobin Davis static void cxt5047_hp2_automute(struct hda_codec *codec)
912fb3409e7STobin Davis {
913fb3409e7STobin Davis 	struct conexant_spec *spec = codec->spec;
914fb3409e7STobin Davis 	unsigned int bits;
915fb3409e7STobin Davis 
916fb3409e7STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
917fb3409e7STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
918fb3409e7STobin Davis 
91947fd830aSTakashi Iwai 	bits = spec->hp_present ? HDA_AMP_MUTE : 0;
92047fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
92147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
922fb3409e7STobin Davis 	/* Mute/Unmute PCM 2 for good measure - some systems need this */
92347fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
92447fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
925fb3409e7STobin Davis }
926fb3409e7STobin Davis 
927c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
928c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
929c9b443d4STobin Davis {
930c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
931c9b443d4STobin Davis 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
932c9b443d4STobin Davis 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
933c9b443d4STobin Davis 		{}
934c9b443d4STobin Davis 	};
935c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
936c9b443d4STobin Davis 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
937c9b443d4STobin Davis 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
938c9b443d4STobin Davis 		{}
939c9b443d4STobin Davis 	};
940c9b443d4STobin Davis 	unsigned int present;
941c9b443d4STobin Davis 
9427f29673bSTobin Davis 	present = snd_hda_codec_read(codec, 0x15, 0,
943c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
944c9b443d4STobin Davis 	if (present)
945c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
946c9b443d4STobin Davis 	else
947c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
948c9b443d4STobin Davis }
949c9b443d4STobin Davis 
950c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
951c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
952c9b443d4STobin Davis 				  unsigned int res)
953c9b443d4STobin Davis {
954c9b443d4STobin Davis 	res >>= 26;
955c9b443d4STobin Davis 	switch (res) {
956c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
957c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
958c9b443d4STobin Davis 		break;
959c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
960c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
961c9b443d4STobin Davis 		break;
962c9b443d4STobin Davis 	}
963c9b443d4STobin Davis }
964c9b443d4STobin Davis 
965fb3409e7STobin Davis /* unsolicited event for HP jack sensing - non-EAPD systems */
966fb3409e7STobin Davis static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
967fb3409e7STobin Davis 				  unsigned int res)
968fb3409e7STobin Davis {
969fb3409e7STobin Davis 	res >>= 26;
970fb3409e7STobin Davis 	switch (res) {
971fb3409e7STobin Davis 	case CONEXANT_HP_EVENT:
972fb3409e7STobin Davis 		cxt5047_hp2_automute(codec);
973fb3409e7STobin Davis 		break;
974fb3409e7STobin Davis 	case CONEXANT_MIC_EVENT:
975fb3409e7STobin Davis 		cxt5047_hp_automic(codec);
976fb3409e7STobin Davis 		break;
977fb3409e7STobin Davis 	}
978fb3409e7STobin Davis }
979fb3409e7STobin Davis 
980c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_mixers[] = {
981c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
982c9b443d4STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
9837f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
9847f29673bSTobin Davis 	HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
985c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
986c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
987c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
988c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
98982f30040STobin Davis 	HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
99082f30040STobin Davis 	HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
991b7589cebSTobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
992b7589cebSTobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
993b7589cebSTobin Davis 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
994b7589cebSTobin Davis 	HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
99582f30040STobin Davis 
99682f30040STobin Davis 	{}
99782f30040STobin Davis };
99882f30040STobin Davis 
99982f30040STobin Davis static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
100082f30040STobin Davis 	{
100182f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
100282f30040STobin Davis 		.name = "Capture Source",
100382f30040STobin Davis 		.info = conexant_mux_enum_info,
100482f30040STobin Davis 		.get = conexant_mux_enum_get,
100582f30040STobin Davis 		.put = conexant_mux_enum_put
100682f30040STobin Davis 	},
100782f30040STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
100882f30040STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
100982f30040STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
101082f30040STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
101182f30040STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
101282f30040STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1013*cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
101482f30040STobin Davis 	{
101582f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
101682f30040STobin Davis 		.name = "Master Playback Switch",
101782f30040STobin Davis 		.info = cxt_eapd_info,
101882f30040STobin Davis 		.get = cxt_eapd_get,
1019c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1020c9b443d4STobin Davis 		.private_value = 0x13,
1021c9b443d4STobin Davis 	},
1022c9b443d4STobin Davis 
1023c9b443d4STobin Davis 	{}
1024c9b443d4STobin Davis };
1025c9b443d4STobin Davis 
1026c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1027c9b443d4STobin Davis 	{
1028c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1029c9b443d4STobin Davis 		.name = "Capture Source",
1030c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1031c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1032c9b443d4STobin Davis 		.put = conexant_mux_enum_put
1033c9b443d4STobin Davis 	},
1034c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1035c9b443d4STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1036c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1037c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1038c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1039c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1040c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1041c9b443d4STobin Davis 	{
1042c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1043c9b443d4STobin Davis 		.name = "Master Playback Switch",
104482f30040STobin Davis 		.info = cxt_eapd_info,
104582f30040STobin Davis 		.get = cxt_eapd_get,
1046c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1047c9b443d4STobin Davis 		.private_value = 0x13,
1048c9b443d4STobin Davis 	},
1049c9b443d4STobin Davis 	{ } /* end */
1050c9b443d4STobin Davis };
1051c9b443d4STobin Davis 
1052c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1053c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1054c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1055c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1056c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
10577f29673bSTobin Davis 	/* HP, Speaker  */
1058b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1059b7589cebSTobin Davis 	{0x13, AC_VERB_SET_CONNECT_SEL,0x1},
10607f29673bSTobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
10617f29673bSTobin Davis 	/* Record selector: Mic */
10627f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
10637f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
10647f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
10657f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1066c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1067c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1068c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1069c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1070c9b443d4STobin Davis 	/* SPDIF route: PCM */
1071c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
107282f30040STobin Davis 	/* Enable unsolicited events */
107382f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
107482f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1075c9b443d4STobin Davis 	{ } /* end */
1076c9b443d4STobin Davis };
1077c9b443d4STobin Davis 
1078c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1079c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1080c9b443d4STobin Davis 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1081c9b443d4STobin Davis 	/* pin sensing on HP and Mic jacks */
1082c9b443d4STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1083c9b443d4STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
108482f30040STobin Davis 	/* Speaker routing */
108582f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1086c9b443d4STobin Davis 	{}
1087c9b443d4STobin Davis };
1088c9b443d4STobin Davis 
1089c9b443d4STobin Davis /* configuration for HP Laptops */
1090c9b443d4STobin Davis static struct hda_verb cxt5047_hp_init_verbs[] = {
109182f30040STobin Davis 	/* pin sensing on HP jack */
1092c9b443d4STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
109382f30040STobin Davis 	/* Record selector: Ext Mic */
109482f30040STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
109582f30040STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
109682f30040STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
109782f30040STobin Davis 	/* Speaker routing */
109882f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1099c9b443d4STobin Davis 	{}
1100c9b443d4STobin Davis };
1101c9b443d4STobin Davis 
1102c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1103c9b443d4STobin Davis  * configuration.
1104c9b443d4STobin Davis  */
1105c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1106c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
110782f30040STobin Davis 	.num_items = 4,
1108c9b443d4STobin Davis 	.items = {
110982f30040STobin Davis 		{ "LINE1 pin", 0x0 },
111082f30040STobin Davis 		{ "MIC1 pin", 0x1 },
111182f30040STobin Davis 		{ "MIC2 pin", 0x2 },
111282f30040STobin Davis 		{ "CD pin", 0x3 },
1113c9b443d4STobin Davis         },
1114c9b443d4STobin Davis };
1115c9b443d4STobin Davis 
1116c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1117c9b443d4STobin Davis 
1118c9b443d4STobin Davis 	/* Output only controls */
111982f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
112082f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
112182f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
112282f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1123c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1124c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1125c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1126c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
112782f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
112882f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
112982f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
113082f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1131c9b443d4STobin Davis 
1132c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1133c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1134c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1135c9b443d4STobin Davis 
113682f30040STobin Davis 	/* EAPD Switch Control */
113782f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
113882f30040STobin Davis 
1139c9b443d4STobin Davis 	/* Loopback mixer controls */
114082f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
114182f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
114282f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
114382f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
114482f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
114582f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
114682f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
114782f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1148c9b443d4STobin Davis 
114982f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
115082f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
115182f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
115282f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
115382f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
115482f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
115582f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
115682f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1157c9b443d4STobin Davis 	{
1158c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1159c9b443d4STobin Davis 		.name = "Input Source",
1160c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1161c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1162c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1163c9b443d4STobin Davis 	},
1164c9b443d4STobin Davis 	{ } /* end */
1165c9b443d4STobin Davis };
1166c9b443d4STobin Davis 
1167c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1168c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1169c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1170c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1171c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1172c9b443d4STobin Davis 
1173c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1174c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1175c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1176c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1177c9b443d4STobin Davis 	 * control.
1178c9b443d4STobin Davis 	 */
1179c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1180c9b443d4STobin Davis 
1181c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1182c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1183c9b443d4STobin Davis 	 */
1184c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1185c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1186c9b443d4STobin Davis 
1187c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1188c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1189c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1190c9b443d4STobin Davis 
1191c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1192c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1193c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1194c9b443d4STobin Davis 	 * input/output buffers as needed.
1195c9b443d4STobin Davis 	 */
1196c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1197c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1198c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1199c9b443d4STobin Davis 
1200c9b443d4STobin Davis 	/* Mute capture amp left and right */
1201c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1202c9b443d4STobin Davis 
1203c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1204c9b443d4STobin Davis 	 * pin)
1205c9b443d4STobin Davis 	 */
1206c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1207c9b443d4STobin Davis 
1208c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1209c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1210c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1211c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1212c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1213c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1214c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1215c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1216c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1217c9b443d4STobin Davis 
1218c9b443d4STobin Davis 	{ }
1219c9b443d4STobin Davis };
1220c9b443d4STobin Davis #endif
1221c9b443d4STobin Davis 
1222c9b443d4STobin Davis 
1223c9b443d4STobin Davis /* initialize jack-sensing, too */
1224c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1225c9b443d4STobin Davis {
1226c9b443d4STobin Davis 	conexant_init(codec);
1227c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1228c9b443d4STobin Davis 	return 0;
1229c9b443d4STobin Davis }
1230c9b443d4STobin Davis 
1231c9b443d4STobin Davis 
1232c9b443d4STobin Davis enum {
1233f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1234f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1235f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1236c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1237c9b443d4STobin Davis 	CXT5047_TEST,
1238c9b443d4STobin Davis #endif
1239f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1240c9b443d4STobin Davis };
1241c9b443d4STobin Davis 
1242f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = {
1243f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1244f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1245f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1246c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1247f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1248c9b443d4STobin Davis #endif
1249f5fcc13cSTakashi Iwai };
1250c9b443d4STobin Davis 
1251f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1252f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1253f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
125482f30040STobin Davis 	SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
1255f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1256f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1257c9b443d4STobin Davis 	{}
1258c9b443d4STobin Davis };
1259c9b443d4STobin Davis 
1260c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1261c9b443d4STobin Davis {
1262c9b443d4STobin Davis 	struct conexant_spec *spec;
1263c9b443d4STobin Davis 	int board_config;
1264c9b443d4STobin Davis 
1265c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1266c9b443d4STobin Davis 	if (!spec)
1267c9b443d4STobin Davis 		return -ENOMEM;
1268c9b443d4STobin Davis 	mutex_init(&spec->amp_mutex);
1269c9b443d4STobin Davis 	codec->spec = spec;
1270c9b443d4STobin Davis 
1271c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1272c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1273c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1274c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1275c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1276c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1277c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1278c9b443d4STobin Davis 	spec->input_mux = &cxt5047_capture_source;
1279c9b443d4STobin Davis 	spec->num_mixers = 1;
1280c9b443d4STobin Davis 	spec->mixers[0] = cxt5047_mixers;
1281c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1282c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1283c9b443d4STobin Davis 	spec->spdif_route = 0;
12845cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
12855cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1286c9b443d4STobin Davis 
1287c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1288c9b443d4STobin Davis 
1289f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1290f5fcc13cSTakashi Iwai 						  cxt5047_models,
1291f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1292c9b443d4STobin Davis 	switch (board_config) {
1293c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1294fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
1295c9b443d4STobin Davis 		break;
1296c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1297c9b443d4STobin Davis 		spec->input_mux = &cxt5047_hp_capture_source;
1298c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1299c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_hp_init_verbs;
1300c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_hp_mixers;
1301fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1302c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1303c9b443d4STobin Davis 		break;
1304c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
130582f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1306c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1307c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
130882f30040STobin Davis 		spec->mixers[0] = cxt5047_toshiba_mixers;
1309fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1310c9b443d4STobin Davis 		break;
1311c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1312c9b443d4STobin Davis 	case CXT5047_TEST:
1313c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1314c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1315c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1316fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1317c9b443d4STobin Davis #endif
1318c9b443d4STobin Davis 	}
1319c9b443d4STobin Davis 	return 0;
1320c9b443d4STobin Davis }
1321c9b443d4STobin Davis 
1322c9b443d4STobin Davis struct hda_codec_preset snd_hda_preset_conexant[] = {
132382f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
132482f30040STobin Davis 	  .patch = patch_cxt5045 },
132582f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
132682f30040STobin Davis 	  .patch = patch_cxt5047 },
1327c9b443d4STobin Davis 	{} /* terminator */
1328c9b443d4STobin Davis };
1329