2 * HD audio interface patch for Conexant HDA audio codec
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
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.
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.
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
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>
30 #include "hda_codec.h"
31 #include "hda_local.h"
33 #define CXT_PIN_DIR_IN 0x00
34 #define CXT_PIN_DIR_OUT 0x01
35 #define CXT_PIN_DIR_INOUT 0x02
36 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
37 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39 #define CONEXANT_HP_EVENT 0x37
40 #define CONEXANT_MIC_EVENT 0x38
42 /* Conexant 5051 specific */
44 #define CXT5051_SPDIF_OUT 0x1C
45 #define CXT5051_PORTB_EVENT 0x38
46 #define CXT5051_PORTC_EVENT 0x39
49 struct conexant_jack {
53 struct snd_jack *jack;
57 struct conexant_spec {
59 struct snd_kcontrol_new *mixers[5];
62 const struct hda_verb *init_verbs[5]; /* initialization verbs
66 unsigned int num_init_verbs;
69 struct hda_multi_out multiout; /* playback set-up
70 * max_channels, dacs must be set
71 * dig_out_nid and hp_nid are optional
73 unsigned int cur_eapd;
74 unsigned int hp_present;
75 unsigned int no_auto_mic;
76 unsigned int need_dac_fix;
79 unsigned int num_adc_nids;
81 hda_nid_t dig_in_nid; /* digital-in NID; optional */
83 unsigned int cur_adc_idx;
85 unsigned int cur_adc_stream_tag;
86 unsigned int cur_adc_format;
89 const struct hda_input_mux *input_mux;
90 hda_nid_t *capsrc_nids;
91 unsigned int cur_mux[3];
94 const struct hda_channel_mode *channel_mode;
98 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
100 unsigned int spdif_route;
103 struct snd_array jacks;
105 /* dynamic controls, init_verbs and input_mux */
106 struct auto_pin_cfg autocfg;
107 struct hda_input_mux private_imux;
108 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
112 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
113 struct hda_codec *codec,
114 struct snd_pcm_substream *substream)
116 struct conexant_spec *spec = codec->spec;
117 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
121 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
122 struct hda_codec *codec,
123 unsigned int stream_tag,
125 struct snd_pcm_substream *substream)
127 struct conexant_spec *spec = codec->spec;
128 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
133 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
134 struct hda_codec *codec,
135 struct snd_pcm_substream *substream)
137 struct conexant_spec *spec = codec->spec;
138 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
144 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
145 struct hda_codec *codec,
146 struct snd_pcm_substream *substream)
148 struct conexant_spec *spec = codec->spec;
149 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
152 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
153 struct hda_codec *codec,
154 struct snd_pcm_substream *substream)
156 struct conexant_spec *spec = codec->spec;
157 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
160 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
161 struct hda_codec *codec,
162 unsigned int stream_tag,
164 struct snd_pcm_substream *substream)
166 struct conexant_spec *spec = codec->spec;
167 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
175 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
176 struct hda_codec *codec,
177 unsigned int stream_tag,
179 struct snd_pcm_substream *substream)
181 struct conexant_spec *spec = codec->spec;
182 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
183 stream_tag, 0, format);
187 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
188 struct hda_codec *codec,
189 struct snd_pcm_substream *substream)
191 struct conexant_spec *spec = codec->spec;
192 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
198 static struct hda_pcm_stream conexant_pcm_analog_playback = {
202 .nid = 0, /* fill later */
204 .open = conexant_playback_pcm_open,
205 .prepare = conexant_playback_pcm_prepare,
206 .cleanup = conexant_playback_pcm_cleanup
210 static struct hda_pcm_stream conexant_pcm_analog_capture = {
214 .nid = 0, /* fill later */
216 .prepare = conexant_capture_pcm_prepare,
217 .cleanup = conexant_capture_pcm_cleanup
222 static struct hda_pcm_stream conexant_pcm_digital_playback = {
226 .nid = 0, /* fill later */
228 .open = conexant_dig_playback_pcm_open,
229 .close = conexant_dig_playback_pcm_close,
230 .prepare = conexant_dig_playback_pcm_prepare
234 static struct hda_pcm_stream conexant_pcm_digital_capture = {
238 /* NID is set in alc_build_pcms */
241 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
242 struct hda_codec *codec,
243 unsigned int stream_tag,
245 struct snd_pcm_substream *substream)
247 struct conexant_spec *spec = codec->spec;
248 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
249 spec->cur_adc_stream_tag = stream_tag;
250 spec->cur_adc_format = format;
251 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
255 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
256 struct hda_codec *codec,
257 struct snd_pcm_substream *substream)
259 struct conexant_spec *spec = codec->spec;
260 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
265 static struct hda_pcm_stream cx5051_pcm_analog_capture = {
269 .nid = 0, /* fill later */
271 .prepare = cx5051_capture_pcm_prepare,
272 .cleanup = cx5051_capture_pcm_cleanup
276 static int conexant_build_pcms(struct hda_codec *codec)
278 struct conexant_spec *spec = codec->spec;
279 struct hda_pcm *info = spec->pcm_rec;
282 codec->pcm_info = info;
284 info->name = "CONEXANT Analog";
285 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
286 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
287 spec->multiout.max_channels;
288 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
289 spec->multiout.dac_nids[0];
290 if (codec->vendor_id == 0x14f15051)
291 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
292 cx5051_pcm_analog_capture;
294 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
295 conexant_pcm_analog_capture;
296 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
297 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
299 if (spec->multiout.dig_out_nid) {
302 info->name = "Conexant Digital";
303 info->pcm_type = HDA_PCM_TYPE_SPDIF;
304 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
305 conexant_pcm_digital_playback;
306 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
307 spec->multiout.dig_out_nid;
308 if (spec->dig_in_nid) {
309 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
310 conexant_pcm_digital_capture;
311 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
319 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
320 struct snd_ctl_elem_info *uinfo)
322 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
323 struct conexant_spec *spec = codec->spec;
325 return snd_hda_input_mux_info(spec->input_mux, uinfo);
328 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
329 struct snd_ctl_elem_value *ucontrol)
331 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
332 struct conexant_spec *spec = codec->spec;
333 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
335 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
339 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
340 struct snd_ctl_elem_value *ucontrol)
342 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
343 struct conexant_spec *spec = codec->spec;
344 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
346 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
347 spec->capsrc_nids[adc_idx],
348 &spec->cur_mux[adc_idx]);
351 #ifdef CONFIG_SND_JACK
352 static int conexant_add_jack(struct hda_codec *codec,
353 hda_nid_t nid, int type)
355 struct conexant_spec *spec;
356 struct conexant_jack *jack;
360 snd_array_init(&spec->jacks, sizeof(*jack), 32);
361 jack = snd_array_new(&spec->jacks);
362 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
370 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
373 static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
375 struct conexant_spec *spec = codec->spec;
376 struct conexant_jack *jacks = spec->jacks.list;
380 for (i = 0; i < spec->jacks.used; i++) {
381 if (jacks->nid == nid) {
382 unsigned int present;
383 present = snd_hda_codec_read(codec, nid, 0,
384 AC_VERB_GET_PIN_SENSE, 0) &
385 AC_PINSENSE_PRESENCE;
387 present = (present) ? jacks->type : 0 ;
389 snd_jack_report(jacks->jack,
397 static int conexant_init_jacks(struct hda_codec *codec)
399 struct conexant_spec *spec = codec->spec;
402 for (i = 0; i < spec->num_init_verbs; i++) {
403 const struct hda_verb *hv;
405 hv = spec->init_verbs[i];
408 switch (hv->param ^ AC_USRSP_EN) {
409 case CONEXANT_HP_EVENT:
410 err = conexant_add_jack(codec, hv->nid,
412 conexant_report_jack(codec, hv->nid);
414 case CXT5051_PORTC_EVENT:
415 case CONEXANT_MIC_EVENT:
416 err = conexant_add_jack(codec, hv->nid,
417 SND_JACK_MICROPHONE);
418 conexant_report_jack(codec, hv->nid);
430 static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
434 static inline int conexant_init_jacks(struct hda_codec *codec)
440 static int conexant_init(struct hda_codec *codec)
442 struct conexant_spec *spec = codec->spec;
445 for (i = 0; i < spec->num_init_verbs; i++)
446 snd_hda_sequence_write(codec, spec->init_verbs[i]);
450 static void conexant_free(struct hda_codec *codec)
452 #ifdef CONFIG_SND_JACK
453 struct conexant_spec *spec = codec->spec;
454 if (spec->jacks.list) {
455 struct conexant_jack *jacks = spec->jacks.list;
457 for (i = 0; i < spec->jacks.used; i++)
458 snd_device_free(codec->bus->card, &jacks[i].jack);
459 snd_array_free(&spec->jacks);
465 static int conexant_build_controls(struct hda_codec *codec)
467 struct conexant_spec *spec = codec->spec;
471 for (i = 0; i < spec->num_mixers; i++) {
472 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
476 if (spec->multiout.dig_out_nid) {
477 err = snd_hda_create_spdif_out_ctls(codec,
478 spec->multiout.dig_out_nid);
481 err = snd_hda_create_spdif_share_sw(codec,
485 spec->multiout.share_spdif = 1;
487 if (spec->dig_in_nid) {
488 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
495 static struct hda_codec_ops conexant_patch_ops = {
496 .build_controls = conexant_build_controls,
497 .build_pcms = conexant_build_pcms,
498 .init = conexant_init,
499 .free = conexant_free,
504 * the private value = nid | (invert << 8)
507 #define cxt_eapd_info snd_ctl_boolean_mono_info
509 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
510 struct snd_ctl_elem_value *ucontrol)
512 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
513 struct conexant_spec *spec = codec->spec;
514 int invert = (kcontrol->private_value >> 8) & 1;
516 ucontrol->value.integer.value[0] = !spec->cur_eapd;
518 ucontrol->value.integer.value[0] = spec->cur_eapd;
523 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
524 struct snd_ctl_elem_value *ucontrol)
526 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
527 struct conexant_spec *spec = codec->spec;
528 int invert = (kcontrol->private_value >> 8) & 1;
529 hda_nid_t nid = kcontrol->private_value & 0xff;
532 eapd = !!ucontrol->value.integer.value[0];
535 if (eapd == spec->cur_eapd)
538 spec->cur_eapd = eapd;
539 snd_hda_codec_write_cache(codec, nid,
540 0, AC_VERB_SET_EAPD_BTLENABLE,
545 /* controls for test mode */
546 #ifdef CONFIG_SND_DEBUG
548 #define CXT_EAPD_SWITCH(xname, nid, mask) \
549 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
550 .info = cxt_eapd_info, \
551 .get = cxt_eapd_get, \
552 .put = cxt_eapd_put, \
553 .private_value = nid | (mask<<16) }
557 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
558 struct snd_ctl_elem_info *uinfo)
560 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
561 struct conexant_spec *spec = codec->spec;
562 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
563 spec->num_channel_mode);
566 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
567 struct snd_ctl_elem_value *ucontrol)
569 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
570 struct conexant_spec *spec = codec->spec;
571 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
572 spec->num_channel_mode,
573 spec->multiout.max_channels);
576 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
577 struct snd_ctl_elem_value *ucontrol)
579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
580 struct conexant_spec *spec = codec->spec;
581 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
582 spec->num_channel_mode,
583 &spec->multiout.max_channels);
584 if (err >= 0 && spec->need_dac_fix)
585 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
589 #define CXT_PIN_MODE(xname, nid, dir) \
590 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
591 .info = conexant_ch_mode_info, \
592 .get = conexant_ch_mode_get, \
593 .put = conexant_ch_mode_put, \
594 .private_value = nid | (dir<<16) }
596 #endif /* CONFIG_SND_DEBUG */
598 /* Conexant 5045 specific */
600 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
601 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
602 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
603 #define CXT5045_SPDIF_OUT 0x18
605 static struct hda_channel_mode cxt5045_modes[1] = {
609 static struct hda_input_mux cxt5045_capture_source = {
617 static struct hda_input_mux cxt5045_capture_source_benq = {
626 static struct hda_input_mux cxt5045_capture_source_hp530 = {
634 /* turn on/off EAPD (+ mute HP) as a master switch */
635 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
636 struct snd_ctl_elem_value *ucontrol)
638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639 struct conexant_spec *spec = codec->spec;
642 if (!cxt_eapd_put(kcontrol, ucontrol))
645 /* toggle internal speakers mute depending of presence of
648 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
649 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
652 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
653 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
658 /* bind volumes of both NID 0x10 and 0x11 */
659 static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
660 .ops = &snd_hda_bind_vol,
662 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
663 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
668 /* toggle input of built-in and mic jack appropriately */
669 static void cxt5045_hp_automic(struct hda_codec *codec)
671 static struct hda_verb mic_jack_on[] = {
672 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
673 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
676 static struct hda_verb mic_jack_off[] = {
677 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
678 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
681 unsigned int present;
683 present = snd_hda_codec_read(codec, 0x12, 0,
684 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
686 snd_hda_sequence_write(codec, mic_jack_on);
688 snd_hda_sequence_write(codec, mic_jack_off);
692 /* mute internal speaker if HP is plugged */
693 static void cxt5045_hp_automute(struct hda_codec *codec)
695 struct conexant_spec *spec = codec->spec;
698 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
699 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
701 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
702 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
706 /* unsolicited event for HP jack sensing */
707 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
712 case CONEXANT_HP_EVENT:
713 cxt5045_hp_automute(codec);
715 case CONEXANT_MIC_EVENT:
716 cxt5045_hp_automic(codec);
722 static struct snd_kcontrol_new cxt5045_mixers[] = {
724 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
725 .name = "Capture Source",
726 .info = conexant_mux_enum_info,
727 .get = conexant_mux_enum_get,
728 .put = conexant_mux_enum_put
730 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
731 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
732 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
733 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
734 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
735 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
736 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
737 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
738 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
739 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
740 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
742 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
743 .name = "Master Playback Switch",
744 .info = cxt_eapd_info,
746 .put = cxt5045_hp_master_sw_put,
747 .private_value = 0x10,
753 static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
754 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
755 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
756 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
757 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
762 static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
764 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
765 .name = "Capture Source",
766 .info = conexant_mux_enum_info,
767 .get = conexant_mux_enum_get,
768 .put = conexant_mux_enum_put
770 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
771 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
772 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
773 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
774 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
775 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
776 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
777 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
778 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
779 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
780 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
782 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
783 .name = "Master Playback Switch",
784 .info = cxt_eapd_info,
786 .put = cxt5045_hp_master_sw_put,
787 .private_value = 0x10,
793 static struct hda_verb cxt5045_init_verbs[] = {
795 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
796 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
798 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
799 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
800 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
801 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
802 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
803 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
804 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
805 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
806 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
807 /* Record selector: Int mic */
808 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
809 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
810 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
811 /* SPDIF route: PCM */
812 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
813 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
815 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
819 static struct hda_verb cxt5045_benq_init_verbs[] = {
821 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
822 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
823 /* Line In,HP, Amp */
824 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
825 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
826 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
827 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
828 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
829 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
830 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
831 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
832 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
833 /* Record selector: Int mic */
834 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
835 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
836 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
837 /* SPDIF route: PCM */
838 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
839 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
841 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
845 static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
846 /* pin sensing on HP jack */
847 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
851 static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
852 /* pin sensing on HP jack */
853 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
857 #ifdef CONFIG_SND_DEBUG
858 /* Test configuration for debugging, modelled after the ALC260 test
861 static struct hda_input_mux cxt5045_test_capture_source = {
866 { "LINE1 pin", 0x2 },
867 { "HP-OUT pin", 0x3 },
872 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
874 /* Output controls */
875 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
876 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
877 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
878 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
879 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
880 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
882 /* Modes for retasking pin widgets */
883 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
884 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
886 /* EAPD Switch Control */
887 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
889 /* Loopback mixer controls */
891 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
892 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
893 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
894 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
895 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
896 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
897 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
898 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
899 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
900 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
902 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
903 .name = "Input Source",
904 .info = conexant_mux_enum_info,
905 .get = conexant_mux_enum_get,
906 .put = conexant_mux_enum_put,
908 /* Audio input controls */
909 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
910 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
911 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
912 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
913 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
914 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
915 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
916 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
917 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
918 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
922 static struct hda_verb cxt5045_test_init_verbs[] = {
923 /* Set connections */
924 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
925 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
926 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
927 /* Enable retasking pins as output, initially without power amp */
928 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
929 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
931 /* Disable digital (SPDIF) pins initially, but users can enable
932 * them via a mixer switch. In the case of SPDIF-out, this initverb
933 * payload also sets the generation to 0, output to be in "consumer"
934 * PCM format, copyright asserted, no pre-emphasis and no validity
937 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
938 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
940 /* Start with output sum widgets muted and their output gains at min */
941 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
942 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
944 /* Unmute retasking pin widget output buffers since the default
945 * state appears to be output. As the pin mode is changed by the
946 * user the pin mode control will take care of enabling the pin's
947 * input/output buffers as needed.
949 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
950 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
952 /* Mute capture amp left and right */
953 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
955 /* Set ADC connection select to match default mixer setting (mic1
958 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
959 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
961 /* Mute all inputs to mixer widget (even unconnected ones) */
962 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
963 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
964 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
965 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
966 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
973 /* initialize jack-sensing, too */
974 static int cxt5045_init(struct hda_codec *codec)
976 conexant_init(codec);
977 cxt5045_hp_automute(codec);
983 CXT5045_LAPTOP_HPSENSE,
984 CXT5045_LAPTOP_MICSENSE,
985 CXT5045_LAPTOP_HPMICSENSE,
987 CXT5045_LAPTOP_HP530,
988 #ifdef CONFIG_SND_DEBUG
994 static const char *cxt5045_models[CXT5045_MODELS] = {
995 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
996 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
997 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
998 [CXT5045_BENQ] = "benq",
999 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1000 #ifdef CONFIG_SND_DEBUG
1001 [CXT5045_TEST] = "test",
1005 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1006 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1007 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1008 CXT5045_LAPTOP_HPSENSE),
1009 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1010 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1011 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1012 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1013 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1014 CXT5045_LAPTOP_HPMICSENSE),
1015 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1016 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1017 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1018 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1019 CXT5045_LAPTOP_HPMICSENSE),
1020 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1024 static int patch_cxt5045(struct hda_codec *codec)
1026 struct conexant_spec *spec;
1029 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1034 spec->multiout.max_channels = 2;
1035 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1036 spec->multiout.dac_nids = cxt5045_dac_nids;
1037 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1038 spec->num_adc_nids = 1;
1039 spec->adc_nids = cxt5045_adc_nids;
1040 spec->capsrc_nids = cxt5045_capsrc_nids;
1041 spec->input_mux = &cxt5045_capture_source;
1042 spec->num_mixers = 1;
1043 spec->mixers[0] = cxt5045_mixers;
1044 spec->num_init_verbs = 1;
1045 spec->init_verbs[0] = cxt5045_init_verbs;
1046 spec->spdif_route = 0;
1047 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1048 spec->channel_mode = cxt5045_modes,
1051 codec->patch_ops = conexant_patch_ops;
1053 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1056 switch (board_config) {
1057 case CXT5045_LAPTOP_HPSENSE:
1058 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1059 spec->input_mux = &cxt5045_capture_source;
1060 spec->num_init_verbs = 2;
1061 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1062 spec->mixers[0] = cxt5045_mixers;
1063 codec->patch_ops.init = cxt5045_init;
1065 case CXT5045_LAPTOP_MICSENSE:
1066 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1067 spec->input_mux = &cxt5045_capture_source;
1068 spec->num_init_verbs = 2;
1069 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1070 spec->mixers[0] = cxt5045_mixers;
1071 codec->patch_ops.init = cxt5045_init;
1074 case CXT5045_LAPTOP_HPMICSENSE:
1075 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1076 spec->input_mux = &cxt5045_capture_source;
1077 spec->num_init_verbs = 3;
1078 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1079 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1080 spec->mixers[0] = cxt5045_mixers;
1081 codec->patch_ops.init = cxt5045_init;
1084 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1085 spec->input_mux = &cxt5045_capture_source_benq;
1086 spec->num_init_verbs = 1;
1087 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1088 spec->mixers[0] = cxt5045_mixers;
1089 spec->mixers[1] = cxt5045_benq_mixers;
1090 spec->num_mixers = 2;
1091 codec->patch_ops.init = cxt5045_init;
1093 case CXT5045_LAPTOP_HP530:
1094 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1095 spec->input_mux = &cxt5045_capture_source_hp530;
1096 spec->num_init_verbs = 2;
1097 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1098 spec->mixers[0] = cxt5045_mixers_hp530;
1099 codec->patch_ops.init = cxt5045_init;
1101 #ifdef CONFIG_SND_DEBUG
1103 spec->input_mux = &cxt5045_test_capture_source;
1104 spec->mixers[0] = cxt5045_test_mixer;
1105 spec->init_verbs[0] = cxt5045_test_init_verbs;
1111 switch (codec->subsystem_id >> 16) {
1113 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1114 * Fix max PCM level to 0 dB
1115 * (originall it has 0x2b steps with 0dB offset 0x14)
1117 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1118 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1119 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1120 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1121 (1 << AC_AMPCAP_MUTE_SHIFT));
1129 /* Conexant 5047 specific */
1130 #define CXT5047_SPDIF_OUT 0x11
1132 static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
1133 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1134 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1136 static struct hda_channel_mode cxt5047_modes[1] = {
1140 static struct hda_input_mux cxt5047_capture_source = {
1147 static struct hda_input_mux cxt5047_hp_capture_source = {
1154 static struct hda_input_mux cxt5047_toshiba_capture_source = {
1162 /* turn on/off EAPD (+ mute HP) as a master switch */
1163 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1164 struct snd_ctl_elem_value *ucontrol)
1166 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1167 struct conexant_spec *spec = codec->spec;
1170 if (!cxt_eapd_put(kcontrol, ucontrol))
1173 /* toggle internal speakers mute depending of presence of
1174 * the headphone jack
1176 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1177 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1178 HDA_AMP_MUTE, bits);
1179 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1180 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1181 HDA_AMP_MUTE, bits);
1185 /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
1186 static struct hda_bind_ctls cxt5047_bind_master_vol = {
1187 .ops = &snd_hda_bind_vol,
1189 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1190 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1195 /* mute internal speaker if HP is plugged */
1196 static void cxt5047_hp_automute(struct hda_codec *codec)
1198 struct conexant_spec *spec = codec->spec;
1201 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1202 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1204 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1205 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1206 HDA_AMP_MUTE, bits);
1207 /* Mute/Unmute PCM 2 for good measure - some systems need this */
1208 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1209 HDA_AMP_MUTE, bits);
1212 /* mute internal speaker if HP is plugged */
1213 static void cxt5047_hp2_automute(struct hda_codec *codec)
1215 struct conexant_spec *spec = codec->spec;
1218 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1219 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1221 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1222 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1223 HDA_AMP_MUTE, bits);
1224 /* Mute/Unmute PCM 2 for good measure - some systems need this */
1225 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1226 HDA_AMP_MUTE, bits);
1229 /* toggle input of built-in and mic jack appropriately */
1230 static void cxt5047_hp_automic(struct hda_codec *codec)
1232 static struct hda_verb mic_jack_on[] = {
1233 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1234 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1237 static struct hda_verb mic_jack_off[] = {
1238 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1239 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1242 unsigned int present;
1244 present = snd_hda_codec_read(codec, 0x15, 0,
1245 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1247 snd_hda_sequence_write(codec, mic_jack_on);
1249 snd_hda_sequence_write(codec, mic_jack_off);
1252 /* unsolicited event for HP jack sensing */
1253 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1256 switch (res >> 26) {
1257 case CONEXANT_HP_EVENT:
1258 cxt5047_hp_automute(codec);
1260 case CONEXANT_MIC_EVENT:
1261 cxt5047_hp_automic(codec);
1266 /* unsolicited event for HP jack sensing - non-EAPD systems */
1267 static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1272 case CONEXANT_HP_EVENT:
1273 cxt5047_hp2_automute(codec);
1275 case CONEXANT_MIC_EVENT:
1276 cxt5047_hp_automic(codec);
1281 static struct snd_kcontrol_new cxt5047_mixers[] = {
1282 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1283 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1284 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1285 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
1286 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1287 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1288 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1289 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1290 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1291 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1292 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1293 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1294 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1295 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
1300 static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1302 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1303 .name = "Capture Source",
1304 .info = conexant_mux_enum_info,
1305 .get = conexant_mux_enum_get,
1306 .put = conexant_mux_enum_put
1308 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1309 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1310 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1311 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1312 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1313 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1314 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
1316 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1317 .name = "Master Playback Switch",
1318 .info = cxt_eapd_info,
1319 .get = cxt_eapd_get,
1320 .put = cxt5047_hp_master_sw_put,
1321 .private_value = 0x13,
1327 static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1329 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1330 .name = "Capture Source",
1331 .info = conexant_mux_enum_info,
1332 .get = conexant_mux_enum_get,
1333 .put = conexant_mux_enum_put
1335 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1336 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1337 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1338 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1339 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1340 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1341 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1343 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1344 .name = "Master Playback Switch",
1345 .info = cxt_eapd_info,
1346 .get = cxt_eapd_get,
1347 .put = cxt5047_hp_master_sw_put,
1348 .private_value = 0x13,
1353 static struct hda_verb cxt5047_init_verbs[] = {
1354 /* Line in, Mic, Built-in Mic */
1355 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1356 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1357 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1359 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1360 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
1361 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1362 /* Record selector: Mic */
1363 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1364 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1365 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1366 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1367 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1368 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1369 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1370 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1371 /* SPDIF route: PCM */
1372 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1373 /* Enable unsolicited events */
1374 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1375 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1379 /* configuration for Toshiba Laptops */
1380 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1381 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1382 /* pin sensing on HP and Mic jacks */
1383 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1384 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1385 /* Speaker routing */
1386 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1390 /* configuration for HP Laptops */
1391 static struct hda_verb cxt5047_hp_init_verbs[] = {
1392 /* pin sensing on HP jack */
1393 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1394 /* 0x13 is actually shared by both HP and speaker;
1395 * setting the connection to 0 (=0x19) makes the master volume control
1396 * working mysteriouslly...
1398 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1399 /* Record selector: Ext Mic */
1400 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1401 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1402 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1403 /* Speaker routing */
1404 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1408 /* Test configuration for debugging, modelled after the ALC260 test
1411 #ifdef CONFIG_SND_DEBUG
1412 static struct hda_input_mux cxt5047_test_capture_source = {
1415 { "LINE1 pin", 0x0 },
1416 { "MIC1 pin", 0x1 },
1417 { "MIC2 pin", 0x2 },
1422 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1424 /* Output only controls */
1425 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1426 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1427 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1428 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1429 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1431 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1432 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1433 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1434 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1435 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1436 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1438 /* Modes for retasking pin widgets */
1439 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1440 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1442 /* EAPD Switch Control */
1443 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1445 /* Loopback mixer controls */
1446 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1447 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1448 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1449 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1450 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1451 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1452 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1453 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1455 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1456 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1457 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1458 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1459 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1460 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1461 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1462 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1464 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1465 .name = "Input Source",
1466 .info = conexant_mux_enum_info,
1467 .get = conexant_mux_enum_get,
1468 .put = conexant_mux_enum_put,
1470 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1471 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1472 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1473 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1474 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1475 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1476 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1477 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1478 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1479 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1484 static struct hda_verb cxt5047_test_init_verbs[] = {
1485 /* Enable retasking pins as output, initially without power amp */
1486 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1487 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1488 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1490 /* Disable digital (SPDIF) pins initially, but users can enable
1491 * them via a mixer switch. In the case of SPDIF-out, this initverb
1492 * payload also sets the generation to 0, output to be in "consumer"
1493 * PCM format, copyright asserted, no pre-emphasis and no validity
1496 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1498 /* Ensure mic1, mic2, line1 pin widgets take input from the
1499 * OUT1 sum bus when acting as an output.
1501 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1502 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1504 /* Start with output sum widgets muted and their output gains at min */
1505 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1506 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1508 /* Unmute retasking pin widget output buffers since the default
1509 * state appears to be output. As the pin mode is changed by the
1510 * user the pin mode control will take care of enabling the pin's
1511 * input/output buffers as needed.
1513 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1514 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1515 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1517 /* Mute capture amp left and right */
1518 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1520 /* Set ADC connection select to match default mixer setting (mic1
1523 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1525 /* Mute all inputs to mixer widget (even unconnected ones) */
1526 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1530 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1531 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1533 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1540 /* initialize jack-sensing, too */
1541 static int cxt5047_hp_init(struct hda_codec *codec)
1543 conexant_init(codec);
1544 cxt5047_hp_automute(codec);
1550 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1551 CXT5047_LAPTOP_HP, /* Some HP laptops */
1552 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1553 #ifdef CONFIG_SND_DEBUG
1559 static const char *cxt5047_models[CXT5047_MODELS] = {
1560 [CXT5047_LAPTOP] = "laptop",
1561 [CXT5047_LAPTOP_HP] = "laptop-hp",
1562 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1563 #ifdef CONFIG_SND_DEBUG
1564 [CXT5047_TEST] = "test",
1568 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1569 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1570 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1572 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1576 static int patch_cxt5047(struct hda_codec *codec)
1578 struct conexant_spec *spec;
1581 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1586 spec->multiout.max_channels = 2;
1587 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1588 spec->multiout.dac_nids = cxt5047_dac_nids;
1589 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1590 spec->num_adc_nids = 1;
1591 spec->adc_nids = cxt5047_adc_nids;
1592 spec->capsrc_nids = cxt5047_capsrc_nids;
1593 spec->input_mux = &cxt5047_capture_source;
1594 spec->num_mixers = 1;
1595 spec->mixers[0] = cxt5047_mixers;
1596 spec->num_init_verbs = 1;
1597 spec->init_verbs[0] = cxt5047_init_verbs;
1598 spec->spdif_route = 0;
1599 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1600 spec->channel_mode = cxt5047_modes,
1602 codec->patch_ops = conexant_patch_ops;
1604 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1607 switch (board_config) {
1608 case CXT5047_LAPTOP:
1609 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
1611 case CXT5047_LAPTOP_HP:
1612 spec->input_mux = &cxt5047_hp_capture_source;
1613 spec->num_init_verbs = 2;
1614 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1615 spec->mixers[0] = cxt5047_hp_mixers;
1616 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1617 codec->patch_ops.init = cxt5047_hp_init;
1619 case CXT5047_LAPTOP_EAPD:
1620 spec->input_mux = &cxt5047_toshiba_capture_source;
1621 spec->num_init_verbs = 2;
1622 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1623 spec->mixers[0] = cxt5047_toshiba_mixers;
1624 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1626 #ifdef CONFIG_SND_DEBUG
1628 spec->input_mux = &cxt5047_test_capture_source;
1629 spec->mixers[0] = cxt5047_test_mixer;
1630 spec->init_verbs[0] = cxt5047_test_init_verbs;
1631 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1637 /* Conexant 5051 specific */
1638 static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1639 static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1641 static struct hda_channel_mode cxt5051_modes[1] = {
1645 static void cxt5051_update_speaker(struct hda_codec *codec)
1647 struct conexant_spec *spec = codec->spec;
1648 unsigned int pinctl;
1649 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1650 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1654 /* turn on/off EAPD (+ mute HP) as a master switch */
1655 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1656 struct snd_ctl_elem_value *ucontrol)
1658 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1660 if (!cxt_eapd_put(kcontrol, ucontrol))
1662 cxt5051_update_speaker(codec);
1666 /* toggle input of built-in and mic jack appropriately */
1667 static void cxt5051_portb_automic(struct hda_codec *codec)
1669 struct conexant_spec *spec = codec->spec;
1670 unsigned int present;
1672 if (spec->no_auto_mic)
1674 present = snd_hda_codec_read(codec, 0x17, 0,
1675 AC_VERB_GET_PIN_SENSE, 0) &
1676 AC_PINSENSE_PRESENCE;
1677 snd_hda_codec_write(codec, 0x14, 0,
1678 AC_VERB_SET_CONNECT_SEL,
1679 present ? 0x01 : 0x00);
1682 /* switch the current ADC according to the jack state */
1683 static void cxt5051_portc_automic(struct hda_codec *codec)
1685 struct conexant_spec *spec = codec->spec;
1686 unsigned int present;
1689 if (spec->no_auto_mic)
1691 present = snd_hda_codec_read(codec, 0x18, 0,
1692 AC_VERB_GET_PIN_SENSE, 0) &
1693 AC_PINSENSE_PRESENCE;
1695 spec->cur_adc_idx = 1;
1697 spec->cur_adc_idx = 0;
1698 new_adc = spec->adc_nids[spec->cur_adc_idx];
1699 if (spec->cur_adc && spec->cur_adc != new_adc) {
1700 /* stream is running, let's swap the current ADC */
1701 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1702 spec->cur_adc = new_adc;
1703 snd_hda_codec_setup_stream(codec, new_adc,
1704 spec->cur_adc_stream_tag, 0,
1705 spec->cur_adc_format);
1709 /* mute internal speaker if HP is plugged */
1710 static void cxt5051_hp_automute(struct hda_codec *codec)
1712 struct conexant_spec *spec = codec->spec;
1714 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1715 AC_VERB_GET_PIN_SENSE, 0) &
1716 AC_PINSENSE_PRESENCE;
1717 cxt5051_update_speaker(codec);
1720 /* unsolicited event for HP jack sensing */
1721 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1724 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1725 switch (res >> 26) {
1726 case CONEXANT_HP_EVENT:
1727 cxt5051_hp_automute(codec);
1729 case CXT5051_PORTB_EVENT:
1730 cxt5051_portb_automic(codec);
1732 case CXT5051_PORTC_EVENT:
1733 cxt5051_portc_automic(codec);
1736 conexant_report_jack(codec, nid);
1739 static struct snd_kcontrol_new cxt5051_mixers[] = {
1740 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1741 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1742 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1743 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1744 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1745 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1746 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1748 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1749 .name = "Master Playback Switch",
1750 .info = cxt_eapd_info,
1751 .get = cxt_eapd_get,
1752 .put = cxt5051_hp_master_sw_put,
1753 .private_value = 0x1a,
1759 static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1760 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1761 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1762 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1763 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1764 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1766 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1767 .name = "Master Playback Switch",
1768 .info = cxt_eapd_info,
1769 .get = cxt_eapd_get,
1770 .put = cxt5051_hp_master_sw_put,
1771 .private_value = 0x1a,
1777 static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1778 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1779 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1780 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1782 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1783 .name = "Master Playback Switch",
1784 .info = cxt_eapd_info,
1785 .get = cxt_eapd_get,
1786 .put = cxt5051_hp_master_sw_put,
1787 .private_value = 0x1a,
1793 static struct hda_verb cxt5051_init_verbs[] = {
1795 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1796 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1797 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1798 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1799 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1800 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1802 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1803 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1805 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1806 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1808 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1809 /* Record selector: Int mic */
1810 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1811 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1812 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1813 /* SPDIF route: PCM */
1814 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1816 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1817 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1818 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1819 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1823 static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1825 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1826 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1827 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1828 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1830 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1831 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1833 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1834 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1836 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1837 /* Record selector: Int mic */
1838 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1839 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1840 /* SPDIF route: PCM */
1841 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1843 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1844 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1845 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1849 static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1851 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1852 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1853 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1854 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1855 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1856 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1858 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1859 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1861 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1862 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1864 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1865 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1867 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1868 /* Record selector: Int mic */
1869 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1870 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1871 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1872 /* SPDIF route: PCM */
1873 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1875 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1876 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1877 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1878 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1879 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1883 /* initialize jack-sensing, too */
1884 static int cxt5051_init(struct hda_codec *codec)
1886 conexant_init(codec);
1887 conexant_init_jacks(codec);
1888 if (codec->patch_ops.unsol_event) {
1889 cxt5051_hp_automute(codec);
1890 cxt5051_portb_automic(codec);
1891 cxt5051_portc_automic(codec);
1898 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1899 CXT5051_HP, /* no docking */
1900 CXT5051_HP_DV6736, /* HP without mic switch */
1901 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
1905 static const char *cxt5051_models[CXT5051_MODELS] = {
1906 [CXT5051_LAPTOP] = "laptop",
1907 [CXT5051_HP] = "hp",
1908 [CXT5051_HP_DV6736] = "hp-dv6736",
1909 [CXT5051_LENOVO_X200] = "lenovo-x200",
1912 static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1913 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1914 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1916 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1917 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1921 static int patch_cxt5051(struct hda_codec *codec)
1923 struct conexant_spec *spec;
1926 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1931 codec->patch_ops = conexant_patch_ops;
1932 codec->patch_ops.init = cxt5051_init;
1934 spec->multiout.max_channels = 2;
1935 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1936 spec->multiout.dac_nids = cxt5051_dac_nids;
1937 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1938 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1939 spec->adc_nids = cxt5051_adc_nids;
1940 spec->num_mixers = 1;
1941 spec->mixers[0] = cxt5051_mixers;
1942 spec->num_init_verbs = 1;
1943 spec->init_verbs[0] = cxt5051_init_verbs;
1944 spec->spdif_route = 0;
1945 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1946 spec->channel_mode = cxt5051_modes;
1948 spec->cur_adc_idx = 0;
1950 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1952 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1955 switch (board_config) {
1957 spec->mixers[0] = cxt5051_hp_mixers;
1959 case CXT5051_HP_DV6736:
1960 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1961 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1962 spec->no_auto_mic = 1;
1964 case CXT5051_LENOVO_X200:
1965 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1976 static struct hda_codec_preset snd_hda_preset_conexant[] = {
1977 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1978 .patch = patch_cxt5045 },
1979 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1980 .patch = patch_cxt5047 },
1981 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1982 .patch = patch_cxt5051 },
1986 MODULE_ALIAS("snd-hda-codec-id:14f15045");
1987 MODULE_ALIAS("snd-hda-codec-id:14f15047");
1988 MODULE_ALIAS("snd-hda-codec-id:14f15051");
1990 MODULE_LICENSE("GPL");
1991 MODULE_DESCRIPTION("Conexant HD-audio codec");
1993 static struct hda_codec_preset_list conexant_list = {
1994 .preset = snd_hda_preset_conexant,
1995 .owner = THIS_MODULE,
1998 static int __init patch_conexant_init(void)
2000 return snd_hda_add_codec_preset(&conexant_list);
2003 static void __exit patch_conexant_exit(void)
2005 snd_hda_delete_codec_preset(&conexant_list);
2008 module_init(patch_conexant_init)
2009 module_exit(patch_conexant_exit)