xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision 9f113e0ef47451defa950eed738d87387c0aa8f6)
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>
28c9b443d4STobin Davis #include "hda_codec.h"
29c9b443d4STobin Davis #include "hda_local.h"
30c9b443d4STobin Davis 
31c9b443d4STobin Davis #define CXT_PIN_DIR_IN              0x00
32c9b443d4STobin Davis #define CXT_PIN_DIR_OUT             0x01
33c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT           0x02
34c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
35c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
36c9b443d4STobin Davis 
37c9b443d4STobin Davis #define CONEXANT_HP_EVENT	0x37
38c9b443d4STobin Davis #define CONEXANT_MIC_EVENT	0x38
39c9b443d4STobin Davis 
40c9b443d4STobin Davis 
41c9b443d4STobin Davis 
42c9b443d4STobin Davis struct conexant_spec {
43c9b443d4STobin Davis 
44c9b443d4STobin Davis 	struct snd_kcontrol_new *mixers[5];
45c9b443d4STobin Davis 	int num_mixers;
46c9b443d4STobin Davis 
47c9b443d4STobin Davis 	const struct hda_verb *init_verbs[5];	/* initialization verbs
48c9b443d4STobin Davis 						 * don't forget NULL
49c9b443d4STobin Davis 						 * termination!
50c9b443d4STobin Davis 						 */
51c9b443d4STobin Davis 	unsigned int num_init_verbs;
52c9b443d4STobin Davis 
53c9b443d4STobin Davis 	/* playback */
54c9b443d4STobin Davis 	struct hda_multi_out multiout;	/* playback set-up
55c9b443d4STobin Davis 					 * max_channels, dacs must be set
56c9b443d4STobin Davis 					 * dig_out_nid and hp_nid are optional
57c9b443d4STobin Davis 					 */
58c9b443d4STobin Davis 	unsigned int cur_eapd;
5982f30040STobin Davis 	unsigned int hp_present;
60c9b443d4STobin Davis 	unsigned int need_dac_fix;
61c9b443d4STobin Davis 
62c9b443d4STobin Davis 	/* capture */
63c9b443d4STobin Davis 	unsigned int num_adc_nids;
64c9b443d4STobin Davis 	hda_nid_t *adc_nids;
65c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
66c9b443d4STobin Davis 
67c9b443d4STobin Davis 	/* capture source */
68c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
69c9b443d4STobin Davis 	hda_nid_t *capsrc_nids;
70c9b443d4STobin Davis 	unsigned int cur_mux[3];
71c9b443d4STobin Davis 
72c9b443d4STobin Davis 	/* channel model */
73c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
74c9b443d4STobin Davis 	int num_channel_mode;
75c9b443d4STobin Davis 
76c9b443d4STobin Davis 	/* PCM information */
77c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
78c9b443d4STobin Davis 
79c9b443d4STobin Davis 	struct mutex amp_mutex;	/* PCM volume/mute control mutex */
80c9b443d4STobin Davis 	unsigned int spdif_route;
81c9b443d4STobin Davis 
82c9b443d4STobin Davis 	/* dynamic controls, init_verbs and input_mux */
83c9b443d4STobin Davis 	struct auto_pin_cfg autocfg;
84c9b443d4STobin Davis 	unsigned int num_kctl_alloc, num_kctl_used;
85c9b443d4STobin Davis 	struct snd_kcontrol_new *kctl_alloc;
86c9b443d4STobin Davis 	struct hda_input_mux private_imux;
8741923e44STakashi Iwai 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
88c9b443d4STobin Davis 
89c9b443d4STobin Davis };
90c9b443d4STobin Davis 
91c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
92c9b443d4STobin Davis 				      struct hda_codec *codec,
93c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
94c9b443d4STobin Davis {
95c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
96c9b443d4STobin Davis 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
97c9b443d4STobin Davis }
98c9b443d4STobin Davis 
99c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
100c9b443d4STobin Davis 					 struct hda_codec *codec,
101c9b443d4STobin Davis 					 unsigned int stream_tag,
102c9b443d4STobin Davis 					 unsigned int format,
103c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
104c9b443d4STobin Davis {
105c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
106c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
107c9b443d4STobin Davis 						stream_tag,
108c9b443d4STobin Davis 						format, substream);
109c9b443d4STobin Davis }
110c9b443d4STobin Davis 
111c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
112c9b443d4STobin Davis 					 struct hda_codec *codec,
113c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
114c9b443d4STobin Davis {
115c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
116c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
117c9b443d4STobin Davis }
118c9b443d4STobin Davis 
119c9b443d4STobin Davis /*
120c9b443d4STobin Davis  * Digital out
121c9b443d4STobin Davis  */
122c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
123c9b443d4STobin Davis 					  struct hda_codec *codec,
124c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
125c9b443d4STobin Davis {
126c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
127c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
128c9b443d4STobin Davis }
129c9b443d4STobin Davis 
130c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
131c9b443d4STobin Davis 					 struct hda_codec *codec,
132c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
133c9b443d4STobin Davis {
134c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
135c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
136c9b443d4STobin Davis }
137c9b443d4STobin Davis 
1386b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1396b97eb45STakashi Iwai 					 struct hda_codec *codec,
1406b97eb45STakashi Iwai 					 unsigned int stream_tag,
1416b97eb45STakashi Iwai 					 unsigned int format,
1426b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
1436b97eb45STakashi Iwai {
1446b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1456b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1466b97eb45STakashi Iwai 					     stream_tag,
1476b97eb45STakashi Iwai 					     format, substream);
1486b97eb45STakashi Iwai }
1496b97eb45STakashi Iwai 
150c9b443d4STobin Davis /*
151c9b443d4STobin Davis  * Analog capture
152c9b443d4STobin Davis  */
153c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
154c9b443d4STobin Davis 				      struct hda_codec *codec,
155c9b443d4STobin Davis 				      unsigned int stream_tag,
156c9b443d4STobin Davis 				      unsigned int format,
157c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
158c9b443d4STobin Davis {
159c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
160c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
161c9b443d4STobin Davis 				   stream_tag, 0, format);
162c9b443d4STobin Davis 	return 0;
163c9b443d4STobin Davis }
164c9b443d4STobin Davis 
165c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
166c9b443d4STobin Davis 				      struct hda_codec *codec,
167c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
168c9b443d4STobin Davis {
169c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
170c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
171c9b443d4STobin Davis 				   0, 0, 0);
172c9b443d4STobin Davis 	return 0;
173c9b443d4STobin Davis }
174c9b443d4STobin Davis 
175c9b443d4STobin Davis 
176c9b443d4STobin Davis 
177c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = {
178c9b443d4STobin Davis 	.substreams = 1,
179c9b443d4STobin Davis 	.channels_min = 2,
180c9b443d4STobin Davis 	.channels_max = 2,
181c9b443d4STobin Davis 	.nid = 0, /* fill later */
182c9b443d4STobin Davis 	.ops = {
183c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
184c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
185c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
186c9b443d4STobin Davis 	},
187c9b443d4STobin Davis };
188c9b443d4STobin Davis 
189c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = {
190c9b443d4STobin Davis 	.substreams = 1,
191c9b443d4STobin Davis 	.channels_min = 2,
192c9b443d4STobin Davis 	.channels_max = 2,
193c9b443d4STobin Davis 	.nid = 0, /* fill later */
194c9b443d4STobin Davis 	.ops = {
195c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
196c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
197c9b443d4STobin Davis 	},
198c9b443d4STobin Davis };
199c9b443d4STobin Davis 
200c9b443d4STobin Davis 
201c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = {
202c9b443d4STobin Davis 	.substreams = 1,
203c9b443d4STobin Davis 	.channels_min = 2,
204c9b443d4STobin Davis 	.channels_max = 2,
205c9b443d4STobin Davis 	.nid = 0, /* fill later */
206c9b443d4STobin Davis 	.ops = {
207c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2086b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2096b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
210c9b443d4STobin Davis 	},
211c9b443d4STobin Davis };
212c9b443d4STobin Davis 
213c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = {
214c9b443d4STobin Davis 	.substreams = 1,
215c9b443d4STobin Davis 	.channels_min = 2,
216c9b443d4STobin Davis 	.channels_max = 2,
217c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
218c9b443d4STobin Davis };
219c9b443d4STobin Davis 
220c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
221c9b443d4STobin Davis {
222c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
223c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
224c9b443d4STobin Davis 
225c9b443d4STobin Davis 	codec->num_pcms = 1;
226c9b443d4STobin Davis 	codec->pcm_info = info;
227c9b443d4STobin Davis 
228c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
229c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
230c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
231c9b443d4STobin Davis 		spec->multiout.max_channels;
232c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
233c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
234c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture;
235c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
236c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
237c9b443d4STobin Davis 
238c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
239c9b443d4STobin Davis 		info++;
240c9b443d4STobin Davis 		codec->num_pcms++;
241c9b443d4STobin Davis 		info->name = "Conexant Digital";
242c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
243c9b443d4STobin Davis 			conexant_pcm_digital_playback;
244c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
245c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
246c9b443d4STobin Davis 		if (spec->dig_in_nid) {
247c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
248c9b443d4STobin Davis 				conexant_pcm_digital_capture;
249c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
250c9b443d4STobin Davis 				spec->dig_in_nid;
251c9b443d4STobin Davis 		}
252c9b443d4STobin Davis 	}
253c9b443d4STobin Davis 
254c9b443d4STobin Davis 	return 0;
255c9b443d4STobin Davis }
256c9b443d4STobin Davis 
257c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
258c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
259c9b443d4STobin Davis {
260c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
261c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
262c9b443d4STobin Davis 
263c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
264c9b443d4STobin Davis }
265c9b443d4STobin Davis 
266c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
267c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
268c9b443d4STobin Davis {
269c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
270c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
271c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
272c9b443d4STobin Davis 
273c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
274c9b443d4STobin Davis 	return 0;
275c9b443d4STobin Davis }
276c9b443d4STobin Davis 
277c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
278c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
279c9b443d4STobin Davis {
280c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
281c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
282c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
283c9b443d4STobin Davis 
284c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
285c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
286c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
287c9b443d4STobin Davis }
288c9b443d4STobin Davis 
289c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
290c9b443d4STobin Davis {
291c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
292c9b443d4STobin Davis 	int i;
293c9b443d4STobin Davis 
294c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
295c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
296c9b443d4STobin Davis 	return 0;
297c9b443d4STobin Davis }
298c9b443d4STobin Davis 
299c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
300c9b443d4STobin Davis {
301c9b443d4STobin Davis         struct conexant_spec *spec = codec->spec;
302c9b443d4STobin Davis         unsigned int i;
303c9b443d4STobin Davis 
304c9b443d4STobin Davis         if (spec->kctl_alloc) {
305c9b443d4STobin Davis                 for (i = 0; i < spec->num_kctl_used; i++)
306c9b443d4STobin Davis                         kfree(spec->kctl_alloc[i].name);
307c9b443d4STobin Davis                 kfree(spec->kctl_alloc);
308c9b443d4STobin Davis         }
309c9b443d4STobin Davis 
310c9b443d4STobin Davis 	kfree(codec->spec);
311c9b443d4STobin Davis }
312c9b443d4STobin Davis 
313c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
314c9b443d4STobin Davis {
315c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
316c9b443d4STobin Davis 	unsigned int i;
317c9b443d4STobin Davis 	int err;
318c9b443d4STobin Davis 
319c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
320c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
321c9b443d4STobin Davis 		if (err < 0)
322c9b443d4STobin Davis 			return err;
323c9b443d4STobin Davis 	}
324c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
325c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
326c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
327c9b443d4STobin Davis 		if (err < 0)
328c9b443d4STobin Davis 			return err;
329c9b443d4STobin Davis 	}
330c9b443d4STobin Davis 	if (spec->dig_in_nid) {
331c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
332c9b443d4STobin Davis 		if (err < 0)
333c9b443d4STobin Davis 			return err;
334c9b443d4STobin Davis 	}
335c9b443d4STobin Davis 	return 0;
336c9b443d4STobin Davis }
337c9b443d4STobin Davis 
338c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
339c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
340c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
341c9b443d4STobin Davis 	.init = conexant_init,
342c9b443d4STobin Davis 	.free = conexant_free,
343c9b443d4STobin Davis };
344c9b443d4STobin Davis 
345c9b443d4STobin Davis /*
346c9b443d4STobin Davis  * EAPD control
347c9b443d4STobin Davis  * the private value = nid | (invert << 8)
348c9b443d4STobin Davis  */
349c9b443d4STobin Davis 
350a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
351c9b443d4STobin Davis 
35282f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
353c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
354c9b443d4STobin Davis {
355c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
356c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
357c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
358c9b443d4STobin Davis 	if (invert)
359c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
360c9b443d4STobin Davis 	else
361c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
362c9b443d4STobin Davis 	return 0;
36382f30040STobin Davis 
364c9b443d4STobin Davis }
365c9b443d4STobin Davis 
36682f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
367c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
368c9b443d4STobin Davis {
369c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
370c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
371c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
372c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
373c9b443d4STobin Davis 	unsigned int eapd;
37482f30040STobin Davis 
37568ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
376c9b443d4STobin Davis 	if (invert)
377c9b443d4STobin Davis 		eapd = !eapd;
37882beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
379c9b443d4STobin Davis 		return 0;
38082f30040STobin Davis 
381c9b443d4STobin Davis 	spec->cur_eapd = eapd;
38282beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
383c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
384c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
385c9b443d4STobin Davis 	return 1;
386c9b443d4STobin Davis }
387c9b443d4STobin Davis 
38886d72bdfSTakashi Iwai /* controls for test mode */
38986d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
39086d72bdfSTakashi Iwai 
39182f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
39282f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
39382f30040STobin Davis 	  .info = cxt_eapd_info, \
39482f30040STobin Davis 	  .get = cxt_eapd_get, \
39582f30040STobin Davis 	  .put = cxt_eapd_put, \
39682f30040STobin Davis 	  .private_value = nid | (mask<<16) }
39782f30040STobin Davis 
39882f30040STobin Davis 
39982f30040STobin Davis 
400c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
401c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
402c9b443d4STobin Davis {
403c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
404c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
405c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
406c9b443d4STobin Davis 				    spec->num_channel_mode);
407c9b443d4STobin Davis }
408c9b443d4STobin Davis 
409c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
410c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
411c9b443d4STobin Davis {
412c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
413c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
414c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
415c9b443d4STobin Davis 				   spec->num_channel_mode,
416c9b443d4STobin Davis 				   spec->multiout.max_channels);
417c9b443d4STobin Davis }
418c9b443d4STobin Davis 
419c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
420c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
421c9b443d4STobin Davis {
422c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
423c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
424c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
425c9b443d4STobin Davis 				      spec->num_channel_mode,
426c9b443d4STobin Davis 				      &spec->multiout.max_channels);
427c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
428c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
429c9b443d4STobin Davis 	return err;
430c9b443d4STobin Davis }
431c9b443d4STobin Davis 
432c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
433c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
434c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
435c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
436c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
437c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
438c9b443d4STobin Davis 
43986d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
44086d72bdfSTakashi Iwai 
441c9b443d4STobin Davis /* Conexant 5045 specific */
442c9b443d4STobin Davis 
443c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
444c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
445c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
446c9b443d4STobin Davis #define CXT5045_SPDIF_OUT	0x13
447c9b443d4STobin Davis 
4485cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
4495cd57529STobin Davis 	{ 2, NULL },
4505cd57529STobin Davis };
451c9b443d4STobin Davis 
452c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
453c9b443d4STobin Davis 	.num_items = 2,
454c9b443d4STobin Davis 	.items = {
45582f30040STobin Davis 		{ "IntMic", 0x1 },
456f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
457c9b443d4STobin Davis 	}
458c9b443d4STobin Davis };
459c9b443d4STobin Davis 
4605218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = {
4615218c892SJiang Zhe 	.num_items = 3,
4625218c892SJiang Zhe 	.items = {
4635218c892SJiang Zhe 		{ "IntMic", 0x1 },
4645218c892SJiang Zhe 		{ "ExtMic", 0x2 },
4655218c892SJiang Zhe 		{ "LineIn", 0x3 },
4665218c892SJiang Zhe 	}
4675218c892SJiang Zhe };
4685218c892SJiang Zhe 
469c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
470c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
471c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
472c9b443d4STobin Davis {
473c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
474c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
47582f30040STobin Davis 	unsigned int bits;
476c9b443d4STobin Davis 
47782f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
478c9b443d4STobin Davis 		return 0;
479c9b443d4STobin Davis 
48082f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
48182f30040STobin Davis 	 * the headphone jack
48282f30040STobin Davis 	 */
48347fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
48447fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
48547fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
4867f29673bSTobin Davis 
48747fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
48847fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
48947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
490c9b443d4STobin Davis 	return 1;
491c9b443d4STobin Davis }
492c9b443d4STobin Davis 
493c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
494cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
495cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
496cca3b371STakashi Iwai 	.values = {
497cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
498cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
499cca3b371STakashi Iwai 		0
500cca3b371STakashi Iwai 	},
501cca3b371STakashi Iwai };
502c9b443d4STobin Davis 
5037f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
5047f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
5057f29673bSTobin Davis {
5067f29673bSTobin Davis 	static struct hda_verb mic_jack_on[] = {
5077f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
5087f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5097f29673bSTobin Davis 		{}
5107f29673bSTobin Davis 	};
5117f29673bSTobin Davis 	static struct hda_verb mic_jack_off[] = {
5127f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
5137f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5147f29673bSTobin Davis 		{}
5157f29673bSTobin Davis 	};
5167f29673bSTobin Davis 	unsigned int present;
5177f29673bSTobin Davis 
5187f29673bSTobin Davis 	present = snd_hda_codec_read(codec, 0x12, 0,
5197f29673bSTobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5207f29673bSTobin Davis 	if (present)
5217f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
5227f29673bSTobin Davis 	else
5237f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
5247f29673bSTobin Davis }
5257f29673bSTobin Davis 
526c9b443d4STobin Davis 
527c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
528c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
529c9b443d4STobin Davis {
53082f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
531dd87da1cSTobin Davis 	unsigned int bits;
532c9b443d4STobin Davis 
53382f30040STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
534c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
535dd87da1cSTobin Davis 
53647fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
53747fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
53847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
539c9b443d4STobin Davis }
540c9b443d4STobin Davis 
541c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
542c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
543c9b443d4STobin Davis 				   unsigned int res)
544c9b443d4STobin Davis {
545c9b443d4STobin Davis 	res >>= 26;
546c9b443d4STobin Davis 	switch (res) {
547c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
548c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
549c9b443d4STobin Davis 		break;
5507f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
5517f29673bSTobin Davis 		cxt5045_hp_automic(codec);
5527f29673bSTobin Davis 		break;
5537f29673bSTobin Davis 
554c9b443d4STobin Davis 	}
555c9b443d4STobin Davis }
556c9b443d4STobin Davis 
557c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
558c9b443d4STobin Davis 	{
559c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
560c9b443d4STobin Davis 		.name = "Capture Source",
561c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
562c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
563c9b443d4STobin Davis 		.put = conexant_mux_enum_put
564c9b443d4STobin Davis 	},
565c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
566c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
567c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
568c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
569c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
570c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
571c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
572c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
573c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
574c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
575cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
576c9b443d4STobin Davis 	{
577c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
578c9b443d4STobin Davis 		.name = "Master Playback Switch",
57982f30040STobin Davis 		.info = cxt_eapd_info,
58082f30040STobin Davis 		.get = cxt_eapd_get,
581c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
58282f30040STobin Davis 		.private_value = 0x10,
583c9b443d4STobin Davis 	},
584c9b443d4STobin Davis 
585c9b443d4STobin Davis 	{}
586c9b443d4STobin Davis };
587c9b443d4STobin Davis 
5885218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
5895218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
5905218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
5915218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
5925218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
5935218c892SJiang Zhe 
5945218c892SJiang Zhe 	{}
5955218c892SJiang Zhe };
5965218c892SJiang Zhe 
597c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
598c9b443d4STobin Davis 	/* Line in, Mic */
599c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6007f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
601c9b443d4STobin Davis 	/* HP, Amp  */
602c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
603c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
60482f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
605c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
606c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
607c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
608c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
609c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
610c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
61182f30040STobin Davis 	/* Record selector: Int mic */
6127f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
61382f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
614c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
615c9b443d4STobin Davis 	/* SPDIF route: PCM */
616c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
617c9b443d4STobin Davis 	/* EAPD */
61882f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
619c9b443d4STobin Davis 	{ } /* end */
620c9b443d4STobin Davis };
621c9b443d4STobin Davis 
6225218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = {
6235218c892SJiang Zhe 	/* Int Mic, Mic */
6245218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
6255218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
6265218c892SJiang Zhe 	/* Line In,HP, Amp  */
6275218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6285218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
6295218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6305218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
6315218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6325218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6335218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6345218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6355218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6365218c892SJiang Zhe 	/* Record selector: Int mic */
6375218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
6385218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
6395218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
6405218c892SJiang Zhe 	/* SPDIF route: PCM */
6415218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
6425218c892SJiang Zhe 	/* EAPD */
6435218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
6445218c892SJiang Zhe 	{ } /* end */
6455218c892SJiang Zhe };
6467f29673bSTobin Davis 
6477f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
6487f29673bSTobin Davis 	/* pin sensing on HP jack */
6497f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
650d3091fadSTakashi Iwai 	{ } /* end */
6517f29673bSTobin Davis };
6527f29673bSTobin Davis 
6537f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
6547f29673bSTobin Davis 	/* pin sensing on HP jack */
6557f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
656d3091fadSTakashi Iwai 	{ } /* end */
6577f29673bSTobin Davis };
6587f29673bSTobin Davis 
659c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
660c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
661c9b443d4STobin Davis  * configuration.
662c9b443d4STobin Davis  */
663c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
664c9b443d4STobin Davis 	.num_items = 5,
665c9b443d4STobin Davis 	.items = {
666c9b443d4STobin Davis 		{ "MIXER", 0x0 },
667c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
668c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
669c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
670c9b443d4STobin Davis 		{ "CD pin", 0x4 },
671c9b443d4STobin Davis         },
672c9b443d4STobin Davis };
673c9b443d4STobin Davis 
674c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
675c9b443d4STobin Davis 
676c9b443d4STobin Davis 	/* Output controls */
677c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
678c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
6797f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
6807f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
6817f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
6827f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
683c9b443d4STobin Davis 
684c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
685c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
686c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
687c9b443d4STobin Davis 
68882f30040STobin Davis 	/* EAPD Switch Control */
68982f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
69082f30040STobin Davis 
691c9b443d4STobin Davis 	/* Loopback mixer controls */
692c9b443d4STobin Davis 
6937f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
6947f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
6957f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
6967f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
6977f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
6987f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
6997f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
7007f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
7017f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
7027f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
703c9b443d4STobin Davis 	{
704c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
705c9b443d4STobin Davis 		.name = "Input Source",
706c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
707c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
708c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
709c9b443d4STobin Davis 	},
710fb3409e7STobin Davis 	/* Audio input controls */
711fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
712fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
713fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
714fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
715fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
716fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
717fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
718fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
719fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
720fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
721c9b443d4STobin Davis 	{ } /* end */
722c9b443d4STobin Davis };
723c9b443d4STobin Davis 
724c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
7257f29673bSTobin Davis 	/* Set connections */
7267f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
7277f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
7287f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
729c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
730c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7317f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
732c9b443d4STobin Davis 
733c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
734c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
735c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
736c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
737c9b443d4STobin Davis 	 * control.
738c9b443d4STobin Davis 	 */
739c9b443d4STobin Davis 	{0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
740c9b443d4STobin Davis 
741c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
742c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
743c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
744c9b443d4STobin Davis 
745c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
746c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
747c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
748c9b443d4STobin Davis 	 * input/output buffers as needed.
749c9b443d4STobin Davis 	 */
750c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
751c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
752c9b443d4STobin Davis 
753c9b443d4STobin Davis 	/* Mute capture amp left and right */
754c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
755c9b443d4STobin Davis 
756c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
757c9b443d4STobin Davis 	 * pin)
758c9b443d4STobin Davis 	 */
759c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7607f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
761c9b443d4STobin Davis 
762c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
763c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
764c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
765c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
766c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
767c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
768c9b443d4STobin Davis 
769c9b443d4STobin Davis 	{ }
770c9b443d4STobin Davis };
771c9b443d4STobin Davis #endif
772c9b443d4STobin Davis 
773c9b443d4STobin Davis 
774c9b443d4STobin Davis /* initialize jack-sensing, too */
775c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
776c9b443d4STobin Davis {
777c9b443d4STobin Davis 	conexant_init(codec);
778c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
779c9b443d4STobin Davis 	return 0;
780c9b443d4STobin Davis }
781c9b443d4STobin Davis 
782c9b443d4STobin Davis 
783c9b443d4STobin Davis enum {
78415908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
78515908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
78615908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
7875218c892SJiang Zhe 	CXT5045_BENQ,
788c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
789c9b443d4STobin Davis 	CXT5045_TEST,
790c9b443d4STobin Davis #endif
791f5fcc13cSTakashi Iwai 	CXT5045_MODELS
792c9b443d4STobin Davis };
793c9b443d4STobin Davis 
794f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = {
79515908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
79615908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
79715908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
7985218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
799c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
800f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
801c9b443d4STobin Davis #endif
802f5fcc13cSTakashi Iwai };
803c9b443d4STobin Davis 
804f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
80515908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
80615908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
80715908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
80815908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
80915908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
81015908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
81115908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HPSENSE),
81215908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
8135218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
81415908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
81515908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
81615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPSENSE),
81715908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
81815908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
81915908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
82015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
82115908c36SMarc Boucher 	SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
82215908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
823c9b443d4STobin Davis 	{}
824c9b443d4STobin Davis };
825c9b443d4STobin Davis 
826c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
827c9b443d4STobin Davis {
828c9b443d4STobin Davis 	struct conexant_spec *spec;
829c9b443d4STobin Davis 	int board_config;
830c9b443d4STobin Davis 
831c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
832c9b443d4STobin Davis 	if (!spec)
833c9b443d4STobin Davis 		return -ENOMEM;
834c9b443d4STobin Davis 	mutex_init(&spec->amp_mutex);
835c9b443d4STobin Davis 	codec->spec = spec;
836c9b443d4STobin Davis 
837c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
838c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
839c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
840c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
841c9b443d4STobin Davis 	spec->num_adc_nids = 1;
842c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
843c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
844c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
845c9b443d4STobin Davis 	spec->num_mixers = 1;
846c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
847c9b443d4STobin Davis 	spec->num_init_verbs = 1;
848c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
849c9b443d4STobin Davis 	spec->spdif_route = 0;
8505cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
8515cd57529STobin Davis 	spec->channel_mode = cxt5045_modes,
8525cd57529STobin Davis 
853c9b443d4STobin Davis 
854c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
855c9b443d4STobin Davis 
856f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
857f5fcc13cSTakashi Iwai 						  cxt5045_models,
858f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
859c9b443d4STobin Davis 	switch (board_config) {
86015908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
8617f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
862c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
863c9b443d4STobin Davis 		spec->num_init_verbs = 2;
8647f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
8657f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
8667f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
8677f29673bSTobin Davis 		break;
86815908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
8697f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
8707f29673bSTobin Davis 		spec->num_init_verbs = 2;
8717f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
872c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
873c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
874c9b443d4STobin Davis 		break;
87515908c36SMarc Boucher 	default:
87615908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
87715908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
87815908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
87915908c36SMarc Boucher 		spec->num_init_verbs = 3;
88015908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
88115908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
88215908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
88315908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
88415908c36SMarc Boucher 		break;
8855218c892SJiang Zhe 	case CXT5045_BENQ:
8865218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
8875218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
8885218c892SJiang Zhe 		spec->num_init_verbs = 1;
8895218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
8905218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
8915218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
8925218c892SJiang Zhe 		spec->num_mixers = 2;
8935218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
8945218c892SJiang Zhe 		break;
895c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
896c9b443d4STobin Davis 	case CXT5045_TEST:
897c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
898c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
899c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
90015908c36SMarc Boucher 		break;
90115908c36SMarc Boucher 
902c9b443d4STobin Davis #endif
903c9b443d4STobin Davis 	}
90448ecb7e8STakashi Iwai 
90548ecb7e8STakashi Iwai 	/*
90648ecb7e8STakashi Iwai 	 * Fix max PCM level to 0 dB
90748ecb7e8STakashi Iwai 	 * (originall it has 0x2b steps with 0dB offset 0x14)
90848ecb7e8STakashi Iwai 	 */
90948ecb7e8STakashi Iwai 	snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
91048ecb7e8STakashi Iwai 				  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
91148ecb7e8STakashi Iwai 				  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
91248ecb7e8STakashi Iwai 				  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
91348ecb7e8STakashi Iwai 				  (1 << AC_AMPCAP_MUTE_SHIFT));
91448ecb7e8STakashi Iwai 
915c9b443d4STobin Davis 	return 0;
916c9b443d4STobin Davis }
917c9b443d4STobin Davis 
918c9b443d4STobin Davis 
919c9b443d4STobin Davis /* Conexant 5047 specific */
92082f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
921c9b443d4STobin Davis 
92282f30040STobin Davis static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
923c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
924c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
925c9b443d4STobin Davis 
9265cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
9275cd57529STobin Davis 	{ 2, NULL },
9285cd57529STobin Davis };
929c9b443d4STobin Davis 
930c9b443d4STobin Davis static struct hda_input_mux cxt5047_capture_source = {
9317f29673bSTobin Davis 	.num_items = 1,
932c9b443d4STobin Davis 	.items = {
9337f29673bSTobin Davis 		{ "Mic", 0x2 },
934c9b443d4STobin Davis 	}
935c9b443d4STobin Davis };
936c9b443d4STobin Davis 
937c9b443d4STobin Davis static struct hda_input_mux cxt5047_hp_capture_source = {
938c9b443d4STobin Davis 	.num_items = 1,
939c9b443d4STobin Davis 	.items = {
94082f30040STobin Davis 		{ "ExtMic", 0x2 },
94182f30040STobin Davis 	}
94282f30040STobin Davis };
94382f30040STobin Davis 
94482f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
94582f30040STobin Davis 	.num_items = 2,
94682f30040STobin Davis 	.items = {
94782f30040STobin Davis 		{ "ExtMic", 0x2 },
94882f30040STobin Davis 		{ "Line-In", 0x1 },
949c9b443d4STobin Davis 	}
950c9b443d4STobin Davis };
951c9b443d4STobin Davis 
952c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
953c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
954c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
955c9b443d4STobin Davis {
956c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
957c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
95882f30040STobin Davis 	unsigned int bits;
959c9b443d4STobin Davis 
96082f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
961c9b443d4STobin Davis 		return 0;
962c9b443d4STobin Davis 
96382f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
96482f30040STobin Davis 	 * the headphone jack
96582f30040STobin Davis 	 */
96647fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
96747fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
96847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
96947fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
97047fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
97147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
972c9b443d4STobin Davis 	return 1;
973c9b443d4STobin Davis }
974c9b443d4STobin Davis 
97582f30040STobin Davis /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
976cca3b371STakashi Iwai static struct hda_bind_ctls cxt5047_bind_master_vol = {
977cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
978cca3b371STakashi Iwai 	.values = {
979cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
980cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
981cca3b371STakashi Iwai 		0
982cca3b371STakashi Iwai 	},
983cca3b371STakashi Iwai };
984c9b443d4STobin Davis 
985c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
986c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
987c9b443d4STobin Davis {
98882f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
989dd87da1cSTobin Davis 	unsigned int bits;
990c9b443d4STobin Davis 
99182f30040STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
992c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
993dd87da1cSTobin Davis 
99447fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
99547fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
99647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
99782f30040STobin Davis 	/* Mute/Unmute PCM 2 for good measure - some systems need this */
99847fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
99947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1000c9b443d4STobin Davis }
1001c9b443d4STobin Davis 
1002fb3409e7STobin Davis /* mute internal speaker if HP is plugged */
1003fb3409e7STobin Davis static void cxt5047_hp2_automute(struct hda_codec *codec)
1004fb3409e7STobin Davis {
1005fb3409e7STobin Davis 	struct conexant_spec *spec = codec->spec;
1006fb3409e7STobin Davis 	unsigned int bits;
1007fb3409e7STobin Davis 
1008fb3409e7STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1009fb3409e7STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1010fb3409e7STobin Davis 
101147fd830aSTakashi Iwai 	bits = spec->hp_present ? HDA_AMP_MUTE : 0;
101247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
101347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1014fb3409e7STobin Davis 	/* Mute/Unmute PCM 2 for good measure - some systems need this */
101547fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
101647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1017fb3409e7STobin Davis }
1018fb3409e7STobin Davis 
1019c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1020c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1021c9b443d4STobin Davis {
1022c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
1023*9f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1024*9f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1025c9b443d4STobin Davis 		{}
1026c9b443d4STobin Davis 	};
1027c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
1028*9f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1029*9f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1030c9b443d4STobin Davis 		{}
1031c9b443d4STobin Davis 	};
1032c9b443d4STobin Davis 	unsigned int present;
1033c9b443d4STobin Davis 
10347f29673bSTobin Davis 	present = snd_hda_codec_read(codec, 0x15, 0,
1035c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1036c9b443d4STobin Davis 	if (present)
1037c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1038c9b443d4STobin Davis 	else
1039c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1040c9b443d4STobin Davis }
1041c9b443d4STobin Davis 
1042c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1043c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1044c9b443d4STobin Davis 				  unsigned int res)
1045c9b443d4STobin Davis {
1046*9f113e0eSMarc Boucher 	switch (res >> 26) {
1047c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1048c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1049c9b443d4STobin Davis 		break;
1050c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1051c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1052c9b443d4STobin Davis 		break;
1053c9b443d4STobin Davis 	}
1054c9b443d4STobin Davis }
1055c9b443d4STobin Davis 
1056fb3409e7STobin Davis /* unsolicited event for HP jack sensing - non-EAPD systems */
1057fb3409e7STobin Davis static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1058fb3409e7STobin Davis 				  unsigned int res)
1059fb3409e7STobin Davis {
1060fb3409e7STobin Davis 	res >>= 26;
1061fb3409e7STobin Davis 	switch (res) {
1062fb3409e7STobin Davis 	case CONEXANT_HP_EVENT:
1063fb3409e7STobin Davis 		cxt5047_hp2_automute(codec);
1064fb3409e7STobin Davis 		break;
1065fb3409e7STobin Davis 	case CONEXANT_MIC_EVENT:
1066fb3409e7STobin Davis 		cxt5047_hp_automic(codec);
1067fb3409e7STobin Davis 		break;
1068fb3409e7STobin Davis 	}
1069fb3409e7STobin Davis }
1070fb3409e7STobin Davis 
1071c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_mixers[] = {
1072c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1073c9b443d4STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
10747f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
10757f29673bSTobin Davis 	HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
1076c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1077c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1078c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1079c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
108082f30040STobin Davis 	HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
108182f30040STobin Davis 	HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1082b7589cebSTobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1083b7589cebSTobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1084b7589cebSTobin Davis 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1085b7589cebSTobin Davis 	HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
108682f30040STobin Davis 
108782f30040STobin Davis 	{}
108882f30040STobin Davis };
108982f30040STobin Davis 
109082f30040STobin Davis static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
109182f30040STobin Davis 	{
109282f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
109382f30040STobin Davis 		.name = "Capture Source",
109482f30040STobin Davis 		.info = conexant_mux_enum_info,
109582f30040STobin Davis 		.get = conexant_mux_enum_get,
109682f30040STobin Davis 		.put = conexant_mux_enum_put
109782f30040STobin Davis 	},
109882f30040STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
109982f30040STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
110082f30040STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
110182f30040STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
110282f30040STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
110382f30040STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1104cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
110582f30040STobin Davis 	{
110682f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
110782f30040STobin Davis 		.name = "Master Playback Switch",
110882f30040STobin Davis 		.info = cxt_eapd_info,
110982f30040STobin Davis 		.get = cxt_eapd_get,
1110c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1111c9b443d4STobin Davis 		.private_value = 0x13,
1112c9b443d4STobin Davis 	},
1113c9b443d4STobin Davis 
1114c9b443d4STobin Davis 	{}
1115c9b443d4STobin Davis };
1116c9b443d4STobin Davis 
1117c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1118c9b443d4STobin Davis 	{
1119c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1120c9b443d4STobin Davis 		.name = "Capture Source",
1121c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1122c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1123c9b443d4STobin Davis 		.put = conexant_mux_enum_put
1124c9b443d4STobin Davis 	},
1125c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1126c9b443d4STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1127c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1128c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1129c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1130c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1131c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1132c9b443d4STobin Davis 	{
1133c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1134c9b443d4STobin Davis 		.name = "Master Playback Switch",
113582f30040STobin Davis 		.info = cxt_eapd_info,
113682f30040STobin Davis 		.get = cxt_eapd_get,
1137c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1138c9b443d4STobin Davis 		.private_value = 0x13,
1139c9b443d4STobin Davis 	},
1140c9b443d4STobin Davis 	{ } /* end */
1141c9b443d4STobin Davis };
1142c9b443d4STobin Davis 
1143c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1144c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1145c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1146c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1147c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
11487f29673bSTobin Davis 	/* HP, Speaker  */
1149b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1150b7589cebSTobin Davis 	{0x13, AC_VERB_SET_CONNECT_SEL,0x1},
11517f29673bSTobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
11527f29673bSTobin Davis 	/* Record selector: Mic */
11537f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
11547f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
11557f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
11567f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1157c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1158c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1159c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1160c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1161c9b443d4STobin Davis 	/* SPDIF route: PCM */
1162c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
116382f30040STobin Davis 	/* Enable unsolicited events */
116482f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
116582f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1166c9b443d4STobin Davis 	{ } /* end */
1167c9b443d4STobin Davis };
1168c9b443d4STobin Davis 
1169c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1170c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1171c9b443d4STobin Davis 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1172c9b443d4STobin Davis 	/* pin sensing on HP and Mic jacks */
1173c9b443d4STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1174c9b443d4STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
117582f30040STobin Davis 	/* Speaker routing */
117682f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1177c9b443d4STobin Davis 	{}
1178c9b443d4STobin Davis };
1179c9b443d4STobin Davis 
1180c9b443d4STobin Davis /* configuration for HP Laptops */
1181c9b443d4STobin Davis static struct hda_verb cxt5047_hp_init_verbs[] = {
118282f30040STobin Davis 	/* pin sensing on HP jack */
1183c9b443d4STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
118482f30040STobin Davis 	/* Record selector: Ext Mic */
118582f30040STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
118682f30040STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
118782f30040STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
118882f30040STobin Davis 	/* Speaker routing */
118982f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1190c9b443d4STobin Davis 	{}
1191c9b443d4STobin Davis };
1192c9b443d4STobin Davis 
1193c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1194c9b443d4STobin Davis  * configuration.
1195c9b443d4STobin Davis  */
1196c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1197c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
119882f30040STobin Davis 	.num_items = 4,
1199c9b443d4STobin Davis 	.items = {
120082f30040STobin Davis 		{ "LINE1 pin", 0x0 },
120182f30040STobin Davis 		{ "MIC1 pin", 0x1 },
120282f30040STobin Davis 		{ "MIC2 pin", 0x2 },
120382f30040STobin Davis 		{ "CD pin", 0x3 },
1204c9b443d4STobin Davis         },
1205c9b443d4STobin Davis };
1206c9b443d4STobin Davis 
1207c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1208c9b443d4STobin Davis 
1209c9b443d4STobin Davis 	/* Output only controls */
121082f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
121182f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
121282f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
121382f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1214c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1215c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1216c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1217c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
121882f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
121982f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
122082f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
122182f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1222c9b443d4STobin Davis 
1223c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1224c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1225c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1226c9b443d4STobin Davis 
122782f30040STobin Davis 	/* EAPD Switch Control */
122882f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
122982f30040STobin Davis 
1230c9b443d4STobin Davis 	/* Loopback mixer controls */
123182f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
123282f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
123382f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
123482f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
123582f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
123682f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
123782f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
123882f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1239c9b443d4STobin Davis 
124082f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
124182f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
124282f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
124382f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
124482f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
124582f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
124682f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
124782f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1248c9b443d4STobin Davis 	{
1249c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1250c9b443d4STobin Davis 		.name = "Input Source",
1251c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1252c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1253c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1254c9b443d4STobin Davis 	},
1255*9f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1256*9f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1257*9f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1258*9f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1259*9f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1260*9f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1261*9f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1262*9f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1263*9f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1264*9f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1265*9f113e0eSMarc Boucher 
1266c9b443d4STobin Davis 	{ } /* end */
1267c9b443d4STobin Davis };
1268c9b443d4STobin Davis 
1269c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1270c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1271c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1272c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1273c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1274c9b443d4STobin Davis 
1275c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1276c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1277c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1278c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1279c9b443d4STobin Davis 	 * control.
1280c9b443d4STobin Davis 	 */
1281c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1282c9b443d4STobin Davis 
1283c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1284c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1285c9b443d4STobin Davis 	 */
1286c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1287c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1288c9b443d4STobin Davis 
1289c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1290c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1291c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1292c9b443d4STobin Davis 
1293c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1294c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1295c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1296c9b443d4STobin Davis 	 * input/output buffers as needed.
1297c9b443d4STobin Davis 	 */
1298c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1299c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1300c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1301c9b443d4STobin Davis 
1302c9b443d4STobin Davis 	/* Mute capture amp left and right */
1303c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1304c9b443d4STobin Davis 
1305c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1306c9b443d4STobin Davis 	 * pin)
1307c9b443d4STobin Davis 	 */
1308c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1309c9b443d4STobin Davis 
1310c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1311c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1312c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1313c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1314c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1315c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1316c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1317c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1318c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1319c9b443d4STobin Davis 
1320c9b443d4STobin Davis 	{ }
1321c9b443d4STobin Davis };
1322c9b443d4STobin Davis #endif
1323c9b443d4STobin Davis 
1324c9b443d4STobin Davis 
1325c9b443d4STobin Davis /* initialize jack-sensing, too */
1326c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1327c9b443d4STobin Davis {
1328c9b443d4STobin Davis 	conexant_init(codec);
1329c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1330c9b443d4STobin Davis 	return 0;
1331c9b443d4STobin Davis }
1332c9b443d4STobin Davis 
1333c9b443d4STobin Davis 
1334c9b443d4STobin Davis enum {
1335f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1336f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1337f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1338c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1339c9b443d4STobin Davis 	CXT5047_TEST,
1340c9b443d4STobin Davis #endif
1341f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1342c9b443d4STobin Davis };
1343c9b443d4STobin Davis 
1344f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = {
1345f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1346f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1347f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1348c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1349f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1350c9b443d4STobin Davis #endif
1351f5fcc13cSTakashi Iwai };
1352c9b443d4STobin Davis 
1353f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1354f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1355ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1356f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
135782f30040STobin Davis 	SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
1358f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1359c9b443d4STobin Davis 	{}
1360c9b443d4STobin Davis };
1361c9b443d4STobin Davis 
1362c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1363c9b443d4STobin Davis {
1364c9b443d4STobin Davis 	struct conexant_spec *spec;
1365c9b443d4STobin Davis 	int board_config;
1366c9b443d4STobin Davis 
1367c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1368c9b443d4STobin Davis 	if (!spec)
1369c9b443d4STobin Davis 		return -ENOMEM;
1370c9b443d4STobin Davis 	mutex_init(&spec->amp_mutex);
1371c9b443d4STobin Davis 	codec->spec = spec;
1372c9b443d4STobin Davis 
1373c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1374c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1375c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1376c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1377c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1378c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1379c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1380c9b443d4STobin Davis 	spec->input_mux = &cxt5047_capture_source;
1381c9b443d4STobin Davis 	spec->num_mixers = 1;
1382c9b443d4STobin Davis 	spec->mixers[0] = cxt5047_mixers;
1383c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1384c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1385c9b443d4STobin Davis 	spec->spdif_route = 0;
13865cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
13875cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1388c9b443d4STobin Davis 
1389c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1390c9b443d4STobin Davis 
1391f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1392f5fcc13cSTakashi Iwai 						  cxt5047_models,
1393f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1394c9b443d4STobin Davis 	switch (board_config) {
1395c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1396fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
1397c9b443d4STobin Davis 		break;
1398c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1399c9b443d4STobin Davis 		spec->input_mux = &cxt5047_hp_capture_source;
1400c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1401c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_hp_init_verbs;
1402c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_hp_mixers;
1403fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1404c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1405c9b443d4STobin Davis 		break;
1406c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
140782f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1408c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1409c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
141082f30040STobin Davis 		spec->mixers[0] = cxt5047_toshiba_mixers;
1411fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1412c9b443d4STobin Davis 		break;
1413c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1414c9b443d4STobin Davis 	case CXT5047_TEST:
1415c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1416c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1417c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1418fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1419c9b443d4STobin Davis #endif
1420c9b443d4STobin Davis 	}
1421c9b443d4STobin Davis 	return 0;
1422c9b443d4STobin Davis }
1423c9b443d4STobin Davis 
1424c9b443d4STobin Davis struct hda_codec_preset snd_hda_preset_conexant[] = {
142582f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
142682f30040STobin Davis 	  .patch = patch_cxt5045 },
142782f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
142882f30040STobin Davis 	  .patch = patch_cxt5047 },
1429c9b443d4STobin Davis 	{} /* terminator */
1430c9b443d4STobin Davis };
1431