xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision 9e4641541e9681a568483133813332cfafa34d86)
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"
303c9a3203SHarvey Harrison #include "hda_patch.h"
31c9b443d4STobin Davis 
32c9b443d4STobin Davis #define CXT_PIN_DIR_IN              0x00
33c9b443d4STobin Davis #define CXT_PIN_DIR_OUT             0x01
34c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT           0x02
35c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
36c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
37c9b443d4STobin Davis 
38c9b443d4STobin Davis #define CONEXANT_HP_EVENT	0x37
39c9b443d4STobin Davis #define CONEXANT_MIC_EVENT	0x38
40c9b443d4STobin Davis 
41c9b443d4STobin Davis 
42c9b443d4STobin Davis 
43c9b443d4STobin Davis struct conexant_spec {
44c9b443d4STobin Davis 
45c9b443d4STobin Davis 	struct snd_kcontrol_new *mixers[5];
46c9b443d4STobin Davis 	int num_mixers;
47c9b443d4STobin Davis 
48c9b443d4STobin Davis 	const struct hda_verb *init_verbs[5];	/* initialization verbs
49c9b443d4STobin Davis 						 * don't forget NULL
50c9b443d4STobin Davis 						 * termination!
51c9b443d4STobin Davis 						 */
52c9b443d4STobin Davis 	unsigned int num_init_verbs;
53c9b443d4STobin Davis 
54c9b443d4STobin Davis 	/* playback */
55c9b443d4STobin Davis 	struct hda_multi_out multiout;	/* playback set-up
56c9b443d4STobin Davis 					 * max_channels, dacs must be set
57c9b443d4STobin Davis 					 * dig_out_nid and hp_nid are optional
58c9b443d4STobin Davis 					 */
59c9b443d4STobin Davis 	unsigned int cur_eapd;
6082f30040STobin Davis 	unsigned int hp_present;
61c9b443d4STobin Davis 	unsigned int need_dac_fix;
62c9b443d4STobin Davis 
63c9b443d4STobin Davis 	/* capture */
64c9b443d4STobin Davis 	unsigned int num_adc_nids;
65c9b443d4STobin Davis 	hda_nid_t *adc_nids;
66c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
67c9b443d4STobin Davis 
68461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
69461e2c78STakashi Iwai 	hda_nid_t cur_adc;
70461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
71461e2c78STakashi Iwai 	unsigned int cur_adc_format;
72461e2c78STakashi Iwai 
73c9b443d4STobin Davis 	/* capture source */
74c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
75c9b443d4STobin Davis 	hda_nid_t *capsrc_nids;
76c9b443d4STobin Davis 	unsigned int cur_mux[3];
77c9b443d4STobin Davis 
78c9b443d4STobin Davis 	/* channel model */
79c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
80c9b443d4STobin Davis 	int num_channel_mode;
81c9b443d4STobin Davis 
82c9b443d4STobin Davis 	/* PCM information */
83c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
84c9b443d4STobin Davis 
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;
1019a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1029a08160bSTakashi Iwai 					     hinfo);
103c9b443d4STobin Davis }
104c9b443d4STobin Davis 
105c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
106c9b443d4STobin Davis 					 struct hda_codec *codec,
107c9b443d4STobin Davis 					 unsigned int stream_tag,
108c9b443d4STobin Davis 					 unsigned int format,
109c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
110c9b443d4STobin Davis {
111c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
112c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
113c9b443d4STobin Davis 						stream_tag,
114c9b443d4STobin Davis 						format, substream);
115c9b443d4STobin Davis }
116c9b443d4STobin Davis 
117c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
118c9b443d4STobin Davis 					 struct hda_codec *codec,
119c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
120c9b443d4STobin Davis {
121c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
122c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
123c9b443d4STobin Davis }
124c9b443d4STobin Davis 
125c9b443d4STobin Davis /*
126c9b443d4STobin Davis  * Digital out
127c9b443d4STobin Davis  */
128c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
129c9b443d4STobin Davis 					  struct hda_codec *codec,
130c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
131c9b443d4STobin Davis {
132c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
133c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
134c9b443d4STobin Davis }
135c9b443d4STobin Davis 
136c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
137c9b443d4STobin Davis 					 struct hda_codec *codec,
138c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
139c9b443d4STobin Davis {
140c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
141c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
142c9b443d4STobin Davis }
143c9b443d4STobin Davis 
1446b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1456b97eb45STakashi Iwai 					 struct hda_codec *codec,
1466b97eb45STakashi Iwai 					 unsigned int stream_tag,
1476b97eb45STakashi Iwai 					 unsigned int format,
1486b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
1496b97eb45STakashi Iwai {
1506b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1516b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1526b97eb45STakashi Iwai 					     stream_tag,
1536b97eb45STakashi Iwai 					     format, substream);
1546b97eb45STakashi Iwai }
1556b97eb45STakashi Iwai 
156c9b443d4STobin Davis /*
157c9b443d4STobin Davis  * Analog capture
158c9b443d4STobin Davis  */
159c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
160c9b443d4STobin Davis 				      struct hda_codec *codec,
161c9b443d4STobin Davis 				      unsigned int stream_tag,
162c9b443d4STobin Davis 				      unsigned int format,
163c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
164c9b443d4STobin Davis {
165c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
166c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
167c9b443d4STobin Davis 				   stream_tag, 0, format);
168c9b443d4STobin Davis 	return 0;
169c9b443d4STobin Davis }
170c9b443d4STobin Davis 
171c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
172c9b443d4STobin Davis 				      struct hda_codec *codec,
173c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
174c9b443d4STobin Davis {
175c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
176888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
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;
244888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
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";
2877ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
288c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
289c9b443d4STobin Davis 			conexant_pcm_digital_playback;
290c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
291c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
292c9b443d4STobin Davis 		if (spec->dig_in_nid) {
293c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
294c9b443d4STobin Davis 				conexant_pcm_digital_capture;
295c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
296c9b443d4STobin Davis 				spec->dig_in_nid;
297c9b443d4STobin Davis 		}
298c9b443d4STobin Davis 	}
299c9b443d4STobin Davis 
300c9b443d4STobin Davis 	return 0;
301c9b443d4STobin Davis }
302c9b443d4STobin Davis 
303c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
304c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
305c9b443d4STobin Davis {
306c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
307c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
308c9b443d4STobin Davis 
309c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
310c9b443d4STobin Davis }
311c9b443d4STobin Davis 
312c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
313c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
314c9b443d4STobin Davis {
315c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
316c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
317c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
318c9b443d4STobin Davis 
319c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
320c9b443d4STobin Davis 	return 0;
321c9b443d4STobin Davis }
322c9b443d4STobin Davis 
323c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
324c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
325c9b443d4STobin Davis {
326c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
328c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
329c9b443d4STobin Davis 
330c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
331c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
332c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
333c9b443d4STobin Davis }
334c9b443d4STobin Davis 
335c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
336c9b443d4STobin Davis {
337c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
338c9b443d4STobin Davis 	int i;
339c9b443d4STobin Davis 
340c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
341c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
342c9b443d4STobin Davis 	return 0;
343c9b443d4STobin Davis }
344c9b443d4STobin Davis 
345c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
346c9b443d4STobin Davis {
347c9b443d4STobin Davis         struct conexant_spec *spec = codec->spec;
348c9b443d4STobin Davis         unsigned int i;
349c9b443d4STobin Davis 
350c9b443d4STobin Davis         if (spec->kctl_alloc) {
351c9b443d4STobin Davis                 for (i = 0; i < spec->num_kctl_used; i++)
352c9b443d4STobin Davis                         kfree(spec->kctl_alloc[i].name);
353c9b443d4STobin Davis                 kfree(spec->kctl_alloc);
354c9b443d4STobin Davis         }
355c9b443d4STobin Davis 
356c9b443d4STobin Davis 	kfree(codec->spec);
357c9b443d4STobin Davis }
358c9b443d4STobin Davis 
359c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
360c9b443d4STobin Davis {
361c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
362c9b443d4STobin Davis 	unsigned int i;
363c9b443d4STobin Davis 	int err;
364c9b443d4STobin Davis 
365c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
366c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
367c9b443d4STobin Davis 		if (err < 0)
368c9b443d4STobin Davis 			return err;
369c9b443d4STobin Davis 	}
370c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
371c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
372c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
373c9b443d4STobin Davis 		if (err < 0)
374c9b443d4STobin Davis 			return err;
3759a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
3769a08160bSTakashi Iwai 						    &spec->multiout);
3779a08160bSTakashi Iwai 		if (err < 0)
3789a08160bSTakashi Iwai 			return err;
3799a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
380c9b443d4STobin Davis 	}
381c9b443d4STobin Davis 	if (spec->dig_in_nid) {
382c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
383c9b443d4STobin Davis 		if (err < 0)
384c9b443d4STobin Davis 			return err;
385c9b443d4STobin Davis 	}
386c9b443d4STobin Davis 	return 0;
387c9b443d4STobin Davis }
388c9b443d4STobin Davis 
389c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
390c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
391c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
392c9b443d4STobin Davis 	.init = conexant_init,
393c9b443d4STobin Davis 	.free = conexant_free,
394c9b443d4STobin Davis };
395c9b443d4STobin Davis 
396c9b443d4STobin Davis /*
397c9b443d4STobin Davis  * EAPD control
398c9b443d4STobin Davis  * the private value = nid | (invert << 8)
399c9b443d4STobin Davis  */
400c9b443d4STobin Davis 
401a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
402c9b443d4STobin Davis 
40382f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
404c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
405c9b443d4STobin Davis {
406c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
408c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
409c9b443d4STobin Davis 	if (invert)
410c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
411c9b443d4STobin Davis 	else
412c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
413c9b443d4STobin Davis 	return 0;
41482f30040STobin Davis 
415c9b443d4STobin Davis }
416c9b443d4STobin Davis 
41782f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
418c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
419c9b443d4STobin Davis {
420c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
421c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
422c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
423c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
424c9b443d4STobin Davis 	unsigned int eapd;
42582f30040STobin Davis 
42668ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
427c9b443d4STobin Davis 	if (invert)
428c9b443d4STobin Davis 		eapd = !eapd;
42982beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
430c9b443d4STobin Davis 		return 0;
43182f30040STobin Davis 
432c9b443d4STobin Davis 	spec->cur_eapd = eapd;
43382beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
434c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
435c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
436c9b443d4STobin Davis 	return 1;
437c9b443d4STobin Davis }
438c9b443d4STobin Davis 
43986d72bdfSTakashi Iwai /* controls for test mode */
44086d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
44186d72bdfSTakashi Iwai 
44282f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
44382f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
44482f30040STobin Davis 	  .info = cxt_eapd_info, \
44582f30040STobin Davis 	  .get = cxt_eapd_get, \
44682f30040STobin Davis 	  .put = cxt_eapd_put, \
44782f30040STobin Davis 	  .private_value = nid | (mask<<16) }
44882f30040STobin Davis 
44982f30040STobin Davis 
45082f30040STobin Davis 
451c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
452c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
453c9b443d4STobin Davis {
454c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
455c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
456c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
457c9b443d4STobin Davis 				    spec->num_channel_mode);
458c9b443d4STobin Davis }
459c9b443d4STobin Davis 
460c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
461c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
462c9b443d4STobin Davis {
463c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
464c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
465c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
466c9b443d4STobin Davis 				   spec->num_channel_mode,
467c9b443d4STobin Davis 				   spec->multiout.max_channels);
468c9b443d4STobin Davis }
469c9b443d4STobin Davis 
470c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
471c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
472c9b443d4STobin Davis {
473c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
474c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
475c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
476c9b443d4STobin Davis 				      spec->num_channel_mode,
477c9b443d4STobin Davis 				      &spec->multiout.max_channels);
478c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
479c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
480c9b443d4STobin Davis 	return err;
481c9b443d4STobin Davis }
482c9b443d4STobin Davis 
483c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
484c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
485c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
486c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
487c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
488c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
489c9b443d4STobin Davis 
49086d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
49186d72bdfSTakashi Iwai 
492c9b443d4STobin Davis /* Conexant 5045 specific */
493c9b443d4STobin Davis 
494c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
495c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
496c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
497cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
498c9b443d4STobin Davis 
4995cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
5005cd57529STobin Davis 	{ 2, NULL },
5015cd57529STobin Davis };
502c9b443d4STobin Davis 
503c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
504c9b443d4STobin Davis 	.num_items = 2,
505c9b443d4STobin Davis 	.items = {
50682f30040STobin Davis 		{ "IntMic", 0x1 },
507f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
508c9b443d4STobin Davis 	}
509c9b443d4STobin Davis };
510c9b443d4STobin Davis 
5115218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = {
5125218c892SJiang Zhe 	.num_items = 3,
5135218c892SJiang Zhe 	.items = {
5145218c892SJiang Zhe 		{ "IntMic", 0x1 },
5155218c892SJiang Zhe 		{ "ExtMic", 0x2 },
5165218c892SJiang Zhe 		{ "LineIn", 0x3 },
5175218c892SJiang Zhe 	}
5185218c892SJiang Zhe };
5195218c892SJiang Zhe 
5202de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = {
5212de3c232SJiang zhe 	.num_items = 2,
5222de3c232SJiang zhe 	.items = {
5232de3c232SJiang zhe 		{ "ExtMic", 0x1 },
5242de3c232SJiang zhe 		{ "IntMic", 0x2 },
5252de3c232SJiang zhe 	}
5262de3c232SJiang zhe };
5272de3c232SJiang zhe 
528c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
529c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
530c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
531c9b443d4STobin Davis {
532c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
533c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
53482f30040STobin Davis 	unsigned int bits;
535c9b443d4STobin Davis 
53682f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
537c9b443d4STobin Davis 		return 0;
538c9b443d4STobin Davis 
53982f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
54082f30040STobin Davis 	 * the headphone jack
54182f30040STobin Davis 	 */
54247fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
54347fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
54447fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
5457f29673bSTobin Davis 
54647fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
54747fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
54847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
549c9b443d4STobin Davis 	return 1;
550c9b443d4STobin Davis }
551c9b443d4STobin Davis 
552c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
553cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
554cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
555cca3b371STakashi Iwai 	.values = {
556cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
557cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
558cca3b371STakashi Iwai 		0
559cca3b371STakashi Iwai 	},
560cca3b371STakashi Iwai };
561c9b443d4STobin Davis 
5627f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
5637f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
5647f29673bSTobin Davis {
5657f29673bSTobin Davis 	static struct hda_verb mic_jack_on[] = {
5667f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
5677f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5687f29673bSTobin Davis 		{}
5697f29673bSTobin Davis 	};
5707f29673bSTobin Davis 	static struct hda_verb mic_jack_off[] = {
5717f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
5727f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5737f29673bSTobin Davis 		{}
5747f29673bSTobin Davis 	};
5757f29673bSTobin Davis 	unsigned int present;
5767f29673bSTobin Davis 
5777f29673bSTobin Davis 	present = snd_hda_codec_read(codec, 0x12, 0,
5787f29673bSTobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5797f29673bSTobin Davis 	if (present)
5807f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
5817f29673bSTobin Davis 	else
5827f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
5837f29673bSTobin Davis }
5847f29673bSTobin Davis 
585c9b443d4STobin Davis 
586c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
587c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
588c9b443d4STobin Davis {
58982f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
590dd87da1cSTobin Davis 	unsigned int bits;
591c9b443d4STobin Davis 
59282f30040STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
593c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
594dd87da1cSTobin Davis 
59547fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
59647fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
59747fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
598c9b443d4STobin Davis }
599c9b443d4STobin Davis 
600c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
601c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
602c9b443d4STobin Davis 				   unsigned int res)
603c9b443d4STobin Davis {
604c9b443d4STobin Davis 	res >>= 26;
605c9b443d4STobin Davis 	switch (res) {
606c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
607c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
608c9b443d4STobin Davis 		break;
6097f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
6107f29673bSTobin Davis 		cxt5045_hp_automic(codec);
6117f29673bSTobin Davis 		break;
6127f29673bSTobin Davis 
613c9b443d4STobin Davis 	}
614c9b443d4STobin Davis }
615c9b443d4STobin Davis 
616c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
617c9b443d4STobin Davis 	{
618c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
619c9b443d4STobin Davis 		.name = "Capture Source",
620c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
621c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
622c9b443d4STobin Davis 		.put = conexant_mux_enum_put
623c9b443d4STobin Davis 	},
624c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
625c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
626c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
627c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
628c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
629c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
630c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
631c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
632c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
633c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
634cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
635c9b443d4STobin Davis 	{
636c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
637c9b443d4STobin Davis 		.name = "Master Playback Switch",
63882f30040STobin Davis 		.info = cxt_eapd_info,
63982f30040STobin Davis 		.get = cxt_eapd_get,
640c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
64182f30040STobin Davis 		.private_value = 0x10,
642c9b443d4STobin Davis 	},
643c9b443d4STobin Davis 
644c9b443d4STobin Davis 	{}
645c9b443d4STobin Davis };
646c9b443d4STobin Davis 
6475218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
6485218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
6495218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
6505218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
6515218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
6525218c892SJiang Zhe 
6535218c892SJiang Zhe 	{}
6545218c892SJiang Zhe };
6555218c892SJiang Zhe 
6562de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
6572de3c232SJiang zhe 	{
6582de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6592de3c232SJiang zhe 		.name = "Capture Source",
6602de3c232SJiang zhe 		.info = conexant_mux_enum_info,
6612de3c232SJiang zhe 		.get = conexant_mux_enum_get,
6622de3c232SJiang zhe 		.put = conexant_mux_enum_put
6632de3c232SJiang zhe 	},
6642de3c232SJiang zhe 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
6652de3c232SJiang zhe 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
6662de3c232SJiang zhe 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
6672de3c232SJiang zhe 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
6682de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
6692de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
6702de3c232SJiang zhe 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
6712de3c232SJiang zhe 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
6722de3c232SJiang zhe 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
6732de3c232SJiang zhe 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
6742de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
6752de3c232SJiang zhe 	{
6762de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6772de3c232SJiang zhe 		.name = "Master Playback Switch",
6782de3c232SJiang zhe 		.info = cxt_eapd_info,
6792de3c232SJiang zhe 		.get = cxt_eapd_get,
6802de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
6812de3c232SJiang zhe 		.private_value = 0x10,
6822de3c232SJiang zhe 	},
6832de3c232SJiang zhe 
6842de3c232SJiang zhe 	{}
6852de3c232SJiang zhe };
6862de3c232SJiang zhe 
687c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
688c9b443d4STobin Davis 	/* Line in, Mic */
6894090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
6907f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
691c9b443d4STobin Davis 	/* HP, Amp  */
692c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
693c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
69482f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
695c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
696c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
697c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
698c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
699c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
700c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
70182f30040STobin Davis 	/* Record selector: Int mic */
7027f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
70382f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
704c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
705c9b443d4STobin Davis 	/* SPDIF route: PCM */
706cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
707c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
708c9b443d4STobin Davis 	/* EAPD */
70982f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
710c9b443d4STobin Davis 	{ } /* end */
711c9b443d4STobin Davis };
712c9b443d4STobin Davis 
7135218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = {
7145218c892SJiang Zhe 	/* Int Mic, Mic */
7155218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
7165218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
7175218c892SJiang Zhe 	/* Line In,HP, Amp  */
7185218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7195218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
7205218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7215218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
7225218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7235218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7245218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7255218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7265218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7275218c892SJiang Zhe 	/* Record selector: Int mic */
7285218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
7295218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
7305218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
7315218c892SJiang Zhe 	/* SPDIF route: PCM */
732cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7335218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
7345218c892SJiang Zhe 	/* EAPD */
7355218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
7365218c892SJiang Zhe 	{ } /* end */
7375218c892SJiang Zhe };
7387f29673bSTobin Davis 
7397f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
7407f29673bSTobin Davis 	/* pin sensing on HP jack */
7417f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
742d3091fadSTakashi Iwai 	{ } /* end */
7437f29673bSTobin Davis };
7447f29673bSTobin Davis 
7457f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
7467f29673bSTobin Davis 	/* pin sensing on HP jack */
7477f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
748d3091fadSTakashi Iwai 	{ } /* end */
7497f29673bSTobin Davis };
7507f29673bSTobin Davis 
751c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
752c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
753c9b443d4STobin Davis  * configuration.
754c9b443d4STobin Davis  */
755c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
756c9b443d4STobin Davis 	.num_items = 5,
757c9b443d4STobin Davis 	.items = {
758c9b443d4STobin Davis 		{ "MIXER", 0x0 },
759c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
760c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
761c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
762c9b443d4STobin Davis 		{ "CD pin", 0x4 },
763c9b443d4STobin Davis         },
764c9b443d4STobin Davis };
765c9b443d4STobin Davis 
766c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
767c9b443d4STobin Davis 
768c9b443d4STobin Davis 	/* Output controls */
769c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
770c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
7717f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
7727f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
7737f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
7747f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
775c9b443d4STobin Davis 
776c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
777c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
778c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
779c9b443d4STobin Davis 
78082f30040STobin Davis 	/* EAPD Switch Control */
78182f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
78282f30040STobin Davis 
783c9b443d4STobin Davis 	/* Loopback mixer controls */
784c9b443d4STobin Davis 
7857f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
7867f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
7877f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
7887f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
7897f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
7907f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
7917f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
7927f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
7937f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
7947f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
795c9b443d4STobin Davis 	{
796c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
797c9b443d4STobin Davis 		.name = "Input Source",
798c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
799c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
800c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
801c9b443d4STobin Davis 	},
802fb3409e7STobin Davis 	/* Audio input controls */
803fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
804fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
805fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
806fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
807fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
808fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
809fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
810fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
811fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
812fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
813c9b443d4STobin Davis 	{ } /* end */
814c9b443d4STobin Davis };
815c9b443d4STobin Davis 
816c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
8177f29673bSTobin Davis 	/* Set connections */
8187f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
8197f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
8207f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
821c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
822c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8237f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
824c9b443d4STobin Davis 
825c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
826c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
827c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
828c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
829c9b443d4STobin Davis 	 * control.
830c9b443d4STobin Davis 	 */
831cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
832cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
833c9b443d4STobin Davis 
834c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
835c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
836c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
837c9b443d4STobin Davis 
838c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
839c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
840c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
841c9b443d4STobin Davis 	 * input/output buffers as needed.
842c9b443d4STobin Davis 	 */
843c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
844c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
845c9b443d4STobin Davis 
846c9b443d4STobin Davis 	/* Mute capture amp left and right */
847c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
848c9b443d4STobin Davis 
849c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
850c9b443d4STobin Davis 	 * pin)
851c9b443d4STobin Davis 	 */
852c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8537f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
854c9b443d4STobin Davis 
855c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
856c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
857c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
858c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
859c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
860c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
861c9b443d4STobin Davis 
862c9b443d4STobin Davis 	{ }
863c9b443d4STobin Davis };
864c9b443d4STobin Davis #endif
865c9b443d4STobin Davis 
866c9b443d4STobin Davis 
867c9b443d4STobin Davis /* initialize jack-sensing, too */
868c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
869c9b443d4STobin Davis {
870c9b443d4STobin Davis 	conexant_init(codec);
871c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
872c9b443d4STobin Davis 	return 0;
873c9b443d4STobin Davis }
874c9b443d4STobin Davis 
875c9b443d4STobin Davis 
876c9b443d4STobin Davis enum {
87715908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
87815908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
87915908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
8805218c892SJiang Zhe 	CXT5045_BENQ,
8812de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
882c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
883c9b443d4STobin Davis 	CXT5045_TEST,
884c9b443d4STobin Davis #endif
885f5fcc13cSTakashi Iwai 	CXT5045_MODELS
886c9b443d4STobin Davis };
887c9b443d4STobin Davis 
888f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = {
88915908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
89015908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
89115908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
8925218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
8932de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
894c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
895f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
896c9b443d4STobin Davis #endif
897f5fcc13cSTakashi Iwai };
898c9b443d4STobin Davis 
899f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
90015908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
90115908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
90215908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
90315908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
90415908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
90515908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
9060f6a5156STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
9072de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
90815908c36SMarc Boucher 	SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
9096a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
9105218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
91115908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
91215908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
913*9e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
914*9e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
91515908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
91615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
91715908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
91815908c36SMarc Boucher 	SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
91915908c36SMarc Boucher 	SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
92015908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
921c9b443d4STobin Davis 	{}
922c9b443d4STobin Davis };
923c9b443d4STobin Davis 
924c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
925c9b443d4STobin Davis {
926c9b443d4STobin Davis 	struct conexant_spec *spec;
927c9b443d4STobin Davis 	int board_config;
928c9b443d4STobin Davis 
929c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
930c9b443d4STobin Davis 	if (!spec)
931c9b443d4STobin Davis 		return -ENOMEM;
932c9b443d4STobin Davis 	codec->spec = spec;
933c9b443d4STobin Davis 
934c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
935c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
936c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
937c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
938c9b443d4STobin Davis 	spec->num_adc_nids = 1;
939c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
940c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
941c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
942c9b443d4STobin Davis 	spec->num_mixers = 1;
943c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
944c9b443d4STobin Davis 	spec->num_init_verbs = 1;
945c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
946c9b443d4STobin Davis 	spec->spdif_route = 0;
9475cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
9485cd57529STobin Davis 	spec->channel_mode = cxt5045_modes,
9495cd57529STobin Davis 
950c9b443d4STobin Davis 
951c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
952c9b443d4STobin Davis 
953f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
954f5fcc13cSTakashi Iwai 						  cxt5045_models,
955f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
956c9b443d4STobin Davis 	switch (board_config) {
95715908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
9587f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
959c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
960c9b443d4STobin Davis 		spec->num_init_verbs = 2;
9617f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
9627f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
9637f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
9647f29673bSTobin Davis 		break;
96515908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
96686376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
9677f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
9687f29673bSTobin Davis 		spec->num_init_verbs = 2;
9697f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
970c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
971c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
972c9b443d4STobin Davis 		break;
97315908c36SMarc Boucher 	default:
97415908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
97515908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
97615908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
97715908c36SMarc Boucher 		spec->num_init_verbs = 3;
97815908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
97915908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
98015908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
98115908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
98215908c36SMarc Boucher 		break;
9835218c892SJiang Zhe 	case CXT5045_BENQ:
9845218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
9855218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
9865218c892SJiang Zhe 		spec->num_init_verbs = 1;
9875218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
9885218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
9895218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
9905218c892SJiang Zhe 		spec->num_mixers = 2;
9915218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
9925218c892SJiang Zhe 		break;
9932de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
9942de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
9952de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
9962de3c232SJiang zhe 		spec->num_init_verbs = 2;
9972de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
9982de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
9992de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
10002de3c232SJiang zhe 		break;
1001c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1002c9b443d4STobin Davis 	case CXT5045_TEST:
1003c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1004c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1005c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
100615908c36SMarc Boucher 		break;
100715908c36SMarc Boucher 
1008c9b443d4STobin Davis #endif
1009c9b443d4STobin Davis 	}
101048ecb7e8STakashi Iwai 
1011031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1012031005f7STakashi Iwai 	case 0x103c:
1013031005f7STakashi Iwai 		/* HP laptop has a really bad sound over 0dB on NID 0x17.
101448ecb7e8STakashi Iwai 		 * Fix max PCM level to 0 dB
101548ecb7e8STakashi Iwai 		 * (originall it has 0x2b steps with 0dB offset 0x14)
101648ecb7e8STakashi Iwai 		 */
101748ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
101848ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
101948ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
102048ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
102148ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1022031005f7STakashi Iwai 		break;
1023031005f7STakashi Iwai 	}
102448ecb7e8STakashi Iwai 
1025c9b443d4STobin Davis 	return 0;
1026c9b443d4STobin Davis }
1027c9b443d4STobin Davis 
1028c9b443d4STobin Davis 
1029c9b443d4STobin Davis /* Conexant 5047 specific */
103082f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1031c9b443d4STobin Davis 
103282f30040STobin Davis static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
1033c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1034c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1035c9b443d4STobin Davis 
10365cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
10375cd57529STobin Davis 	{ 2, NULL },
10385cd57529STobin Davis };
1039c9b443d4STobin Davis 
1040c9b443d4STobin Davis static struct hda_input_mux cxt5047_capture_source = {
10417f29673bSTobin Davis 	.num_items = 1,
1042c9b443d4STobin Davis 	.items = {
10437f29673bSTobin Davis 		{ "Mic", 0x2 },
1044c9b443d4STobin Davis 	}
1045c9b443d4STobin Davis };
1046c9b443d4STobin Davis 
1047c9b443d4STobin Davis static struct hda_input_mux cxt5047_hp_capture_source = {
1048c9b443d4STobin Davis 	.num_items = 1,
1049c9b443d4STobin Davis 	.items = {
105082f30040STobin Davis 		{ "ExtMic", 0x2 },
105182f30040STobin Davis 	}
105282f30040STobin Davis };
105382f30040STobin Davis 
105482f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
105582f30040STobin Davis 	.num_items = 2,
105682f30040STobin Davis 	.items = {
105782f30040STobin Davis 		{ "ExtMic", 0x2 },
105882f30040STobin Davis 		{ "Line-In", 0x1 },
1059c9b443d4STobin Davis 	}
1060c9b443d4STobin Davis };
1061c9b443d4STobin Davis 
1062c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1063c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1064c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1065c9b443d4STobin Davis {
1066c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1067c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
106882f30040STobin Davis 	unsigned int bits;
1069c9b443d4STobin Davis 
107082f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1071c9b443d4STobin Davis 		return 0;
1072c9b443d4STobin Davis 
107382f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
107482f30040STobin Davis 	 * the headphone jack
107582f30040STobin Davis 	 */
107647fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
107747fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
107847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
107947fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
108047fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
108147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1082c9b443d4STobin Davis 	return 1;
1083c9b443d4STobin Davis }
1084c9b443d4STobin Davis 
108582f30040STobin Davis /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
1086cca3b371STakashi Iwai static struct hda_bind_ctls cxt5047_bind_master_vol = {
1087cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
1088cca3b371STakashi Iwai 	.values = {
1089cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1090cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1091cca3b371STakashi Iwai 		0
1092cca3b371STakashi Iwai 	},
1093cca3b371STakashi Iwai };
1094c9b443d4STobin Davis 
1095c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1096c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1097c9b443d4STobin Davis {
109882f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1099dd87da1cSTobin Davis 	unsigned int bits;
1100c9b443d4STobin Davis 
110182f30040STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1102c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1103dd87da1cSTobin Davis 
110447fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
110547fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
110647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
110782f30040STobin Davis 	/* Mute/Unmute PCM 2 for good measure - some systems need this */
110847fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
110947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1110c9b443d4STobin Davis }
1111c9b443d4STobin Davis 
1112fb3409e7STobin Davis /* mute internal speaker if HP is plugged */
1113fb3409e7STobin Davis static void cxt5047_hp2_automute(struct hda_codec *codec)
1114fb3409e7STobin Davis {
1115fb3409e7STobin Davis 	struct conexant_spec *spec = codec->spec;
1116fb3409e7STobin Davis 	unsigned int bits;
1117fb3409e7STobin Davis 
1118fb3409e7STobin Davis 	spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1119fb3409e7STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1120fb3409e7STobin Davis 
112147fd830aSTakashi Iwai 	bits = spec->hp_present ? HDA_AMP_MUTE : 0;
112247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
112347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1124fb3409e7STobin Davis 	/* Mute/Unmute PCM 2 for good measure - some systems need this */
112547fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
112647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1127fb3409e7STobin Davis }
1128fb3409e7STobin Davis 
1129c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1130c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1131c9b443d4STobin Davis {
1132c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
11339f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11349f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1135c9b443d4STobin Davis 		{}
1136c9b443d4STobin Davis 	};
1137c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
11389f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11399f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1140c9b443d4STobin Davis 		{}
1141c9b443d4STobin Davis 	};
1142c9b443d4STobin Davis 	unsigned int present;
1143c9b443d4STobin Davis 
11447f29673bSTobin Davis 	present = snd_hda_codec_read(codec, 0x15, 0,
1145c9b443d4STobin Davis 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1146c9b443d4STobin Davis 	if (present)
1147c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1148c9b443d4STobin Davis 	else
1149c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1150c9b443d4STobin Davis }
1151c9b443d4STobin Davis 
1152c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1153c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1154c9b443d4STobin Davis 				  unsigned int res)
1155c9b443d4STobin Davis {
11569f113e0eSMarc Boucher 	switch (res >> 26) {
1157c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1158c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1159c9b443d4STobin Davis 		break;
1160c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1161c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1162c9b443d4STobin Davis 		break;
1163c9b443d4STobin Davis 	}
1164c9b443d4STobin Davis }
1165c9b443d4STobin Davis 
1166fb3409e7STobin Davis /* unsolicited event for HP jack sensing - non-EAPD systems */
1167fb3409e7STobin Davis static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1168fb3409e7STobin Davis 				  unsigned int res)
1169fb3409e7STobin Davis {
1170fb3409e7STobin Davis 	res >>= 26;
1171fb3409e7STobin Davis 	switch (res) {
1172fb3409e7STobin Davis 	case CONEXANT_HP_EVENT:
1173fb3409e7STobin Davis 		cxt5047_hp2_automute(codec);
1174fb3409e7STobin Davis 		break;
1175fb3409e7STobin Davis 	case CONEXANT_MIC_EVENT:
1176fb3409e7STobin Davis 		cxt5047_hp_automic(codec);
1177fb3409e7STobin Davis 		break;
1178fb3409e7STobin Davis 	}
1179fb3409e7STobin Davis }
1180fb3409e7STobin Davis 
1181c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_mixers[] = {
1182c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1183c9b443d4STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
11847f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
11857f29673bSTobin Davis 	HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
1186c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1187c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1188c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1189c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
119082f30040STobin Davis 	HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
119182f30040STobin Davis 	HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1192b7589cebSTobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1193b7589cebSTobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1194b7589cebSTobin Davis 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1195b7589cebSTobin Davis 	HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
119682f30040STobin Davis 
119782f30040STobin Davis 	{}
119882f30040STobin Davis };
119982f30040STobin Davis 
120082f30040STobin Davis static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
120182f30040STobin Davis 	{
120282f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
120382f30040STobin Davis 		.name = "Capture Source",
120482f30040STobin Davis 		.info = conexant_mux_enum_info,
120582f30040STobin Davis 		.get = conexant_mux_enum_get,
120682f30040STobin Davis 		.put = conexant_mux_enum_put
120782f30040STobin Davis 	},
120882f30040STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
120982f30040STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
121082f30040STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
121182f30040STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
121282f30040STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
121382f30040STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1214cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
121582f30040STobin Davis 	{
121682f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
121782f30040STobin Davis 		.name = "Master Playback Switch",
121882f30040STobin Davis 		.info = cxt_eapd_info,
121982f30040STobin Davis 		.get = cxt_eapd_get,
1220c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1221c9b443d4STobin Davis 		.private_value = 0x13,
1222c9b443d4STobin Davis 	},
1223c9b443d4STobin Davis 
1224c9b443d4STobin Davis 	{}
1225c9b443d4STobin Davis };
1226c9b443d4STobin Davis 
1227c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1228c9b443d4STobin Davis 	{
1229c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1230c9b443d4STobin Davis 		.name = "Capture Source",
1231c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1232c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1233c9b443d4STobin Davis 		.put = conexant_mux_enum_put
1234c9b443d4STobin Davis 	},
1235c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1236c9b443d4STobin Davis 	HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1237c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1238c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1239c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1240c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1241c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1242c9b443d4STobin Davis 	{
1243c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1244c9b443d4STobin Davis 		.name = "Master Playback Switch",
124582f30040STobin Davis 		.info = cxt_eapd_info,
124682f30040STobin Davis 		.get = cxt_eapd_get,
1247c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1248c9b443d4STobin Davis 		.private_value = 0x13,
1249c9b443d4STobin Davis 	},
1250c9b443d4STobin Davis 	{ } /* end */
1251c9b443d4STobin Davis };
1252c9b443d4STobin Davis 
1253c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1254c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1255c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1256c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1257c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
12587f29673bSTobin Davis 	/* HP, Speaker  */
1259b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1260b7589cebSTobin Davis 	{0x13, AC_VERB_SET_CONNECT_SEL,0x1},
12617f29673bSTobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
12627f29673bSTobin Davis 	/* Record selector: Mic */
12637f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
12647f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
12657f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
12667f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1267c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1268c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1269c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1270c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1271c9b443d4STobin Davis 	/* SPDIF route: PCM */
1272c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
127382f30040STobin Davis 	/* Enable unsolicited events */
127482f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
127582f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1276c9b443d4STobin Davis 	{ } /* end */
1277c9b443d4STobin Davis };
1278c9b443d4STobin Davis 
1279c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1280c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1281c9b443d4STobin Davis 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1282c9b443d4STobin Davis 	/* pin sensing on HP and Mic jacks */
1283c9b443d4STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1284c9b443d4STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
128582f30040STobin Davis 	/* Speaker routing */
128682f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1287c9b443d4STobin Davis 	{}
1288c9b443d4STobin Davis };
1289c9b443d4STobin Davis 
1290c9b443d4STobin Davis /* configuration for HP Laptops */
1291c9b443d4STobin Davis static struct hda_verb cxt5047_hp_init_verbs[] = {
129282f30040STobin Davis 	/* pin sensing on HP jack */
1293c9b443d4STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1294b84f08d4STakashi Iwai 	/* 0x13 is actually shared by both HP and speaker;
1295b84f08d4STakashi Iwai 	 * setting the connection to 0 (=0x19) makes the master volume control
1296b84f08d4STakashi Iwai 	 * working mysteriouslly...
1297b84f08d4STakashi Iwai 	 */
1298b84f08d4STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
129982f30040STobin Davis 	/* Record selector: Ext Mic */
130082f30040STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
130182f30040STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
130282f30040STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
130382f30040STobin Davis 	/* Speaker routing */
130482f30040STobin Davis 	{0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1305c9b443d4STobin Davis 	{}
1306c9b443d4STobin Davis };
1307c9b443d4STobin Davis 
1308c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1309c9b443d4STobin Davis  * configuration.
1310c9b443d4STobin Davis  */
1311c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1312c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
131382f30040STobin Davis 	.num_items = 4,
1314c9b443d4STobin Davis 	.items = {
131582f30040STobin Davis 		{ "LINE1 pin", 0x0 },
131682f30040STobin Davis 		{ "MIC1 pin", 0x1 },
131782f30040STobin Davis 		{ "MIC2 pin", 0x2 },
131882f30040STobin Davis 		{ "CD pin", 0x3 },
1319c9b443d4STobin Davis         },
1320c9b443d4STobin Davis };
1321c9b443d4STobin Davis 
1322c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1323c9b443d4STobin Davis 
1324c9b443d4STobin Davis 	/* Output only controls */
132582f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
132682f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
132782f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
132882f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1329c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1330c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1331c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1332c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
133382f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
133482f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
133582f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
133682f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1337c9b443d4STobin Davis 
1338c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1339c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1340c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1341c9b443d4STobin Davis 
134282f30040STobin Davis 	/* EAPD Switch Control */
134382f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
134482f30040STobin Davis 
1345c9b443d4STobin Davis 	/* Loopback mixer controls */
134682f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
134782f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
134882f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
134982f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
135082f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
135182f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
135282f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
135382f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1354c9b443d4STobin Davis 
135582f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
135682f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
135782f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
135882f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
135982f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
136082f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
136182f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
136282f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1363c9b443d4STobin Davis 	{
1364c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1365c9b443d4STobin Davis 		.name = "Input Source",
1366c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1367c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1368c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1369c9b443d4STobin Davis 	},
13709f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
13719f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
13729f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
13739f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
13749f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
13759f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
13769f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
13779f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
13789f113e0eSMarc Boucher 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
13799f113e0eSMarc Boucher 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
13809f113e0eSMarc Boucher 
1381c9b443d4STobin Davis 	{ } /* end */
1382c9b443d4STobin Davis };
1383c9b443d4STobin Davis 
1384c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1385c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1386c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1387c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1388c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1389c9b443d4STobin Davis 
1390c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1391c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1392c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1393c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1394c9b443d4STobin Davis 	 * control.
1395c9b443d4STobin Davis 	 */
1396c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1397c9b443d4STobin Davis 
1398c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1399c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1400c9b443d4STobin Davis 	 */
1401c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1402c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1403c9b443d4STobin Davis 
1404c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1405c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1406c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1407c9b443d4STobin Davis 
1408c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1409c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1410c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1411c9b443d4STobin Davis 	 * input/output buffers as needed.
1412c9b443d4STobin Davis 	 */
1413c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1414c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1415c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1416c9b443d4STobin Davis 
1417c9b443d4STobin Davis 	/* Mute capture amp left and right */
1418c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1419c9b443d4STobin Davis 
1420c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1421c9b443d4STobin Davis 	 * pin)
1422c9b443d4STobin Davis 	 */
1423c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1424c9b443d4STobin Davis 
1425c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1426c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1427c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1428c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1429c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1430c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1431c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1432c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1433c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1434c9b443d4STobin Davis 
1435c9b443d4STobin Davis 	{ }
1436c9b443d4STobin Davis };
1437c9b443d4STobin Davis #endif
1438c9b443d4STobin Davis 
1439c9b443d4STobin Davis 
1440c9b443d4STobin Davis /* initialize jack-sensing, too */
1441c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1442c9b443d4STobin Davis {
1443c9b443d4STobin Davis 	conexant_init(codec);
1444c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1445c9b443d4STobin Davis 	return 0;
1446c9b443d4STobin Davis }
1447c9b443d4STobin Davis 
1448c9b443d4STobin Davis 
1449c9b443d4STobin Davis enum {
1450f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1451f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1452f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1453c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1454c9b443d4STobin Davis 	CXT5047_TEST,
1455c9b443d4STobin Davis #endif
1456f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1457c9b443d4STobin Davis };
1458c9b443d4STobin Davis 
1459f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = {
1460f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1461f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1462f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1463c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1464f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1465c9b443d4STobin Davis #endif
1466f5fcc13cSTakashi Iwai };
1467c9b443d4STobin Davis 
1468f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1469f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1470ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1471f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
147282f30040STobin Davis 	SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
1473f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1474c9b443d4STobin Davis 	{}
1475c9b443d4STobin Davis };
1476c9b443d4STobin Davis 
1477c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1478c9b443d4STobin Davis {
1479c9b443d4STobin Davis 	struct conexant_spec *spec;
1480c9b443d4STobin Davis 	int board_config;
1481c9b443d4STobin Davis 
1482c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1483c9b443d4STobin Davis 	if (!spec)
1484c9b443d4STobin Davis 		return -ENOMEM;
1485c9b443d4STobin Davis 	codec->spec = spec;
1486c9b443d4STobin Davis 
1487c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1488c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1489c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1490c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1491c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1492c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1493c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1494c9b443d4STobin Davis 	spec->input_mux = &cxt5047_capture_source;
1495c9b443d4STobin Davis 	spec->num_mixers = 1;
1496c9b443d4STobin Davis 	spec->mixers[0] = cxt5047_mixers;
1497c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1498c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1499c9b443d4STobin Davis 	spec->spdif_route = 0;
15005cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
15015cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1502c9b443d4STobin Davis 
1503c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1504c9b443d4STobin Davis 
1505f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1506f5fcc13cSTakashi Iwai 						  cxt5047_models,
1507f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1508c9b443d4STobin Davis 	switch (board_config) {
1509c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1510fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
1511c9b443d4STobin Davis 		break;
1512c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1513c9b443d4STobin Davis 		spec->input_mux = &cxt5047_hp_capture_source;
1514c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1515c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_hp_init_verbs;
1516c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_hp_mixers;
1517fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1518c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1519c9b443d4STobin Davis 		break;
1520c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
152182f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1522c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1523c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
152482f30040STobin Davis 		spec->mixers[0] = cxt5047_toshiba_mixers;
1525fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1526c9b443d4STobin Davis 		break;
1527c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1528c9b443d4STobin Davis 	case CXT5047_TEST:
1529c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1530c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1531c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1532fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1533c9b443d4STobin Davis #endif
1534c9b443d4STobin Davis 	}
1535c9b443d4STobin Davis 	return 0;
1536c9b443d4STobin Davis }
1537c9b443d4STobin Davis 
1538461e2c78STakashi Iwai /* Conexant 5051 specific */
1539461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1540461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1541461e2c78STakashi Iwai #define CXT5051_SPDIF_OUT	0x1C
1542461e2c78STakashi Iwai #define CXT5051_PORTB_EVENT	0x38
1543461e2c78STakashi Iwai #define CXT5051_PORTC_EVENT	0x39
1544461e2c78STakashi Iwai 
1545461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = {
1546461e2c78STakashi Iwai 	{ 2, NULL },
1547461e2c78STakashi Iwai };
1548461e2c78STakashi Iwai 
1549461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1550461e2c78STakashi Iwai {
1551461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1552461e2c78STakashi Iwai 	unsigned int pinctl;
1553461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1554461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1555461e2c78STakashi Iwai 			    pinctl);
1556461e2c78STakashi Iwai }
1557461e2c78STakashi Iwai 
1558461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1559461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1560461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1561461e2c78STakashi Iwai {
1562461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1563461e2c78STakashi Iwai 
1564461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1565461e2c78STakashi Iwai 		return 0;
1566461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1567461e2c78STakashi Iwai 	return 1;
1568461e2c78STakashi Iwai }
1569461e2c78STakashi Iwai 
1570461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1571461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1572461e2c78STakashi Iwai {
1573461e2c78STakashi Iwai 	unsigned int present;
1574461e2c78STakashi Iwai 
1575461e2c78STakashi Iwai 	present = snd_hda_codec_read(codec, 0x17, 0,
1576461e2c78STakashi Iwai 				     AC_VERB_GET_PIN_SENSE, 0) &
1577461e2c78STakashi Iwai 		AC_PINSENSE_PRESENCE;
1578461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1579461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1580461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1581461e2c78STakashi Iwai }
1582461e2c78STakashi Iwai 
1583461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1584461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1585461e2c78STakashi Iwai {
1586461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1587461e2c78STakashi Iwai 	unsigned int present;
1588461e2c78STakashi Iwai 	hda_nid_t new_adc;
1589461e2c78STakashi Iwai 
1590461e2c78STakashi Iwai 	present = snd_hda_codec_read(codec, 0x18, 0,
1591461e2c78STakashi Iwai 				     AC_VERB_GET_PIN_SENSE, 0) &
1592461e2c78STakashi Iwai 		AC_PINSENSE_PRESENCE;
1593461e2c78STakashi Iwai 	if (present)
1594461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1595461e2c78STakashi Iwai 	else
1596461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1597461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1598461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1599461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1600888afa15STakashi Iwai 		snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1601461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1602461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1603461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1604461e2c78STakashi Iwai 					   spec->cur_adc_format);
1605461e2c78STakashi Iwai 	}
1606461e2c78STakashi Iwai }
1607461e2c78STakashi Iwai 
1608461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1609461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1610461e2c78STakashi Iwai {
1611461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1612461e2c78STakashi Iwai 
1613461e2c78STakashi Iwai 	spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1614461e2c78STakashi Iwai 				     AC_VERB_GET_PIN_SENSE, 0) &
1615461e2c78STakashi Iwai 		AC_PINSENSE_PRESENCE;
1616461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1617461e2c78STakashi Iwai }
1618461e2c78STakashi Iwai 
1619461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1620461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1621461e2c78STakashi Iwai 				   unsigned int res)
1622461e2c78STakashi Iwai {
1623461e2c78STakashi Iwai 	switch (res >> 26) {
1624461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1625461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1626461e2c78STakashi Iwai 		break;
1627461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1628461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1629461e2c78STakashi Iwai 		break;
1630461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1631461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1632461e2c78STakashi Iwai 		break;
1633461e2c78STakashi Iwai 	}
1634461e2c78STakashi Iwai }
1635461e2c78STakashi Iwai 
1636461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_mixers[] = {
1637461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1638461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1639461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1640461e2c78STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1641461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1642461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1643461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1644461e2c78STakashi Iwai 	{
1645461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1646461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1647461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1648461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1649461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1650461e2c78STakashi Iwai 		.private_value = 0x1a,
1651461e2c78STakashi Iwai 	},
1652461e2c78STakashi Iwai 
1653461e2c78STakashi Iwai 	{}
1654461e2c78STakashi Iwai };
1655461e2c78STakashi Iwai 
1656461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1657461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1658461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1659461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1660461e2c78STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1661461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1662461e2c78STakashi Iwai 	{
1663461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1664461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1665461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1666461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1667461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1668461e2c78STakashi Iwai 		.private_value = 0x1a,
1669461e2c78STakashi Iwai 	},
1670461e2c78STakashi Iwai 
1671461e2c78STakashi Iwai 	{}
1672461e2c78STakashi Iwai };
1673461e2c78STakashi Iwai 
1674461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = {
1675461e2c78STakashi Iwai 	/* Line in, Mic */
1676461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1677461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1678461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1679461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1680461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1681461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1682461e2c78STakashi Iwai 	/* SPK  */
1683461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1684461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1685461e2c78STakashi Iwai 	/* HP, Amp  */
1686461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1687461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1688461e2c78STakashi Iwai 	/* DAC1 */
1689461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1690461e2c78STakashi Iwai 	/* Record selector: Int mic */
1691461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1692461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1693461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1694461e2c78STakashi Iwai 	/* SPDIF route: PCM */
1695461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1696461e2c78STakashi Iwai 	/* EAPD */
1697461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1698461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1699461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1700461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1701461e2c78STakashi Iwai 	{ } /* end */
1702461e2c78STakashi Iwai };
1703461e2c78STakashi Iwai 
1704461e2c78STakashi Iwai /* initialize jack-sensing, too */
1705461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1706461e2c78STakashi Iwai {
1707461e2c78STakashi Iwai 	conexant_init(codec);
1708461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1709461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1710461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1711461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1712461e2c78STakashi Iwai 	}
1713461e2c78STakashi Iwai 	return 0;
1714461e2c78STakashi Iwai }
1715461e2c78STakashi Iwai 
1716461e2c78STakashi Iwai 
1717461e2c78STakashi Iwai enum {
1718461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1719461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
1720461e2c78STakashi Iwai 	CXT5051_MODELS
1721461e2c78STakashi Iwai };
1722461e2c78STakashi Iwai 
1723461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = {
1724461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1725461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
1726461e2c78STakashi Iwai };
1727461e2c78STakashi Iwai 
1728461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1729461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1730461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1731461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1732461e2c78STakashi Iwai 	{}
1733461e2c78STakashi Iwai };
1734461e2c78STakashi Iwai 
1735461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1736461e2c78STakashi Iwai {
1737461e2c78STakashi Iwai 	struct conexant_spec *spec;
1738461e2c78STakashi Iwai 	int board_config;
1739461e2c78STakashi Iwai 
1740461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1741461e2c78STakashi Iwai 	if (!spec)
1742461e2c78STakashi Iwai 		return -ENOMEM;
1743461e2c78STakashi Iwai 	codec->spec = spec;
1744461e2c78STakashi Iwai 
1745461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
1746461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
1747461e2c78STakashi Iwai 
1748461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
1749461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1750461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
1751461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1752461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1753461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
1754461e2c78STakashi Iwai 	spec->num_mixers = 1;
1755461e2c78STakashi Iwai 	spec->mixers[0] = cxt5051_mixers;
1756461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
1757461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
1758461e2c78STakashi Iwai 	spec->spdif_route = 0;
1759461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1760461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
1761461e2c78STakashi Iwai 	spec->cur_adc = 0;
1762461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
1763461e2c78STakashi Iwai 
1764461e2c78STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1765461e2c78STakashi Iwai 						  cxt5051_models,
1766461e2c78STakashi Iwai 						  cxt5051_cfg_tbl);
1767461e2c78STakashi Iwai 	switch (board_config) {
1768461e2c78STakashi Iwai 	case CXT5051_HP:
1769461e2c78STakashi Iwai 		codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1770461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
1771461e2c78STakashi Iwai 		break;
1772461e2c78STakashi Iwai 	default:
1773461e2c78STakashi Iwai 	case CXT5051_LAPTOP:
1774461e2c78STakashi Iwai 		codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1775461e2c78STakashi Iwai 		break;
1776461e2c78STakashi Iwai 	}
1777461e2c78STakashi Iwai 
1778461e2c78STakashi Iwai 	return 0;
1779461e2c78STakashi Iwai }
1780461e2c78STakashi Iwai 
1781461e2c78STakashi Iwai 
1782461e2c78STakashi Iwai /*
1783461e2c78STakashi Iwai  */
1784461e2c78STakashi Iwai 
1785c9b443d4STobin Davis struct hda_codec_preset snd_hda_preset_conexant[] = {
178682f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
178782f30040STobin Davis 	  .patch = patch_cxt5045 },
178882f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
178982f30040STobin Davis 	  .patch = patch_cxt5047 },
1790461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1791461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
1792c9b443d4STobin Davis 	{} /* terminator */
1793c9b443d4STobin Davis };
1794