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