xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision 7dd65feb)
1 /*
2  * HD audio interface patch for Conexant HDA audio codec
3  *
4  * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5  * 		      Takashi Iwai <tiwai@suse.de>
6  * 		      Tobin Davis  <tdavis@dsl-only.net>
7  *
8  *  This driver is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This driver is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22 
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
27 #include <sound/core.h>
28 #include <sound/jack.h>
29 
30 #include "hda_codec.h"
31 #include "hda_local.h"
32 #include "hda_beep.h"
33 
34 #define CXT_PIN_DIR_IN              0x00
35 #define CXT_PIN_DIR_OUT             0x01
36 #define CXT_PIN_DIR_INOUT           0x02
37 #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
38 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39 
40 #define CONEXANT_HP_EVENT	0x37
41 #define CONEXANT_MIC_EVENT	0x38
42 
43 /* Conexant 5051 specific */
44 
45 #define CXT5051_SPDIF_OUT	0x1C
46 #define CXT5051_PORTB_EVENT	0x38
47 #define CXT5051_PORTC_EVENT	0x39
48 
49 
50 struct conexant_jack {
51 
52 	hda_nid_t nid;
53 	int type;
54 	struct snd_jack *jack;
55 
56 };
57 
58 struct conexant_spec {
59 
60 	struct snd_kcontrol_new *mixers[5];
61 	int num_mixers;
62 	hda_nid_t vmaster_nid;
63 
64 	const struct hda_verb *init_verbs[5];	/* initialization verbs
65 						 * don't forget NULL
66 						 * termination!
67 						 */
68 	unsigned int num_init_verbs;
69 
70 	/* playback */
71 	struct hda_multi_out multiout;	/* playback set-up
72 					 * max_channels, dacs must be set
73 					 * dig_out_nid and hp_nid are optional
74 					 */
75 	unsigned int cur_eapd;
76 	unsigned int hp_present;
77 	unsigned int no_auto_mic;
78 	unsigned int need_dac_fix;
79 
80 	/* capture */
81 	unsigned int num_adc_nids;
82 	hda_nid_t *adc_nids;
83 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
84 
85 	unsigned int cur_adc_idx;
86 	hda_nid_t cur_adc;
87 	unsigned int cur_adc_stream_tag;
88 	unsigned int cur_adc_format;
89 
90 	/* capture source */
91 	const struct hda_input_mux *input_mux;
92 	hda_nid_t *capsrc_nids;
93 	unsigned int cur_mux[3];
94 
95 	/* channel model */
96 	const struct hda_channel_mode *channel_mode;
97 	int num_channel_mode;
98 
99 	/* PCM information */
100 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
101 
102 	unsigned int spdif_route;
103 
104 	/* jack detection */
105 	struct snd_array jacks;
106 
107 	/* dynamic controls, init_verbs and input_mux */
108 	struct auto_pin_cfg autocfg;
109 	struct hda_input_mux private_imux;
110 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
111 
112 	unsigned int dell_automute;
113 	unsigned int port_d_mode;
114 	unsigned char ext_mic_bias;
115 	unsigned int dell_vostro;
116 };
117 
118 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
119 				      struct hda_codec *codec,
120 				      struct snd_pcm_substream *substream)
121 {
122 	struct conexant_spec *spec = codec->spec;
123 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
124 					     hinfo);
125 }
126 
127 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
128 					 struct hda_codec *codec,
129 					 unsigned int stream_tag,
130 					 unsigned int format,
131 					 struct snd_pcm_substream *substream)
132 {
133 	struct conexant_spec *spec = codec->spec;
134 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
135 						stream_tag,
136 						format, substream);
137 }
138 
139 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
140 					 struct hda_codec *codec,
141 					 struct snd_pcm_substream *substream)
142 {
143 	struct conexant_spec *spec = codec->spec;
144 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
145 }
146 
147 /*
148  * Digital out
149  */
150 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
151 					  struct hda_codec *codec,
152 					  struct snd_pcm_substream *substream)
153 {
154 	struct conexant_spec *spec = codec->spec;
155 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
156 }
157 
158 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
159 					 struct hda_codec *codec,
160 					 struct snd_pcm_substream *substream)
161 {
162 	struct conexant_spec *spec = codec->spec;
163 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
164 }
165 
166 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
167 					 struct hda_codec *codec,
168 					 unsigned int stream_tag,
169 					 unsigned int format,
170 					 struct snd_pcm_substream *substream)
171 {
172 	struct conexant_spec *spec = codec->spec;
173 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
174 					     stream_tag,
175 					     format, substream);
176 }
177 
178 /*
179  * Analog capture
180  */
181 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
182 				      struct hda_codec *codec,
183 				      unsigned int stream_tag,
184 				      unsigned int format,
185 				      struct snd_pcm_substream *substream)
186 {
187 	struct conexant_spec *spec = codec->spec;
188 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
189 				   stream_tag, 0, format);
190 	return 0;
191 }
192 
193 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
194 				      struct hda_codec *codec,
195 				      struct snd_pcm_substream *substream)
196 {
197 	struct conexant_spec *spec = codec->spec;
198 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
199 	return 0;
200 }
201 
202 
203 
204 static struct hda_pcm_stream conexant_pcm_analog_playback = {
205 	.substreams = 1,
206 	.channels_min = 2,
207 	.channels_max = 2,
208 	.nid = 0, /* fill later */
209 	.ops = {
210 		.open = conexant_playback_pcm_open,
211 		.prepare = conexant_playback_pcm_prepare,
212 		.cleanup = conexant_playback_pcm_cleanup
213 	},
214 };
215 
216 static struct hda_pcm_stream conexant_pcm_analog_capture = {
217 	.substreams = 1,
218 	.channels_min = 2,
219 	.channels_max = 2,
220 	.nid = 0, /* fill later */
221 	.ops = {
222 		.prepare = conexant_capture_pcm_prepare,
223 		.cleanup = conexant_capture_pcm_cleanup
224 	},
225 };
226 
227 
228 static struct hda_pcm_stream conexant_pcm_digital_playback = {
229 	.substreams = 1,
230 	.channels_min = 2,
231 	.channels_max = 2,
232 	.nid = 0, /* fill later */
233 	.ops = {
234 		.open = conexant_dig_playback_pcm_open,
235 		.close = conexant_dig_playback_pcm_close,
236 		.prepare = conexant_dig_playback_pcm_prepare
237 	},
238 };
239 
240 static struct hda_pcm_stream conexant_pcm_digital_capture = {
241 	.substreams = 1,
242 	.channels_min = 2,
243 	.channels_max = 2,
244 	/* NID is set in alc_build_pcms */
245 };
246 
247 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
248 				      struct hda_codec *codec,
249 				      unsigned int stream_tag,
250 				      unsigned int format,
251 				      struct snd_pcm_substream *substream)
252 {
253 	struct conexant_spec *spec = codec->spec;
254 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
255 	spec->cur_adc_stream_tag = stream_tag;
256 	spec->cur_adc_format = format;
257 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
258 	return 0;
259 }
260 
261 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
262 				      struct hda_codec *codec,
263 				      struct snd_pcm_substream *substream)
264 {
265 	struct conexant_spec *spec = codec->spec;
266 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
267 	spec->cur_adc = 0;
268 	return 0;
269 }
270 
271 static struct hda_pcm_stream cx5051_pcm_analog_capture = {
272 	.substreams = 1,
273 	.channels_min = 2,
274 	.channels_max = 2,
275 	.nid = 0, /* fill later */
276 	.ops = {
277 		.prepare = cx5051_capture_pcm_prepare,
278 		.cleanup = cx5051_capture_pcm_cleanup
279 	},
280 };
281 
282 static int conexant_build_pcms(struct hda_codec *codec)
283 {
284 	struct conexant_spec *spec = codec->spec;
285 	struct hda_pcm *info = spec->pcm_rec;
286 
287 	codec->num_pcms = 1;
288 	codec->pcm_info = info;
289 
290 	info->name = "CONEXANT Analog";
291 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
292 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
293 		spec->multiout.max_channels;
294 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
295 		spec->multiout.dac_nids[0];
296 	if (codec->vendor_id == 0x14f15051)
297 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
298 			cx5051_pcm_analog_capture;
299 	else
300 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
301 			conexant_pcm_analog_capture;
302 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
303 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
304 
305 	if (spec->multiout.dig_out_nid) {
306 		info++;
307 		codec->num_pcms++;
308 		info->name = "Conexant Digital";
309 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
310 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
311 			conexant_pcm_digital_playback;
312 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
313 			spec->multiout.dig_out_nid;
314 		if (spec->dig_in_nid) {
315 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
316 				conexant_pcm_digital_capture;
317 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
318 				spec->dig_in_nid;
319 		}
320 	}
321 
322 	return 0;
323 }
324 
325 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
326 	       			  struct snd_ctl_elem_info *uinfo)
327 {
328 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
329 	struct conexant_spec *spec = codec->spec;
330 
331 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
332 }
333 
334 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
335 				 struct snd_ctl_elem_value *ucontrol)
336 {
337 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
338 	struct conexant_spec *spec = codec->spec;
339 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
340 
341 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
342 	return 0;
343 }
344 
345 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
346 				 struct snd_ctl_elem_value *ucontrol)
347 {
348 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
349 	struct conexant_spec *spec = codec->spec;
350 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
351 
352 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
353 				     spec->capsrc_nids[adc_idx],
354 				     &spec->cur_mux[adc_idx]);
355 }
356 
357 #ifdef CONFIG_SND_HDA_INPUT_JACK
358 static void conexant_free_jack_priv(struct snd_jack *jack)
359 {
360 	struct conexant_jack *jacks = jack->private_data;
361 	jacks->nid = 0;
362 	jacks->jack = NULL;
363 }
364 
365 static int conexant_add_jack(struct hda_codec *codec,
366 		hda_nid_t nid, int type)
367 {
368 	struct conexant_spec *spec;
369 	struct conexant_jack *jack;
370 	const char *name;
371 	int err;
372 
373 	spec = codec->spec;
374 	snd_array_init(&spec->jacks, sizeof(*jack), 32);
375 	jack = snd_array_new(&spec->jacks);
376 	name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
377 
378 	if (!jack)
379 		return -ENOMEM;
380 
381 	jack->nid = nid;
382 	jack->type = type;
383 
384 	err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
385 	if (err < 0)
386 		return err;
387 	jack->jack->private_data = jack;
388 	jack->jack->private_free = conexant_free_jack_priv;
389 	return 0;
390 }
391 
392 static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
393 {
394 	struct conexant_spec *spec = codec->spec;
395 	struct conexant_jack *jacks = spec->jacks.list;
396 
397 	if (jacks) {
398 		int i;
399 		for (i = 0; i < spec->jacks.used; i++) {
400 			if (jacks->nid == nid) {
401 				unsigned int present;
402 				present = snd_hda_jack_detect(codec, nid);
403 
404 				present = (present) ? jacks->type : 0 ;
405 
406 				snd_jack_report(jacks->jack,
407 						present);
408 			}
409 			jacks++;
410 		}
411 	}
412 }
413 
414 static int conexant_init_jacks(struct hda_codec *codec)
415 {
416 	struct conexant_spec *spec = codec->spec;
417 	int i;
418 
419 	for (i = 0; i < spec->num_init_verbs; i++) {
420 		const struct hda_verb *hv;
421 
422 		hv = spec->init_verbs[i];
423 		while (hv->nid) {
424 			int err = 0;
425 			switch (hv->param ^ AC_USRSP_EN) {
426 			case CONEXANT_HP_EVENT:
427 				err = conexant_add_jack(codec, hv->nid,
428 						SND_JACK_HEADPHONE);
429 				conexant_report_jack(codec, hv->nid);
430 				break;
431 			case CXT5051_PORTC_EVENT:
432 			case CONEXANT_MIC_EVENT:
433 				err = conexant_add_jack(codec, hv->nid,
434 						SND_JACK_MICROPHONE);
435 				conexant_report_jack(codec, hv->nid);
436 				break;
437 			}
438 			if (err < 0)
439 				return err;
440 			++hv;
441 		}
442 	}
443 	return 0;
444 
445 }
446 #else
447 static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
448 {
449 }
450 
451 static inline int conexant_init_jacks(struct hda_codec *codec)
452 {
453 	return 0;
454 }
455 #endif
456 
457 static int conexant_init(struct hda_codec *codec)
458 {
459 	struct conexant_spec *spec = codec->spec;
460 	int i;
461 
462 	for (i = 0; i < spec->num_init_verbs; i++)
463 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
464 	return 0;
465 }
466 
467 static void conexant_free(struct hda_codec *codec)
468 {
469 #ifdef CONFIG_SND_HDA_INPUT_JACK
470 	struct conexant_spec *spec = codec->spec;
471 	if (spec->jacks.list) {
472 		struct conexant_jack *jacks = spec->jacks.list;
473 		int i;
474 		for (i = 0; i < spec->jacks.used; i++, jacks++) {
475 			if (jacks->jack)
476 				snd_device_free(codec->bus->card, jacks->jack);
477 		}
478 		snd_array_free(&spec->jacks);
479 	}
480 #endif
481 	snd_hda_detach_beep_device(codec);
482 	kfree(codec->spec);
483 }
484 
485 static struct snd_kcontrol_new cxt_capture_mixers[] = {
486 	{
487 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
488 		.name = "Capture Source",
489 		.info = conexant_mux_enum_info,
490 		.get = conexant_mux_enum_get,
491 		.put = conexant_mux_enum_put
492 	},
493 	{}
494 };
495 
496 static const char *slave_vols[] = {
497 	"Headphone Playback Volume",
498 	"Speaker Playback Volume",
499 	NULL
500 };
501 
502 static const char *slave_sws[] = {
503 	"Headphone Playback Switch",
504 	"Speaker Playback Switch",
505 	NULL
506 };
507 
508 static int conexant_build_controls(struct hda_codec *codec)
509 {
510 	struct conexant_spec *spec = codec->spec;
511 	unsigned int i;
512 	int err;
513 
514 	for (i = 0; i < spec->num_mixers; i++) {
515 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
516 		if (err < 0)
517 			return err;
518 	}
519 	if (spec->multiout.dig_out_nid) {
520 		err = snd_hda_create_spdif_out_ctls(codec,
521 						    spec->multiout.dig_out_nid);
522 		if (err < 0)
523 			return err;
524 		err = snd_hda_create_spdif_share_sw(codec,
525 						    &spec->multiout);
526 		if (err < 0)
527 			return err;
528 		spec->multiout.share_spdif = 1;
529 	}
530 	if (spec->dig_in_nid) {
531 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
532 		if (err < 0)
533 			return err;
534 	}
535 
536 	/* if we have no master control, let's create it */
537 	if (spec->vmaster_nid &&
538 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
539 		unsigned int vmaster_tlv[4];
540 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
541 					HDA_OUTPUT, vmaster_tlv);
542 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
543 					  vmaster_tlv, slave_vols);
544 		if (err < 0)
545 			return err;
546 	}
547 	if (spec->vmaster_nid &&
548 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
549 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
550 					  NULL, slave_sws);
551 		if (err < 0)
552 			return err;
553 	}
554 
555 	if (spec->input_mux) {
556 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
557 		if (err < 0)
558 			return err;
559 	}
560 
561 	return 0;
562 }
563 
564 static struct hda_codec_ops conexant_patch_ops = {
565 	.build_controls = conexant_build_controls,
566 	.build_pcms = conexant_build_pcms,
567 	.init = conexant_init,
568 	.free = conexant_free,
569 };
570 
571 /*
572  * EAPD control
573  * the private value = nid | (invert << 8)
574  */
575 
576 #define cxt_eapd_info		snd_ctl_boolean_mono_info
577 
578 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
579 			     struct snd_ctl_elem_value *ucontrol)
580 {
581 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
582 	struct conexant_spec *spec = codec->spec;
583 	int invert = (kcontrol->private_value >> 8) & 1;
584 	if (invert)
585 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
586 	else
587 		ucontrol->value.integer.value[0] = spec->cur_eapd;
588 	return 0;
589 
590 }
591 
592 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
593 			     struct snd_ctl_elem_value *ucontrol)
594 {
595 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
596 	struct conexant_spec *spec = codec->spec;
597 	int invert = (kcontrol->private_value >> 8) & 1;
598 	hda_nid_t nid = kcontrol->private_value & 0xff;
599 	unsigned int eapd;
600 
601 	eapd = !!ucontrol->value.integer.value[0];
602 	if (invert)
603 		eapd = !eapd;
604 	if (eapd == spec->cur_eapd)
605 		return 0;
606 
607 	spec->cur_eapd = eapd;
608 	snd_hda_codec_write_cache(codec, nid,
609 				  0, AC_VERB_SET_EAPD_BTLENABLE,
610 				  eapd ? 0x02 : 0x00);
611 	return 1;
612 }
613 
614 /* controls for test mode */
615 #ifdef CONFIG_SND_DEBUG
616 
617 #define CXT_EAPD_SWITCH(xname, nid, mask) \
618 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
619 	  .info = cxt_eapd_info, \
620 	  .get = cxt_eapd_get, \
621 	  .put = cxt_eapd_put, \
622 	  .private_value = nid | (mask<<16) }
623 
624 
625 
626 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
627 				 struct snd_ctl_elem_info *uinfo)
628 {
629 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
630 	struct conexant_spec *spec = codec->spec;
631 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
632 				    spec->num_channel_mode);
633 }
634 
635 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
636 				struct snd_ctl_elem_value *ucontrol)
637 {
638 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639 	struct conexant_spec *spec = codec->spec;
640 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
641 				   spec->num_channel_mode,
642 				   spec->multiout.max_channels);
643 }
644 
645 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
646 				struct snd_ctl_elem_value *ucontrol)
647 {
648 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
649 	struct conexant_spec *spec = codec->spec;
650 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
651 				      spec->num_channel_mode,
652 				      &spec->multiout.max_channels);
653 	if (err >= 0 && spec->need_dac_fix)
654 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
655 	return err;
656 }
657 
658 #define CXT_PIN_MODE(xname, nid, dir) \
659 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
660 	  .info = conexant_ch_mode_info, \
661 	  .get = conexant_ch_mode_get, \
662 	  .put = conexant_ch_mode_put, \
663 	  .private_value = nid | (dir<<16) }
664 
665 #endif /* CONFIG_SND_DEBUG */
666 
667 /* Conexant 5045 specific */
668 
669 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
670 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
671 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
672 #define CXT5045_SPDIF_OUT	0x18
673 
674 static struct hda_channel_mode cxt5045_modes[1] = {
675 	{ 2, NULL },
676 };
677 
678 static struct hda_input_mux cxt5045_capture_source = {
679 	.num_items = 2,
680 	.items = {
681 		{ "IntMic", 0x1 },
682 		{ "ExtMic", 0x2 },
683 	}
684 };
685 
686 static struct hda_input_mux cxt5045_capture_source_benq = {
687 	.num_items = 5,
688 	.items = {
689 		{ "IntMic", 0x1 },
690 		{ "ExtMic", 0x2 },
691 		{ "LineIn", 0x3 },
692 		{ "CD",     0x4 },
693 		{ "Mixer",  0x0 },
694 	}
695 };
696 
697 static struct hda_input_mux cxt5045_capture_source_hp530 = {
698 	.num_items = 2,
699 	.items = {
700 		{ "ExtMic", 0x1 },
701 		{ "IntMic", 0x2 },
702 	}
703 };
704 
705 /* turn on/off EAPD (+ mute HP) as a master switch */
706 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
707 				    struct snd_ctl_elem_value *ucontrol)
708 {
709 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
710 	struct conexant_spec *spec = codec->spec;
711 	unsigned int bits;
712 
713 	if (!cxt_eapd_put(kcontrol, ucontrol))
714 		return 0;
715 
716 	/* toggle internal speakers mute depending of presence of
717 	 * the headphone jack
718 	 */
719 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
720 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
721 				 HDA_AMP_MUTE, bits);
722 
723 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
724 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
725 				 HDA_AMP_MUTE, bits);
726 	return 1;
727 }
728 
729 /* bind volumes of both NID 0x10 and 0x11 */
730 static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
731 	.ops = &snd_hda_bind_vol,
732 	.values = {
733 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
734 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
735 		0
736 	},
737 };
738 
739 /* toggle input of built-in and mic jack appropriately */
740 static void cxt5045_hp_automic(struct hda_codec *codec)
741 {
742 	static struct hda_verb mic_jack_on[] = {
743 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
744 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
745 		{}
746 	};
747 	static struct hda_verb mic_jack_off[] = {
748 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
749 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
750 		{}
751 	};
752 	unsigned int present;
753 
754 	present = snd_hda_jack_detect(codec, 0x12);
755 	if (present)
756 		snd_hda_sequence_write(codec, mic_jack_on);
757 	else
758 		snd_hda_sequence_write(codec, mic_jack_off);
759 }
760 
761 
762 /* mute internal speaker if HP is plugged */
763 static void cxt5045_hp_automute(struct hda_codec *codec)
764 {
765 	struct conexant_spec *spec = codec->spec;
766 	unsigned int bits;
767 
768 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
769 
770 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
771 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
772 				 HDA_AMP_MUTE, bits);
773 }
774 
775 /* unsolicited event for HP jack sensing */
776 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
777 				   unsigned int res)
778 {
779 	res >>= 26;
780 	switch (res) {
781 	case CONEXANT_HP_EVENT:
782 		cxt5045_hp_automute(codec);
783 		break;
784 	case CONEXANT_MIC_EVENT:
785 		cxt5045_hp_automic(codec);
786 		break;
787 
788 	}
789 }
790 
791 static struct snd_kcontrol_new cxt5045_mixers[] = {
792 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
793 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
794 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
795 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
796 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
797 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
798 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
799 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
800 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
801 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
802 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
803 	{
804 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
805 		.name = "Master Playback Switch",
806 		.info = cxt_eapd_info,
807 		.get = cxt_eapd_get,
808 		.put = cxt5045_hp_master_sw_put,
809 		.private_value = 0x10,
810 	},
811 
812 	{}
813 };
814 
815 static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
816 	HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
817 	HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
818 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
819 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
820 
821 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
822 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
823 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
824 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
825 
826 	HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
827 	HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
828 
829 	{}
830 };
831 
832 static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
833 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
834 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
835 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
836 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
837 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
838 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
839 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
840 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
841 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
842 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
843 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
844 	{
845 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
846 		.name = "Master Playback Switch",
847 		.info = cxt_eapd_info,
848 		.get = cxt_eapd_get,
849 		.put = cxt5045_hp_master_sw_put,
850 		.private_value = 0x10,
851 	},
852 
853 	{}
854 };
855 
856 static struct hda_verb cxt5045_init_verbs[] = {
857 	/* Line in, Mic */
858 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
859 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
860 	/* HP, Amp  */
861 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
862 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
863 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
864 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
865 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
866 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
867 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
868 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
869 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
870 	/* Record selector: Int mic */
871 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
872 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
873 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
874 	/* SPDIF route: PCM */
875 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
876 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
877 	/* EAPD */
878 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
879 	{ } /* end */
880 };
881 
882 static struct hda_verb cxt5045_benq_init_verbs[] = {
883 	/* Int Mic, Mic */
884 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
885 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
886 	/* Line In,HP, Amp  */
887 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
888 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
889 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
890 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
891 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
892 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
893 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
894 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
895 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
896 	/* Record selector: Int mic */
897 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
898 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
899 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
900 	/* SPDIF route: PCM */
901 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
902 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
903 	/* EAPD */
904 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
905 	{ } /* end */
906 };
907 
908 static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
909 	/* pin sensing on HP jack */
910 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
911 	{ } /* end */
912 };
913 
914 static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
915 	/* pin sensing on HP jack */
916 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
917 	{ } /* end */
918 };
919 
920 #ifdef CONFIG_SND_DEBUG
921 /* Test configuration for debugging, modelled after the ALC260 test
922  * configuration.
923  */
924 static struct hda_input_mux cxt5045_test_capture_source = {
925 	.num_items = 5,
926 	.items = {
927 		{ "MIXER", 0x0 },
928 		{ "MIC1 pin", 0x1 },
929 		{ "LINE1 pin", 0x2 },
930 		{ "HP-OUT pin", 0x3 },
931 		{ "CD pin", 0x4 },
932         },
933 };
934 
935 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
936 
937 	/* Output controls */
938 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
939 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
940 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
941 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
942 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
943 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
944 
945 	/* Modes for retasking pin widgets */
946 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
947 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
948 
949 	/* EAPD Switch Control */
950 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
951 
952 	/* Loopback mixer controls */
953 
954 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
955 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
956 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
957 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
958 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
959 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
960 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
961 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
962 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
963 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
964 	{
965 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
966 		.name = "Input Source",
967 		.info = conexant_mux_enum_info,
968 		.get = conexant_mux_enum_get,
969 		.put = conexant_mux_enum_put,
970 	},
971 	/* Audio input controls */
972 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
973 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
974 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
975 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
976 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
977 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
978 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
979 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
980 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
981 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
982 	{ } /* end */
983 };
984 
985 static struct hda_verb cxt5045_test_init_verbs[] = {
986 	/* Set connections */
987 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
988 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
989 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
990 	/* Enable retasking pins as output, initially without power amp */
991 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
992 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
993 
994 	/* Disable digital (SPDIF) pins initially, but users can enable
995 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
996 	 * payload also sets the generation to 0, output to be in "consumer"
997 	 * PCM format, copyright asserted, no pre-emphasis and no validity
998 	 * control.
999 	 */
1000 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1001 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1002 
1003 	/* Start with output sum widgets muted and their output gains at min */
1004 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1005 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1006 
1007 	/* Unmute retasking pin widget output buffers since the default
1008 	 * state appears to be output.  As the pin mode is changed by the
1009 	 * user the pin mode control will take care of enabling the pin's
1010 	 * input/output buffers as needed.
1011 	 */
1012 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1013 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1014 
1015 	/* Mute capture amp left and right */
1016 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1017 
1018 	/* Set ADC connection select to match default mixer setting (mic1
1019 	 * pin)
1020 	 */
1021 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1022 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1023 
1024 	/* Mute all inputs to mixer widget (even unconnected ones) */
1025 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1026 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1027 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1028 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1029 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1030 
1031 	{ }
1032 };
1033 #endif
1034 
1035 
1036 /* initialize jack-sensing, too */
1037 static int cxt5045_init(struct hda_codec *codec)
1038 {
1039 	conexant_init(codec);
1040 	cxt5045_hp_automute(codec);
1041 	return 0;
1042 }
1043 
1044 
1045 enum {
1046 	CXT5045_LAPTOP_HPSENSE,
1047 	CXT5045_LAPTOP_MICSENSE,
1048 	CXT5045_LAPTOP_HPMICSENSE,
1049 	CXT5045_BENQ,
1050 	CXT5045_LAPTOP_HP530,
1051 #ifdef CONFIG_SND_DEBUG
1052 	CXT5045_TEST,
1053 #endif
1054 	CXT5045_MODELS
1055 };
1056 
1057 static const char *cxt5045_models[CXT5045_MODELS] = {
1058 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
1059 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
1060 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
1061 	[CXT5045_BENQ]			= "benq",
1062 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1063 #ifdef CONFIG_SND_DEBUG
1064 	[CXT5045_TEST]		= "test",
1065 #endif
1066 };
1067 
1068 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1069 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1070 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1071 			   CXT5045_LAPTOP_HPSENSE),
1072 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1073 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1074 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1075 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1076 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1077 		      CXT5045_LAPTOP_HPMICSENSE),
1078 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1079 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1080 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1081 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1082 			   CXT5045_LAPTOP_HPMICSENSE),
1083 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1084 	{}
1085 };
1086 
1087 static int patch_cxt5045(struct hda_codec *codec)
1088 {
1089 	struct conexant_spec *spec;
1090 	int board_config;
1091 
1092 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1093 	if (!spec)
1094 		return -ENOMEM;
1095 	codec->spec = spec;
1096 	codec->pin_amp_workaround = 1;
1097 
1098 	spec->multiout.max_channels = 2;
1099 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1100 	spec->multiout.dac_nids = cxt5045_dac_nids;
1101 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1102 	spec->num_adc_nids = 1;
1103 	spec->adc_nids = cxt5045_adc_nids;
1104 	spec->capsrc_nids = cxt5045_capsrc_nids;
1105 	spec->input_mux = &cxt5045_capture_source;
1106 	spec->num_mixers = 1;
1107 	spec->mixers[0] = cxt5045_mixers;
1108 	spec->num_init_verbs = 1;
1109 	spec->init_verbs[0] = cxt5045_init_verbs;
1110 	spec->spdif_route = 0;
1111 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1112 	spec->channel_mode = cxt5045_modes,
1113 
1114 
1115 	codec->patch_ops = conexant_patch_ops;
1116 
1117 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1118 						  cxt5045_models,
1119 						  cxt5045_cfg_tbl);
1120 	switch (board_config) {
1121 	case CXT5045_LAPTOP_HPSENSE:
1122 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1123 		spec->input_mux = &cxt5045_capture_source;
1124 		spec->num_init_verbs = 2;
1125 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1126 		spec->mixers[0] = cxt5045_mixers;
1127 		codec->patch_ops.init = cxt5045_init;
1128 		break;
1129 	case CXT5045_LAPTOP_MICSENSE:
1130 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1131 		spec->input_mux = &cxt5045_capture_source;
1132 		spec->num_init_verbs = 2;
1133 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1134 		spec->mixers[0] = cxt5045_mixers;
1135 		codec->patch_ops.init = cxt5045_init;
1136 		break;
1137 	default:
1138 	case CXT5045_LAPTOP_HPMICSENSE:
1139 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1140 		spec->input_mux = &cxt5045_capture_source;
1141 		spec->num_init_verbs = 3;
1142 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1143 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1144 		spec->mixers[0] = cxt5045_mixers;
1145 		codec->patch_ops.init = cxt5045_init;
1146 		break;
1147 	case CXT5045_BENQ:
1148 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1149 		spec->input_mux = &cxt5045_capture_source_benq;
1150 		spec->num_init_verbs = 1;
1151 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
1152 		spec->mixers[0] = cxt5045_mixers;
1153 		spec->mixers[1] = cxt5045_benq_mixers;
1154 		spec->num_mixers = 2;
1155 		codec->patch_ops.init = cxt5045_init;
1156 		break;
1157 	case CXT5045_LAPTOP_HP530:
1158 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1159 		spec->input_mux = &cxt5045_capture_source_hp530;
1160 		spec->num_init_verbs = 2;
1161 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1162 		spec->mixers[0] = cxt5045_mixers_hp530;
1163 		codec->patch_ops.init = cxt5045_init;
1164 		break;
1165 #ifdef CONFIG_SND_DEBUG
1166 	case CXT5045_TEST:
1167 		spec->input_mux = &cxt5045_test_capture_source;
1168 		spec->mixers[0] = cxt5045_test_mixer;
1169 		spec->init_verbs[0] = cxt5045_test_init_verbs;
1170 		break;
1171 
1172 #endif
1173 	}
1174 
1175 	switch (codec->subsystem_id >> 16) {
1176 	case 0x103c:
1177 	case 0x1734:
1178 		/* HP & Fujitsu-Siemens laptops have really bad sound over 0dB
1179 		 * on NID 0x17. Fix max PCM level to 0 dB
1180 		 * (originally it has 0x2b steps with 0dB offset 0x14)
1181 		 */
1182 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1183 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1184 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1185 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1186 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1187 		break;
1188 	}
1189 
1190 	return 0;
1191 }
1192 
1193 
1194 /* Conexant 5047 specific */
1195 #define CXT5047_SPDIF_OUT	0x11
1196 
1197 static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1198 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1199 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1200 
1201 static struct hda_channel_mode cxt5047_modes[1] = {
1202 	{ 2, NULL },
1203 };
1204 
1205 static struct hda_input_mux cxt5047_toshiba_capture_source = {
1206 	.num_items = 2,
1207 	.items = {
1208 		{ "ExtMic", 0x2 },
1209 		{ "Line-In", 0x1 },
1210 	}
1211 };
1212 
1213 /* turn on/off EAPD (+ mute HP) as a master switch */
1214 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1215 				    struct snd_ctl_elem_value *ucontrol)
1216 {
1217 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1218 	struct conexant_spec *spec = codec->spec;
1219 	unsigned int bits;
1220 
1221 	if (!cxt_eapd_put(kcontrol, ucontrol))
1222 		return 0;
1223 
1224 	/* toggle internal speakers mute depending of presence of
1225 	 * the headphone jack
1226 	 */
1227 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1228 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1229 	 * pin widgets unlike other codecs.  In this case, we need to
1230 	 * set index 0x01 for the volume from the mixer amp 0x19.
1231 	 */
1232 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1233 				 HDA_AMP_MUTE, bits);
1234 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1235 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1236 				 HDA_AMP_MUTE, bits);
1237 	return 1;
1238 }
1239 
1240 /* mute internal speaker if HP is plugged */
1241 static void cxt5047_hp_automute(struct hda_codec *codec)
1242 {
1243 	struct conexant_spec *spec = codec->spec;
1244 	unsigned int bits;
1245 
1246 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1247 
1248 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1249 	/* See the note in cxt5047_hp_master_sw_put */
1250 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1251 				 HDA_AMP_MUTE, bits);
1252 }
1253 
1254 /* toggle input of built-in and mic jack appropriately */
1255 static void cxt5047_hp_automic(struct hda_codec *codec)
1256 {
1257 	static struct hda_verb mic_jack_on[] = {
1258 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1259 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1260 		{}
1261 	};
1262 	static struct hda_verb mic_jack_off[] = {
1263 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1264 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1265 		{}
1266 	};
1267 	unsigned int present;
1268 
1269 	present = snd_hda_jack_detect(codec, 0x15);
1270 	if (present)
1271 		snd_hda_sequence_write(codec, mic_jack_on);
1272 	else
1273 		snd_hda_sequence_write(codec, mic_jack_off);
1274 }
1275 
1276 /* unsolicited event for HP jack sensing */
1277 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1278 				  unsigned int res)
1279 {
1280 	switch (res >> 26) {
1281 	case CONEXANT_HP_EVENT:
1282 		cxt5047_hp_automute(codec);
1283 		break;
1284 	case CONEXANT_MIC_EVENT:
1285 		cxt5047_hp_automic(codec);
1286 		break;
1287 	}
1288 }
1289 
1290 static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1291 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1292 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1293 	HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
1294 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1295 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1296 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1297 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1298 	{
1299 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1300 		.name = "Master Playback Switch",
1301 		.info = cxt_eapd_info,
1302 		.get = cxt_eapd_get,
1303 		.put = cxt5047_hp_master_sw_put,
1304 		.private_value = 0x13,
1305 	},
1306 
1307 	{}
1308 };
1309 
1310 static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1311 	/* See the note in cxt5047_hp_master_sw_put */
1312 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1313 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1314 	{}
1315 };
1316 
1317 static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1318 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1319 	{ } /* end */
1320 };
1321 
1322 static struct hda_verb cxt5047_init_verbs[] = {
1323 	/* Line in, Mic, Built-in Mic */
1324 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1325 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1326 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1327 	/* HP, Speaker  */
1328 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1329 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1330 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1331 	/* Record selector: Mic */
1332 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1333 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1334 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1335 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1336 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1337 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1338 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1339 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1340 	/* SPDIF route: PCM */
1341 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1342 	/* Enable unsolicited events */
1343 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1344 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1345 	{ } /* end */
1346 };
1347 
1348 /* configuration for Toshiba Laptops */
1349 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1350 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1351 	{}
1352 };
1353 
1354 /* Test configuration for debugging, modelled after the ALC260 test
1355  * configuration.
1356  */
1357 #ifdef CONFIG_SND_DEBUG
1358 static struct hda_input_mux cxt5047_test_capture_source = {
1359 	.num_items = 4,
1360 	.items = {
1361 		{ "LINE1 pin", 0x0 },
1362 		{ "MIC1 pin", 0x1 },
1363 		{ "MIC2 pin", 0x2 },
1364 		{ "CD pin", 0x3 },
1365         },
1366 };
1367 
1368 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1369 
1370 	/* Output only controls */
1371 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1372 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1373 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1374 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1375 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1376 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1377 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1378 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1379 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1380 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1381 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1382 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1383 
1384 	/* Modes for retasking pin widgets */
1385 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1386 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1387 
1388 	/* EAPD Switch Control */
1389 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1390 
1391 	/* Loopback mixer controls */
1392 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1393 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1394 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1395 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1396 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1397 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1398 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1399 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1400 
1401 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1402 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1403 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1404 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1405 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1406 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1407 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1408 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1409 	{
1410 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1411 		.name = "Input Source",
1412 		.info = conexant_mux_enum_info,
1413 		.get = conexant_mux_enum_get,
1414 		.put = conexant_mux_enum_put,
1415 	},
1416 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1417 
1418 	{ } /* end */
1419 };
1420 
1421 static struct hda_verb cxt5047_test_init_verbs[] = {
1422 	/* Enable retasking pins as output, initially without power amp */
1423 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1424 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1425 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1426 
1427 	/* Disable digital (SPDIF) pins initially, but users can enable
1428 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1429 	 * payload also sets the generation to 0, output to be in "consumer"
1430 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1431 	 * control.
1432 	 */
1433 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1434 
1435 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1436 	 * OUT1 sum bus when acting as an output.
1437 	 */
1438 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1439 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1440 
1441 	/* Start with output sum widgets muted and their output gains at min */
1442 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1443 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1444 
1445 	/* Unmute retasking pin widget output buffers since the default
1446 	 * state appears to be output.  As the pin mode is changed by the
1447 	 * user the pin mode control will take care of enabling the pin's
1448 	 * input/output buffers as needed.
1449 	 */
1450 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1451 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1452 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1453 
1454 	/* Mute capture amp left and right */
1455 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1456 
1457 	/* Set ADC connection select to match default mixer setting (mic1
1458 	 * pin)
1459 	 */
1460 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1461 
1462 	/* Mute all inputs to mixer widget (even unconnected ones) */
1463 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1464 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1465 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1466 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1467 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1468 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1469 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1470 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1471 
1472 	{ }
1473 };
1474 #endif
1475 
1476 
1477 /* initialize jack-sensing, too */
1478 static int cxt5047_hp_init(struct hda_codec *codec)
1479 {
1480 	conexant_init(codec);
1481 	cxt5047_hp_automute(codec);
1482 	return 0;
1483 }
1484 
1485 
1486 enum {
1487 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1488 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1489 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1490 #ifdef CONFIG_SND_DEBUG
1491 	CXT5047_TEST,
1492 #endif
1493 	CXT5047_MODELS
1494 };
1495 
1496 static const char *cxt5047_models[CXT5047_MODELS] = {
1497 	[CXT5047_LAPTOP]	= "laptop",
1498 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1499 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1500 #ifdef CONFIG_SND_DEBUG
1501 	[CXT5047_TEST]		= "test",
1502 #endif
1503 };
1504 
1505 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1506 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1507 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1508 			   CXT5047_LAPTOP),
1509 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1510 	{}
1511 };
1512 
1513 static int patch_cxt5047(struct hda_codec *codec)
1514 {
1515 	struct conexant_spec *spec;
1516 	int board_config;
1517 
1518 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1519 	if (!spec)
1520 		return -ENOMEM;
1521 	codec->spec = spec;
1522 	codec->pin_amp_workaround = 1;
1523 
1524 	spec->multiout.max_channels = 2;
1525 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1526 	spec->multiout.dac_nids = cxt5047_dac_nids;
1527 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1528 	spec->num_adc_nids = 1;
1529 	spec->adc_nids = cxt5047_adc_nids;
1530 	spec->capsrc_nids = cxt5047_capsrc_nids;
1531 	spec->num_mixers = 1;
1532 	spec->mixers[0] = cxt5047_base_mixers;
1533 	spec->num_init_verbs = 1;
1534 	spec->init_verbs[0] = cxt5047_init_verbs;
1535 	spec->spdif_route = 0;
1536 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1537 	spec->channel_mode = cxt5047_modes,
1538 
1539 	codec->patch_ops = conexant_patch_ops;
1540 
1541 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1542 						  cxt5047_models,
1543 						  cxt5047_cfg_tbl);
1544 	switch (board_config) {
1545 	case CXT5047_LAPTOP:
1546 		spec->num_mixers = 2;
1547 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1548 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1549 		break;
1550 	case CXT5047_LAPTOP_HP:
1551 		spec->num_mixers = 2;
1552 		spec->mixers[1] = cxt5047_hp_only_mixers;
1553 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1554 		codec->patch_ops.init = cxt5047_hp_init;
1555 		break;
1556 	case CXT5047_LAPTOP_EAPD:
1557 		spec->input_mux = &cxt5047_toshiba_capture_source;
1558 		spec->num_mixers = 2;
1559 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1560 		spec->num_init_verbs = 2;
1561 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1562 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1563 		break;
1564 #ifdef CONFIG_SND_DEBUG
1565 	case CXT5047_TEST:
1566 		spec->input_mux = &cxt5047_test_capture_source;
1567 		spec->mixers[0] = cxt5047_test_mixer;
1568 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1569 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1570 #endif
1571 	}
1572 	spec->vmaster_nid = 0x13;
1573 	return 0;
1574 }
1575 
1576 /* Conexant 5051 specific */
1577 static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1578 static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1579 
1580 static struct hda_channel_mode cxt5051_modes[1] = {
1581 	{ 2, NULL },
1582 };
1583 
1584 static void cxt5051_update_speaker(struct hda_codec *codec)
1585 {
1586 	struct conexant_spec *spec = codec->spec;
1587 	unsigned int pinctl;
1588 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1589 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1590 			    pinctl);
1591 }
1592 
1593 /* turn on/off EAPD (+ mute HP) as a master switch */
1594 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1595 				    struct snd_ctl_elem_value *ucontrol)
1596 {
1597 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1598 
1599 	if (!cxt_eapd_put(kcontrol, ucontrol))
1600 		return 0;
1601 	cxt5051_update_speaker(codec);
1602 	return 1;
1603 }
1604 
1605 /* toggle input of built-in and mic jack appropriately */
1606 static void cxt5051_portb_automic(struct hda_codec *codec)
1607 {
1608 	struct conexant_spec *spec = codec->spec;
1609 	unsigned int present;
1610 
1611 	if (spec->no_auto_mic)
1612 		return;
1613 	present = snd_hda_jack_detect(codec, 0x17);
1614 	snd_hda_codec_write(codec, 0x14, 0,
1615 			    AC_VERB_SET_CONNECT_SEL,
1616 			    present ? 0x01 : 0x00);
1617 }
1618 
1619 /* switch the current ADC according to the jack state */
1620 static void cxt5051_portc_automic(struct hda_codec *codec)
1621 {
1622 	struct conexant_spec *spec = codec->spec;
1623 	unsigned int present;
1624 	hda_nid_t new_adc;
1625 
1626 	if (spec->no_auto_mic)
1627 		return;
1628 	present = snd_hda_jack_detect(codec, 0x18);
1629 	if (present)
1630 		spec->cur_adc_idx = 1;
1631 	else
1632 		spec->cur_adc_idx = 0;
1633 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1634 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1635 		/* stream is running, let's swap the current ADC */
1636 		snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1637 		spec->cur_adc = new_adc;
1638 		snd_hda_codec_setup_stream(codec, new_adc,
1639 					   spec->cur_adc_stream_tag, 0,
1640 					   spec->cur_adc_format);
1641 	}
1642 }
1643 
1644 /* mute internal speaker if HP is plugged */
1645 static void cxt5051_hp_automute(struct hda_codec *codec)
1646 {
1647 	struct conexant_spec *spec = codec->spec;
1648 
1649 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1650 	cxt5051_update_speaker(codec);
1651 }
1652 
1653 /* unsolicited event for HP jack sensing */
1654 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1655 				   unsigned int res)
1656 {
1657 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1658 	switch (res >> 26) {
1659 	case CONEXANT_HP_EVENT:
1660 		cxt5051_hp_automute(codec);
1661 		break;
1662 	case CXT5051_PORTB_EVENT:
1663 		cxt5051_portb_automic(codec);
1664 		break;
1665 	case CXT5051_PORTC_EVENT:
1666 		cxt5051_portc_automic(codec);
1667 		break;
1668 	}
1669 	conexant_report_jack(codec, nid);
1670 }
1671 
1672 static struct snd_kcontrol_new cxt5051_mixers[] = {
1673 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1674 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1675 	HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1676 	HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1677 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1678 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1679 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1680 	{
1681 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1682 		.name = "Master Playback Switch",
1683 		.info = cxt_eapd_info,
1684 		.get = cxt_eapd_get,
1685 		.put = cxt5051_hp_master_sw_put,
1686 		.private_value = 0x1a,
1687 	},
1688 
1689 	{}
1690 };
1691 
1692 static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1693 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1694 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1695 	HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1696 	HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1697 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1698 	{
1699 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1700 		.name = "Master Playback Switch",
1701 		.info = cxt_eapd_info,
1702 		.get = cxt_eapd_get,
1703 		.put = cxt5051_hp_master_sw_put,
1704 		.private_value = 0x1a,
1705 	},
1706 
1707 	{}
1708 };
1709 
1710 static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1711 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1712 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1713 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1714 	{
1715 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1716 		.name = "Master Playback Switch",
1717 		.info = cxt_eapd_info,
1718 		.get = cxt_eapd_get,
1719 		.put = cxt5051_hp_master_sw_put,
1720 		.private_value = 0x1a,
1721 	},
1722 
1723 	{}
1724 };
1725 
1726 static struct hda_verb cxt5051_init_verbs[] = {
1727 	/* Line in, Mic */
1728 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1729 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1730 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1731 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1732 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1733 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1734 	/* SPK  */
1735 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1736 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1737 	/* HP, Amp  */
1738 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1739 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1740 	/* DAC1 */
1741 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1742 	/* Record selector: Int mic */
1743 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1744 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1745 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1746 	/* SPDIF route: PCM */
1747 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1748 	/* EAPD */
1749 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1750 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1751 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1752 	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1753 	{ } /* end */
1754 };
1755 
1756 static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1757 	/* Line in, Mic */
1758 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1759 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1760 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1761 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1762 	/* SPK  */
1763 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1764 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1765 	/* HP, Amp  */
1766 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1767 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1768 	/* DAC1 */
1769 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1770 	/* Record selector: Int mic */
1771 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1772 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1773 	/* SPDIF route: PCM */
1774 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1775 	/* EAPD */
1776 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1777 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1778 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1779 	{ } /* end */
1780 };
1781 
1782 static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1783 	/* Line in, Mic */
1784 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1785 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1786 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1787 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1788 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1789 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1790 	/* SPK  */
1791 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1792 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1793 	/* HP, Amp  */
1794 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1795 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1796 	/* Docking HP */
1797 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1798 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1799 	/* DAC1 */
1800 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1801 	/* Record selector: Int mic */
1802 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1803 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1804 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1805 	/* SPDIF route: PCM */
1806 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1807 	/* EAPD */
1808 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1809 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1810 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1811 	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1812 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1813 	{ } /* end */
1814 };
1815 
1816 /* initialize jack-sensing, too */
1817 static int cxt5051_init(struct hda_codec *codec)
1818 {
1819 	conexant_init(codec);
1820 	conexant_init_jacks(codec);
1821 	if (codec->patch_ops.unsol_event) {
1822 		cxt5051_hp_automute(codec);
1823 		cxt5051_portb_automic(codec);
1824 		cxt5051_portc_automic(codec);
1825 	}
1826 	return 0;
1827 }
1828 
1829 
1830 enum {
1831 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1832 	CXT5051_HP,	/* no docking */
1833 	CXT5051_HP_DV6736,	/* HP without mic switch */
1834 	CXT5051_LENOVO_X200,	/* Lenovo X200 laptop */
1835 	CXT5051_MODELS
1836 };
1837 
1838 static const char *cxt5051_models[CXT5051_MODELS] = {
1839 	[CXT5051_LAPTOP]	= "laptop",
1840 	[CXT5051_HP]		= "hp",
1841 	[CXT5051_HP_DV6736]	= "hp-dv6736",
1842 	[CXT5051_LENOVO_X200]	= "lenovo-x200",
1843 };
1844 
1845 static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1846 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1847 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1848 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1849 		      CXT5051_LAPTOP),
1850 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1851 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1852 	{}
1853 };
1854 
1855 static int patch_cxt5051(struct hda_codec *codec)
1856 {
1857 	struct conexant_spec *spec;
1858 	int board_config;
1859 
1860 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1861 	if (!spec)
1862 		return -ENOMEM;
1863 	codec->spec = spec;
1864 	codec->pin_amp_workaround = 1;
1865 
1866 	codec->patch_ops = conexant_patch_ops;
1867 	codec->patch_ops.init = cxt5051_init;
1868 
1869 	spec->multiout.max_channels = 2;
1870 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1871 	spec->multiout.dac_nids = cxt5051_dac_nids;
1872 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1873 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1874 	spec->adc_nids = cxt5051_adc_nids;
1875 	spec->num_mixers = 1;
1876 	spec->mixers[0] = cxt5051_mixers;
1877 	spec->num_init_verbs = 1;
1878 	spec->init_verbs[0] = cxt5051_init_verbs;
1879 	spec->spdif_route = 0;
1880 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1881 	spec->channel_mode = cxt5051_modes;
1882 	spec->cur_adc = 0;
1883 	spec->cur_adc_idx = 0;
1884 
1885 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1886 
1887 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1888 						  cxt5051_models,
1889 						  cxt5051_cfg_tbl);
1890 	switch (board_config) {
1891 	case CXT5051_HP:
1892 		spec->mixers[0] = cxt5051_hp_mixers;
1893 		break;
1894 	case CXT5051_HP_DV6736:
1895 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1896 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1897 		spec->no_auto_mic = 1;
1898 		break;
1899 	case CXT5051_LENOVO_X200:
1900 		spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1901 		break;
1902 	}
1903 
1904 	return 0;
1905 }
1906 
1907 /* Conexant 5066 specific */
1908 
1909 static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1910 static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1911 static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1912 #define CXT5066_SPDIF_OUT	0x21
1913 
1914 /* OLPC's microphone port is DC coupled for use with external sensors,
1915  * therefore we use a 50% mic bias in order to center the input signal with
1916  * the DC input range of the codec. */
1917 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1918 
1919 static struct hda_channel_mode cxt5066_modes[1] = {
1920 	{ 2, NULL },
1921 };
1922 
1923 static void cxt5066_update_speaker(struct hda_codec *codec)
1924 {
1925 	struct conexant_spec *spec = codec->spec;
1926 	unsigned int pinctl;
1927 
1928 	snd_printdd("CXT5066: update speaker, hp_present=%d\n",
1929 		spec->hp_present);
1930 
1931 	/* Port A (HP) */
1932 	pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
1933 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1934 			pinctl);
1935 
1936 	/* Port D (HP/LO) */
1937 	pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
1938 		? spec->port_d_mode : 0;
1939 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1940 			pinctl);
1941 
1942 	/* CLASS_D AMP */
1943 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1944 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1945 			pinctl);
1946 
1947 	if (spec->dell_automute) {
1948 		/* DELL AIO Port Rule: PortA > PortD > IntSpk */
1949 		pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
1950 			? PIN_OUT : 0;
1951 		snd_hda_codec_write(codec, 0x1c, 0,
1952 			AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
1953 	}
1954 }
1955 
1956 /* turn on/off EAPD (+ mute HP) as a master switch */
1957 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1958 				    struct snd_ctl_elem_value *ucontrol)
1959 {
1960 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1961 
1962 	if (!cxt_eapd_put(kcontrol, ucontrol))
1963 		return 0;
1964 
1965 	cxt5066_update_speaker(codec);
1966 	return 1;
1967 }
1968 
1969 /* toggle input of built-in and mic jack appropriately */
1970 static void cxt5066_automic(struct hda_codec *codec)
1971 {
1972 	struct conexant_spec *spec = codec->spec;
1973 	struct hda_verb ext_mic_present[] = {
1974 		/* enable external mic, port B */
1975 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
1976 
1977 		/* switch to external mic input */
1978 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
1979 
1980 		/* disable internal mic, port C */
1981 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1982 		{}
1983 	};
1984 	static struct hda_verb ext_mic_absent[] = {
1985 		/* enable internal mic, port C */
1986 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1987 
1988 		/* switch to internal mic input */
1989 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
1990 
1991 		/* disable external mic, port B */
1992 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
1993 		{}
1994 	};
1995 	unsigned int present;
1996 
1997 	present = snd_hda_jack_detect(codec, 0x1a);
1998 	if (present) {
1999 		snd_printdd("CXT5066: external microphone detected\n");
2000 		snd_hda_sequence_write(codec, ext_mic_present);
2001 	} else {
2002 		snd_printdd("CXT5066: external microphone absent\n");
2003 		snd_hda_sequence_write(codec, ext_mic_absent);
2004 	}
2005 }
2006 
2007 /* toggle input of built-in digital mic and mic jack appropriately */
2008 static void cxt5066_vostro_automic(struct hda_codec *codec)
2009 {
2010 	struct conexant_spec *spec = codec->spec;
2011 	unsigned int present;
2012 
2013 	struct hda_verb ext_mic_present[] = {
2014 		/* enable external mic, port B */
2015 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
2016 
2017 		/* switch to external mic input */
2018 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
2019 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2020 
2021 		/* disable internal digital mic */
2022 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2023 		{}
2024 	};
2025 	static struct hda_verb ext_mic_absent[] = {
2026 		/* enable internal mic, port C */
2027 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2028 
2029 		/* switch to internal mic input */
2030 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2031 
2032 		/* disable external mic, port B */
2033 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2034 		{}
2035 	};
2036 
2037 	present = snd_hda_jack_detect(codec, 0x1a);
2038 	if (present) {
2039 		snd_printdd("CXT5066: external microphone detected\n");
2040 		snd_hda_sequence_write(codec, ext_mic_present);
2041 	} else {
2042 		snd_printdd("CXT5066: external microphone absent\n");
2043 		snd_hda_sequence_write(codec, ext_mic_absent);
2044 	}
2045 }
2046 
2047 /* mute internal speaker if HP is plugged */
2048 static void cxt5066_hp_automute(struct hda_codec *codec)
2049 {
2050 	struct conexant_spec *spec = codec->spec;
2051 	unsigned int portA, portD;
2052 
2053 	/* Port A */
2054 	portA = snd_hda_jack_detect(codec, 0x19);
2055 
2056 	/* Port D */
2057 	portD = snd_hda_jack_detect(codec, 0x1c);
2058 
2059 	spec->hp_present = !!(portA | portD);
2060 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2061 		portA, portD, spec->hp_present);
2062 	cxt5066_update_speaker(codec);
2063 }
2064 
2065 /* unsolicited event for jack sensing */
2066 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2067 {
2068 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2069 	switch (res >> 26) {
2070 	case CONEXANT_HP_EVENT:
2071 		cxt5066_hp_automute(codec);
2072 		break;
2073 	case CONEXANT_MIC_EVENT:
2074 		cxt5066_automic(codec);
2075 		break;
2076 	}
2077 }
2078 
2079 /* unsolicited event for jack sensing */
2080 static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2081 {
2082 	snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2083 	switch (res >> 26) {
2084 	case CONEXANT_HP_EVENT:
2085 		cxt5066_hp_automute(codec);
2086 		break;
2087 	case CONEXANT_MIC_EVENT:
2088 		cxt5066_vostro_automic(codec);
2089 		break;
2090 	}
2091 }
2092 
2093 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2094 	.num_items = 5,
2095 	.items = {
2096 		{ "0dB",  0 },
2097 		{ "10dB", 1 },
2098 		{ "20dB", 2 },
2099 		{ "30dB", 3 },
2100 		{ "40dB", 4 },
2101 	},
2102 };
2103 
2104 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2105 					   struct snd_ctl_elem_info *uinfo)
2106 {
2107 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2108 }
2109 
2110 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2111 					  struct snd_ctl_elem_value *ucontrol)
2112 {
2113 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2114 	int val;
2115 	hda_nid_t nid = kcontrol->private_value & 0xff;
2116 	int inout = (kcontrol->private_value & 0x100) ?
2117 		AC_AMP_GET_INPUT : AC_AMP_GET_OUTPUT;
2118 
2119 	val = snd_hda_codec_read(codec, nid, 0,
2120 		AC_VERB_GET_AMP_GAIN_MUTE, inout);
2121 
2122 	ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
2123 	return 0;
2124 }
2125 
2126 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2127 					  struct snd_ctl_elem_value *ucontrol)
2128 {
2129 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2130 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2131 	unsigned int idx;
2132 	hda_nid_t nid = kcontrol->private_value & 0xff;
2133 	int inout = (kcontrol->private_value & 0x100) ?
2134 		AC_AMP_SET_INPUT : AC_AMP_SET_OUTPUT;
2135 
2136 	if (!imux->num_items)
2137 		return 0;
2138 	idx = ucontrol->value.enumerated.item[0];
2139 	if (idx >= imux->num_items)
2140 		idx = imux->num_items - 1;
2141 
2142 	snd_hda_codec_write_cache(codec, nid, 0,
2143 		AC_VERB_SET_AMP_GAIN_MUTE,
2144 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | inout |
2145 			imux->items[idx].index);
2146 
2147 	return 1;
2148 }
2149 
2150 static struct hda_input_mux cxt5066_capture_source = {
2151 	.num_items = 4,
2152 	.items = {
2153 		{ "Mic B", 0 },
2154 		{ "Mic C", 1 },
2155 		{ "Mic E", 2 },
2156 		{ "Mic F", 3 },
2157 	},
2158 };
2159 
2160 static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2161 	.ops = &snd_hda_bind_vol,
2162 	.values = {
2163 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2164 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2165 		0
2166 	},
2167 };
2168 
2169 static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2170 	.ops = &snd_hda_bind_sw,
2171 	.values = {
2172 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2173 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2174 		0
2175 	},
2176 };
2177 
2178 static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2179 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2180 	{}
2181 };
2182 
2183 static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2184 	{
2185 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2186 		.name = "Master Playback Volume",
2187 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2188 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2189 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2190 		.info = snd_hda_mixer_amp_volume_info,
2191 		.get = snd_hda_mixer_amp_volume_get,
2192 		.put = snd_hda_mixer_amp_volume_put,
2193 		.tlv = { .c = snd_hda_mixer_amp_tlv },
2194 		/* offset by 28 volume steps to limit minimum gain to -46dB */
2195 		.private_value =
2196 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2197 	},
2198 	{}
2199 };
2200 
2201 static struct snd_kcontrol_new cxt5066_mixers[] = {
2202 	{
2203 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2204 		.name = "Master Playback Switch",
2205 		.info = cxt_eapd_info,
2206 		.get = cxt_eapd_get,
2207 		.put = cxt5066_hp_master_sw_put,
2208 		.private_value = 0x1d,
2209 	},
2210 
2211 	{
2212 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2213 		.name = "Ext Mic Boost Capture Enum",
2214 		.info = cxt5066_mic_boost_mux_enum_info,
2215 		.get = cxt5066_mic_boost_mux_enum_get,
2216 		.put = cxt5066_mic_boost_mux_enum_put,
2217 		.private_value = 0x17,
2218 	},
2219 
2220 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2221 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2222 	{}
2223 };
2224 
2225 static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2226 	{
2227 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2228 		.name = "Int Mic Boost Capture Enum",
2229 		.info = cxt5066_mic_boost_mux_enum_info,
2230 		.get = cxt5066_mic_boost_mux_enum_get,
2231 		.put = cxt5066_mic_boost_mux_enum_put,
2232 		.private_value = 0x23 | 0x100,
2233 	},
2234 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
2235 	{}
2236 };
2237 
2238 static struct hda_verb cxt5066_init_verbs[] = {
2239 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2240 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2241 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2242 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2243 
2244 	/* Speakers  */
2245 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2246 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2247 
2248 	/* HP, Amp  */
2249 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2250 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2251 
2252 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2253 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2254 
2255 	/* DAC1 */
2256 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2257 
2258 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2259 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2260 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2261 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2262 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2263 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2264 
2265 	/* no digital microphone support yet */
2266 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2267 
2268 	/* Audio input selector */
2269 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2270 
2271 	/* SPDIF route: PCM */
2272 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2273 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2274 
2275 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2276 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2277 
2278 	/* EAPD */
2279 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2280 
2281 	/* not handling these yet */
2282 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2283 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2284 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2285 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2286 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2287 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2288 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2289 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2290 	{ } /* end */
2291 };
2292 
2293 static struct hda_verb cxt5066_init_verbs_olpc[] = {
2294 	/* Port A: headphones */
2295 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2296 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2297 
2298 	/* Port B: external microphone */
2299 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, CXT5066_OLPC_EXT_MIC_BIAS},
2300 
2301 	/* Port C: internal microphone */
2302 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2303 
2304 	/* Port D: unused */
2305 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2306 
2307 	/* Port E: unused, but has primary EAPD */
2308 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2309 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2310 
2311 	/* Port F: unused */
2312 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2313 
2314 	/* Port G: internal speakers */
2315 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2316 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2317 
2318 	/* DAC1 */
2319 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2320 
2321 	/* DAC2: unused */
2322 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2323 
2324 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2325 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2326 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2327 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2328 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2329 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2330 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2331 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2332 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2333 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2334 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2335 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2336 
2337 	/* Disable digital microphone port */
2338 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2339 
2340 	/* Audio input selectors */
2341 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2342 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2343 
2344 	/* Disable SPDIF */
2345 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2346 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2347 
2348 	/* enable unsolicited events for Port A and B */
2349 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2350 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2351 	{ } /* end */
2352 };
2353 
2354 static struct hda_verb cxt5066_init_verbs_vostro[] = {
2355 	/* Port A: headphones */
2356 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2357 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2358 
2359 	/* Port B: external microphone */
2360 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2361 
2362 	/* Port C: unused */
2363 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2364 
2365 	/* Port D: unused */
2366 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2367 
2368 	/* Port E: unused, but has primary EAPD */
2369 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2370 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2371 
2372 	/* Port F: unused */
2373 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2374 
2375 	/* Port G: internal speakers */
2376 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2377 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2378 
2379 	/* DAC1 */
2380 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2381 
2382 	/* DAC2: unused */
2383 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2384 
2385 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2386 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2387 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2388 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2389 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2390 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2391 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2392 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2393 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2394 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2395 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2396 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2397 
2398 	/* Digital microphone port */
2399 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2400 
2401 	/* Audio input selectors */
2402 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2403 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2404 
2405 	/* Disable SPDIF */
2406 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2407 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2408 
2409 	/* enable unsolicited events for Port A and B */
2410 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2411 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2412 	{ } /* end */
2413 };
2414 
2415 static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2416 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2417 	{ } /* end */
2418 };
2419 
2420 /* initialize jack-sensing, too */
2421 static int cxt5066_init(struct hda_codec *codec)
2422 {
2423 	struct conexant_spec *spec = codec->spec;
2424 
2425 	snd_printdd("CXT5066: init\n");
2426 	conexant_init(codec);
2427 	if (codec->patch_ops.unsol_event) {
2428 		cxt5066_hp_automute(codec);
2429 		if (spec->dell_vostro)
2430 			cxt5066_vostro_automic(codec);
2431 		else
2432 			cxt5066_automic(codec);
2433 	}
2434 	return 0;
2435 }
2436 
2437 enum {
2438 	CXT5066_LAPTOP,			/* Laptops w/ EAPD support */
2439 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
2440 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
2441 	CXT5066_DELL_VOSTO,	/* Dell Vostro 1015i */
2442 	CXT5066_MODELS
2443 };
2444 
2445 static const char *cxt5066_models[CXT5066_MODELS] = {
2446 	[CXT5066_LAPTOP]		= "laptop",
2447 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
2448 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
2449 	[CXT5066_DELL_VOSTO]    = "dell-vostro"
2450 };
2451 
2452 static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2453 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2454 		      CXT5066_LAPTOP),
2455 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2456 		      CXT5066_DELL_LAPTOP),
2457 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
2458 	SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
2459 	{}
2460 };
2461 
2462 static int patch_cxt5066(struct hda_codec *codec)
2463 {
2464 	struct conexant_spec *spec;
2465 	int board_config;
2466 
2467 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2468 	if (!spec)
2469 		return -ENOMEM;
2470 	codec->spec = spec;
2471 
2472 	codec->patch_ops = conexant_patch_ops;
2473 	codec->patch_ops.init = cxt5066_init;
2474 
2475 	spec->dell_automute = 0;
2476 	spec->multiout.max_channels = 2;
2477 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2478 	spec->multiout.dac_nids = cxt5066_dac_nids;
2479 	spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
2480 	spec->num_adc_nids = 1;
2481 	spec->adc_nids = cxt5066_adc_nids;
2482 	spec->capsrc_nids = cxt5066_capsrc_nids;
2483 	spec->input_mux = &cxt5066_capture_source;
2484 
2485 	spec->port_d_mode = PIN_HP;
2486 	spec->ext_mic_bias = PIN_VREF80;
2487 
2488 	spec->num_init_verbs = 1;
2489 	spec->init_verbs[0] = cxt5066_init_verbs;
2490 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2491 	spec->channel_mode = cxt5066_modes;
2492 	spec->cur_adc = 0;
2493 	spec->cur_adc_idx = 0;
2494 
2495 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2496 						  cxt5066_models, cxt5066_cfg_tbl);
2497 	switch (board_config) {
2498 	default:
2499 	case CXT5066_LAPTOP:
2500 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2501 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2502 		break;
2503 	case CXT5066_DELL_LAPTOP:
2504 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2505 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2506 
2507 		spec->port_d_mode = PIN_OUT;
2508 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
2509 		spec->num_init_verbs++;
2510 		spec->dell_automute = 1;
2511 		break;
2512 	case CXT5066_OLPC_XO_1_5:
2513 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
2514 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
2515 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2516 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2517 		spec->port_d_mode = 0;
2518 		spec->ext_mic_bias = CXT5066_OLPC_EXT_MIC_BIAS;
2519 
2520 		/* no S/PDIF out */
2521 		spec->multiout.dig_out_nid = 0;
2522 
2523 		/* input source automatically selected */
2524 		spec->input_mux = NULL;
2525 		break;
2526 	case CXT5066_DELL_VOSTO:
2527 		codec->patch_ops.unsol_event = cxt5066_vostro_event;
2528 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
2529 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2530 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2531 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
2532 		spec->port_d_mode = 0;
2533 		spec->dell_vostro = 1;
2534 		snd_hda_attach_beep_device(codec, 0x13);
2535 
2536 		/* no S/PDIF out */
2537 		spec->multiout.dig_out_nid = 0;
2538 
2539 		/* input source automatically selected */
2540 		spec->input_mux = NULL;
2541 		break;
2542 	}
2543 
2544 	return 0;
2545 }
2546 
2547 /*
2548  */
2549 
2550 static struct hda_codec_preset snd_hda_preset_conexant[] = {
2551 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
2552 	  .patch = patch_cxt5045 },
2553 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
2554 	  .patch = patch_cxt5047 },
2555 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
2556 	  .patch = patch_cxt5051 },
2557 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
2558 	  .patch = patch_cxt5066 },
2559 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
2560 	  .patch = patch_cxt5066 },
2561 	{} /* terminator */
2562 };
2563 
2564 MODULE_ALIAS("snd-hda-codec-id:14f15045");
2565 MODULE_ALIAS("snd-hda-codec-id:14f15047");
2566 MODULE_ALIAS("snd-hda-codec-id:14f15051");
2567 MODULE_ALIAS("snd-hda-codec-id:14f15066");
2568 MODULE_ALIAS("snd-hda-codec-id:14f15067");
2569 
2570 MODULE_LICENSE("GPL");
2571 MODULE_DESCRIPTION("Conexant HD-audio codec");
2572 
2573 static struct hda_codec_preset_list conexant_list = {
2574 	.preset = snd_hda_preset_conexant,
2575 	.owner = THIS_MODULE,
2576 };
2577 
2578 static int __init patch_conexant_init(void)
2579 {
2580 	return snd_hda_add_codec_preset(&conexant_list);
2581 }
2582 
2583 static void __exit patch_conexant_exit(void)
2584 {
2585 	snd_hda_delete_codec_preset(&conexant_list);
2586 }
2587 
2588 module_init(patch_conexant_init)
2589 module_exit(patch_conexant_exit)
2590