xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision 82f30040ada635d5d42a244b6eb84607d9881f5a)
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;
60*82f30040STobin 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 
139c9b443d4STobin Davis /*
140c9b443d4STobin Davis  * Analog capture
141c9b443d4STobin Davis  */
142c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
143c9b443d4STobin Davis 				      struct hda_codec *codec,
144c9b443d4STobin Davis 				      unsigned int stream_tag,
145c9b443d4STobin Davis 				      unsigned int format,
146c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
147c9b443d4STobin Davis {
148c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
149c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
150c9b443d4STobin Davis 				   stream_tag, 0, format);
151c9b443d4STobin Davis 	return 0;
152c9b443d4STobin Davis }
153c9b443d4STobin Davis 
154c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
155c9b443d4STobin Davis 				      struct hda_codec *codec,
156c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
157c9b443d4STobin Davis {
158c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
159c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
160c9b443d4STobin Davis 				   0, 0, 0);
161c9b443d4STobin Davis 	return 0;
162c9b443d4STobin Davis }
163c9b443d4STobin Davis 
164c9b443d4STobin Davis 
165c9b443d4STobin Davis 
166c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = {
167c9b443d4STobin Davis 	.substreams = 1,
168c9b443d4STobin Davis 	.channels_min = 2,
169c9b443d4STobin Davis 	.channels_max = 2,
170c9b443d4STobin Davis 	.nid = 0, /* fill later */
171c9b443d4STobin Davis 	.ops = {
172c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
173c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
174c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
175c9b443d4STobin Davis 	},
176c9b443d4STobin Davis };
177c9b443d4STobin Davis 
178c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = {
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 		.prepare = conexant_capture_pcm_prepare,
185c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
186c9b443d4STobin Davis 	},
187c9b443d4STobin Davis };
188c9b443d4STobin Davis 
189c9b443d4STobin Davis 
190c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = {
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 		.open = conexant_dig_playback_pcm_open,
197c9b443d4STobin Davis 		.close = conexant_dig_playback_pcm_close
198c9b443d4STobin Davis 	},
199c9b443d4STobin Davis };
200c9b443d4STobin Davis 
201c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = {
202c9b443d4STobin Davis 	.substreams = 1,
203c9b443d4STobin Davis 	.channels_min = 2,
204c9b443d4STobin Davis 	.channels_max = 2,
205c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
206c9b443d4STobin Davis };
207c9b443d4STobin Davis 
208c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
209c9b443d4STobin Davis {
210c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
211c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
212c9b443d4STobin Davis 
213c9b443d4STobin Davis 	codec->num_pcms = 1;
214c9b443d4STobin Davis 	codec->pcm_info = info;
215c9b443d4STobin Davis 
216c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
217c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
218c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
219c9b443d4STobin Davis 		spec->multiout.max_channels;
220c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
221c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
222c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture;
223c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
224c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
225c9b443d4STobin Davis 
226c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
227c9b443d4STobin Davis 		info++;
228c9b443d4STobin Davis 		codec->num_pcms++;
229c9b443d4STobin Davis 		info->name = "Conexant Digital";
230c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
231c9b443d4STobin Davis 			conexant_pcm_digital_playback;
232c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
233c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
234c9b443d4STobin Davis 		if (spec->dig_in_nid) {
235c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
236c9b443d4STobin Davis 				conexant_pcm_digital_capture;
237c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
238c9b443d4STobin Davis 				spec->dig_in_nid;
239c9b443d4STobin Davis 		}
240c9b443d4STobin Davis 	}
241c9b443d4STobin Davis 
242c9b443d4STobin Davis 	return 0;
243c9b443d4STobin Davis }
244c9b443d4STobin Davis 
245c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
246c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
247c9b443d4STobin Davis {
248c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
249c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
250c9b443d4STobin Davis 
251c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
252c9b443d4STobin Davis }
253c9b443d4STobin Davis 
254c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
255c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
256c9b443d4STobin Davis {
257c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
258c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
259c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
260c9b443d4STobin Davis 
261c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
262c9b443d4STobin Davis 	return 0;
263c9b443d4STobin Davis }
264c9b443d4STobin Davis 
265c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
266c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
267c9b443d4STobin Davis {
268c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
269c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
270c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
271c9b443d4STobin Davis 
272c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
273c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
274c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
275c9b443d4STobin Davis }
276c9b443d4STobin Davis 
277c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
278c9b443d4STobin Davis {
279c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
280c9b443d4STobin Davis 	int i;
281c9b443d4STobin Davis 
282c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
283c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
284c9b443d4STobin Davis 	return 0;
285c9b443d4STobin Davis }
286c9b443d4STobin Davis 
287c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
288c9b443d4STobin Davis {
289c9b443d4STobin Davis         struct conexant_spec *spec = codec->spec;
290c9b443d4STobin Davis         unsigned int i;
291c9b443d4STobin Davis 
292c9b443d4STobin Davis         if (spec->kctl_alloc) {
293c9b443d4STobin Davis                 for (i = 0; i < spec->num_kctl_used; i++)
294c9b443d4STobin Davis                         kfree(spec->kctl_alloc[i].name);
295c9b443d4STobin Davis                 kfree(spec->kctl_alloc);
296c9b443d4STobin Davis         }
297c9b443d4STobin Davis 
298c9b443d4STobin Davis 	kfree(codec->spec);
299c9b443d4STobin Davis }
300c9b443d4STobin Davis 
301c9b443d4STobin Davis #ifdef CONFIG_PM
302c9b443d4STobin Davis static int conexant_resume(struct hda_codec *codec)
303c9b443d4STobin Davis {
304c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
305c9b443d4STobin Davis 	int i;
306c9b443d4STobin Davis 
307c9b443d4STobin Davis 	codec->patch_ops.init(codec);
308c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++)
309c9b443d4STobin Davis 		snd_hda_resume_ctls(codec, spec->mixers[i]);
310c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid)
311c9b443d4STobin Davis 		snd_hda_resume_spdif_out(codec);
312c9b443d4STobin Davis 	if (spec->dig_in_nid)
313c9b443d4STobin Davis 		snd_hda_resume_spdif_in(codec);
314c9b443d4STobin Davis 	return 0;
315c9b443d4STobin Davis }
316c9b443d4STobin Davis #endif
317c9b443d4STobin Davis 
318c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
319c9b443d4STobin Davis {
320c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
321c9b443d4STobin Davis 	unsigned int i;
322c9b443d4STobin Davis 	int err;
323c9b443d4STobin Davis 
324c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
325c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
326c9b443d4STobin Davis 		if (err < 0)
327c9b443d4STobin Davis 			return err;
328c9b443d4STobin Davis 	}
329c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
330c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
331c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
332c9b443d4STobin Davis 		if (err < 0)
333c9b443d4STobin Davis 			return err;
334c9b443d4STobin Davis 	}
335c9b443d4STobin Davis 	if (spec->dig_in_nid) {
336c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
337c9b443d4STobin Davis 		if (err < 0)
338c9b443d4STobin Davis 			return err;
339c9b443d4STobin Davis 	}
340c9b443d4STobin Davis 	return 0;
341c9b443d4STobin Davis }
342c9b443d4STobin Davis 
343c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
344c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
345c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
346c9b443d4STobin Davis 	.init = conexant_init,
347c9b443d4STobin Davis 	.free = conexant_free,
348c9b443d4STobin Davis #ifdef CONFIG_PM
349c9b443d4STobin Davis 	.resume = conexant_resume,
350c9b443d4STobin Davis #endif
351c9b443d4STobin Davis };
352c9b443d4STobin Davis 
353c9b443d4STobin Davis /*
354c9b443d4STobin Davis  * EAPD control
355c9b443d4STobin Davis  * the private value = nid | (invert << 8)
356c9b443d4STobin Davis  */
357c9b443d4STobin Davis 
358*82f30040STobin Davis static int cxt_eapd_info(struct snd_kcontrol *kcontrol,
359c9b443d4STobin Davis 			      struct snd_ctl_elem_info *uinfo)
360c9b443d4STobin Davis {
361c9b443d4STobin Davis 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
362c9b443d4STobin Davis 	uinfo->count = 1;
363c9b443d4STobin Davis 	uinfo->value.integer.min = 0;
364c9b443d4STobin Davis 	uinfo->value.integer.max = 1;
365c9b443d4STobin Davis 	return 0;
366c9b443d4STobin Davis }
367c9b443d4STobin Davis 
368*82f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
369c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
370c9b443d4STobin Davis {
371c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
372c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
373c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
374c9b443d4STobin Davis 	if (invert)
375c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
376c9b443d4STobin Davis 	else
377c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
378c9b443d4STobin Davis 	return 0;
379*82f30040STobin Davis 
380c9b443d4STobin Davis }
381c9b443d4STobin Davis 
382*82f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
383c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
384c9b443d4STobin Davis {
385c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
386c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
387c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
388c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
389c9b443d4STobin Davis 	unsigned int eapd;
390*82f30040STobin Davis 
391c9b443d4STobin Davis 	eapd = ucontrol->value.integer.value[0];
392c9b443d4STobin Davis 	if (invert)
393c9b443d4STobin Davis 		eapd = !eapd;
394c9b443d4STobin Davis 	if (eapd == spec->cur_eapd && !codec->in_resume)
395c9b443d4STobin Davis 		return 0;
396*82f30040STobin Davis 
397c9b443d4STobin Davis 	spec->cur_eapd = eapd;
398c9b443d4STobin Davis 	snd_hda_codec_write(codec, nid,
399c9b443d4STobin Davis 			    0, AC_VERB_SET_EAPD_BTLENABLE,
400c9b443d4STobin Davis 			    eapd ? 0x02 : 0x00);
401c9b443d4STobin Davis 	return 1;
402c9b443d4STobin Davis }
403c9b443d4STobin Davis 
40486d72bdfSTakashi Iwai /* controls for test mode */
40586d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
40686d72bdfSTakashi Iwai 
407*82f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
408*82f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
409*82f30040STobin Davis 	  .info = cxt_eapd_info, \
410*82f30040STobin Davis 	  .get = cxt_eapd_get, \
411*82f30040STobin Davis 	  .put = cxt_eapd_put, \
412*82f30040STobin Davis 	  .private_value = nid | (mask<<16) }
413*82f30040STobin Davis 
414*82f30040STobin Davis 
415*82f30040STobin Davis 
416c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
417c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
418c9b443d4STobin Davis {
419c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
420c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
421c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
422c9b443d4STobin Davis 				    spec->num_channel_mode);
423c9b443d4STobin Davis }
424c9b443d4STobin Davis 
425c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
426c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
427c9b443d4STobin Davis {
428c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
429c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
430c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
431c9b443d4STobin Davis 				   spec->num_channel_mode,
432c9b443d4STobin Davis 				   spec->multiout.max_channels);
433c9b443d4STobin Davis }
434c9b443d4STobin Davis 
435c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
436c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
437c9b443d4STobin Davis {
438c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
439c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
440c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
441c9b443d4STobin Davis 				      spec->num_channel_mode,
442c9b443d4STobin Davis 				      &spec->multiout.max_channels);
443c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
444c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
445c9b443d4STobin Davis 	return err;
446c9b443d4STobin Davis }
447c9b443d4STobin Davis 
448c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
449c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
450c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
451c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
452c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
453c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
454c9b443d4STobin Davis 
455c9b443d4STobin Davis static int cxt_gpio_data_info(struct snd_kcontrol *kcontrol,
456c9b443d4STobin Davis 			      struct snd_ctl_elem_info *uinfo)
457c9b443d4STobin Davis {
458c9b443d4STobin Davis 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
459c9b443d4STobin Davis 	uinfo->count = 1;
460c9b443d4STobin Davis 	uinfo->value.integer.min = 0;
461c9b443d4STobin Davis 	uinfo->value.integer.max = 1;
462c9b443d4STobin Davis 	return 0;
463c9b443d4STobin Davis }
464c9b443d4STobin Davis 
465c9b443d4STobin Davis static int cxt_gpio_data_get(struct snd_kcontrol *kcontrol,
466c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
467c9b443d4STobin Davis {
468c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
469c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xffff;
470c9b443d4STobin Davis 	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
471c9b443d4STobin Davis 	long *valp = ucontrol->value.integer.value;
472c9b443d4STobin Davis 	unsigned int val = snd_hda_codec_read(codec, nid, 0,
473c9b443d4STobin Davis 					      AC_VERB_GET_GPIO_DATA, 0x00);
474c9b443d4STobin Davis 
475c9b443d4STobin Davis 	*valp = (val & mask) != 0;
476c9b443d4STobin Davis 	return 0;
477c9b443d4STobin Davis }
478c9b443d4STobin Davis 
479c9b443d4STobin Davis static int cxt_gpio_data_put(struct snd_kcontrol *kcontrol,
480c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
481c9b443d4STobin Davis {
482c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
483c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xffff;
484c9b443d4STobin Davis 	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
485c9b443d4STobin Davis 	long val = *ucontrol->value.integer.value;
486c9b443d4STobin Davis 	unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
487c9b443d4STobin Davis 						    AC_VERB_GET_GPIO_DATA,
488c9b443d4STobin Davis 						    0x00);
489c9b443d4STobin Davis 	unsigned int old_data = gpio_data;
490c9b443d4STobin Davis 
491c9b443d4STobin Davis 	/* Set/unset the masked GPIO bit(s) as needed */
492c9b443d4STobin Davis 	if (val == 0)
493c9b443d4STobin Davis 		gpio_data &= ~mask;
494c9b443d4STobin Davis 	else
495c9b443d4STobin Davis 		gpio_data |= mask;
496c9b443d4STobin Davis 	if (gpio_data == old_data && !codec->in_resume)
497c9b443d4STobin Davis 		return 0;
498c9b443d4STobin Davis 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_GPIO_DATA, gpio_data);
499c9b443d4STobin Davis 	return 1;
500c9b443d4STobin Davis }
501c9b443d4STobin Davis 
502c9b443d4STobin Davis #define CXT_GPIO_DATA_SWITCH(xname, nid, mask) \
503c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
504c9b443d4STobin Davis 	  .info = cxt_gpio_data_info, \
505c9b443d4STobin Davis 	  .get = cxt_gpio_data_get, \
506c9b443d4STobin Davis 	  .put = cxt_gpio_data_put, \
507c9b443d4STobin Davis 	  .private_value = nid | (mask<<16) }
508*82f30040STobin Davis #if 0
509c9b443d4STobin Davis static int cxt_spdif_ctrl_info(struct snd_kcontrol *kcontrol,
510c9b443d4STobin Davis 			       struct snd_ctl_elem_info *uinfo)
511c9b443d4STobin Davis {
512c9b443d4STobin Davis 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
513c9b443d4STobin Davis 	uinfo->count = 1;
514c9b443d4STobin Davis 	uinfo->value.integer.min = 0;
515c9b443d4STobin Davis 	uinfo->value.integer.max = 1;
516c9b443d4STobin Davis 	return 0;
517c9b443d4STobin Davis }
518c9b443d4STobin Davis 
519c9b443d4STobin Davis static int cxt_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
520c9b443d4STobin Davis 			      struct snd_ctl_elem_value *ucontrol)
521c9b443d4STobin Davis {
522c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
523c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xffff;
524c9b443d4STobin Davis 	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
525c9b443d4STobin Davis 	long *valp = ucontrol->value.integer.value;
526c9b443d4STobin Davis 	unsigned int val = snd_hda_codec_read(codec, nid, 0,
527c9b443d4STobin Davis 					      AC_VERB_GET_DIGI_CONVERT, 0x00);
528c9b443d4STobin Davis 
529c9b443d4STobin Davis 	*valp = (val & mask) != 0;
530c9b443d4STobin Davis 	return 0;
531c9b443d4STobin Davis }
532c9b443d4STobin Davis 
533c9b443d4STobin Davis static int cxt_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
534c9b443d4STobin Davis 			      struct snd_ctl_elem_value *ucontrol)
535c9b443d4STobin Davis {
536c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
537c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xffff;
538c9b443d4STobin Davis 	unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
539c9b443d4STobin Davis 	long val = *ucontrol->value.integer.value;
540c9b443d4STobin Davis 	unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
541c9b443d4STobin Davis 						    AC_VERB_GET_DIGI_CONVERT,
542c9b443d4STobin Davis 						    0x00);
543c9b443d4STobin Davis 	unsigned int old_data = ctrl_data;
544c9b443d4STobin Davis 
545c9b443d4STobin Davis 	/* Set/unset the masked control bit(s) as needed */
546c9b443d4STobin Davis 	if (val == 0)
547c9b443d4STobin Davis 		ctrl_data &= ~mask;
548c9b443d4STobin Davis 	else
549c9b443d4STobin Davis 		ctrl_data |= mask;
550c9b443d4STobin Davis 	if (ctrl_data == old_data && !codec->in_resume)
551c9b443d4STobin Davis 		return 0;
552c9b443d4STobin Davis 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
553c9b443d4STobin Davis 			    ctrl_data);
554c9b443d4STobin Davis 	return 1;
555c9b443d4STobin Davis }
556c9b443d4STobin Davis 
557c9b443d4STobin Davis #define CXT_SPDIF_CTRL_SWITCH(xname, nid, mask) \
558c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
559c9b443d4STobin Davis 	  .info = cxt_spdif_ctrl_info, \
560c9b443d4STobin Davis 	  .get = cxt_spdif_ctrl_get, \
561c9b443d4STobin Davis 	  .put = cxt_spdif_ctrl_put, \
562c9b443d4STobin Davis 	  .private_value = nid | (mask<<16) }
563*82f30040STobin Davis #endif
56486d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
56586d72bdfSTakashi Iwai 
566c9b443d4STobin Davis /* Conexant 5045 specific */
567c9b443d4STobin Davis 
568c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
569c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
570c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
571c9b443d4STobin Davis #define CXT5045_SPDIF_OUT	0x13
572c9b443d4STobin Davis 
5735cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
5745cd57529STobin Davis 	{ 2, NULL },
5755cd57529STobin Davis };
576c9b443d4STobin Davis 
577c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
578c9b443d4STobin Davis 	.num_items = 2,
579c9b443d4STobin Davis 	.items = {
580*82f30040STobin Davis 		{ "IntMic", 0x1 },
581c9b443d4STobin Davis 		{ "LineIn", 0x2 },
582c9b443d4STobin Davis 	}
583c9b443d4STobin Davis };
584c9b443d4STobin Davis 
585c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
586c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
587c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
588c9b443d4STobin Davis {
589c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
590c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
591*82f30040STobin Davis 	unsigned int bits;
592c9b443d4STobin Davis 
593*82f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
594c9b443d4STobin Davis 		return 0;
595c9b443d4STobin Davis 
596*82f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
597*82f30040STobin Davis 	 * the headphone jack
598*82f30040STobin Davis 	 */
599*82f30040STobin Davis 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : 0x80;
600*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, 0x80, bits);
601*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, 0x80, bits);
602*82f30040STobin Davis 	bits = spec->cur_eapd ? 0 : 0x80;
603*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0, 0x80, bits);
604*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0, 0x80, bits);
605c9b443d4STobin Davis 	return 1;
606c9b443d4STobin Davis }
607c9b443d4STobin Davis 
608c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
609c9b443d4STobin Davis static int cxt5045_hp_master_vol_put(struct snd_kcontrol *kcontrol,
610c9b443d4STobin Davis 				     struct snd_ctl_elem_value *ucontrol)
611c9b443d4STobin Davis {
612c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613c9b443d4STobin Davis 	long *valp = ucontrol->value.integer.value;
614c9b443d4STobin Davis 	int change;
615c9b443d4STobin Davis 
616c9b443d4STobin Davis 	change = snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0,
617c9b443d4STobin Davis 					  0x7f, valp[0] & 0x7f);
618c9b443d4STobin Davis 	change |= snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0,
619c9b443d4STobin Davis 					   0x7f, valp[1] & 0x7f);
620c9b443d4STobin Davis 	snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0,
621c9b443d4STobin Davis 				 0x7f, valp[0] & 0x7f);
622c9b443d4STobin Davis 	snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0,
623c9b443d4STobin Davis 				 0x7f, valp[1] & 0x7f);
624c9b443d4STobin Davis 	return change;
625c9b443d4STobin Davis }
626c9b443d4STobin Davis 
627c9b443d4STobin Davis 
628c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
629c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
630c9b443d4STobin Davis {
631*82f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
632*82f30040STobin Davis 	unsigned int bits = (spec->hp_present || !spec->cur_eapd) ? 0x80 : 0;
633c9b443d4STobin Davis 
634*82f30040STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
635c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
636*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, 0x80, bits);
637*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, 0x80, bits);
638c9b443d4STobin Davis }
639c9b443d4STobin Davis 
640c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
641c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
642c9b443d4STobin Davis 				   unsigned int res)
643c9b443d4STobin Davis {
644c9b443d4STobin Davis 	res >>= 26;
645c9b443d4STobin Davis 	switch (res) {
646c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
647c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
648c9b443d4STobin Davis 		break;
649c9b443d4STobin Davis 	}
650c9b443d4STobin Davis }
651c9b443d4STobin Davis 
652c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
653c9b443d4STobin Davis 	{
654c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
655c9b443d4STobin Davis 		.name = "Capture Source",
656c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
657c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
658c9b443d4STobin Davis 		.put = conexant_mux_enum_put
659c9b443d4STobin Davis 	},
660*82f30040STobin Davis 	HDA_CODEC_VOLUME("Int Mic Volume", 0x17, 0x01, HDA_INPUT),
661*82f30040STobin Davis 	HDA_CODEC_MUTE("Int Mic Switch", 0x17, 0x01, HDA_INPUT),
662*82f30040STobin Davis 	HDA_CODEC_VOLUME("Ext Mic Volume", 0x17, 0x02, HDA_INPUT),
663*82f30040STobin Davis 	HDA_CODEC_MUTE("Ext Mic Switch", 0x17, 0x02, HDA_INPUT),
664*82f30040STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
665*82f30040STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
666c9b443d4STobin Davis 	{
667c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
668c9b443d4STobin Davis 		.name = "Master Playback Volume",
669c9b443d4STobin Davis 		.info = snd_hda_mixer_amp_volume_info,
670c9b443d4STobin Davis 		.get = snd_hda_mixer_amp_volume_get,
671c9b443d4STobin Davis 		.put = cxt5045_hp_master_vol_put,
672*82f30040STobin Davis 		.private_value = HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
673c9b443d4STobin Davis 	},
674c9b443d4STobin Davis 	{
675c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
676c9b443d4STobin Davis 		.name = "Master Playback Switch",
677*82f30040STobin Davis 		.info = cxt_eapd_info,
678*82f30040STobin Davis 		.get = cxt_eapd_get,
679c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
680*82f30040STobin Davis 		.private_value = 0x10,
681c9b443d4STobin Davis 	},
682c9b443d4STobin Davis 
683c9b443d4STobin Davis 	{}
684c9b443d4STobin Davis };
685c9b443d4STobin Davis 
686c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
687c9b443d4STobin Davis 	/* Line in, Mic */
688c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
689c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
690c9b443d4STobin Davis 	/* HP, Amp  */
691*82f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
692*82f30040STobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL,0x01},
693c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE,
694*82f30040STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x01},
695*82f30040STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE,
696*82f30040STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x02},
697*82f30040STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE,
698*82f30040STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
699*82f30040STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE,
700*82f30040STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x04},
701*82f30040STobin Davis 	/* Record selector: Int mic */
702*82f30040STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x0},
703*82f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
704c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
705c9b443d4STobin Davis 	/* SPDIF route: PCM */
706c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
707c9b443d4STobin Davis 	/* pin sensing on HP and Mic jacks */
708c9b443d4STobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
709c9b443d4STobin Davis 	/* EAPD */
710*82f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
711c9b443d4STobin Davis 	{ } /* end */
712c9b443d4STobin Davis };
713c9b443d4STobin Davis 
714c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
715c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
716c9b443d4STobin Davis  * configuration.
717c9b443d4STobin Davis  */
718c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
719c9b443d4STobin Davis 	.num_items = 5,
720c9b443d4STobin Davis 	.items = {
721c9b443d4STobin Davis 		{ "MIXER", 0x0 },
722c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
723c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
724c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
725c9b443d4STobin Davis 		{ "CD pin", 0x4 },
726c9b443d4STobin Davis         },
727c9b443d4STobin Davis };
728c9b443d4STobin Davis 
729c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
730c9b443d4STobin Davis 
731c9b443d4STobin Davis 	/* Output controls */
732c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
733c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
734c9b443d4STobin Davis 
735c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
736c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
737c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
738c9b443d4STobin Davis 
739*82f30040STobin Davis 	/* EAPD Switch Control */
740*82f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
741*82f30040STobin Davis 
742c9b443d4STobin Davis 	/* Loopback mixer controls */
743c9b443d4STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x17, 0x01, HDA_INPUT),
744c9b443d4STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x17, 0x01, HDA_INPUT),
745c9b443d4STobin Davis 	HDA_CODEC_VOLUME("LINE loopback Playback Volume", 0x17, 0x02, HDA_INPUT),
746c9b443d4STobin Davis 	HDA_CODEC_MUTE("LINE loopback Playback Switch", 0x17, 0x02, HDA_INPUT),
747c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x17, 0x03, HDA_INPUT),
748c9b443d4STobin Davis 	HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x17, 0x03, HDA_INPUT),
749c9b443d4STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x04, HDA_INPUT),
750c9b443d4STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x04, HDA_INPUT),
751c9b443d4STobin Davis 
752*82f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x17, 0x0, HDA_INPUT),
753*82f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x17, 0x0, HDA_INPUT),
754*82f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x17, 0x1, HDA_INPUT),
755*82f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x17, 0x1, HDA_INPUT),
756*82f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x17, 0x2, HDA_INPUT),
757*82f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x17, 0x2, HDA_INPUT),
758*82f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x17, 0x3, HDA_INPUT),
759*82f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x17, 0x3, HDA_INPUT),
760*82f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-5 Volume", 0x17, 0x4, HDA_INPUT),
761*82f30040STobin Davis 	HDA_CODEC_MUTE("Capture-5 Switch", 0x17, 0x4, HDA_INPUT),
762c9b443d4STobin Davis 	{
763c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
764c9b443d4STobin Davis 		.name = "Input Source",
765c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
766c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
767c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
768c9b443d4STobin Davis 	},
769c9b443d4STobin Davis 
770c9b443d4STobin Davis 	{ } /* end */
771c9b443d4STobin Davis };
772c9b443d4STobin Davis 
773c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
774c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
775c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
776*82f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
777c9b443d4STobin Davis 
778c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
779c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
780c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
781c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
782c9b443d4STobin Davis 	 * control.
783c9b443d4STobin Davis 	 */
784c9b443d4STobin Davis 	{0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
785c9b443d4STobin Davis 
786c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
787c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
788c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
789c9b443d4STobin Davis 
790c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
791c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
792c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
793c9b443d4STobin Davis 	 * input/output buffers as needed.
794c9b443d4STobin Davis 	 */
795c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
796c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
797c9b443d4STobin Davis 
798c9b443d4STobin Davis 	/* Mute capture amp left and right */
799c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
800c9b443d4STobin Davis 
801c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
802c9b443d4STobin Davis 	 * pin)
803c9b443d4STobin Davis 	 */
804c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
805c9b443d4STobin Davis 
806c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
807c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
808c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
809c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
810c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
811c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
812c9b443d4STobin Davis 
813c9b443d4STobin Davis 	{ }
814c9b443d4STobin Davis };
815c9b443d4STobin Davis #endif
816c9b443d4STobin Davis 
817c9b443d4STobin Davis 
818c9b443d4STobin Davis /* initialize jack-sensing, too */
819c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
820c9b443d4STobin Davis {
821c9b443d4STobin Davis 	conexant_init(codec);
822c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
823c9b443d4STobin Davis 	return 0;
824c9b443d4STobin Davis }
825c9b443d4STobin Davis 
826c9b443d4STobin Davis 
827c9b443d4STobin Davis enum {
828f5fcc13cSTakashi Iwai 	CXT5045_LAPTOP,	/* Laptops w/ EAPD support */
829c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
830c9b443d4STobin Davis 	CXT5045_TEST,
831c9b443d4STobin Davis #endif
832f5fcc13cSTakashi Iwai 	CXT5045_MODELS
833c9b443d4STobin Davis };
834c9b443d4STobin Davis 
835f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = {
836f5fcc13cSTakashi Iwai 	[CXT5045_LAPTOP]	= "laptop",
837c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
838f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
839c9b443d4STobin Davis #endif
840f5fcc13cSTakashi Iwai };
841c9b443d4STobin Davis 
842f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
843f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP),
844*82f30040STobin Davis 	SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP),
845*82f30040STobin Davis 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP),
846c9b443d4STobin Davis 	{}
847c9b443d4STobin Davis };
848c9b443d4STobin Davis 
849c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
850c9b443d4STobin Davis {
851c9b443d4STobin Davis 	struct conexant_spec *spec;
852c9b443d4STobin Davis 	int board_config;
853c9b443d4STobin Davis 
854c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
855c9b443d4STobin Davis 	if (!spec)
856c9b443d4STobin Davis 		return -ENOMEM;
857c9b443d4STobin Davis 	mutex_init(&spec->amp_mutex);
858c9b443d4STobin Davis 	codec->spec = spec;
859c9b443d4STobin Davis 
860c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
861c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
862c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
863c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
864c9b443d4STobin Davis 	spec->num_adc_nids = 1;
865c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
866c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
867c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
868c9b443d4STobin Davis 	spec->num_mixers = 1;
869c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
870c9b443d4STobin Davis 	spec->num_init_verbs = 1;
871c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
872c9b443d4STobin Davis 	spec->spdif_route = 0;
8735cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
8745cd57529STobin Davis 	spec->channel_mode = cxt5045_modes,
8755cd57529STobin Davis 
876c9b443d4STobin Davis 
877c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
878c9b443d4STobin Davis 	codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
879c9b443d4STobin Davis 
880f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
881f5fcc13cSTakashi Iwai 						  cxt5045_models,
882f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
883c9b443d4STobin Davis 	switch (board_config) {
884c9b443d4STobin Davis 	case CXT5045_LAPTOP:
885c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
886c9b443d4STobin Davis 		spec->num_init_verbs = 2;
887c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5045_init_verbs;
888c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
889c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
890c9b443d4STobin Davis 		break;
891c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
892c9b443d4STobin Davis 	case CXT5045_TEST:
893c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
894c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
895c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
896c9b443d4STobin Davis #endif
897c9b443d4STobin Davis 	}
898c9b443d4STobin Davis 	return 0;
899c9b443d4STobin Davis }
900c9b443d4STobin Davis 
901c9b443d4STobin Davis 
902c9b443d4STobin Davis /* Conexant 5047 specific */
903*82f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
904c9b443d4STobin Davis 
905*82f30040STobin Davis static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
906c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
907c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
908c9b443d4STobin Davis 
9095cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
9105cd57529STobin Davis 	{ 2, NULL },
9115cd57529STobin Davis };
912c9b443d4STobin Davis 
913c9b443d4STobin Davis static struct hda_input_mux cxt5047_capture_source = {
914c9b443d4STobin Davis 	.num_items = 2,
915c9b443d4STobin Davis 	.items = {
916*82f30040STobin Davis 		{ "ExtMic", 0x0 },
917*82f30040STobin Davis 		{ "IntMic", 0x1 },
918c9b443d4STobin Davis 	}
919c9b443d4STobin Davis };
920c9b443d4STobin Davis 
921c9b443d4STobin Davis static struct hda_input_mux cxt5047_hp_capture_source = {
922c9b443d4STobin Davis 	.num_items = 1,
923c9b443d4STobin Davis 	.items = {
924*82f30040STobin Davis 		{ "ExtMic", 0x2 },
925*82f30040STobin Davis 	}
926*82f30040STobin Davis };
927*82f30040STobin Davis 
928*82f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
929*82f30040STobin Davis 	.num_items = 2,
930*82f30040STobin Davis 	.items = {
931*82f30040STobin Davis 		{ "ExtMic", 0x2 },
932*82f30040STobin Davis 		{ "Line-In", 0x1 },
933c9b443d4STobin Davis 	}
934c9b443d4STobin Davis };
935c9b443d4STobin Davis 
936c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
937c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
938c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
939c9b443d4STobin Davis {
940c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
941c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
942*82f30040STobin Davis 	unsigned int bits;
943c9b443d4STobin Davis 
944*82f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
945c9b443d4STobin Davis 		return 0;
946c9b443d4STobin Davis 
947*82f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
948*82f30040STobin Davis 	 * the headphone jack
949*82f30040STobin Davis 	 */
950*82f30040STobin Davis 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : 0x80;
951*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0, 0x80, bits);
952*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0, 0x80, bits);
953*82f30040STobin Davis 	bits = spec->cur_eapd ? 0 : 0x80;
954*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0, 0x80, bits);
955*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0, 0x80, bits);
956c9b443d4STobin Davis 	return 1;
957c9b443d4STobin Davis }
958c9b443d4STobin Davis 
959*82f30040STobin Davis /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
960c9b443d4STobin Davis static int cxt5047_hp_master_vol_put(struct snd_kcontrol *kcontrol,
961c9b443d4STobin Davis 				     struct snd_ctl_elem_value *ucontrol)
962c9b443d4STobin Davis {
963c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
964c9b443d4STobin Davis 	long *valp = ucontrol->value.integer.value;
965c9b443d4STobin Davis 	int change;
966c9b443d4STobin Davis 
967*82f30040STobin Davis 	change = snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0,
968c9b443d4STobin Davis 					  0x7f, valp[0] & 0x7f);
969*82f30040STobin Davis 	change |= snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0,
970c9b443d4STobin Davis 					   0x7f, valp[1] & 0x7f);
971c9b443d4STobin Davis 	snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0,
972c9b443d4STobin Davis 				 0x7f, valp[0] & 0x7f);
973c9b443d4STobin Davis 	snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0,
974c9b443d4STobin Davis 				 0x7f, valp[1] & 0x7f);
975c9b443d4STobin Davis 	return change;
976c9b443d4STobin Davis }
977c9b443d4STobin Davis 
978c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
979c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
980c9b443d4STobin Davis {
981*82f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
982*82f30040STobin Davis 	unsigned int bits = spec->hp_present || !spec->cur_eapd ? 0x80 : 0;
983c9b443d4STobin Davis 
984*82f30040STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
985c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
986*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0, 0x80, bits);
987*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0, 0x80, bits);
988*82f30040STobin Davis 	/* Mute/Unmute PCM 2 for good measure - some systems need this */
989*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x1c, 0, HDA_OUTPUT, 0, 0x80, bits);
990*82f30040STobin Davis 	snd_hda_codec_amp_update(codec, 0x1c, 1, HDA_OUTPUT, 0, 0x80, bits);
991c9b443d4STobin Davis }
992c9b443d4STobin Davis 
993c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
994c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
995c9b443d4STobin Davis {
996c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
997c9b443d4STobin Davis 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
998c9b443d4STobin Davis 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
999c9b443d4STobin Davis 		{}
1000c9b443d4STobin Davis 	};
1001c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
1002c9b443d4STobin Davis 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1003c9b443d4STobin Davis 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1004c9b443d4STobin Davis 		{}
1005c9b443d4STobin Davis 	};
1006c9b443d4STobin Davis 	unsigned int present;
1007c9b443d4STobin Davis 
1008c9b443d4STobin Davis 	present = snd_hda_codec_read(codec, 0x08, 0,
1009c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1010c9b443d4STobin Davis 	if (present)
1011c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1012c9b443d4STobin Davis 	else
1013c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1014c9b443d4STobin Davis }
1015c9b443d4STobin Davis 
1016c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1017c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1018c9b443d4STobin Davis 				  unsigned int res)
1019c9b443d4STobin Davis {
1020c9b443d4STobin Davis 	res >>= 26;
1021c9b443d4STobin Davis 	switch (res) {
1022c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1023c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1024c9b443d4STobin Davis 		break;
1025c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1026c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1027c9b443d4STobin Davis 		break;
1028c9b443d4STobin Davis 	}
1029c9b443d4STobin Davis }
1030c9b443d4STobin Davis 
1031c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_mixers[] = {
1032c9b443d4STobin Davis 	{
1033c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1034c9b443d4STobin Davis 		.name = "Capture Source",
1035c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1036c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1037c9b443d4STobin Davis 		.put = conexant_mux_enum_put
1038c9b443d4STobin Davis 	},
1039c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1040c9b443d4STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1041c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1042c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1043c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1044c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1045*82f30040STobin Davis 	HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1046*82f30040STobin Davis 	HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1047*82f30040STobin Davis 	{
1048*82f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1049*82f30040STobin Davis 		.name = "Master Playback Volume",
1050*82f30040STobin Davis 		.info = snd_hda_mixer_amp_volume_info,
1051*82f30040STobin Davis 		.get = snd_hda_mixer_amp_volume_get,
1052*82f30040STobin Davis 		.put = cxt5047_hp_master_vol_put,
1053*82f30040STobin Davis 		.private_value = HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1054*82f30040STobin Davis 	},
1055c9b443d4STobin Davis 	{
1056c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1057c9b443d4STobin Davis 		.name = "Master Playback Switch",
1058*82f30040STobin Davis 		.info = cxt_eapd_info,
1059*82f30040STobin Davis 		.get = cxt_eapd_get,
1060*82f30040STobin Davis 		.put = cxt5047_hp_master_sw_put,
1061*82f30040STobin Davis 		.private_value = 0x13,
1062*82f30040STobin Davis 	},
1063*82f30040STobin Davis 
1064*82f30040STobin Davis 	{}
1065*82f30040STobin Davis };
1066*82f30040STobin Davis 
1067*82f30040STobin Davis static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1068*82f30040STobin Davis 	{
1069*82f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1070*82f30040STobin Davis 		.name = "Capture Source",
1071*82f30040STobin Davis 		.info = conexant_mux_enum_info,
1072*82f30040STobin Davis 		.get = conexant_mux_enum_get,
1073*82f30040STobin Davis 		.put = conexant_mux_enum_put
1074*82f30040STobin Davis 	},
1075*82f30040STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1076*82f30040STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1077*82f30040STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1078*82f30040STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1079*82f30040STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1080*82f30040STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1081*82f30040STobin Davis 	{
1082*82f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1083*82f30040STobin Davis 		.name = "Master Playback Volume",
1084*82f30040STobin Davis 		.info = snd_hda_mixer_amp_volume_info,
1085*82f30040STobin Davis 		.get = snd_hda_mixer_amp_volume_get,
1086*82f30040STobin Davis 		.put = cxt5047_hp_master_vol_put,
1087*82f30040STobin Davis 		.private_value = HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1088*82f30040STobin Davis 	},
1089*82f30040STobin Davis 	{
1090*82f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1091*82f30040STobin Davis 		.name = "Master Playback Switch",
1092*82f30040STobin Davis 		.info = cxt_eapd_info,
1093*82f30040STobin Davis 		.get = cxt_eapd_get,
1094c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1095c9b443d4STobin Davis 		.private_value = 0x13,
1096c9b443d4STobin Davis 	},
1097c9b443d4STobin Davis 
1098c9b443d4STobin Davis 	{}
1099c9b443d4STobin Davis };
1100c9b443d4STobin Davis 
1101c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1102c9b443d4STobin Davis 	{
1103c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1104c9b443d4STobin Davis 		.name = "Capture Source",
1105c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1106c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1107c9b443d4STobin Davis 		.put = conexant_mux_enum_put
1108c9b443d4STobin Davis 	},
1109c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1110c9b443d4STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1111c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1112c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1113c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1114c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1115c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1116c9b443d4STobin Davis 	{
1117c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1118c9b443d4STobin Davis 		.name = "Master Playback Switch",
1119*82f30040STobin Davis 		.info = cxt_eapd_info,
1120*82f30040STobin Davis 		.get = cxt_eapd_get,
1121c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1122c9b443d4STobin Davis 		.private_value = 0x13,
1123c9b443d4STobin Davis 	},
1124c9b443d4STobin Davis 	{ } /* end */
1125c9b443d4STobin Davis };
1126c9b443d4STobin Davis 
1127c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1128c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1129c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1130c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1131c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1132*82f30040STobin Davis 	/* HP, Amp, Speaker  */
1133c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1134*82f30040STobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x00},
1135c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1136c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1137c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1138c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1139*82f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1140c9b443d4STobin Davis 	/* Record selector: Front mic */
1141c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1142c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1143c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1144c9b443d4STobin Davis 	/* SPDIF route: PCM */
1145c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1146*82f30040STobin Davis 	/* Enable unsolicited events */
1147*82f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1148*82f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1149c9b443d4STobin Davis 	{ } /* end */
1150c9b443d4STobin Davis };
1151c9b443d4STobin Davis 
1152c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1153c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1154c9b443d4STobin Davis 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1155c9b443d4STobin Davis 	/* pin sensing on HP and Mic jacks */
1156c9b443d4STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1157c9b443d4STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1158*82f30040STobin Davis 	/* Speaker routing */
1159*82f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1160*82f30040STobin Davis 	/* Change default to ExtMic for recording */
1161*82f30040STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x2},
1162c9b443d4STobin Davis 	{}
1163c9b443d4STobin Davis };
1164c9b443d4STobin Davis 
1165c9b443d4STobin Davis /* configuration for HP Laptops */
1166c9b443d4STobin Davis static struct hda_verb cxt5047_hp_init_verbs[] = {
1167*82f30040STobin Davis 	/* pin sensing on HP jack */
1168c9b443d4STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1169*82f30040STobin Davis 	/* Record selector: Ext Mic */
1170*82f30040STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1171*82f30040STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x02},
1172*82f30040STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1173*82f30040STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1174*82f30040STobin Davis 	/* Speaker routing */
1175*82f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1176c9b443d4STobin Davis 	{}
1177c9b443d4STobin Davis };
1178c9b443d4STobin Davis 
1179c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1180c9b443d4STobin Davis  * configuration.
1181c9b443d4STobin Davis  */
1182c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1183c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
1184*82f30040STobin Davis 	.num_items = 4,
1185c9b443d4STobin Davis 	.items = {
1186*82f30040STobin Davis 		{ "LINE1 pin", 0x0 },
1187*82f30040STobin Davis 		{ "MIC1 pin", 0x1 },
1188*82f30040STobin Davis 		{ "MIC2 pin", 0x2 },
1189*82f30040STobin Davis 		{ "CD pin", 0x3 },
1190c9b443d4STobin Davis         },
1191c9b443d4STobin Davis };
1192c9b443d4STobin Davis 
1193c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1194c9b443d4STobin Davis 
1195c9b443d4STobin Davis 	/* Output only controls */
1196*82f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1197*82f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1198*82f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1199*82f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1200c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1201c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1202c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1203c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1204*82f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1205*82f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1206*82f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1207*82f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1208c9b443d4STobin Davis 
1209c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1210c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1211c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1212c9b443d4STobin Davis 
1213*82f30040STobin Davis 	/* EAPD Switch Control */
1214*82f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1215*82f30040STobin Davis 
1216c9b443d4STobin Davis 	/* Loopback mixer controls */
1217*82f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1218*82f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1219*82f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1220*82f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1221*82f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1222*82f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1223*82f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1224*82f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1225c9b443d4STobin Davis 
1226*82f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1227*82f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1228*82f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1229*82f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1230*82f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1231*82f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1232*82f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1233*82f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1234c9b443d4STobin Davis 	{
1235c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1236c9b443d4STobin Davis 		.name = "Input Source",
1237c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1238c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1239c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1240c9b443d4STobin Davis 	},
1241*82f30040STobin Davis        /* Controls for GPIO pins, assuming they exist and are configured
1242*82f30040STobin Davis 	* as outputs
1243*82f30040STobin Davis 	*/
1244*82f30040STobin Davis 	CXT_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
1245*82f30040STobin Davis 	CXT_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
1246*82f30040STobin Davis 	CXT_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
1247*82f30040STobin Davis 	CXT_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
1248c9b443d4STobin Davis 
1249c9b443d4STobin Davis 	{ } /* end */
1250c9b443d4STobin Davis };
1251c9b443d4STobin Davis 
1252c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1253c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1254c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1255c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1256c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1257c9b443d4STobin Davis 
1258c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1259c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1260c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1261c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1262c9b443d4STobin Davis 	 * control.
1263c9b443d4STobin Davis 	 */
1264c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1265c9b443d4STobin Davis 
1266c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1267c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1268c9b443d4STobin Davis 	 */
1269c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1270c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1271c9b443d4STobin Davis 
1272c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1273c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1274c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1275c9b443d4STobin Davis 
1276c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1277c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1278c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1279c9b443d4STobin Davis 	 * input/output buffers as needed.
1280c9b443d4STobin Davis 	 */
1281c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1282c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1283c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1284c9b443d4STobin Davis 
1285c9b443d4STobin Davis 	/* Mute capture amp left and right */
1286c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1287c9b443d4STobin Davis 
1288c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1289c9b443d4STobin Davis 	 * pin)
1290c9b443d4STobin Davis 	 */
1291c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1292c9b443d4STobin Davis 
1293c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1294c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1295c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1296c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1297c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1298c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1299c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1300c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1301c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1302c9b443d4STobin Davis 
1303c9b443d4STobin Davis 	{ }
1304c9b443d4STobin Davis };
1305c9b443d4STobin Davis #endif
1306c9b443d4STobin Davis 
1307c9b443d4STobin Davis 
1308c9b443d4STobin Davis /* initialize jack-sensing, too */
1309c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1310c9b443d4STobin Davis {
1311c9b443d4STobin Davis 	conexant_init(codec);
1312c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1313c9b443d4STobin Davis 	return 0;
1314c9b443d4STobin Davis }
1315c9b443d4STobin Davis 
1316c9b443d4STobin Davis 
1317c9b443d4STobin Davis enum {
1318f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1319f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1320f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1321c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1322c9b443d4STobin Davis 	CXT5047_TEST,
1323c9b443d4STobin Davis #endif
1324f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1325c9b443d4STobin Davis };
1326c9b443d4STobin Davis 
1327f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = {
1328f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1329f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1330f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1331c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1332f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1333c9b443d4STobin Davis #endif
1334f5fcc13cSTakashi Iwai };
1335c9b443d4STobin Davis 
1336f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1337f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1338f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
1339*82f30040STobin Davis 	SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
1340f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1341f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1342c9b443d4STobin Davis 	{}
1343c9b443d4STobin Davis };
1344c9b443d4STobin Davis 
1345c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1346c9b443d4STobin Davis {
1347c9b443d4STobin Davis 	struct conexant_spec *spec;
1348c9b443d4STobin Davis 	int board_config;
1349c9b443d4STobin Davis 
1350c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1351c9b443d4STobin Davis 	if (!spec)
1352c9b443d4STobin Davis 		return -ENOMEM;
1353c9b443d4STobin Davis 	mutex_init(&spec->amp_mutex);
1354c9b443d4STobin Davis 	codec->spec = spec;
1355c9b443d4STobin Davis 
1356c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1357c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1358c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1359c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1360c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1361c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1362c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1363c9b443d4STobin Davis 	spec->input_mux = &cxt5047_capture_source;
1364c9b443d4STobin Davis 	spec->num_mixers = 1;
1365c9b443d4STobin Davis 	spec->mixers[0] = cxt5047_mixers;
1366c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1367c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1368c9b443d4STobin Davis 	spec->spdif_route = 0;
13695cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
13705cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1371c9b443d4STobin Davis 
1372c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1373c9b443d4STobin Davis 	codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1374c9b443d4STobin Davis 
1375f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1376f5fcc13cSTakashi Iwai 						  cxt5047_models,
1377f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1378c9b443d4STobin Davis 	switch (board_config) {
1379c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1380c9b443d4STobin Davis 		break;
1381c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1382c9b443d4STobin Davis 		spec->input_mux = &cxt5047_hp_capture_source;
1383c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1384c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_hp_init_verbs;
1385c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_hp_mixers;
1386c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1387c9b443d4STobin Davis 		break;
1388c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
1389*82f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1390c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1391c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1392*82f30040STobin Davis 		spec->mixers[0] = cxt5047_toshiba_mixers;
1393c9b443d4STobin Davis 		break;
1394c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1395c9b443d4STobin Davis 	case CXT5047_TEST:
1396c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1397c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1398c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1399c9b443d4STobin Davis #endif
1400c9b443d4STobin Davis 	}
1401c9b443d4STobin Davis 	return 0;
1402c9b443d4STobin Davis }
1403c9b443d4STobin Davis 
1404c9b443d4STobin Davis struct hda_codec_preset snd_hda_preset_conexant[] = {
1405*82f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
1406*82f30040STobin Davis 	  .patch = patch_cxt5045 },
1407*82f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1408*82f30040STobin Davis 	  .patch = patch_cxt5047 },
1409c9b443d4STobin Davis 	{} /* terminator */
1410c9b443d4STobin Davis };
1411