xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision cbef97892e0c545575342332d0d84a910ca4c587)
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 
67461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
68461e2c78STakashi Iwai 	hda_nid_t cur_adc;
69461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
70461e2c78STakashi Iwai 	unsigned int cur_adc_format;
71461e2c78STakashi Iwai 
72c9b443d4STobin Davis 	/* capture source */
73c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
74c9b443d4STobin Davis 	hda_nid_t *capsrc_nids;
75c9b443d4STobin Davis 	unsigned int cur_mux[3];
76c9b443d4STobin Davis 
77c9b443d4STobin Davis 	/* channel model */
78c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
79c9b443d4STobin Davis 	int num_channel_mode;
80c9b443d4STobin Davis 
81c9b443d4STobin Davis 	/* PCM information */
82c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
83c9b443d4STobin Davis 
84c9b443d4STobin Davis 	struct mutex amp_mutex;	/* PCM volume/mute control mutex */
85c9b443d4STobin Davis 	unsigned int spdif_route;
86c9b443d4STobin Davis 
87c9b443d4STobin Davis 	/* dynamic controls, init_verbs and input_mux */
88c9b443d4STobin Davis 	struct auto_pin_cfg autocfg;
89c9b443d4STobin Davis 	unsigned int num_kctl_alloc, num_kctl_used;
90c9b443d4STobin Davis 	struct snd_kcontrol_new *kctl_alloc;
91c9b443d4STobin Davis 	struct hda_input_mux private_imux;
9241923e44STakashi Iwai 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
93c9b443d4STobin Davis 
94c9b443d4STobin Davis };
95c9b443d4STobin Davis 
96c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
97c9b443d4STobin Davis 				      struct hda_codec *codec,
98c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
99c9b443d4STobin Davis {
100c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
101c9b443d4STobin Davis 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
102c9b443d4STobin Davis }
103c9b443d4STobin Davis 
104c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
105c9b443d4STobin Davis 					 struct hda_codec *codec,
106c9b443d4STobin Davis 					 unsigned int stream_tag,
107c9b443d4STobin Davis 					 unsigned int format,
108c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
109c9b443d4STobin Davis {
110c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
111c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
112c9b443d4STobin Davis 						stream_tag,
113c9b443d4STobin Davis 						format, substream);
114c9b443d4STobin Davis }
115c9b443d4STobin Davis 
116c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
117c9b443d4STobin Davis 					 struct hda_codec *codec,
118c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
119c9b443d4STobin Davis {
120c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
121c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
122c9b443d4STobin Davis }
123c9b443d4STobin Davis 
124c9b443d4STobin Davis /*
125c9b443d4STobin Davis  * Digital out
126c9b443d4STobin Davis  */
127c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
128c9b443d4STobin Davis 					  struct hda_codec *codec,
129c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
130c9b443d4STobin Davis {
131c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
132c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
133c9b443d4STobin Davis }
134c9b443d4STobin Davis 
135c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
136c9b443d4STobin Davis 					 struct hda_codec *codec,
137c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
138c9b443d4STobin Davis {
139c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
140c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
141c9b443d4STobin Davis }
142c9b443d4STobin Davis 
1436b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1446b97eb45STakashi Iwai 					 struct hda_codec *codec,
1456b97eb45STakashi Iwai 					 unsigned int stream_tag,
1466b97eb45STakashi Iwai 					 unsigned int format,
1476b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
1486b97eb45STakashi Iwai {
1496b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1506b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1516b97eb45STakashi Iwai 					     stream_tag,
1526b97eb45STakashi Iwai 					     format, substream);
1536b97eb45STakashi Iwai }
1546b97eb45STakashi Iwai 
155c9b443d4STobin Davis /*
156c9b443d4STobin Davis  * Analog capture
157c9b443d4STobin Davis  */
158c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
159c9b443d4STobin Davis 				      struct hda_codec *codec,
160c9b443d4STobin Davis 				      unsigned int stream_tag,
161c9b443d4STobin Davis 				      unsigned int format,
162c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
163c9b443d4STobin Davis {
164c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
165c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
166c9b443d4STobin Davis 				   stream_tag, 0, format);
167c9b443d4STobin Davis 	return 0;
168c9b443d4STobin Davis }
169c9b443d4STobin Davis 
170c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
171c9b443d4STobin Davis 				      struct hda_codec *codec,
172c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
173c9b443d4STobin Davis {
174c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
175c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
176c9b443d4STobin Davis 				   0, 0, 0);
177c9b443d4STobin Davis 	return 0;
178c9b443d4STobin Davis }
179c9b443d4STobin Davis 
180c9b443d4STobin Davis 
181c9b443d4STobin Davis 
182c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = {
183c9b443d4STobin Davis 	.substreams = 1,
184c9b443d4STobin Davis 	.channels_min = 2,
185c9b443d4STobin Davis 	.channels_max = 2,
186c9b443d4STobin Davis 	.nid = 0, /* fill later */
187c9b443d4STobin Davis 	.ops = {
188c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
189c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
190c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
191c9b443d4STobin Davis 	},
192c9b443d4STobin Davis };
193c9b443d4STobin Davis 
194c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = {
195c9b443d4STobin Davis 	.substreams = 1,
196c9b443d4STobin Davis 	.channels_min = 2,
197c9b443d4STobin Davis 	.channels_max = 2,
198c9b443d4STobin Davis 	.nid = 0, /* fill later */
199c9b443d4STobin Davis 	.ops = {
200c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
201c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
202c9b443d4STobin Davis 	},
203c9b443d4STobin Davis };
204c9b443d4STobin Davis 
205c9b443d4STobin Davis 
206c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = {
207c9b443d4STobin Davis 	.substreams = 1,
208c9b443d4STobin Davis 	.channels_min = 2,
209c9b443d4STobin Davis 	.channels_max = 2,
210c9b443d4STobin Davis 	.nid = 0, /* fill later */
211c9b443d4STobin Davis 	.ops = {
212c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2136b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2146b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
215c9b443d4STobin Davis 	},
216c9b443d4STobin Davis };
217c9b443d4STobin Davis 
218c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = {
219c9b443d4STobin Davis 	.substreams = 1,
220c9b443d4STobin Davis 	.channels_min = 2,
221c9b443d4STobin Davis 	.channels_max = 2,
222c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
223c9b443d4STobin Davis };
224c9b443d4STobin Davis 
225461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
226461e2c78STakashi Iwai 				      struct hda_codec *codec,
227461e2c78STakashi Iwai 				      unsigned int stream_tag,
228461e2c78STakashi Iwai 				      unsigned int format,
229461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
230461e2c78STakashi Iwai {
231461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
232461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
233461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
234461e2c78STakashi Iwai 	spec->cur_adc_format = format;
235461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
236461e2c78STakashi Iwai 	return 0;
237461e2c78STakashi Iwai }
238461e2c78STakashi Iwai 
239461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
240461e2c78STakashi Iwai 				      struct hda_codec *codec,
241461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
242461e2c78STakashi Iwai {
243461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
244461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0);
245461e2c78STakashi Iwai 	spec->cur_adc = 0;
246461e2c78STakashi Iwai 	return 0;
247461e2c78STakashi Iwai }
248461e2c78STakashi Iwai 
249461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = {
250461e2c78STakashi Iwai 	.substreams = 1,
251461e2c78STakashi Iwai 	.channels_min = 2,
252461e2c78STakashi Iwai 	.channels_max = 2,
253461e2c78STakashi Iwai 	.nid = 0, /* fill later */
254461e2c78STakashi Iwai 	.ops = {
255461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
256461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
257461e2c78STakashi Iwai 	},
258461e2c78STakashi Iwai };
259461e2c78STakashi Iwai 
260c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
261c9b443d4STobin Davis {
262c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
263c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
264c9b443d4STobin Davis 
265c9b443d4STobin Davis 	codec->num_pcms = 1;
266c9b443d4STobin Davis 	codec->pcm_info = info;
267c9b443d4STobin Davis 
268c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
269c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
270c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
271c9b443d4STobin Davis 		spec->multiout.max_channels;
272c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
273c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
274461e2c78STakashi Iwai 	if (codec->vendor_id == 0x14f15051)
275461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
276461e2c78STakashi Iwai 			cx5051_pcm_analog_capture;
277461e2c78STakashi Iwai 	else
278461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
279461e2c78STakashi Iwai 			conexant_pcm_analog_capture;
280c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
281c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
282c9b443d4STobin Davis 
283c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
284c9b443d4STobin Davis 		info++;
285c9b443d4STobin Davis 		codec->num_pcms++;
286c9b443d4STobin Davis 		info->name = "Conexant Digital";
287c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
288c9b443d4STobin Davis 			conexant_pcm_digital_playback;
289c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
290c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
291c9b443d4STobin Davis 		if (spec->dig_in_nid) {
292c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
293c9b443d4STobin Davis 				conexant_pcm_digital_capture;
294c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
295c9b443d4STobin Davis 				spec->dig_in_nid;
296c9b443d4STobin Davis 		}
297c9b443d4STobin Davis 	}
298c9b443d4STobin Davis 
299c9b443d4STobin Davis 	return 0;
300c9b443d4STobin Davis }
301c9b443d4STobin Davis 
302c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
303c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
304c9b443d4STobin Davis {
305c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
306c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
307c9b443d4STobin Davis 
308c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
309c9b443d4STobin Davis }
310c9b443d4STobin Davis 
311c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
312c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
313c9b443d4STobin Davis {
314c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
315c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
316c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
317c9b443d4STobin Davis 
318c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
319c9b443d4STobin Davis 	return 0;
320c9b443d4STobin Davis }
321c9b443d4STobin Davis 
322c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
323c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
324c9b443d4STobin Davis {
325c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
326c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
327c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
328c9b443d4STobin Davis 
329c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
330c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
331c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
332c9b443d4STobin Davis }
333c9b443d4STobin Davis 
334c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
335c9b443d4STobin Davis {
336c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
337c9b443d4STobin Davis 	int i;
338c9b443d4STobin Davis 
339c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
340c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
341c9b443d4STobin Davis 	return 0;
342c9b443d4STobin Davis }
343c9b443d4STobin Davis 
344c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
345c9b443d4STobin Davis {
346c9b443d4STobin Davis         struct conexant_spec *spec = codec->spec;
347c9b443d4STobin Davis         unsigned int i;
348c9b443d4STobin Davis 
349c9b443d4STobin Davis         if (spec->kctl_alloc) {
350c9b443d4STobin Davis                 for (i = 0; i < spec->num_kctl_used; i++)
351c9b443d4STobin Davis                         kfree(spec->kctl_alloc[i].name);
352c9b443d4STobin Davis                 kfree(spec->kctl_alloc);
353c9b443d4STobin Davis         }
354c9b443d4STobin Davis 
355c9b443d4STobin Davis 	kfree(codec->spec);
356c9b443d4STobin Davis }
357c9b443d4STobin Davis 
358c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
359c9b443d4STobin Davis {
360c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
361c9b443d4STobin Davis 	unsigned int i;
362c9b443d4STobin Davis 	int err;
363c9b443d4STobin Davis 
364c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
365c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
366c9b443d4STobin Davis 		if (err < 0)
367c9b443d4STobin Davis 			return err;
368c9b443d4STobin Davis 	}
369c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
370c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
371c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
372c9b443d4STobin Davis 		if (err < 0)
373c9b443d4STobin Davis 			return err;
374c9b443d4STobin Davis 	}
375c9b443d4STobin Davis 	if (spec->dig_in_nid) {
376c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
377c9b443d4STobin Davis 		if (err < 0)
378c9b443d4STobin Davis 			return err;
379c9b443d4STobin Davis 	}
380c9b443d4STobin Davis 	return 0;
381c9b443d4STobin Davis }
382c9b443d4STobin Davis 
383c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
384c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
385c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
386c9b443d4STobin Davis 	.init = conexant_init,
387c9b443d4STobin Davis 	.free = conexant_free,
388c9b443d4STobin Davis };
389c9b443d4STobin Davis 
390c9b443d4STobin Davis /*
391c9b443d4STobin Davis  * EAPD control
392c9b443d4STobin Davis  * the private value = nid | (invert << 8)
393c9b443d4STobin Davis  */
394c9b443d4STobin Davis 
395a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
396c9b443d4STobin Davis 
39782f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
398c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
399c9b443d4STobin Davis {
400c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
401c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
402c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
403c9b443d4STobin Davis 	if (invert)
404c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
405c9b443d4STobin Davis 	else
406c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
407c9b443d4STobin Davis 	return 0;
40882f30040STobin Davis 
409c9b443d4STobin Davis }
410c9b443d4STobin Davis 
41182f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
412c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
413c9b443d4STobin Davis {
414c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
415c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
416c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
417c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
418c9b443d4STobin Davis 	unsigned int eapd;
41982f30040STobin Davis 
42068ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
421c9b443d4STobin Davis 	if (invert)
422c9b443d4STobin Davis 		eapd = !eapd;
42382beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
424c9b443d4STobin Davis 		return 0;
42582f30040STobin Davis 
426c9b443d4STobin Davis 	spec->cur_eapd = eapd;
42782beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
428c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
429c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
430c9b443d4STobin Davis 	return 1;
431c9b443d4STobin Davis }
432c9b443d4STobin Davis 
43386d72bdfSTakashi Iwai /* controls for test mode */
43486d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
43586d72bdfSTakashi Iwai 
43682f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
43782f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
43882f30040STobin Davis 	  .info = cxt_eapd_info, \
43982f30040STobin Davis 	  .get = cxt_eapd_get, \
44082f30040STobin Davis 	  .put = cxt_eapd_put, \
44182f30040STobin Davis 	  .private_value = nid | (mask<<16) }
44282f30040STobin Davis 
44382f30040STobin Davis 
44482f30040STobin Davis 
445c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
446c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
447c9b443d4STobin Davis {
448c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
449c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
450c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
451c9b443d4STobin Davis 				    spec->num_channel_mode);
452c9b443d4STobin Davis }
453c9b443d4STobin Davis 
454c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
455c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
456c9b443d4STobin Davis {
457c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
458c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
459c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
460c9b443d4STobin Davis 				   spec->num_channel_mode,
461c9b443d4STobin Davis 				   spec->multiout.max_channels);
462c9b443d4STobin Davis }
463c9b443d4STobin Davis 
464c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
465c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
466c9b443d4STobin Davis {
467c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
468c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
469c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
470c9b443d4STobin Davis 				      spec->num_channel_mode,
471c9b443d4STobin Davis 				      &spec->multiout.max_channels);
472c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
473c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
474c9b443d4STobin Davis 	return err;
475c9b443d4STobin Davis }
476c9b443d4STobin Davis 
477c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
478c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
479c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
480c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
481c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
482c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
483c9b443d4STobin Davis 
48486d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
48586d72bdfSTakashi Iwai 
486c9b443d4STobin Davis /* Conexant 5045 specific */
487c9b443d4STobin Davis 
488c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
489c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
490c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
491*cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
492c9b443d4STobin Davis 
4935cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
4945cd57529STobin Davis 	{ 2, NULL },
4955cd57529STobin Davis };
496c9b443d4STobin Davis 
497c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
498c9b443d4STobin Davis 	.num_items = 2,
499c9b443d4STobin Davis 	.items = {
50082f30040STobin Davis 		{ "IntMic", 0x1 },
501f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
502c9b443d4STobin Davis 	}
503c9b443d4STobin Davis };
504c9b443d4STobin Davis 
5055218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = {
5065218c892SJiang Zhe 	.num_items = 3,
5075218c892SJiang Zhe 	.items = {
5085218c892SJiang Zhe 		{ "IntMic", 0x1 },
5095218c892SJiang Zhe 		{ "ExtMic", 0x2 },
5105218c892SJiang Zhe 		{ "LineIn", 0x3 },
5115218c892SJiang Zhe 	}
5125218c892SJiang Zhe };
5135218c892SJiang Zhe 
514c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
515c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
516c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
517c9b443d4STobin Davis {
518c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
519c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
52082f30040STobin Davis 	unsigned int bits;
521c9b443d4STobin Davis 
52282f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
523c9b443d4STobin Davis 		return 0;
524c9b443d4STobin Davis 
52582f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
52682f30040STobin Davis 	 * the headphone jack
52782f30040STobin Davis 	 */
52847fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
52947fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
53047fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
5317f29673bSTobin Davis 
53247fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
53347fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
53447fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
535c9b443d4STobin Davis 	return 1;
536c9b443d4STobin Davis }
537c9b443d4STobin Davis 
538c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
539cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
540cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
541cca3b371STakashi Iwai 	.values = {
542cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
543cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
544cca3b371STakashi Iwai 		0
545cca3b371STakashi Iwai 	},
546cca3b371STakashi Iwai };
547c9b443d4STobin Davis 
5487f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
5497f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
5507f29673bSTobin Davis {
5517f29673bSTobin Davis 	static struct hda_verb mic_jack_on[] = {
5527f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
5537f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5547f29673bSTobin Davis 		{}
5557f29673bSTobin Davis 	};
5567f29673bSTobin Davis 	static struct hda_verb mic_jack_off[] = {
5577f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
5587f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5597f29673bSTobin Davis 		{}
5607f29673bSTobin Davis 	};
5617f29673bSTobin Davis 	unsigned int present;
5627f29673bSTobin Davis 
5637f29673bSTobin Davis 	present = snd_hda_codec_read(codec, 0x12, 0,
5647f29673bSTobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5657f29673bSTobin Davis 	if (present)
5667f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
5677f29673bSTobin Davis 	else
5687f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
5697f29673bSTobin Davis }
5707f29673bSTobin Davis 
571c9b443d4STobin Davis 
572c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
573c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
574c9b443d4STobin Davis {
57582f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
576dd87da1cSTobin Davis 	unsigned int bits;
577c9b443d4STobin Davis 
57882f30040STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
579c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
580dd87da1cSTobin Davis 
58147fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
58247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
58347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
584c9b443d4STobin Davis }
585c9b443d4STobin Davis 
586c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
587c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
588c9b443d4STobin Davis 				   unsigned int res)
589c9b443d4STobin Davis {
590c9b443d4STobin Davis 	res >>= 26;
591c9b443d4STobin Davis 	switch (res) {
592c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
593c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
594c9b443d4STobin Davis 		break;
5957f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
5967f29673bSTobin Davis 		cxt5045_hp_automic(codec);
5977f29673bSTobin Davis 		break;
5987f29673bSTobin Davis 
599c9b443d4STobin Davis 	}
600c9b443d4STobin Davis }
601c9b443d4STobin Davis 
602c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
603c9b443d4STobin Davis 	{
604c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
605c9b443d4STobin Davis 		.name = "Capture Source",
606c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
607c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
608c9b443d4STobin Davis 		.put = conexant_mux_enum_put
609c9b443d4STobin Davis 	},
610c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
611c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
612c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
613c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
614c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
615c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
616c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
617c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
618c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
619c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
620cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
621c9b443d4STobin Davis 	{
622c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
623c9b443d4STobin Davis 		.name = "Master Playback Switch",
62482f30040STobin Davis 		.info = cxt_eapd_info,
62582f30040STobin Davis 		.get = cxt_eapd_get,
626c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
62782f30040STobin Davis 		.private_value = 0x10,
628c9b443d4STobin Davis 	},
629c9b443d4STobin Davis 
630c9b443d4STobin Davis 	{}
631c9b443d4STobin Davis };
632c9b443d4STobin Davis 
6335218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
6345218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
6355218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
6365218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
6375218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
6385218c892SJiang Zhe 
6395218c892SJiang Zhe 	{}
6405218c892SJiang Zhe };
6415218c892SJiang Zhe 
642c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
643c9b443d4STobin Davis 	/* Line in, Mic */
644c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6457f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
646c9b443d4STobin Davis 	/* HP, Amp  */
647c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
648c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
64982f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
650c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
651c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
652c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
653c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
654c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
655c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
65682f30040STobin Davis 	/* Record selector: Int mic */
6577f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
65882f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
659c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
660c9b443d4STobin Davis 	/* SPDIF route: PCM */
661*cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
662c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
663c9b443d4STobin Davis 	/* EAPD */
66482f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
665c9b443d4STobin Davis 	{ } /* end */
666c9b443d4STobin Davis };
667c9b443d4STobin Davis 
6685218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = {
6695218c892SJiang Zhe 	/* Int Mic, Mic */
6705218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
6715218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
6725218c892SJiang Zhe 	/* Line In,HP, Amp  */
6735218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6745218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
6755218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6765218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
6775218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6785218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6795218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6805218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6815218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6825218c892SJiang Zhe 	/* Record selector: Int mic */
6835218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
6845218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
6855218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
6865218c892SJiang Zhe 	/* SPDIF route: PCM */
687*cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6885218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
6895218c892SJiang Zhe 	/* EAPD */
6905218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
6915218c892SJiang Zhe 	{ } /* end */
6925218c892SJiang Zhe };
6937f29673bSTobin Davis 
6947f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
6957f29673bSTobin Davis 	/* pin sensing on HP jack */
6967f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
697d3091fadSTakashi Iwai 	{ } /* end */
6987f29673bSTobin Davis };
6997f29673bSTobin Davis 
7007f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
7017f29673bSTobin Davis 	/* pin sensing on HP jack */
7027f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
703d3091fadSTakashi Iwai 	{ } /* end */
7047f29673bSTobin Davis };
7057f29673bSTobin Davis 
706c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
707c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
708c9b443d4STobin Davis  * configuration.
709c9b443d4STobin Davis  */
710c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
711c9b443d4STobin Davis 	.num_items = 5,
712c9b443d4STobin Davis 	.items = {
713c9b443d4STobin Davis 		{ "MIXER", 0x0 },
714c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
715c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
716c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
717c9b443d4STobin Davis 		{ "CD pin", 0x4 },
718c9b443d4STobin Davis         },
719c9b443d4STobin Davis };
720c9b443d4STobin Davis 
721c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
722c9b443d4STobin Davis 
723c9b443d4STobin Davis 	/* Output controls */
724c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
725c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
7267f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
7277f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
7287f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
7297f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
730c9b443d4STobin Davis 
731c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
732c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
733c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
734c9b443d4STobin Davis 
73582f30040STobin Davis 	/* EAPD Switch Control */
73682f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
73782f30040STobin Davis 
738c9b443d4STobin Davis 	/* Loopback mixer controls */
739c9b443d4STobin Davis 
7407f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
7417f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
7427f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
7437f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
7447f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
7457f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
7467f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
7477f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
7487f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
7497f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
750c9b443d4STobin Davis 	{
751c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
752c9b443d4STobin Davis 		.name = "Input Source",
753c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
754c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
755c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
756c9b443d4STobin Davis 	},
757fb3409e7STobin Davis 	/* Audio input controls */
758fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
759fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
760fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
761fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
762fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
763fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
764fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
765fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
766fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
767fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
768c9b443d4STobin Davis 	{ } /* end */
769c9b443d4STobin Davis };
770c9b443d4STobin Davis 
771c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
7727f29673bSTobin Davis 	/* Set connections */
7737f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
7747f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
7757f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
776c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
777c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7787f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
779c9b443d4STobin Davis 
780c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
781c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
782c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
783c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
784c9b443d4STobin Davis 	 * control.
785c9b443d4STobin Davis 	 */
786*cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
787*cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
788c9b443d4STobin Davis 
789c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
790c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
791c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
792c9b443d4STobin Davis 
793c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
794c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
795c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
796c9b443d4STobin Davis 	 * input/output buffers as needed.
797c9b443d4STobin Davis 	 */
798c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
799c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
800c9b443d4STobin Davis 
801c9b443d4STobin Davis 	/* Mute capture amp left and right */
802c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
803c9b443d4STobin Davis 
804c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
805c9b443d4STobin Davis 	 * pin)
806c9b443d4STobin Davis 	 */
807c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8087f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
809c9b443d4STobin Davis 
810c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
811c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
812c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
813c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
814c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
815c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
816c9b443d4STobin Davis 
817c9b443d4STobin Davis 	{ }
818c9b443d4STobin Davis };
819c9b443d4STobin Davis #endif
820c9b443d4STobin Davis 
821c9b443d4STobin Davis 
822c9b443d4STobin Davis /* initialize jack-sensing, too */
823c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
824c9b443d4STobin Davis {
825c9b443d4STobin Davis 	conexant_init(codec);
826c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
827c9b443d4STobin Davis 	return 0;
828c9b443d4STobin Davis }
829c9b443d4STobin Davis 
830c9b443d4STobin Davis 
831c9b443d4STobin Davis enum {
83215908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
83315908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
83415908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
8355218c892SJiang Zhe 	CXT5045_BENQ,
836c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
837c9b443d4STobin Davis 	CXT5045_TEST,
838c9b443d4STobin Davis #endif
839f5fcc13cSTakashi Iwai 	CXT5045_MODELS
840c9b443d4STobin Davis };
841c9b443d4STobin Davis 
842f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = {
84315908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
84415908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
84515908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
8465218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
847c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
848f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
849c9b443d4STobin Davis #endif
850f5fcc13cSTakashi Iwai };
851c9b443d4STobin Davis 
852f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
85315908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
85415908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
85515908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
85615908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
85715908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
85815908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
8590f6a5156STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
86015908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HPSENSE),
86115908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
8625218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
86315908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
86415908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
86515908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPSENSE),
86615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
86715908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
86815908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
86915908c36SMarc Boucher 	SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
87015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
87115908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
872c9b443d4STobin Davis 	{}
873c9b443d4STobin Davis };
874c9b443d4STobin Davis 
875c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
876c9b443d4STobin Davis {
877c9b443d4STobin Davis 	struct conexant_spec *spec;
878c9b443d4STobin Davis 	int board_config;
879c9b443d4STobin Davis 
880c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
881c9b443d4STobin Davis 	if (!spec)
882c9b443d4STobin Davis 		return -ENOMEM;
883c9b443d4STobin Davis 	mutex_init(&spec->amp_mutex);
884c9b443d4STobin Davis 	codec->spec = spec;
885c9b443d4STobin Davis 
886c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
887c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
888c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
889c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
890c9b443d4STobin Davis 	spec->num_adc_nids = 1;
891c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
892c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
893c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
894c9b443d4STobin Davis 	spec->num_mixers = 1;
895c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
896c9b443d4STobin Davis 	spec->num_init_verbs = 1;
897c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
898c9b443d4STobin Davis 	spec->spdif_route = 0;
8995cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
9005cd57529STobin Davis 	spec->channel_mode = cxt5045_modes,
9015cd57529STobin Davis 
902c9b443d4STobin Davis 
903c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
904c9b443d4STobin Davis 
905f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
906f5fcc13cSTakashi Iwai 						  cxt5045_models,
907f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
908c9b443d4STobin Davis 	switch (board_config) {
90915908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
9107f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
911c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
912c9b443d4STobin Davis 		spec->num_init_verbs = 2;
9137f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
9147f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
9157f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
9167f29673bSTobin Davis 		break;
91715908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
9187f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
9197f29673bSTobin Davis 		spec->num_init_verbs = 2;
9207f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
921c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
922c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
923c9b443d4STobin Davis 		break;
92415908c36SMarc Boucher 	default:
92515908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
92615908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
92715908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
92815908c36SMarc Boucher 		spec->num_init_verbs = 3;
92915908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
93015908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
93115908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
93215908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
93315908c36SMarc Boucher 		break;
9345218c892SJiang Zhe 	case CXT5045_BENQ:
9355218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
9365218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
9375218c892SJiang Zhe 		spec->num_init_verbs = 1;
9385218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
9395218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
9405218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
9415218c892SJiang Zhe 		spec->num_mixers = 2;
9425218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
9435218c892SJiang Zhe 		break;
944c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
945c9b443d4STobin Davis 	case CXT5045_TEST:
946c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
947c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
948c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
94915908c36SMarc Boucher 		break;
95015908c36SMarc Boucher 
951c9b443d4STobin Davis #endif
952c9b443d4STobin Davis 	}
95348ecb7e8STakashi Iwai 
95448ecb7e8STakashi Iwai 	/*
95548ecb7e8STakashi Iwai 	 * Fix max PCM level to 0 dB
95648ecb7e8STakashi Iwai 	 * (originall it has 0x2b steps with 0dB offset 0x14)
95748ecb7e8STakashi Iwai 	 */
95848ecb7e8STakashi Iwai 	snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
95948ecb7e8STakashi Iwai 				  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
96048ecb7e8STakashi Iwai 				  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
96148ecb7e8STakashi Iwai 				  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
96248ecb7e8STakashi Iwai 				  (1 << AC_AMPCAP_MUTE_SHIFT));
96348ecb7e8STakashi Iwai 
964c9b443d4STobin Davis 	return 0;
965c9b443d4STobin Davis }
966c9b443d4STobin Davis 
967c9b443d4STobin Davis 
968c9b443d4STobin Davis /* Conexant 5047 specific */
96982f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
970c9b443d4STobin Davis 
97182f30040STobin Davis static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
972c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
973c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
974c9b443d4STobin Davis 
9755cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
9765cd57529STobin Davis 	{ 2, NULL },
9775cd57529STobin Davis };
978c9b443d4STobin Davis 
979c9b443d4STobin Davis static struct hda_input_mux cxt5047_capture_source = {
9807f29673bSTobin Davis 	.num_items = 1,
981c9b443d4STobin Davis 	.items = {
9827f29673bSTobin Davis 		{ "Mic", 0x2 },
983c9b443d4STobin Davis 	}
984c9b443d4STobin Davis };
985c9b443d4STobin Davis 
986c9b443d4STobin Davis static struct hda_input_mux cxt5047_hp_capture_source = {
987c9b443d4STobin Davis 	.num_items = 1,
988c9b443d4STobin Davis 	.items = {
98982f30040STobin Davis 		{ "ExtMic", 0x2 },
99082f30040STobin Davis 	}
99182f30040STobin Davis };
99282f30040STobin Davis 
99382f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
99482f30040STobin Davis 	.num_items = 2,
99582f30040STobin Davis 	.items = {
99682f30040STobin Davis 		{ "ExtMic", 0x2 },
99782f30040STobin Davis 		{ "Line-In", 0x1 },
998c9b443d4STobin Davis 	}
999c9b443d4STobin Davis };
1000c9b443d4STobin Davis 
1001c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1002c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1003c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1004c9b443d4STobin Davis {
1005c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1006c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
100782f30040STobin Davis 	unsigned int bits;
1008c9b443d4STobin Davis 
100982f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1010c9b443d4STobin Davis 		return 0;
1011c9b443d4STobin Davis 
101282f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
101382f30040STobin Davis 	 * the headphone jack
101482f30040STobin Davis 	 */
101547fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
101647fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
101747fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
101847fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
101947fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
102047fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1021c9b443d4STobin Davis 	return 1;
1022c9b443d4STobin Davis }
1023c9b443d4STobin Davis 
102482f30040STobin Davis /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
1025cca3b371STakashi Iwai static struct hda_bind_ctls cxt5047_bind_master_vol = {
1026cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
1027cca3b371STakashi Iwai 	.values = {
1028cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1029cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1030cca3b371STakashi Iwai 		0
1031cca3b371STakashi Iwai 	},
1032cca3b371STakashi Iwai };
1033c9b443d4STobin Davis 
1034c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1035c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1036c9b443d4STobin Davis {
103782f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1038dd87da1cSTobin Davis 	unsigned int bits;
1039c9b443d4STobin Davis 
104082f30040STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1041c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1042dd87da1cSTobin Davis 
104347fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
104447fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
104547fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
104682f30040STobin Davis 	/* Mute/Unmute PCM 2 for good measure - some systems need this */
104747fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
104847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1049c9b443d4STobin Davis }
1050c9b443d4STobin Davis 
1051fb3409e7STobin Davis /* mute internal speaker if HP is plugged */
1052fb3409e7STobin Davis static void cxt5047_hp2_automute(struct hda_codec *codec)
1053fb3409e7STobin Davis {
1054fb3409e7STobin Davis 	struct conexant_spec *spec = codec->spec;
1055fb3409e7STobin Davis 	unsigned int bits;
1056fb3409e7STobin Davis 
1057fb3409e7STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1058fb3409e7STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1059fb3409e7STobin Davis 
106047fd830aSTakashi Iwai 	bits = spec->hp_present ? HDA_AMP_MUTE : 0;
106147fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
106247fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1063fb3409e7STobin Davis 	/* Mute/Unmute PCM 2 for good measure - some systems need this */
106447fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
106547fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1066fb3409e7STobin Davis }
1067fb3409e7STobin Davis 
1068c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1069c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1070c9b443d4STobin Davis {
1071c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
10729f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10739f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1074c9b443d4STobin Davis 		{}
1075c9b443d4STobin Davis 	};
1076c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
10779f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10789f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1079c9b443d4STobin Davis 		{}
1080c9b443d4STobin Davis 	};
1081c9b443d4STobin Davis 	unsigned int present;
1082c9b443d4STobin Davis 
10837f29673bSTobin Davis 	present = snd_hda_codec_read(codec, 0x15, 0,
1084c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1085c9b443d4STobin Davis 	if (present)
1086c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1087c9b443d4STobin Davis 	else
1088c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1089c9b443d4STobin Davis }
1090c9b443d4STobin Davis 
1091c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1092c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1093c9b443d4STobin Davis 				  unsigned int res)
1094c9b443d4STobin Davis {
10959f113e0eSMarc Boucher 	switch (res >> 26) {
1096c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1097c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1098c9b443d4STobin Davis 		break;
1099c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1100c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1101c9b443d4STobin Davis 		break;
1102c9b443d4STobin Davis 	}
1103c9b443d4STobin Davis }
1104c9b443d4STobin Davis 
1105fb3409e7STobin Davis /* unsolicited event for HP jack sensing - non-EAPD systems */
1106fb3409e7STobin Davis static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1107fb3409e7STobin Davis 				  unsigned int res)
1108fb3409e7STobin Davis {
1109fb3409e7STobin Davis 	res >>= 26;
1110fb3409e7STobin Davis 	switch (res) {
1111fb3409e7STobin Davis 	case CONEXANT_HP_EVENT:
1112fb3409e7STobin Davis 		cxt5047_hp2_automute(codec);
1113fb3409e7STobin Davis 		break;
1114fb3409e7STobin Davis 	case CONEXANT_MIC_EVENT:
1115fb3409e7STobin Davis 		cxt5047_hp_automic(codec);
1116fb3409e7STobin Davis 		break;
1117fb3409e7STobin Davis 	}
1118fb3409e7STobin Davis }
1119fb3409e7STobin Davis 
1120c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_mixers[] = {
1121c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1122c9b443d4STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
11237f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
11247f29673bSTobin Davis 	HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
1125c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1126c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1127c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1128c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
112982f30040STobin Davis 	HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
113082f30040STobin Davis 	HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1131b7589cebSTobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1132b7589cebSTobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1133b7589cebSTobin Davis 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1134b7589cebSTobin Davis 	HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
113582f30040STobin Davis 
113682f30040STobin Davis 	{}
113782f30040STobin Davis };
113882f30040STobin Davis 
113982f30040STobin Davis static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
114082f30040STobin Davis 	{
114182f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
114282f30040STobin Davis 		.name = "Capture Source",
114382f30040STobin Davis 		.info = conexant_mux_enum_info,
114482f30040STobin Davis 		.get = conexant_mux_enum_get,
114582f30040STobin Davis 		.put = conexant_mux_enum_put
114682f30040STobin Davis 	},
114782f30040STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
114882f30040STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
114982f30040STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
115082f30040STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
115182f30040STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
115282f30040STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1153cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
115482f30040STobin Davis 	{
115582f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
115682f30040STobin Davis 		.name = "Master Playback Switch",
115782f30040STobin Davis 		.info = cxt_eapd_info,
115882f30040STobin Davis 		.get = cxt_eapd_get,
1159c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1160c9b443d4STobin Davis 		.private_value = 0x13,
1161c9b443d4STobin Davis 	},
1162c9b443d4STobin Davis 
1163c9b443d4STobin Davis 	{}
1164c9b443d4STobin Davis };
1165c9b443d4STobin Davis 
1166c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1167c9b443d4STobin Davis 	{
1168c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1169c9b443d4STobin Davis 		.name = "Capture Source",
1170c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1171c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1172c9b443d4STobin Davis 		.put = conexant_mux_enum_put
1173c9b443d4STobin Davis 	},
1174c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1175c9b443d4STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1176c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1177c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1178c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1179c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1180c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1181c9b443d4STobin Davis 	{
1182c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1183c9b443d4STobin Davis 		.name = "Master Playback Switch",
118482f30040STobin Davis 		.info = cxt_eapd_info,
118582f30040STobin Davis 		.get = cxt_eapd_get,
1186c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1187c9b443d4STobin Davis 		.private_value = 0x13,
1188c9b443d4STobin Davis 	},
1189c9b443d4STobin Davis 	{ } /* end */
1190c9b443d4STobin Davis };
1191c9b443d4STobin Davis 
1192c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1193c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1194c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1195c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1196c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
11977f29673bSTobin Davis 	/* HP, Speaker  */
1198b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1199b7589cebSTobin Davis 	{0x13, AC_VERB_SET_CONNECT_SEL,0x1},
12007f29673bSTobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
12017f29673bSTobin Davis 	/* Record selector: Mic */
12027f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
12037f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
12047f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
12057f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1206c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1207c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1208c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1209c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1210c9b443d4STobin Davis 	/* SPDIF route: PCM */
1211c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
121282f30040STobin Davis 	/* Enable unsolicited events */
121382f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
121482f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1215c9b443d4STobin Davis 	{ } /* end */
1216c9b443d4STobin Davis };
1217c9b443d4STobin Davis 
1218c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1219c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1220c9b443d4STobin Davis 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1221c9b443d4STobin Davis 	/* pin sensing on HP and Mic jacks */
1222c9b443d4STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1223c9b443d4STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
122482f30040STobin Davis 	/* Speaker routing */
122582f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1226c9b443d4STobin Davis 	{}
1227c9b443d4STobin Davis };
1228c9b443d4STobin Davis 
1229c9b443d4STobin Davis /* configuration for HP Laptops */
1230c9b443d4STobin Davis static struct hda_verb cxt5047_hp_init_verbs[] = {
123182f30040STobin Davis 	/* pin sensing on HP jack */
1232c9b443d4STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
123382f30040STobin Davis 	/* Record selector: Ext Mic */
123482f30040STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
123582f30040STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
123682f30040STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
123782f30040STobin Davis 	/* Speaker routing */
123882f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1239c9b443d4STobin Davis 	{}
1240c9b443d4STobin Davis };
1241c9b443d4STobin Davis 
1242c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1243c9b443d4STobin Davis  * configuration.
1244c9b443d4STobin Davis  */
1245c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1246c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
124782f30040STobin Davis 	.num_items = 4,
1248c9b443d4STobin Davis 	.items = {
124982f30040STobin Davis 		{ "LINE1 pin", 0x0 },
125082f30040STobin Davis 		{ "MIC1 pin", 0x1 },
125182f30040STobin Davis 		{ "MIC2 pin", 0x2 },
125282f30040STobin Davis 		{ "CD pin", 0x3 },
1253c9b443d4STobin Davis         },
1254c9b443d4STobin Davis };
1255c9b443d4STobin Davis 
1256c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1257c9b443d4STobin Davis 
1258c9b443d4STobin Davis 	/* Output only controls */
125982f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
126082f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
126182f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
126282f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1263c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1264c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1265c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1266c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
126782f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
126882f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
126982f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
127082f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1271c9b443d4STobin Davis 
1272c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1273c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1274c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1275c9b443d4STobin Davis 
127682f30040STobin Davis 	/* EAPD Switch Control */
127782f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
127882f30040STobin Davis 
1279c9b443d4STobin Davis 	/* Loopback mixer controls */
128082f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
128182f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
128282f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
128382f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
128482f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
128582f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
128682f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
128782f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1288c9b443d4STobin Davis 
128982f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
129082f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
129182f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
129282f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
129382f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
129482f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
129582f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
129682f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1297c9b443d4STobin Davis 	{
1298c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1299c9b443d4STobin Davis 		.name = "Input Source",
1300c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1301c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1302c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1303c9b443d4STobin Davis 	},
13049f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
13059f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
13069f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
13079f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
13089f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
13099f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
13109f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
13119f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
13129f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
13139f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
13149f113e0eSMarc Boucher 
1315c9b443d4STobin Davis 	{ } /* end */
1316c9b443d4STobin Davis };
1317c9b443d4STobin Davis 
1318c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1319c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1320c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1321c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1322c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1323c9b443d4STobin Davis 
1324c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1325c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1326c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1327c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1328c9b443d4STobin Davis 	 * control.
1329c9b443d4STobin Davis 	 */
1330c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1331c9b443d4STobin Davis 
1332c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1333c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1334c9b443d4STobin Davis 	 */
1335c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1336c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1337c9b443d4STobin Davis 
1338c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1339c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1340c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1341c9b443d4STobin Davis 
1342c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1343c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1344c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1345c9b443d4STobin Davis 	 * input/output buffers as needed.
1346c9b443d4STobin Davis 	 */
1347c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1348c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1349c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1350c9b443d4STobin Davis 
1351c9b443d4STobin Davis 	/* Mute capture amp left and right */
1352c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1353c9b443d4STobin Davis 
1354c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1355c9b443d4STobin Davis 	 * pin)
1356c9b443d4STobin Davis 	 */
1357c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1358c9b443d4STobin Davis 
1359c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1360c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1361c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1362c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1363c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1364c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1365c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1366c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1367c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1368c9b443d4STobin Davis 
1369c9b443d4STobin Davis 	{ }
1370c9b443d4STobin Davis };
1371c9b443d4STobin Davis #endif
1372c9b443d4STobin Davis 
1373c9b443d4STobin Davis 
1374c9b443d4STobin Davis /* initialize jack-sensing, too */
1375c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1376c9b443d4STobin Davis {
1377c9b443d4STobin Davis 	conexant_init(codec);
1378c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1379c9b443d4STobin Davis 	return 0;
1380c9b443d4STobin Davis }
1381c9b443d4STobin Davis 
1382c9b443d4STobin Davis 
1383c9b443d4STobin Davis enum {
1384f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1385f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1386f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1387c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1388c9b443d4STobin Davis 	CXT5047_TEST,
1389c9b443d4STobin Davis #endif
1390f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1391c9b443d4STobin Davis };
1392c9b443d4STobin Davis 
1393f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = {
1394f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1395f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1396f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1397c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1398f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1399c9b443d4STobin Davis #endif
1400f5fcc13cSTakashi Iwai };
1401c9b443d4STobin Davis 
1402f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1403f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1404ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1405f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
140682f30040STobin Davis 	SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
1407f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1408c9b443d4STobin Davis 	{}
1409c9b443d4STobin Davis };
1410c9b443d4STobin Davis 
1411c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1412c9b443d4STobin Davis {
1413c9b443d4STobin Davis 	struct conexant_spec *spec;
1414c9b443d4STobin Davis 	int board_config;
1415c9b443d4STobin Davis 
1416c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1417c9b443d4STobin Davis 	if (!spec)
1418c9b443d4STobin Davis 		return -ENOMEM;
1419c9b443d4STobin Davis 	mutex_init(&spec->amp_mutex);
1420c9b443d4STobin Davis 	codec->spec = spec;
1421c9b443d4STobin Davis 
1422c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1423c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1424c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1425c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1426c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1427c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1428c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1429c9b443d4STobin Davis 	spec->input_mux = &cxt5047_capture_source;
1430c9b443d4STobin Davis 	spec->num_mixers = 1;
1431c9b443d4STobin Davis 	spec->mixers[0] = cxt5047_mixers;
1432c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1433c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1434c9b443d4STobin Davis 	spec->spdif_route = 0;
14355cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
14365cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1437c9b443d4STobin Davis 
1438c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1439c9b443d4STobin Davis 
1440f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1441f5fcc13cSTakashi Iwai 						  cxt5047_models,
1442f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1443c9b443d4STobin Davis 	switch (board_config) {
1444c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1445fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
1446c9b443d4STobin Davis 		break;
1447c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1448c9b443d4STobin Davis 		spec->input_mux = &cxt5047_hp_capture_source;
1449c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1450c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_hp_init_verbs;
1451c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_hp_mixers;
1452fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1453c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1454c9b443d4STobin Davis 		break;
1455c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
145682f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1457c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1458c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
145982f30040STobin Davis 		spec->mixers[0] = cxt5047_toshiba_mixers;
1460fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1461c9b443d4STobin Davis 		break;
1462c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1463c9b443d4STobin Davis 	case CXT5047_TEST:
1464c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1465c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1466c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1467fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1468c9b443d4STobin Davis #endif
1469c9b443d4STobin Davis 	}
1470c9b443d4STobin Davis 	return 0;
1471c9b443d4STobin Davis }
1472c9b443d4STobin Davis 
1473461e2c78STakashi Iwai /* Conexant 5051 specific */
1474461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1475461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1476461e2c78STakashi Iwai #define CXT5051_SPDIF_OUT	0x1C
1477461e2c78STakashi Iwai #define CXT5051_PORTB_EVENT	0x38
1478461e2c78STakashi Iwai #define CXT5051_PORTC_EVENT	0x39
1479461e2c78STakashi Iwai 
1480461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = {
1481461e2c78STakashi Iwai 	{ 2, NULL },
1482461e2c78STakashi Iwai };
1483461e2c78STakashi Iwai 
1484461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1485461e2c78STakashi Iwai {
1486461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1487461e2c78STakashi Iwai 	unsigned int pinctl;
1488461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1489461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1490461e2c78STakashi Iwai 			    pinctl);
1491461e2c78STakashi Iwai }
1492461e2c78STakashi Iwai 
1493461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1494461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1495461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1496461e2c78STakashi Iwai {
1497461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1498461e2c78STakashi Iwai 
1499461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1500461e2c78STakashi Iwai 		return 0;
1501461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1502461e2c78STakashi Iwai 	return 1;
1503461e2c78STakashi Iwai }
1504461e2c78STakashi Iwai 
1505461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1506461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1507461e2c78STakashi Iwai {
1508461e2c78STakashi Iwai 	unsigned int present;
1509461e2c78STakashi Iwai 
1510461e2c78STakashi Iwai 	present = snd_hda_codec_read(codec, 0x17, 0,
1511461e2c78STakashi Iwai 				     AC_VERB_GET_PIN_SENSE, 0) &
1512461e2c78STakashi Iwai 		AC_PINSENSE_PRESENCE;
1513461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1514461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1515461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1516461e2c78STakashi Iwai }
1517461e2c78STakashi Iwai 
1518461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1519461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1520461e2c78STakashi Iwai {
1521461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1522461e2c78STakashi Iwai 	unsigned int present;
1523461e2c78STakashi Iwai 	hda_nid_t new_adc;
1524461e2c78STakashi Iwai 
1525461e2c78STakashi Iwai 	present = snd_hda_codec_read(codec, 0x18, 0,
1526461e2c78STakashi Iwai 				     AC_VERB_GET_PIN_SENSE, 0) &
1527461e2c78STakashi Iwai 		AC_PINSENSE_PRESENCE;
1528461e2c78STakashi Iwai 	if (present)
1529461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1530461e2c78STakashi Iwai 	else
1531461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1532461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1533461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1534461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1535461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0);
1536461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1537461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1538461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1539461e2c78STakashi Iwai 					   spec->cur_adc_format);
1540461e2c78STakashi Iwai 	}
1541461e2c78STakashi Iwai }
1542461e2c78STakashi Iwai 
1543461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1544461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1545461e2c78STakashi Iwai {
1546461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1547461e2c78STakashi Iwai 
1548461e2c78STakashi Iwai 	spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1549461e2c78STakashi Iwai 				     AC_VERB_GET_PIN_SENSE, 0) &
1550461e2c78STakashi Iwai 		AC_PINSENSE_PRESENCE;
1551461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1552461e2c78STakashi Iwai }
1553461e2c78STakashi Iwai 
1554461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1555461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1556461e2c78STakashi Iwai 				   unsigned int res)
1557461e2c78STakashi Iwai {
1558461e2c78STakashi Iwai 	switch (res >> 26) {
1559461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1560461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1561461e2c78STakashi Iwai 		break;
1562461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1563461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1564461e2c78STakashi Iwai 		break;
1565461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1566461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1567461e2c78STakashi Iwai 		break;
1568461e2c78STakashi Iwai 	}
1569461e2c78STakashi Iwai }
1570461e2c78STakashi Iwai 
1571461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_mixers[] = {
1572461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1573461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1574461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1575461e2c78STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1576461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1577461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1578461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1579461e2c78STakashi Iwai 	{
1580461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1581461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1582461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1583461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1584461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1585461e2c78STakashi Iwai 		.private_value = 0x1a,
1586461e2c78STakashi Iwai 	},
1587461e2c78STakashi Iwai 
1588461e2c78STakashi Iwai 	{}
1589461e2c78STakashi Iwai };
1590461e2c78STakashi Iwai 
1591461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1592461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1593461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1594461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1595461e2c78STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1596461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1597461e2c78STakashi Iwai 	{
1598461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1599461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1600461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1601461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1602461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1603461e2c78STakashi Iwai 		.private_value = 0x1a,
1604461e2c78STakashi Iwai 	},
1605461e2c78STakashi Iwai 
1606461e2c78STakashi Iwai 	{}
1607461e2c78STakashi Iwai };
1608461e2c78STakashi Iwai 
1609461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = {
1610461e2c78STakashi Iwai 	/* Line in, Mic */
1611461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1612461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1613461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1614461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1615461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1616461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1617461e2c78STakashi Iwai 	/* SPK  */
1618461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1619461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1620461e2c78STakashi Iwai 	/* HP, Amp  */
1621461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1622461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1623461e2c78STakashi Iwai 	/* DAC1 */
1624461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1625461e2c78STakashi Iwai 	/* Record selector: Int mic */
1626461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1627461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1628461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1629461e2c78STakashi Iwai 	/* SPDIF route: PCM */
1630461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1631461e2c78STakashi Iwai 	/* EAPD */
1632461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1633461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1634461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1635461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1636461e2c78STakashi Iwai 	{ } /* end */
1637461e2c78STakashi Iwai };
1638461e2c78STakashi Iwai 
1639461e2c78STakashi Iwai /* initialize jack-sensing, too */
1640461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1641461e2c78STakashi Iwai {
1642461e2c78STakashi Iwai 	conexant_init(codec);
1643461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1644461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1645461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1646461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1647461e2c78STakashi Iwai 	}
1648461e2c78STakashi Iwai 	return 0;
1649461e2c78STakashi Iwai }
1650461e2c78STakashi Iwai 
1651461e2c78STakashi Iwai 
1652461e2c78STakashi Iwai enum {
1653461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1654461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
1655461e2c78STakashi Iwai 	CXT5051_MODELS
1656461e2c78STakashi Iwai };
1657461e2c78STakashi Iwai 
1658461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = {
1659461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1660461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
1661461e2c78STakashi Iwai };
1662461e2c78STakashi Iwai 
1663461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1664461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1665461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1666461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1667461e2c78STakashi Iwai 	{}
1668461e2c78STakashi Iwai };
1669461e2c78STakashi Iwai 
1670461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1671461e2c78STakashi Iwai {
1672461e2c78STakashi Iwai 	struct conexant_spec *spec;
1673461e2c78STakashi Iwai 	int board_config;
1674461e2c78STakashi Iwai 
1675461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1676461e2c78STakashi Iwai 	if (!spec)
1677461e2c78STakashi Iwai 		return -ENOMEM;
1678461e2c78STakashi Iwai 	mutex_init(&spec->amp_mutex);
1679461e2c78STakashi Iwai 	codec->spec = spec;
1680461e2c78STakashi Iwai 
1681461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
1682461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
1683461e2c78STakashi Iwai 
1684461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
1685461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1686461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
1687461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1688461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1689461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
1690461e2c78STakashi Iwai 	spec->num_mixers = 1;
1691461e2c78STakashi Iwai 	spec->mixers[0] = cxt5051_mixers;
1692461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
1693461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
1694461e2c78STakashi Iwai 	spec->spdif_route = 0;
1695461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1696461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
1697461e2c78STakashi Iwai 	spec->cur_adc = 0;
1698461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
1699461e2c78STakashi Iwai 
1700461e2c78STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1701461e2c78STakashi Iwai 						  cxt5051_models,
1702461e2c78STakashi Iwai 						  cxt5051_cfg_tbl);
1703461e2c78STakashi Iwai 	switch (board_config) {
1704461e2c78STakashi Iwai 	case CXT5051_HP:
1705461e2c78STakashi Iwai 		codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1706461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
1707461e2c78STakashi Iwai 		break;
1708461e2c78STakashi Iwai 	default:
1709461e2c78STakashi Iwai 	case CXT5051_LAPTOP:
1710461e2c78STakashi Iwai 		codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1711461e2c78STakashi Iwai 		break;
1712461e2c78STakashi Iwai 	}
1713461e2c78STakashi Iwai 
1714461e2c78STakashi Iwai 	return 0;
1715461e2c78STakashi Iwai }
1716461e2c78STakashi Iwai 
1717461e2c78STakashi Iwai 
1718461e2c78STakashi Iwai /*
1719461e2c78STakashi Iwai  */
1720461e2c78STakashi Iwai 
1721c9b443d4STobin Davis struct hda_codec_preset snd_hda_preset_conexant[] = {
172282f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
172382f30040STobin Davis 	  .patch = patch_cxt5045 },
172482f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
172582f30040STobin Davis 	  .patch = patch_cxt5047 },
1726461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1727461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
1728c9b443d4STobin Davis 	{} /* terminator */
1729c9b443d4STobin Davis };
1730