xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision 5801f992276366cd6a4f1f9939a4c9da33d499ee)
1c9b443d4STobin Davis /*
2c9b443d4STobin Davis  * HD audio interface patch for Conexant HDA audio codec
3c9b443d4STobin Davis  *
4c9b443d4STobin Davis  * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5c9b443d4STobin Davis  * 		      Takashi Iwai <tiwai@suse.de>
6c9b443d4STobin Davis  * 		      Tobin Davis  <tdavis@dsl-only.net>
7c9b443d4STobin Davis  *
8c9b443d4STobin Davis  *  This driver is free software; you can redistribute it and/or modify
9c9b443d4STobin Davis  *  it under the terms of the GNU General Public License as published by
10c9b443d4STobin Davis  *  the Free Software Foundation; either version 2 of the License, or
11c9b443d4STobin Davis  *  (at your option) any later version.
12c9b443d4STobin Davis  *
13c9b443d4STobin Davis  *  This driver is distributed in the hope that it will be useful,
14c9b443d4STobin Davis  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15c9b443d4STobin Davis  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c9b443d4STobin Davis  *  GNU General Public License for more details.
17c9b443d4STobin Davis  *
18c9b443d4STobin Davis  *  You should have received a copy of the GNU General Public License
19c9b443d4STobin Davis  *  along with this program; if not, write to the Free Software
20c9b443d4STobin Davis  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21c9b443d4STobin Davis  */
22c9b443d4STobin Davis 
23c9b443d4STobin Davis #include <linux/init.h>
24c9b443d4STobin Davis #include <linux/delay.h>
25c9b443d4STobin Davis #include <linux/slab.h>
26c9b443d4STobin Davis #include <linux/pci.h>
27c9b443d4STobin Davis #include <sound/core.h>
28bc7a166dSUlrich Dangel #include <sound/jack.h>
29bc7a166dSUlrich Dangel 
30c9b443d4STobin Davis #include "hda_codec.h"
31c9b443d4STobin Davis #include "hda_local.h"
32c9b443d4STobin Davis 
33c9b443d4STobin Davis #define CXT_PIN_DIR_IN              0x00
34c9b443d4STobin Davis #define CXT_PIN_DIR_OUT             0x01
35c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT           0x02
36c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
37c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
38c9b443d4STobin Davis 
39c9b443d4STobin Davis #define CONEXANT_HP_EVENT	0x37
40c9b443d4STobin Davis #define CONEXANT_MIC_EVENT	0x38
41c9b443d4STobin Davis 
42bc7a166dSUlrich Dangel /* Conexant 5051 specific */
43c9b443d4STobin Davis 
44bc7a166dSUlrich Dangel #define CXT5051_SPDIF_OUT	0x1C
45bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT	0x38
46bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT	0x39
47bc7a166dSUlrich Dangel 
48bc7a166dSUlrich Dangel 
49bc7a166dSUlrich Dangel struct conexant_jack {
50bc7a166dSUlrich Dangel 
51bc7a166dSUlrich Dangel 	hda_nid_t nid;
52bc7a166dSUlrich Dangel 	int type;
53bc7a166dSUlrich Dangel 	struct snd_jack *jack;
54bc7a166dSUlrich Dangel 
55bc7a166dSUlrich Dangel };
56c9b443d4STobin Davis 
57c9b443d4STobin Davis struct conexant_spec {
58c9b443d4STobin Davis 
59c9b443d4STobin Davis 	struct snd_kcontrol_new *mixers[5];
60c9b443d4STobin Davis 	int num_mixers;
61c9b443d4STobin Davis 
62c9b443d4STobin Davis 	const struct hda_verb *init_verbs[5];	/* initialization verbs
63c9b443d4STobin Davis 						 * don't forget NULL
64c9b443d4STobin Davis 						 * termination!
65c9b443d4STobin Davis 						 */
66c9b443d4STobin Davis 	unsigned int num_init_verbs;
67c9b443d4STobin Davis 
68c9b443d4STobin Davis 	/* playback */
69c9b443d4STobin Davis 	struct hda_multi_out multiout;	/* playback set-up
70c9b443d4STobin Davis 					 * max_channels, dacs must be set
71c9b443d4STobin Davis 					 * dig_out_nid and hp_nid are optional
72c9b443d4STobin Davis 					 */
73c9b443d4STobin Davis 	unsigned int cur_eapd;
7482f30040STobin Davis 	unsigned int hp_present;
75c9b443d4STobin Davis 	unsigned int need_dac_fix;
76c9b443d4STobin Davis 
77c9b443d4STobin Davis 	/* capture */
78c9b443d4STobin Davis 	unsigned int num_adc_nids;
79c9b443d4STobin Davis 	hda_nid_t *adc_nids;
80c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
81c9b443d4STobin Davis 
82461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
83461e2c78STakashi Iwai 	hda_nid_t cur_adc;
84461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
85461e2c78STakashi Iwai 	unsigned int cur_adc_format;
86461e2c78STakashi Iwai 
87c9b443d4STobin Davis 	/* capture source */
88c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
89c9b443d4STobin Davis 	hda_nid_t *capsrc_nids;
90c9b443d4STobin Davis 	unsigned int cur_mux[3];
91c9b443d4STobin Davis 
92c9b443d4STobin Davis 	/* channel model */
93c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
94c9b443d4STobin Davis 	int num_channel_mode;
95c9b443d4STobin Davis 
96c9b443d4STobin Davis 	/* PCM information */
97c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
98c9b443d4STobin Davis 
99c9b443d4STobin Davis 	unsigned int spdif_route;
100c9b443d4STobin Davis 
101bc7a166dSUlrich Dangel 	/* jack detection */
102bc7a166dSUlrich Dangel 	struct snd_array jacks;
103bc7a166dSUlrich Dangel 
104c9b443d4STobin Davis 	/* dynamic controls, init_verbs and input_mux */
105c9b443d4STobin Davis 	struct auto_pin_cfg autocfg;
106c9b443d4STobin Davis 	struct hda_input_mux private_imux;
10741923e44STakashi Iwai 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
108c9b443d4STobin Davis 
109c9b443d4STobin Davis };
110c9b443d4STobin Davis 
111c9b443d4STobin Davis static int conexant_playback_pcm_open(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;
1169a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1179a08160bSTakashi Iwai 					     hinfo);
118c9b443d4STobin Davis }
119c9b443d4STobin Davis 
120c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
121c9b443d4STobin Davis 					 struct hda_codec *codec,
122c9b443d4STobin Davis 					 unsigned int stream_tag,
123c9b443d4STobin Davis 					 unsigned int format,
124c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
125c9b443d4STobin Davis {
126c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
127c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
128c9b443d4STobin Davis 						stream_tag,
129c9b443d4STobin Davis 						format, substream);
130c9b443d4STobin Davis }
131c9b443d4STobin Davis 
132c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
133c9b443d4STobin Davis 					 struct hda_codec *codec,
134c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
135c9b443d4STobin Davis {
136c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
137c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
138c9b443d4STobin Davis }
139c9b443d4STobin Davis 
140c9b443d4STobin Davis /*
141c9b443d4STobin Davis  * Digital out
142c9b443d4STobin Davis  */
143c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
144c9b443d4STobin Davis 					  struct hda_codec *codec,
145c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
146c9b443d4STobin Davis {
147c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
148c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
149c9b443d4STobin Davis }
150c9b443d4STobin Davis 
151c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
152c9b443d4STobin Davis 					 struct hda_codec *codec,
153c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
154c9b443d4STobin Davis {
155c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
156c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
157c9b443d4STobin Davis }
158c9b443d4STobin Davis 
1596b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1606b97eb45STakashi Iwai 					 struct hda_codec *codec,
1616b97eb45STakashi Iwai 					 unsigned int stream_tag,
1626b97eb45STakashi Iwai 					 unsigned int format,
1636b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
1646b97eb45STakashi Iwai {
1656b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1666b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1676b97eb45STakashi Iwai 					     stream_tag,
1686b97eb45STakashi Iwai 					     format, substream);
1696b97eb45STakashi Iwai }
1706b97eb45STakashi Iwai 
171c9b443d4STobin Davis /*
172c9b443d4STobin Davis  * Analog capture
173c9b443d4STobin Davis  */
174c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
175c9b443d4STobin Davis 				      struct hda_codec *codec,
176c9b443d4STobin Davis 				      unsigned int stream_tag,
177c9b443d4STobin Davis 				      unsigned int format,
178c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
179c9b443d4STobin Davis {
180c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
181c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
182c9b443d4STobin Davis 				   stream_tag, 0, format);
183c9b443d4STobin Davis 	return 0;
184c9b443d4STobin Davis }
185c9b443d4STobin Davis 
186c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
187c9b443d4STobin Davis 				      struct hda_codec *codec,
188c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
189c9b443d4STobin Davis {
190c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
191888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
192c9b443d4STobin Davis 	return 0;
193c9b443d4STobin Davis }
194c9b443d4STobin Davis 
195c9b443d4STobin Davis 
196c9b443d4STobin Davis 
197c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = {
198c9b443d4STobin Davis 	.substreams = 1,
199c9b443d4STobin Davis 	.channels_min = 2,
200c9b443d4STobin Davis 	.channels_max = 2,
201c9b443d4STobin Davis 	.nid = 0, /* fill later */
202c9b443d4STobin Davis 	.ops = {
203c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
204c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
205c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
206c9b443d4STobin Davis 	},
207c9b443d4STobin Davis };
208c9b443d4STobin Davis 
209c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = {
210c9b443d4STobin Davis 	.substreams = 1,
211c9b443d4STobin Davis 	.channels_min = 2,
212c9b443d4STobin Davis 	.channels_max = 2,
213c9b443d4STobin Davis 	.nid = 0, /* fill later */
214c9b443d4STobin Davis 	.ops = {
215c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
216c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
217c9b443d4STobin Davis 	},
218c9b443d4STobin Davis };
219c9b443d4STobin Davis 
220c9b443d4STobin Davis 
221c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = {
222c9b443d4STobin Davis 	.substreams = 1,
223c9b443d4STobin Davis 	.channels_min = 2,
224c9b443d4STobin Davis 	.channels_max = 2,
225c9b443d4STobin Davis 	.nid = 0, /* fill later */
226c9b443d4STobin Davis 	.ops = {
227c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2286b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2296b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
230c9b443d4STobin Davis 	},
231c9b443d4STobin Davis };
232c9b443d4STobin Davis 
233c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = {
234c9b443d4STobin Davis 	.substreams = 1,
235c9b443d4STobin Davis 	.channels_min = 2,
236c9b443d4STobin Davis 	.channels_max = 2,
237c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
238c9b443d4STobin Davis };
239c9b443d4STobin Davis 
240461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
241461e2c78STakashi Iwai 				      struct hda_codec *codec,
242461e2c78STakashi Iwai 				      unsigned int stream_tag,
243461e2c78STakashi Iwai 				      unsigned int format,
244461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
245461e2c78STakashi Iwai {
246461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
247461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
248461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
249461e2c78STakashi Iwai 	spec->cur_adc_format = format;
250461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
251461e2c78STakashi Iwai 	return 0;
252461e2c78STakashi Iwai }
253461e2c78STakashi Iwai 
254461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
255461e2c78STakashi Iwai 				      struct hda_codec *codec,
256461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
257461e2c78STakashi Iwai {
258461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
259888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
260461e2c78STakashi Iwai 	spec->cur_adc = 0;
261461e2c78STakashi Iwai 	return 0;
262461e2c78STakashi Iwai }
263461e2c78STakashi Iwai 
264461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = {
265461e2c78STakashi Iwai 	.substreams = 1,
266461e2c78STakashi Iwai 	.channels_min = 2,
267461e2c78STakashi Iwai 	.channels_max = 2,
268461e2c78STakashi Iwai 	.nid = 0, /* fill later */
269461e2c78STakashi Iwai 	.ops = {
270461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
271461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
272461e2c78STakashi Iwai 	},
273461e2c78STakashi Iwai };
274461e2c78STakashi Iwai 
275c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
276c9b443d4STobin Davis {
277c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
278c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
279c9b443d4STobin Davis 
280c9b443d4STobin Davis 	codec->num_pcms = 1;
281c9b443d4STobin Davis 	codec->pcm_info = info;
282c9b443d4STobin Davis 
283c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
284c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
285c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
286c9b443d4STobin Davis 		spec->multiout.max_channels;
287c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
288c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
289461e2c78STakashi Iwai 	if (codec->vendor_id == 0x14f15051)
290461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
291461e2c78STakashi Iwai 			cx5051_pcm_analog_capture;
292461e2c78STakashi Iwai 	else
293461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
294461e2c78STakashi Iwai 			conexant_pcm_analog_capture;
295c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
296c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
297c9b443d4STobin Davis 
298c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
299c9b443d4STobin Davis 		info++;
300c9b443d4STobin Davis 		codec->num_pcms++;
301c9b443d4STobin Davis 		info->name = "Conexant Digital";
3027ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
303c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
304c9b443d4STobin Davis 			conexant_pcm_digital_playback;
305c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
306c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
307c9b443d4STobin Davis 		if (spec->dig_in_nid) {
308c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
309c9b443d4STobin Davis 				conexant_pcm_digital_capture;
310c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
311c9b443d4STobin Davis 				spec->dig_in_nid;
312c9b443d4STobin Davis 		}
313c9b443d4STobin Davis 	}
314c9b443d4STobin Davis 
315c9b443d4STobin Davis 	return 0;
316c9b443d4STobin Davis }
317c9b443d4STobin Davis 
318c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
319c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
320c9b443d4STobin Davis {
321c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
322c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
323c9b443d4STobin Davis 
324c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
325c9b443d4STobin Davis }
326c9b443d4STobin Davis 
327c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
328c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
329c9b443d4STobin Davis {
330c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
331c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
332c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
333c9b443d4STobin Davis 
334c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
335c9b443d4STobin Davis 	return 0;
336c9b443d4STobin Davis }
337c9b443d4STobin Davis 
338c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
339c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
340c9b443d4STobin Davis {
341c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
342c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
343c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
344c9b443d4STobin Davis 
345c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
346c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
347c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
348c9b443d4STobin Davis }
349c9b443d4STobin Davis 
350*5801f992STakashi Iwai #ifdef CONFIG_SND_JACK
351bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec,
352bc7a166dSUlrich Dangel 		hda_nid_t nid, int type)
353bc7a166dSUlrich Dangel {
354bc7a166dSUlrich Dangel 	struct conexant_spec *spec;
355bc7a166dSUlrich Dangel 	struct conexant_jack *jack;
356bc7a166dSUlrich Dangel 	const char *name;
357bc7a166dSUlrich Dangel 
358bc7a166dSUlrich Dangel 	spec = codec->spec;
359bc7a166dSUlrich Dangel 	snd_array_init(&spec->jacks, sizeof(*jack), 32);
360bc7a166dSUlrich Dangel 	jack = snd_array_new(&spec->jacks);
361bc7a166dSUlrich Dangel 	name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
362bc7a166dSUlrich Dangel 
363bc7a166dSUlrich Dangel 	if (!jack)
364bc7a166dSUlrich Dangel 		return -ENOMEM;
365bc7a166dSUlrich Dangel 
366bc7a166dSUlrich Dangel 	jack->nid = nid;
367bc7a166dSUlrich Dangel 	jack->type = type;
368bc7a166dSUlrich Dangel 
369bc7a166dSUlrich Dangel 	return snd_jack_new(codec->bus->card, name, type, &jack->jack);
370bc7a166dSUlrich Dangel }
371bc7a166dSUlrich Dangel 
372bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
373bc7a166dSUlrich Dangel {
374bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
375bc7a166dSUlrich Dangel 	struct conexant_jack *jacks = spec->jacks.list;
376bc7a166dSUlrich Dangel 
377bc7a166dSUlrich Dangel 	if (jacks) {
378bc7a166dSUlrich Dangel 		int i;
379bc7a166dSUlrich Dangel 		for (i = 0; i < spec->jacks.used; i++) {
380bc7a166dSUlrich Dangel 			if (jacks->nid == nid) {
381bc7a166dSUlrich Dangel 				unsigned int present;
382bc7a166dSUlrich Dangel 				present = snd_hda_codec_read(codec, nid, 0,
383bc7a166dSUlrich Dangel 						AC_VERB_GET_PIN_SENSE, 0) &
384bc7a166dSUlrich Dangel 					AC_PINSENSE_PRESENCE;
385bc7a166dSUlrich Dangel 
386bc7a166dSUlrich Dangel 				present = (present) ? jacks->type : 0 ;
387bc7a166dSUlrich Dangel 
388bc7a166dSUlrich Dangel 				snd_jack_report(jacks->jack,
389bc7a166dSUlrich Dangel 						present);
390bc7a166dSUlrich Dangel 			}
391bc7a166dSUlrich Dangel 			jacks++;
392bc7a166dSUlrich Dangel 		}
393bc7a166dSUlrich Dangel 	}
394bc7a166dSUlrich Dangel }
395bc7a166dSUlrich Dangel 
396bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec)
397bc7a166dSUlrich Dangel {
398bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
399bc7a166dSUlrich Dangel 	int i;
400bc7a166dSUlrich Dangel 
401bc7a166dSUlrich Dangel 	for (i = 0; i < spec->num_init_verbs; i++) {
402bc7a166dSUlrich Dangel 		const struct hda_verb *hv;
403bc7a166dSUlrich Dangel 
404bc7a166dSUlrich Dangel 		hv = spec->init_verbs[i];
405bc7a166dSUlrich Dangel 		while (hv->nid) {
406bc7a166dSUlrich Dangel 			int err = 0;
407bc7a166dSUlrich Dangel 			switch (hv->param ^ AC_USRSP_EN) {
408bc7a166dSUlrich Dangel 			case CONEXANT_HP_EVENT:
409bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
410bc7a166dSUlrich Dangel 						SND_JACK_HEADPHONE);
411bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
412bc7a166dSUlrich Dangel 				break;
413bc7a166dSUlrich Dangel 			case CXT5051_PORTC_EVENT:
414bc7a166dSUlrich Dangel 			case CONEXANT_MIC_EVENT:
415bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
416bc7a166dSUlrich Dangel 						SND_JACK_MICROPHONE);
417bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
418bc7a166dSUlrich Dangel 				break;
419bc7a166dSUlrich Dangel 			}
420bc7a166dSUlrich Dangel 			if (err < 0)
421bc7a166dSUlrich Dangel 				return err;
422bc7a166dSUlrich Dangel 			++hv;
423bc7a166dSUlrich Dangel 		}
424bc7a166dSUlrich Dangel 	}
425bc7a166dSUlrich Dangel 	return 0;
426bc7a166dSUlrich Dangel 
427bc7a166dSUlrich Dangel }
428*5801f992STakashi Iwai #else
429*5801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
430*5801f992STakashi Iwai {
431*5801f992STakashi Iwai }
432*5801f992STakashi Iwai 
433*5801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec)
434*5801f992STakashi Iwai {
435*5801f992STakashi Iwai 	return 0;
436*5801f992STakashi Iwai }
437*5801f992STakashi Iwai #endif
438bc7a166dSUlrich Dangel 
439c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
440c9b443d4STobin Davis {
441c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
442c9b443d4STobin Davis 	int i;
443c9b443d4STobin Davis 
444c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
445c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
446c9b443d4STobin Davis 	return 0;
447c9b443d4STobin Davis }
448c9b443d4STobin Davis 
449c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
450c9b443d4STobin Davis {
451bc7a166dSUlrich Dangel #ifdef CONFIG_SND_JACK
452bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
453bc7a166dSUlrich Dangel 	if (spec->jacks.list) {
454bc7a166dSUlrich Dangel 		struct conexant_jack *jacks = spec->jacks.list;
455bc7a166dSUlrich Dangel 		int i;
456bc7a166dSUlrich Dangel 		for (i = 0; i < spec->jacks.used; i++)
457bc7a166dSUlrich Dangel 			snd_device_free(codec->bus->card, &jacks[i].jack);
458bc7a166dSUlrich Dangel 		snd_array_free(&spec->jacks);
459bc7a166dSUlrich Dangel 	}
460bc7a166dSUlrich Dangel #endif
461c9b443d4STobin Davis 	kfree(codec->spec);
462c9b443d4STobin Davis }
463c9b443d4STobin Davis 
464c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
465c9b443d4STobin Davis {
466c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
467c9b443d4STobin Davis 	unsigned int i;
468c9b443d4STobin Davis 	int err;
469c9b443d4STobin Davis 
470c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
471c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
472c9b443d4STobin Davis 		if (err < 0)
473c9b443d4STobin Davis 			return err;
474c9b443d4STobin Davis 	}
475c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
476c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
477c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
478c9b443d4STobin Davis 		if (err < 0)
479c9b443d4STobin Davis 			return err;
4809a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
4819a08160bSTakashi Iwai 						    &spec->multiout);
4829a08160bSTakashi Iwai 		if (err < 0)
4839a08160bSTakashi Iwai 			return err;
4849a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
485c9b443d4STobin Davis 	}
486c9b443d4STobin Davis 	if (spec->dig_in_nid) {
487c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
488c9b443d4STobin Davis 		if (err < 0)
489c9b443d4STobin Davis 			return err;
490c9b443d4STobin Davis 	}
491c9b443d4STobin Davis 	return 0;
492c9b443d4STobin Davis }
493c9b443d4STobin Davis 
494c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
495c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
496c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
497c9b443d4STobin Davis 	.init = conexant_init,
498c9b443d4STobin Davis 	.free = conexant_free,
499c9b443d4STobin Davis };
500c9b443d4STobin Davis 
501c9b443d4STobin Davis /*
502c9b443d4STobin Davis  * EAPD control
503c9b443d4STobin Davis  * the private value = nid | (invert << 8)
504c9b443d4STobin Davis  */
505c9b443d4STobin Davis 
506a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
507c9b443d4STobin Davis 
50882f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
509c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
510c9b443d4STobin Davis {
511c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
512c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
513c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
514c9b443d4STobin Davis 	if (invert)
515c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
516c9b443d4STobin Davis 	else
517c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
518c9b443d4STobin Davis 	return 0;
51982f30040STobin Davis 
520c9b443d4STobin Davis }
521c9b443d4STobin Davis 
52282f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
523c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
524c9b443d4STobin Davis {
525c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
526c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
527c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
528c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
529c9b443d4STobin Davis 	unsigned int eapd;
53082f30040STobin Davis 
53168ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
532c9b443d4STobin Davis 	if (invert)
533c9b443d4STobin Davis 		eapd = !eapd;
53482beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
535c9b443d4STobin Davis 		return 0;
53682f30040STobin Davis 
537c9b443d4STobin Davis 	spec->cur_eapd = eapd;
53882beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
539c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
540c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
541c9b443d4STobin Davis 	return 1;
542c9b443d4STobin Davis }
543c9b443d4STobin Davis 
54486d72bdfSTakashi Iwai /* controls for test mode */
54586d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
54686d72bdfSTakashi Iwai 
54782f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
54882f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
54982f30040STobin Davis 	  .info = cxt_eapd_info, \
55082f30040STobin Davis 	  .get = cxt_eapd_get, \
55182f30040STobin Davis 	  .put = cxt_eapd_put, \
55282f30040STobin Davis 	  .private_value = nid | (mask<<16) }
55382f30040STobin Davis 
55482f30040STobin Davis 
55582f30040STobin Davis 
556c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
557c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
558c9b443d4STobin Davis {
559c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
560c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
561c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
562c9b443d4STobin Davis 				    spec->num_channel_mode);
563c9b443d4STobin Davis }
564c9b443d4STobin Davis 
565c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
566c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
567c9b443d4STobin Davis {
568c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
569c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
570c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
571c9b443d4STobin Davis 				   spec->num_channel_mode,
572c9b443d4STobin Davis 				   spec->multiout.max_channels);
573c9b443d4STobin Davis }
574c9b443d4STobin Davis 
575c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
576c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
577c9b443d4STobin Davis {
578c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
579c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
580c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
581c9b443d4STobin Davis 				      spec->num_channel_mode,
582c9b443d4STobin Davis 				      &spec->multiout.max_channels);
583c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
584c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
585c9b443d4STobin Davis 	return err;
586c9b443d4STobin Davis }
587c9b443d4STobin Davis 
588c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
589c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
590c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
591c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
592c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
593c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
594c9b443d4STobin Davis 
59586d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
59686d72bdfSTakashi Iwai 
597c9b443d4STobin Davis /* Conexant 5045 specific */
598c9b443d4STobin Davis 
599c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
600c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
601c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
602cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
603c9b443d4STobin Davis 
6045cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
6055cd57529STobin Davis 	{ 2, NULL },
6065cd57529STobin Davis };
607c9b443d4STobin Davis 
608c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
609c9b443d4STobin Davis 	.num_items = 2,
610c9b443d4STobin Davis 	.items = {
61182f30040STobin Davis 		{ "IntMic", 0x1 },
612f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
613c9b443d4STobin Davis 	}
614c9b443d4STobin Davis };
615c9b443d4STobin Davis 
6165218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = {
6175218c892SJiang Zhe 	.num_items = 3,
6185218c892SJiang Zhe 	.items = {
6195218c892SJiang Zhe 		{ "IntMic", 0x1 },
6205218c892SJiang Zhe 		{ "ExtMic", 0x2 },
6215218c892SJiang Zhe 		{ "LineIn", 0x3 },
6225218c892SJiang Zhe 	}
6235218c892SJiang Zhe };
6245218c892SJiang Zhe 
6252de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = {
6262de3c232SJiang zhe 	.num_items = 2,
6272de3c232SJiang zhe 	.items = {
6282de3c232SJiang zhe 		{ "ExtMic", 0x1 },
6292de3c232SJiang zhe 		{ "IntMic", 0x2 },
6302de3c232SJiang zhe 	}
6312de3c232SJiang zhe };
6322de3c232SJiang zhe 
633c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
634c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
635c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
636c9b443d4STobin Davis {
637c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
63982f30040STobin Davis 	unsigned int bits;
640c9b443d4STobin Davis 
64182f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
642c9b443d4STobin Davis 		return 0;
643c9b443d4STobin Davis 
64482f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
64582f30040STobin Davis 	 * the headphone jack
64682f30040STobin Davis 	 */
64747fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
64847fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
64947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
6507f29673bSTobin Davis 
65147fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
65247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
65347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
654c9b443d4STobin Davis 	return 1;
655c9b443d4STobin Davis }
656c9b443d4STobin Davis 
657c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
658cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
659cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
660cca3b371STakashi Iwai 	.values = {
661cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
662cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
663cca3b371STakashi Iwai 		0
664cca3b371STakashi Iwai 	},
665cca3b371STakashi Iwai };
666c9b443d4STobin Davis 
6677f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
6687f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
6697f29673bSTobin Davis {
6707f29673bSTobin Davis 	static struct hda_verb mic_jack_on[] = {
6717f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
6727f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
6737f29673bSTobin Davis 		{}
6747f29673bSTobin Davis 	};
6757f29673bSTobin Davis 	static struct hda_verb mic_jack_off[] = {
6767f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
6777f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
6787f29673bSTobin Davis 		{}
6797f29673bSTobin Davis 	};
6807f29673bSTobin Davis 	unsigned int present;
6817f29673bSTobin Davis 
6827f29673bSTobin Davis 	present = snd_hda_codec_read(codec, 0x12, 0,
6837f29673bSTobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6847f29673bSTobin Davis 	if (present)
6857f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
6867f29673bSTobin Davis 	else
6877f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
6887f29673bSTobin Davis }
6897f29673bSTobin Davis 
690c9b443d4STobin Davis 
691c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
692c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
693c9b443d4STobin Davis {
69482f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
695dd87da1cSTobin Davis 	unsigned int bits;
696c9b443d4STobin Davis 
69782f30040STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
698c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
699dd87da1cSTobin Davis 
70047fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
70147fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
70247fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
703c9b443d4STobin Davis }
704c9b443d4STobin Davis 
705c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
706c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
707c9b443d4STobin Davis 				   unsigned int res)
708c9b443d4STobin Davis {
709c9b443d4STobin Davis 	res >>= 26;
710c9b443d4STobin Davis 	switch (res) {
711c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
712c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
713c9b443d4STobin Davis 		break;
7147f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
7157f29673bSTobin Davis 		cxt5045_hp_automic(codec);
7167f29673bSTobin Davis 		break;
7177f29673bSTobin Davis 
718c9b443d4STobin Davis 	}
719c9b443d4STobin Davis }
720c9b443d4STobin Davis 
721c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
722c9b443d4STobin Davis 	{
723c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
724c9b443d4STobin Davis 		.name = "Capture Source",
725c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
726c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
727c9b443d4STobin Davis 		.put = conexant_mux_enum_put
728c9b443d4STobin Davis 	},
729c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
730c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
731c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
732c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
733c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
734c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
735c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
736c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
737c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
738c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
739cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
740c9b443d4STobin Davis 	{
741c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
742c9b443d4STobin Davis 		.name = "Master Playback Switch",
74382f30040STobin Davis 		.info = cxt_eapd_info,
74482f30040STobin Davis 		.get = cxt_eapd_get,
745c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
74682f30040STobin Davis 		.private_value = 0x10,
747c9b443d4STobin Davis 	},
748c9b443d4STobin Davis 
749c9b443d4STobin Davis 	{}
750c9b443d4STobin Davis };
751c9b443d4STobin Davis 
7525218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
7535218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
7545218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
7555218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
7565218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
7575218c892SJiang Zhe 
7585218c892SJiang Zhe 	{}
7595218c892SJiang Zhe };
7605218c892SJiang Zhe 
7612de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
7622de3c232SJiang zhe 	{
7632de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7642de3c232SJiang zhe 		.name = "Capture Source",
7652de3c232SJiang zhe 		.info = conexant_mux_enum_info,
7662de3c232SJiang zhe 		.get = conexant_mux_enum_get,
7672de3c232SJiang zhe 		.put = conexant_mux_enum_put
7682de3c232SJiang zhe 	},
7692de3c232SJiang zhe 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
7702de3c232SJiang zhe 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
7712de3c232SJiang zhe 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
7722de3c232SJiang zhe 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
7732de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
7742de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
7752de3c232SJiang zhe 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
7762de3c232SJiang zhe 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
7772de3c232SJiang zhe 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
7782de3c232SJiang zhe 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
7792de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
7802de3c232SJiang zhe 	{
7812de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7822de3c232SJiang zhe 		.name = "Master Playback Switch",
7832de3c232SJiang zhe 		.info = cxt_eapd_info,
7842de3c232SJiang zhe 		.get = cxt_eapd_get,
7852de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
7862de3c232SJiang zhe 		.private_value = 0x10,
7872de3c232SJiang zhe 	},
7882de3c232SJiang zhe 
7892de3c232SJiang zhe 	{}
7902de3c232SJiang zhe };
7912de3c232SJiang zhe 
792c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
793c9b443d4STobin Davis 	/* Line in, Mic */
7944090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
7957f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
796c9b443d4STobin Davis 	/* HP, Amp  */
797c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
798c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
79982f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
800c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
801c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
802c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
803c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
804c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
805c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
80682f30040STobin Davis 	/* Record selector: Int mic */
8077f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
80882f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
809c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
810c9b443d4STobin Davis 	/* SPDIF route: PCM */
811cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
812c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
813c9b443d4STobin Davis 	/* EAPD */
81482f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
815c9b443d4STobin Davis 	{ } /* end */
816c9b443d4STobin Davis };
817c9b443d4STobin Davis 
8185218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = {
8195218c892SJiang Zhe 	/* Int Mic, Mic */
8205218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8215218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8225218c892SJiang Zhe 	/* Line In,HP, Amp  */
8235218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8245218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
8255218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8265218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
8275218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8285218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8295218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8305218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8315218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8325218c892SJiang Zhe 	/* Record selector: Int mic */
8335218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
8345218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
8355218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
8365218c892SJiang Zhe 	/* SPDIF route: PCM */
837cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8385218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
8395218c892SJiang Zhe 	/* EAPD */
8405218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
8415218c892SJiang Zhe 	{ } /* end */
8425218c892SJiang Zhe };
8437f29673bSTobin Davis 
8447f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
8457f29673bSTobin Davis 	/* pin sensing on HP jack */
8467f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
847d3091fadSTakashi Iwai 	{ } /* end */
8487f29673bSTobin Davis };
8497f29673bSTobin Davis 
8507f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
8517f29673bSTobin Davis 	/* pin sensing on HP jack */
8527f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
853d3091fadSTakashi Iwai 	{ } /* end */
8547f29673bSTobin Davis };
8557f29673bSTobin Davis 
856c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
857c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
858c9b443d4STobin Davis  * configuration.
859c9b443d4STobin Davis  */
860c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
861c9b443d4STobin Davis 	.num_items = 5,
862c9b443d4STobin Davis 	.items = {
863c9b443d4STobin Davis 		{ "MIXER", 0x0 },
864c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
865c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
866c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
867c9b443d4STobin Davis 		{ "CD pin", 0x4 },
868c9b443d4STobin Davis         },
869c9b443d4STobin Davis };
870c9b443d4STobin Davis 
871c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
872c9b443d4STobin Davis 
873c9b443d4STobin Davis 	/* Output controls */
874c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
875c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
8767f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
8777f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
8787f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
8797f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
880c9b443d4STobin Davis 
881c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
882c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
883c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
884c9b443d4STobin Davis 
88582f30040STobin Davis 	/* EAPD Switch Control */
88682f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
88782f30040STobin Davis 
888c9b443d4STobin Davis 	/* Loopback mixer controls */
889c9b443d4STobin Davis 
8907f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
8917f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
8927f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
8937f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
8947f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
8957f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
8967f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
8977f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
8987f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
8997f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
900c9b443d4STobin Davis 	{
901c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
902c9b443d4STobin Davis 		.name = "Input Source",
903c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
904c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
905c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
906c9b443d4STobin Davis 	},
907fb3409e7STobin Davis 	/* Audio input controls */
908fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
909fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
910fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
911fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
912fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
913fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
914fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
915fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
916fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
917fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
918c9b443d4STobin Davis 	{ } /* end */
919c9b443d4STobin Davis };
920c9b443d4STobin Davis 
921c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
9227f29673bSTobin Davis 	/* Set connections */
9237f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
9247f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
9257f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
926c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
927c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9287f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
929c9b443d4STobin Davis 
930c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
931c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
932c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
933c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
934c9b443d4STobin Davis 	 * control.
935c9b443d4STobin Davis 	 */
936cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
937cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
938c9b443d4STobin Davis 
939c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
940c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
941c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
942c9b443d4STobin Davis 
943c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
944c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
945c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
946c9b443d4STobin Davis 	 * input/output buffers as needed.
947c9b443d4STobin Davis 	 */
948c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
949c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
950c9b443d4STobin Davis 
951c9b443d4STobin Davis 	/* Mute capture amp left and right */
952c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
953c9b443d4STobin Davis 
954c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
955c9b443d4STobin Davis 	 * pin)
956c9b443d4STobin Davis 	 */
957c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
9587f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
959c9b443d4STobin Davis 
960c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
961c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
962c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
963c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
964c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
965c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
966c9b443d4STobin Davis 
967c9b443d4STobin Davis 	{ }
968c9b443d4STobin Davis };
969c9b443d4STobin Davis #endif
970c9b443d4STobin Davis 
971c9b443d4STobin Davis 
972c9b443d4STobin Davis /* initialize jack-sensing, too */
973c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
974c9b443d4STobin Davis {
975c9b443d4STobin Davis 	conexant_init(codec);
976c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
977c9b443d4STobin Davis 	return 0;
978c9b443d4STobin Davis }
979c9b443d4STobin Davis 
980c9b443d4STobin Davis 
981c9b443d4STobin Davis enum {
98215908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
98315908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
98415908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
9855218c892SJiang Zhe 	CXT5045_BENQ,
9862de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
987c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
988c9b443d4STobin Davis 	CXT5045_TEST,
989c9b443d4STobin Davis #endif
990f5fcc13cSTakashi Iwai 	CXT5045_MODELS
991c9b443d4STobin Davis };
992c9b443d4STobin Davis 
993f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = {
99415908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
99515908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
99615908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
9975218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
9982de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
999c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1000f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1001c9b443d4STobin Davis #endif
1002f5fcc13cSTakashi Iwai };
1003c9b443d4STobin Davis 
1004f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
100515908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
100615908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
100715908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
100815908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
100915908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
101015908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
10110f6a5156STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
10122de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
101315908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
10146a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
10155218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
101615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
101715908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
10189e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
10199e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
102015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
102115908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
102215908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
102315908c36SMarc Boucher 	SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
102415908c36SMarc Boucher 	SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
102515908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1026c9b443d4STobin Davis 	{}
1027c9b443d4STobin Davis };
1028c9b443d4STobin Davis 
1029c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1030c9b443d4STobin Davis {
1031c9b443d4STobin Davis 	struct conexant_spec *spec;
1032c9b443d4STobin Davis 	int board_config;
1033c9b443d4STobin Davis 
1034c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1035c9b443d4STobin Davis 	if (!spec)
1036c9b443d4STobin Davis 		return -ENOMEM;
1037c9b443d4STobin Davis 	codec->spec = spec;
1038c9b443d4STobin Davis 
1039c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1040c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1041c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1042c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1043c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1044c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1045c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1046c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1047c9b443d4STobin Davis 	spec->num_mixers = 1;
1048c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1049c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1050c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1051c9b443d4STobin Davis 	spec->spdif_route = 0;
10525cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
10535cd57529STobin Davis 	spec->channel_mode = cxt5045_modes,
10545cd57529STobin Davis 
1055c9b443d4STobin Davis 
1056c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1057c9b443d4STobin Davis 
1058f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1059f5fcc13cSTakashi Iwai 						  cxt5045_models,
1060f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
1061c9b443d4STobin Davis 	switch (board_config) {
106215908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
10637f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1064c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1065c9b443d4STobin Davis 		spec->num_init_verbs = 2;
10667f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
10677f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
10687f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
10697f29673bSTobin Davis 		break;
107015908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
107186376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
10727f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
10737f29673bSTobin Davis 		spec->num_init_verbs = 2;
10747f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1075c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1076c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1077c9b443d4STobin Davis 		break;
107815908c36SMarc Boucher 	default:
107915908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
108015908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
108115908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
108215908c36SMarc Boucher 		spec->num_init_verbs = 3;
108315908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
108415908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
108515908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
108615908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
108715908c36SMarc Boucher 		break;
10885218c892SJiang Zhe 	case CXT5045_BENQ:
10895218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
10905218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
10915218c892SJiang Zhe 		spec->num_init_verbs = 1;
10925218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
10935218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
10945218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
10955218c892SJiang Zhe 		spec->num_mixers = 2;
10965218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
10975218c892SJiang Zhe 		break;
10982de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
10992de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11002de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
11012de3c232SJiang zhe 		spec->num_init_verbs = 2;
11022de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11032de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
11042de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
11052de3c232SJiang zhe 		break;
1106c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1107c9b443d4STobin Davis 	case CXT5045_TEST:
1108c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1109c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1110c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
111115908c36SMarc Boucher 		break;
111215908c36SMarc Boucher 
1113c9b443d4STobin Davis #endif
1114c9b443d4STobin Davis 	}
111548ecb7e8STakashi Iwai 
1116031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1117031005f7STakashi Iwai 	case 0x103c:
1118031005f7STakashi Iwai 		/* HP laptop has a really bad sound over 0dB on NID 0x17.
111948ecb7e8STakashi Iwai 		 * Fix max PCM level to 0 dB
112048ecb7e8STakashi Iwai 		 * (originall it has 0x2b steps with 0dB offset 0x14)
112148ecb7e8STakashi Iwai 		 */
112248ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
112348ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
112448ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
112548ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
112648ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1127031005f7STakashi Iwai 		break;
1128031005f7STakashi Iwai 	}
112948ecb7e8STakashi Iwai 
1130c9b443d4STobin Davis 	return 0;
1131c9b443d4STobin Davis }
1132c9b443d4STobin Davis 
1133c9b443d4STobin Davis 
1134c9b443d4STobin Davis /* Conexant 5047 specific */
113582f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1136c9b443d4STobin Davis 
113782f30040STobin Davis static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
1138c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1139c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1140c9b443d4STobin Davis 
11415cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
11425cd57529STobin Davis 	{ 2, NULL },
11435cd57529STobin Davis };
1144c9b443d4STobin Davis 
1145c9b443d4STobin Davis static struct hda_input_mux cxt5047_capture_source = {
11467f29673bSTobin Davis 	.num_items = 1,
1147c9b443d4STobin Davis 	.items = {
11487f29673bSTobin Davis 		{ "Mic", 0x2 },
1149c9b443d4STobin Davis 	}
1150c9b443d4STobin Davis };
1151c9b443d4STobin Davis 
1152c9b443d4STobin Davis static struct hda_input_mux cxt5047_hp_capture_source = {
1153c9b443d4STobin Davis 	.num_items = 1,
1154c9b443d4STobin Davis 	.items = {
115582f30040STobin Davis 		{ "ExtMic", 0x2 },
115682f30040STobin Davis 	}
115782f30040STobin Davis };
115882f30040STobin Davis 
115982f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
116082f30040STobin Davis 	.num_items = 2,
116182f30040STobin Davis 	.items = {
116282f30040STobin Davis 		{ "ExtMic", 0x2 },
116382f30040STobin Davis 		{ "Line-In", 0x1 },
1164c9b443d4STobin Davis 	}
1165c9b443d4STobin Davis };
1166c9b443d4STobin Davis 
1167c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1168c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1169c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1170c9b443d4STobin Davis {
1171c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1172c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
117382f30040STobin Davis 	unsigned int bits;
1174c9b443d4STobin Davis 
117582f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1176c9b443d4STobin Davis 		return 0;
1177c9b443d4STobin Davis 
117882f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
117982f30040STobin Davis 	 * the headphone jack
118082f30040STobin Davis 	 */
118147fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
118247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
118347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
118447fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
118547fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
118647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1187c9b443d4STobin Davis 	return 1;
1188c9b443d4STobin Davis }
1189c9b443d4STobin Davis 
119082f30040STobin Davis /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
1191cca3b371STakashi Iwai static struct hda_bind_ctls cxt5047_bind_master_vol = {
1192cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
1193cca3b371STakashi Iwai 	.values = {
1194cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1195cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1196cca3b371STakashi Iwai 		0
1197cca3b371STakashi Iwai 	},
1198cca3b371STakashi Iwai };
1199c9b443d4STobin Davis 
1200c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1201c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1202c9b443d4STobin Davis {
120382f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1204dd87da1cSTobin Davis 	unsigned int bits;
1205c9b443d4STobin Davis 
120682f30040STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1207c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1208dd87da1cSTobin Davis 
120947fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
121047fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
121147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
121282f30040STobin Davis 	/* Mute/Unmute PCM 2 for good measure - some systems need this */
121347fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
121447fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1215c9b443d4STobin Davis }
1216c9b443d4STobin Davis 
1217fb3409e7STobin Davis /* mute internal speaker if HP is plugged */
1218fb3409e7STobin Davis static void cxt5047_hp2_automute(struct hda_codec *codec)
1219fb3409e7STobin Davis {
1220fb3409e7STobin Davis 	struct conexant_spec *spec = codec->spec;
1221fb3409e7STobin Davis 	unsigned int bits;
1222fb3409e7STobin Davis 
1223fb3409e7STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1224fb3409e7STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1225fb3409e7STobin Davis 
122647fd830aSTakashi Iwai 	bits = spec->hp_present ? HDA_AMP_MUTE : 0;
122747fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
122847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1229fb3409e7STobin Davis 	/* Mute/Unmute PCM 2 for good measure - some systems need this */
123047fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
123147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1232fb3409e7STobin Davis }
1233fb3409e7STobin Davis 
1234c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1235c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1236c9b443d4STobin Davis {
1237c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
12389f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12399f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1240c9b443d4STobin Davis 		{}
1241c9b443d4STobin Davis 	};
1242c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
12439f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12449f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1245c9b443d4STobin Davis 		{}
1246c9b443d4STobin Davis 	};
1247c9b443d4STobin Davis 	unsigned int present;
1248c9b443d4STobin Davis 
12497f29673bSTobin Davis 	present = snd_hda_codec_read(codec, 0x15, 0,
1250c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1251c9b443d4STobin Davis 	if (present)
1252c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1253c9b443d4STobin Davis 	else
1254c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1255c9b443d4STobin Davis }
1256c9b443d4STobin Davis 
1257c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1258c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1259c9b443d4STobin Davis 				  unsigned int res)
1260c9b443d4STobin Davis {
12619f113e0eSMarc Boucher 	switch (res >> 26) {
1262c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1263c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1264c9b443d4STobin Davis 		break;
1265c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1266c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1267c9b443d4STobin Davis 		break;
1268c9b443d4STobin Davis 	}
1269c9b443d4STobin Davis }
1270c9b443d4STobin Davis 
1271fb3409e7STobin Davis /* unsolicited event for HP jack sensing - non-EAPD systems */
1272fb3409e7STobin Davis static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1273fb3409e7STobin Davis 				  unsigned int res)
1274fb3409e7STobin Davis {
1275fb3409e7STobin Davis 	res >>= 26;
1276fb3409e7STobin Davis 	switch (res) {
1277fb3409e7STobin Davis 	case CONEXANT_HP_EVENT:
1278fb3409e7STobin Davis 		cxt5047_hp2_automute(codec);
1279fb3409e7STobin Davis 		break;
1280fb3409e7STobin Davis 	case CONEXANT_MIC_EVENT:
1281fb3409e7STobin Davis 		cxt5047_hp_automic(codec);
1282fb3409e7STobin Davis 		break;
1283fb3409e7STobin Davis 	}
1284fb3409e7STobin Davis }
1285fb3409e7STobin Davis 
1286c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_mixers[] = {
1287c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1288c9b443d4STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
12897f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
12907f29673bSTobin Davis 	HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
1291c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1292c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1293c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1294c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
129582f30040STobin Davis 	HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
129682f30040STobin Davis 	HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1297b7589cebSTobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1298b7589cebSTobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1299b7589cebSTobin Davis 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1300b7589cebSTobin Davis 	HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
130182f30040STobin Davis 
130282f30040STobin Davis 	{}
130382f30040STobin Davis };
130482f30040STobin Davis 
130582f30040STobin Davis static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
130682f30040STobin Davis 	{
130782f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
130882f30040STobin Davis 		.name = "Capture Source",
130982f30040STobin Davis 		.info = conexant_mux_enum_info,
131082f30040STobin Davis 		.get = conexant_mux_enum_get,
131182f30040STobin Davis 		.put = conexant_mux_enum_put
131282f30040STobin Davis 	},
131382f30040STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
131482f30040STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
131582f30040STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
131682f30040STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
131782f30040STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
131882f30040STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1319cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
132082f30040STobin Davis 	{
132182f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
132282f30040STobin Davis 		.name = "Master Playback Switch",
132382f30040STobin Davis 		.info = cxt_eapd_info,
132482f30040STobin Davis 		.get = cxt_eapd_get,
1325c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1326c9b443d4STobin Davis 		.private_value = 0x13,
1327c9b443d4STobin Davis 	},
1328c9b443d4STobin Davis 
1329c9b443d4STobin Davis 	{}
1330c9b443d4STobin Davis };
1331c9b443d4STobin Davis 
1332c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1333c9b443d4STobin Davis 	{
1334c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1335c9b443d4STobin Davis 		.name = "Capture Source",
1336c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1337c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1338c9b443d4STobin Davis 		.put = conexant_mux_enum_put
1339c9b443d4STobin Davis 	},
1340c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1341c9b443d4STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1342c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1343c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1344c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1345c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1346c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1347c9b443d4STobin Davis 	{
1348c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1349c9b443d4STobin Davis 		.name = "Master Playback Switch",
135082f30040STobin Davis 		.info = cxt_eapd_info,
135182f30040STobin Davis 		.get = cxt_eapd_get,
1352c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1353c9b443d4STobin Davis 		.private_value = 0x13,
1354c9b443d4STobin Davis 	},
1355c9b443d4STobin Davis 	{ } /* end */
1356c9b443d4STobin Davis };
1357c9b443d4STobin Davis 
1358c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1359c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1360c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1361c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1362c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
13637f29673bSTobin Davis 	/* HP, Speaker  */
1364b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1365b7589cebSTobin Davis 	{0x13, AC_VERB_SET_CONNECT_SEL,0x1},
13667f29673bSTobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
13677f29673bSTobin Davis 	/* Record selector: Mic */
13687f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
13697f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
13707f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
13717f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1372c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1373c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1374c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1375c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1376c9b443d4STobin Davis 	/* SPDIF route: PCM */
1377c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
137882f30040STobin Davis 	/* Enable unsolicited events */
137982f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
138082f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1381c9b443d4STobin Davis 	{ } /* end */
1382c9b443d4STobin Davis };
1383c9b443d4STobin Davis 
1384c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1385c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1386c9b443d4STobin Davis 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1387c9b443d4STobin Davis 	/* pin sensing on HP and Mic jacks */
1388c9b443d4STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1389c9b443d4STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
139082f30040STobin Davis 	/* Speaker routing */
139182f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1392c9b443d4STobin Davis 	{}
1393c9b443d4STobin Davis };
1394c9b443d4STobin Davis 
1395c9b443d4STobin Davis /* configuration for HP Laptops */
1396c9b443d4STobin Davis static struct hda_verb cxt5047_hp_init_verbs[] = {
139782f30040STobin Davis 	/* pin sensing on HP jack */
1398c9b443d4STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1399b84f08d4STakashi Iwai 	/* 0x13 is actually shared by both HP and speaker;
1400b84f08d4STakashi Iwai 	 * setting the connection to 0 (=0x19) makes the master volume control
1401b84f08d4STakashi Iwai 	 * working mysteriouslly...
1402b84f08d4STakashi Iwai 	 */
1403b84f08d4STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
140482f30040STobin Davis 	/* Record selector: Ext Mic */
140582f30040STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
140682f30040STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
140782f30040STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
140882f30040STobin Davis 	/* Speaker routing */
140982f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1410c9b443d4STobin Davis 	{}
1411c9b443d4STobin Davis };
1412c9b443d4STobin Davis 
1413c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1414c9b443d4STobin Davis  * configuration.
1415c9b443d4STobin Davis  */
1416c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1417c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
141882f30040STobin Davis 	.num_items = 4,
1419c9b443d4STobin Davis 	.items = {
142082f30040STobin Davis 		{ "LINE1 pin", 0x0 },
142182f30040STobin Davis 		{ "MIC1 pin", 0x1 },
142282f30040STobin Davis 		{ "MIC2 pin", 0x2 },
142382f30040STobin Davis 		{ "CD pin", 0x3 },
1424c9b443d4STobin Davis         },
1425c9b443d4STobin Davis };
1426c9b443d4STobin Davis 
1427c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1428c9b443d4STobin Davis 
1429c9b443d4STobin Davis 	/* Output only controls */
143082f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
143182f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
143282f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
143382f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1434c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1435c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1436c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1437c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
143882f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
143982f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
144082f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
144182f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1442c9b443d4STobin Davis 
1443c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1444c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1445c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1446c9b443d4STobin Davis 
144782f30040STobin Davis 	/* EAPD Switch Control */
144882f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
144982f30040STobin Davis 
1450c9b443d4STobin Davis 	/* Loopback mixer controls */
145182f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
145282f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
145382f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
145482f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
145582f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
145682f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
145782f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
145882f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1459c9b443d4STobin Davis 
146082f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
146182f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
146282f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
146382f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
146482f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
146582f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
146682f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
146782f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1468c9b443d4STobin Davis 	{
1469c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1470c9b443d4STobin Davis 		.name = "Input Source",
1471c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1472c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1473c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1474c9b443d4STobin Davis 	},
14759f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
14769f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
14779f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
14789f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
14799f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
14809f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
14819f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
14829f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
14839f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
14849f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
14859f113e0eSMarc Boucher 
1486c9b443d4STobin Davis 	{ } /* end */
1487c9b443d4STobin Davis };
1488c9b443d4STobin Davis 
1489c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1490c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1491c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1492c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1493c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1494c9b443d4STobin Davis 
1495c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1496c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1497c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1498c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1499c9b443d4STobin Davis 	 * control.
1500c9b443d4STobin Davis 	 */
1501c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1502c9b443d4STobin Davis 
1503c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1504c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1505c9b443d4STobin Davis 	 */
1506c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1507c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1508c9b443d4STobin Davis 
1509c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1510c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1511c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1512c9b443d4STobin Davis 
1513c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1514c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1515c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1516c9b443d4STobin Davis 	 * input/output buffers as needed.
1517c9b443d4STobin Davis 	 */
1518c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1519c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1520c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1521c9b443d4STobin Davis 
1522c9b443d4STobin Davis 	/* Mute capture amp left and right */
1523c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1524c9b443d4STobin Davis 
1525c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1526c9b443d4STobin Davis 	 * pin)
1527c9b443d4STobin Davis 	 */
1528c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1529c9b443d4STobin Davis 
1530c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1531c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1532c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1533c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1534c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1535c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1536c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1537c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1538c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1539c9b443d4STobin Davis 
1540c9b443d4STobin Davis 	{ }
1541c9b443d4STobin Davis };
1542c9b443d4STobin Davis #endif
1543c9b443d4STobin Davis 
1544c9b443d4STobin Davis 
1545c9b443d4STobin Davis /* initialize jack-sensing, too */
1546c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1547c9b443d4STobin Davis {
1548c9b443d4STobin Davis 	conexant_init(codec);
1549c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1550c9b443d4STobin Davis 	return 0;
1551c9b443d4STobin Davis }
1552c9b443d4STobin Davis 
1553c9b443d4STobin Davis 
1554c9b443d4STobin Davis enum {
1555f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1556f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1557f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1558c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1559c9b443d4STobin Davis 	CXT5047_TEST,
1560c9b443d4STobin Davis #endif
1561f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1562c9b443d4STobin Davis };
1563c9b443d4STobin Davis 
1564f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = {
1565f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1566f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1567f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1568c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1569f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1570c9b443d4STobin Davis #endif
1571f5fcc13cSTakashi Iwai };
1572c9b443d4STobin Davis 
1573f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1574f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1575ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1576f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
157782f30040STobin Davis 	SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
1578aa9d823bSJoerg Schirottke 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6700", CXT5047_LAPTOP),
1579f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1580c9b443d4STobin Davis 	{}
1581c9b443d4STobin Davis };
1582c9b443d4STobin Davis 
1583c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1584c9b443d4STobin Davis {
1585c9b443d4STobin Davis 	struct conexant_spec *spec;
1586c9b443d4STobin Davis 	int board_config;
1587c9b443d4STobin Davis 
1588c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1589c9b443d4STobin Davis 	if (!spec)
1590c9b443d4STobin Davis 		return -ENOMEM;
1591c9b443d4STobin Davis 	codec->spec = spec;
1592c9b443d4STobin Davis 
1593c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1594c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1595c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1596c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1597c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1598c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1599c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1600c9b443d4STobin Davis 	spec->input_mux = &cxt5047_capture_source;
1601c9b443d4STobin Davis 	spec->num_mixers = 1;
1602c9b443d4STobin Davis 	spec->mixers[0] = cxt5047_mixers;
1603c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1604c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1605c9b443d4STobin Davis 	spec->spdif_route = 0;
16065cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
16075cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1608c9b443d4STobin Davis 
1609c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1610c9b443d4STobin Davis 
1611f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1612f5fcc13cSTakashi Iwai 						  cxt5047_models,
1613f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1614c9b443d4STobin Davis 	switch (board_config) {
1615c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1616fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
1617c9b443d4STobin Davis 		break;
1618c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1619c9b443d4STobin Davis 		spec->input_mux = &cxt5047_hp_capture_source;
1620c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1621c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_hp_init_verbs;
1622c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_hp_mixers;
1623fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1624c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1625c9b443d4STobin Davis 		break;
1626c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
162782f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1628c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1629c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
163082f30040STobin Davis 		spec->mixers[0] = cxt5047_toshiba_mixers;
1631fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1632c9b443d4STobin Davis 		break;
1633c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1634c9b443d4STobin Davis 	case CXT5047_TEST:
1635c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1636c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1637c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1638fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1639c9b443d4STobin Davis #endif
1640c9b443d4STobin Davis 	}
1641c9b443d4STobin Davis 	return 0;
1642c9b443d4STobin Davis }
1643c9b443d4STobin Davis 
1644461e2c78STakashi Iwai /* Conexant 5051 specific */
1645461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1646461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1647461e2c78STakashi Iwai 
1648461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = {
1649461e2c78STakashi Iwai 	{ 2, NULL },
1650461e2c78STakashi Iwai };
1651461e2c78STakashi Iwai 
1652461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1653461e2c78STakashi Iwai {
1654461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1655461e2c78STakashi Iwai 	unsigned int pinctl;
1656461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1657461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1658461e2c78STakashi Iwai 			    pinctl);
1659461e2c78STakashi Iwai }
1660461e2c78STakashi Iwai 
1661461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1662461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1663461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1664461e2c78STakashi Iwai {
1665461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1666461e2c78STakashi Iwai 
1667461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1668461e2c78STakashi Iwai 		return 0;
1669461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1670461e2c78STakashi Iwai 	return 1;
1671461e2c78STakashi Iwai }
1672461e2c78STakashi Iwai 
1673461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1674461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1675461e2c78STakashi Iwai {
1676461e2c78STakashi Iwai 	unsigned int present;
1677461e2c78STakashi Iwai 
1678461e2c78STakashi Iwai 	present = snd_hda_codec_read(codec, 0x17, 0,
1679461e2c78STakashi Iwai 				     AC_VERB_GET_PIN_SENSE, 0) &
1680461e2c78STakashi Iwai 		AC_PINSENSE_PRESENCE;
1681461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1682461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1683461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1684461e2c78STakashi Iwai }
1685461e2c78STakashi Iwai 
1686461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1687461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1688461e2c78STakashi Iwai {
1689461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1690461e2c78STakashi Iwai 	unsigned int present;
1691461e2c78STakashi Iwai 	hda_nid_t new_adc;
1692461e2c78STakashi Iwai 
1693461e2c78STakashi Iwai 	present = snd_hda_codec_read(codec, 0x18, 0,
1694461e2c78STakashi Iwai 				     AC_VERB_GET_PIN_SENSE, 0) &
1695461e2c78STakashi Iwai 		AC_PINSENSE_PRESENCE;
1696461e2c78STakashi Iwai 	if (present)
1697461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1698461e2c78STakashi Iwai 	else
1699461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1700461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1701461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1702461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1703888afa15STakashi Iwai 		snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1704461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1705461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1706461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1707461e2c78STakashi Iwai 					   spec->cur_adc_format);
1708461e2c78STakashi Iwai 	}
1709461e2c78STakashi Iwai }
1710461e2c78STakashi Iwai 
1711461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1712461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1713461e2c78STakashi Iwai {
1714461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1715461e2c78STakashi Iwai 
1716461e2c78STakashi Iwai 	spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1717461e2c78STakashi Iwai 				     AC_VERB_GET_PIN_SENSE, 0) &
1718461e2c78STakashi Iwai 		AC_PINSENSE_PRESENCE;
1719461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1720461e2c78STakashi Iwai }
1721461e2c78STakashi Iwai 
1722461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1723461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1724461e2c78STakashi Iwai 				   unsigned int res)
1725461e2c78STakashi Iwai {
1726acf26c0cSUlrich Dangel 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1727461e2c78STakashi Iwai 	switch (res >> 26) {
1728461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1729461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1730461e2c78STakashi Iwai 		break;
1731461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1732461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1733461e2c78STakashi Iwai 		break;
1734461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1735461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1736461e2c78STakashi Iwai 		break;
1737461e2c78STakashi Iwai 	}
1738acf26c0cSUlrich Dangel 	conexant_report_jack(codec, nid);
1739461e2c78STakashi Iwai }
1740461e2c78STakashi Iwai 
1741461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_mixers[] = {
1742461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1743461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1744461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1745461e2c78STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1746461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1747461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1748461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1749461e2c78STakashi Iwai 	{
1750461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1751461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1752461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1753461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1754461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1755461e2c78STakashi Iwai 		.private_value = 0x1a,
1756461e2c78STakashi Iwai 	},
1757461e2c78STakashi Iwai 
1758461e2c78STakashi Iwai 	{}
1759461e2c78STakashi Iwai };
1760461e2c78STakashi Iwai 
1761461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1762461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1763461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1764461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1765461e2c78STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1766461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1767461e2c78STakashi Iwai 	{
1768461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1769461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1770461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1771461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1772461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1773461e2c78STakashi Iwai 		.private_value = 0x1a,
1774461e2c78STakashi Iwai 	},
1775461e2c78STakashi Iwai 
1776461e2c78STakashi Iwai 	{}
1777461e2c78STakashi Iwai };
1778461e2c78STakashi Iwai 
1779461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = {
1780461e2c78STakashi Iwai 	/* Line in, Mic */
1781461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1782461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1783461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1784461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1785461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1786461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1787461e2c78STakashi Iwai 	/* SPK  */
1788461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1789461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1790461e2c78STakashi Iwai 	/* HP, Amp  */
1791461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1792461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1793461e2c78STakashi Iwai 	/* DAC1 */
1794461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1795461e2c78STakashi Iwai 	/* Record selector: Int mic */
1796461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1797461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1798461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1799461e2c78STakashi Iwai 	/* SPDIF route: PCM */
1800461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1801461e2c78STakashi Iwai 	/* EAPD */
1802461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1803461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1804461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1805461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1806461e2c78STakashi Iwai 	{ } /* end */
1807461e2c78STakashi Iwai };
1808461e2c78STakashi Iwai 
1809461e2c78STakashi Iwai /* initialize jack-sensing, too */
1810461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1811461e2c78STakashi Iwai {
1812461e2c78STakashi Iwai 	conexant_init(codec);
1813acf26c0cSUlrich Dangel 	conexant_init_jacks(codec);
1814461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1815461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1816461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1817461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1818461e2c78STakashi Iwai 	}
1819461e2c78STakashi Iwai 	return 0;
1820461e2c78STakashi Iwai }
1821461e2c78STakashi Iwai 
1822461e2c78STakashi Iwai 
1823461e2c78STakashi Iwai enum {
1824461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1825461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
1826461e2c78STakashi Iwai 	CXT5051_MODELS
1827461e2c78STakashi Iwai };
1828461e2c78STakashi Iwai 
1829461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = {
1830461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1831461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
1832461e2c78STakashi Iwai };
1833461e2c78STakashi Iwai 
1834461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1835461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1836461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1837461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1838461e2c78STakashi Iwai 	{}
1839461e2c78STakashi Iwai };
1840461e2c78STakashi Iwai 
1841461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1842461e2c78STakashi Iwai {
1843461e2c78STakashi Iwai 	struct conexant_spec *spec;
1844461e2c78STakashi Iwai 	int board_config;
1845461e2c78STakashi Iwai 
1846461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1847461e2c78STakashi Iwai 	if (!spec)
1848461e2c78STakashi Iwai 		return -ENOMEM;
1849461e2c78STakashi Iwai 	codec->spec = spec;
1850461e2c78STakashi Iwai 
1851461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
1852461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
1853461e2c78STakashi Iwai 
1854461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
1855461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1856461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
1857461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1858461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1859461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
1860461e2c78STakashi Iwai 	spec->num_mixers = 1;
1861461e2c78STakashi Iwai 	spec->mixers[0] = cxt5051_mixers;
1862461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
1863461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
1864461e2c78STakashi Iwai 	spec->spdif_route = 0;
1865461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1866461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
1867461e2c78STakashi Iwai 	spec->cur_adc = 0;
1868461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
1869461e2c78STakashi Iwai 
1870461e2c78STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1871461e2c78STakashi Iwai 						  cxt5051_models,
1872461e2c78STakashi Iwai 						  cxt5051_cfg_tbl);
1873461e2c78STakashi Iwai 	switch (board_config) {
1874461e2c78STakashi Iwai 	case CXT5051_HP:
1875461e2c78STakashi Iwai 		codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1876461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
1877461e2c78STakashi Iwai 		break;
1878461e2c78STakashi Iwai 	default:
1879461e2c78STakashi Iwai 	case CXT5051_LAPTOP:
1880461e2c78STakashi Iwai 		codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1881461e2c78STakashi Iwai 		break;
1882461e2c78STakashi Iwai 	}
1883461e2c78STakashi Iwai 
1884461e2c78STakashi Iwai 	return 0;
1885461e2c78STakashi Iwai }
1886461e2c78STakashi Iwai 
1887461e2c78STakashi Iwai 
1888461e2c78STakashi Iwai /*
1889461e2c78STakashi Iwai  */
1890461e2c78STakashi Iwai 
18911289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = {
189282f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
189382f30040STobin Davis 	  .patch = patch_cxt5045 },
189482f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
189582f30040STobin Davis 	  .patch = patch_cxt5047 },
1896461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1897461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
1898c9b443d4STobin Davis 	{} /* terminator */
1899c9b443d4STobin Davis };
19001289e9e8STakashi Iwai 
19011289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
19021289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
19031289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
19041289e9e8STakashi Iwai 
19051289e9e8STakashi Iwai MODULE_LICENSE("GPL");
19061289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
19071289e9e8STakashi Iwai 
19081289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
19091289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
19101289e9e8STakashi Iwai 	.owner = THIS_MODULE,
19111289e9e8STakashi Iwai };
19121289e9e8STakashi Iwai 
19131289e9e8STakashi Iwai static int __init patch_conexant_init(void)
19141289e9e8STakashi Iwai {
19151289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
19161289e9e8STakashi Iwai }
19171289e9e8STakashi Iwai 
19181289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
19191289e9e8STakashi Iwai {
19201289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
19211289e9e8STakashi Iwai }
19221289e9e8STakashi Iwai 
19231289e9e8STakashi Iwai module_init(patch_conexant_init)
19241289e9e8STakashi Iwai module_exit(patch_conexant_exit)
1925