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];
61 hda_nid_t vmaster_nid;
63 const struct hda_verb *init_verbs[5]; /* initialization verbs
67 unsigned int num_init_verbs;
70 struct hda_multi_out multiout; /* playback set-up
71 * max_channels, dacs must be set
72 * dig_out_nid and hp_nid are optional
74 unsigned int cur_eapd;
75 unsigned int hp_present;
76 unsigned int no_auto_mic;
77 unsigned int need_dac_fix;
80 unsigned int num_adc_nids;
82 hda_nid_t dig_in_nid; /* digital-in NID; optional */
84 unsigned int cur_adc_idx;
86 unsigned int cur_adc_stream_tag;
87 unsigned int cur_adc_format;
90 const struct hda_input_mux *input_mux;
91 hda_nid_t *capsrc_nids;
92 unsigned int cur_mux[3];
95 const struct hda_channel_mode *channel_mode;
99 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
101 unsigned int spdif_route;
104 struct snd_array jacks;
106 /* dynamic controls, init_verbs and input_mux */
107 struct auto_pin_cfg autocfg;
108 struct hda_input_mux private_imux;
109 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
113 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
114 struct hda_codec *codec,
115 struct snd_pcm_substream *substream)
117 struct conexant_spec *spec = codec->spec;
118 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
122 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
123 struct hda_codec *codec,
124 unsigned int stream_tag,
126 struct snd_pcm_substream *substream)
128 struct conexant_spec *spec = codec->spec;
129 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
134 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
135 struct hda_codec *codec,
136 struct snd_pcm_substream *substream)
138 struct conexant_spec *spec = codec->spec;
139 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
145 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
146 struct hda_codec *codec,
147 struct snd_pcm_substream *substream)
149 struct conexant_spec *spec = codec->spec;
150 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
153 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
154 struct hda_codec *codec,
155 struct snd_pcm_substream *substream)
157 struct conexant_spec *spec = codec->spec;
158 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
161 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
162 struct hda_codec *codec,
163 unsigned int stream_tag,
165 struct snd_pcm_substream *substream)
167 struct conexant_spec *spec = codec->spec;
168 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
176 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
177 struct hda_codec *codec,
178 unsigned int stream_tag,
180 struct snd_pcm_substream *substream)
182 struct conexant_spec *spec = codec->spec;
183 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
184 stream_tag, 0, format);
188 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
189 struct hda_codec *codec,
190 struct snd_pcm_substream *substream)
192 struct conexant_spec *spec = codec->spec;
193 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
199 static struct hda_pcm_stream conexant_pcm_analog_playback = {
203 .nid = 0, /* fill later */
205 .open = conexant_playback_pcm_open,
206 .prepare = conexant_playback_pcm_prepare,
207 .cleanup = conexant_playback_pcm_cleanup
211 static struct hda_pcm_stream conexant_pcm_analog_capture = {
215 .nid = 0, /* fill later */
217 .prepare = conexant_capture_pcm_prepare,
218 .cleanup = conexant_capture_pcm_cleanup
223 static struct hda_pcm_stream conexant_pcm_digital_playback = {
227 .nid = 0, /* fill later */
229 .open = conexant_dig_playback_pcm_open,
230 .close = conexant_dig_playback_pcm_close,
231 .prepare = conexant_dig_playback_pcm_prepare
235 static struct hda_pcm_stream conexant_pcm_digital_capture = {
239 /* NID is set in alc_build_pcms */
242 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
243 struct hda_codec *codec,
244 unsigned int stream_tag,
246 struct snd_pcm_substream *substream)
248 struct conexant_spec *spec = codec->spec;
249 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
250 spec->cur_adc_stream_tag = stream_tag;
251 spec->cur_adc_format = format;
252 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
256 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
257 struct hda_codec *codec,
258 struct snd_pcm_substream *substream)
260 struct conexant_spec *spec = codec->spec;
261 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
266 static struct hda_pcm_stream cx5051_pcm_analog_capture = {
270 .nid = 0, /* fill later */
272 .prepare = cx5051_capture_pcm_prepare,
273 .cleanup = cx5051_capture_pcm_cleanup
277 static int conexant_build_pcms(struct hda_codec *codec)
279 struct conexant_spec *spec = codec->spec;
280 struct hda_pcm *info = spec->pcm_rec;
283 codec->pcm_info = info;
285 info->name = "CONEXANT Analog";
286 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
287 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
288 spec->multiout.max_channels;
289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
290 spec->multiout.dac_nids[0];
291 if (codec->vendor_id == 0x14f15051)
292 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
293 cx5051_pcm_analog_capture;
295 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
296 conexant_pcm_analog_capture;
297 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
298 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
300 if (spec->multiout.dig_out_nid) {
303 info->name = "Conexant Digital";
304 info->pcm_type = HDA_PCM_TYPE_SPDIF;
305 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
306 conexant_pcm_digital_playback;
307 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
308 spec->multiout.dig_out_nid;
309 if (spec->dig_in_nid) {
310 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
311 conexant_pcm_digital_capture;
312 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
320 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
321 struct snd_ctl_elem_info *uinfo)
323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
324 struct conexant_spec *spec = codec->spec;
326 return snd_hda_input_mux_info(spec->input_mux, uinfo);
329 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
330 struct snd_ctl_elem_value *ucontrol)
332 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
333 struct conexant_spec *spec = codec->spec;
334 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
336 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
340 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
341 struct snd_ctl_elem_value *ucontrol)
343 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
344 struct conexant_spec *spec = codec->spec;
345 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
347 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
348 spec->capsrc_nids[adc_idx],
349 &spec->cur_mux[adc_idx]);
352 #ifdef CONFIG_SND_JACK
353 static int conexant_add_jack(struct hda_codec *codec,
354 hda_nid_t nid, int type)
356 struct conexant_spec *spec;
357 struct conexant_jack *jack;
361 snd_array_init(&spec->jacks, sizeof(*jack), 32);
362 jack = snd_array_new(&spec->jacks);
363 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
371 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
374 static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
376 struct conexant_spec *spec = codec->spec;
377 struct conexant_jack *jacks = spec->jacks.list;
381 for (i = 0; i < spec->jacks.used; i++) {
382 if (jacks->nid == nid) {
383 unsigned int present;
384 present = snd_hda_codec_read(codec, nid, 0,
385 AC_VERB_GET_PIN_SENSE, 0) &
386 AC_PINSENSE_PRESENCE;
388 present = (present) ? jacks->type : 0 ;
390 snd_jack_report(jacks->jack,
398 static int conexant_init_jacks(struct hda_codec *codec)
400 struct conexant_spec *spec = codec->spec;
403 for (i = 0; i < spec->num_init_verbs; i++) {
404 const struct hda_verb *hv;
406 hv = spec->init_verbs[i];
409 switch (hv->param ^ AC_USRSP_EN) {
410 case CONEXANT_HP_EVENT:
411 err = conexant_add_jack(codec, hv->nid,
413 conexant_report_jack(codec, hv->nid);
415 case CXT5051_PORTC_EVENT:
416 case CONEXANT_MIC_EVENT:
417 err = conexant_add_jack(codec, hv->nid,
418 SND_JACK_MICROPHONE);
419 conexant_report_jack(codec, hv->nid);
431 static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
435 static inline int conexant_init_jacks(struct hda_codec *codec)
441 static int conexant_init(struct hda_codec *codec)
443 struct conexant_spec *spec = codec->spec;
446 for (i = 0; i < spec->num_init_verbs; i++)
447 snd_hda_sequence_write(codec, spec->init_verbs[i]);
451 static void conexant_free(struct hda_codec *codec)
453 #ifdef CONFIG_SND_JACK
454 struct conexant_spec *spec = codec->spec;
455 if (spec->jacks.list) {
456 struct conexant_jack *jacks = spec->jacks.list;
458 for (i = 0; i < spec->jacks.used; i++)
459 snd_device_free(codec->bus->card, &jacks[i].jack);
460 snd_array_free(&spec->jacks);
466 static struct snd_kcontrol_new cxt_capture_mixers[] = {
468 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
469 .name = "Capture Source",
470 .info = conexant_mux_enum_info,
471 .get = conexant_mux_enum_get,
472 .put = conexant_mux_enum_put
477 static const char *slave_vols[] = {
478 "Headphone Playback Volume",
479 "Speaker Playback Volume",
483 static const char *slave_sws[] = {
484 "Headphone Playback Switch",
485 "Speaker Playback Switch",
489 static int conexant_build_controls(struct hda_codec *codec)
491 struct conexant_spec *spec = codec->spec;
495 for (i = 0; i < spec->num_mixers; i++) {
496 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
500 if (spec->multiout.dig_out_nid) {
501 err = snd_hda_create_spdif_out_ctls(codec,
502 spec->multiout.dig_out_nid);
505 err = snd_hda_create_spdif_share_sw(codec,
509 spec->multiout.share_spdif = 1;
511 if (spec->dig_in_nid) {
512 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
517 /* if we have no master control, let's create it */
518 if (spec->vmaster_nid &&
519 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
520 unsigned int vmaster_tlv[4];
521 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
522 HDA_OUTPUT, vmaster_tlv);
523 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
524 vmaster_tlv, slave_vols);
528 if (spec->vmaster_nid &&
529 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
530 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
536 if (spec->input_mux) {
537 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
545 static struct hda_codec_ops conexant_patch_ops = {
546 .build_controls = conexant_build_controls,
547 .build_pcms = conexant_build_pcms,
548 .init = conexant_init,
549 .free = conexant_free,
554 * the private value = nid | (invert << 8)
557 #define cxt_eapd_info snd_ctl_boolean_mono_info
559 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
560 struct snd_ctl_elem_value *ucontrol)
562 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
563 struct conexant_spec *spec = codec->spec;
564 int invert = (kcontrol->private_value >> 8) & 1;
566 ucontrol->value.integer.value[0] = !spec->cur_eapd;
568 ucontrol->value.integer.value[0] = spec->cur_eapd;
573 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
574 struct snd_ctl_elem_value *ucontrol)
576 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
577 struct conexant_spec *spec = codec->spec;
578 int invert = (kcontrol->private_value >> 8) & 1;
579 hda_nid_t nid = kcontrol->private_value & 0xff;
582 eapd = !!ucontrol->value.integer.value[0];
585 if (eapd == spec->cur_eapd)
588 spec->cur_eapd = eapd;
589 snd_hda_codec_write_cache(codec, nid,
590 0, AC_VERB_SET_EAPD_BTLENABLE,
595 /* controls for test mode */
596 #ifdef CONFIG_SND_DEBUG
598 #define CXT_EAPD_SWITCH(xname, nid, mask) \
599 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
600 .info = cxt_eapd_info, \
601 .get = cxt_eapd_get, \
602 .put = cxt_eapd_put, \
603 .private_value = nid | (mask<<16) }
607 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
608 struct snd_ctl_elem_info *uinfo)
610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
611 struct conexant_spec *spec = codec->spec;
612 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
613 spec->num_channel_mode);
616 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
617 struct snd_ctl_elem_value *ucontrol)
619 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
620 struct conexant_spec *spec = codec->spec;
621 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
622 spec->num_channel_mode,
623 spec->multiout.max_channels);
626 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
627 struct snd_ctl_elem_value *ucontrol)
629 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
630 struct conexant_spec *spec = codec->spec;
631 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
632 spec->num_channel_mode,
633 &spec->multiout.max_channels);
634 if (err >= 0 && spec->need_dac_fix)
635 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
639 #define CXT_PIN_MODE(xname, nid, dir) \
640 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
641 .info = conexant_ch_mode_info, \
642 .get = conexant_ch_mode_get, \
643 .put = conexant_ch_mode_put, \
644 .private_value = nid | (dir<<16) }
646 #endif /* CONFIG_SND_DEBUG */
648 /* Conexant 5045 specific */
650 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
651 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
652 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
653 #define CXT5045_SPDIF_OUT 0x18
655 static struct hda_channel_mode cxt5045_modes[1] = {
659 static struct hda_input_mux cxt5045_capture_source = {
667 static struct hda_input_mux cxt5045_capture_source_benq = {
676 static struct hda_input_mux cxt5045_capture_source_hp530 = {
684 /* turn on/off EAPD (+ mute HP) as a master switch */
685 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
686 struct snd_ctl_elem_value *ucontrol)
688 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
689 struct conexant_spec *spec = codec->spec;
692 if (!cxt_eapd_put(kcontrol, ucontrol))
695 /* toggle internal speakers mute depending of presence of
698 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
699 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
702 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
703 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
708 /* bind volumes of both NID 0x10 and 0x11 */
709 static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
710 .ops = &snd_hda_bind_vol,
712 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
713 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
718 /* toggle input of built-in and mic jack appropriately */
719 static void cxt5045_hp_automic(struct hda_codec *codec)
721 static struct hda_verb mic_jack_on[] = {
722 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
723 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
726 static struct hda_verb mic_jack_off[] = {
727 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
728 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
731 unsigned int present;
733 present = snd_hda_codec_read(codec, 0x12, 0,
734 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
736 snd_hda_sequence_write(codec, mic_jack_on);
738 snd_hda_sequence_write(codec, mic_jack_off);
742 /* mute internal speaker if HP is plugged */
743 static void cxt5045_hp_automute(struct hda_codec *codec)
745 struct conexant_spec *spec = codec->spec;
748 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
749 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
751 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
752 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
756 /* unsolicited event for HP jack sensing */
757 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
762 case CONEXANT_HP_EVENT:
763 cxt5045_hp_automute(codec);
765 case CONEXANT_MIC_EVENT:
766 cxt5045_hp_automic(codec);
772 static struct snd_kcontrol_new cxt5045_mixers[] = {
773 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
774 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
775 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
776 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
777 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
778 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
779 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
780 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
781 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
782 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
783 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
786 .name = "Master Playback Switch",
787 .info = cxt_eapd_info,
789 .put = cxt5045_hp_master_sw_put,
790 .private_value = 0x10,
796 static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
797 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
798 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
799 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
800 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
805 static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
806 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
807 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
808 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
809 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
810 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
811 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
812 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
813 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
814 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
815 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
816 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
818 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
819 .name = "Master Playback Switch",
820 .info = cxt_eapd_info,
822 .put = cxt5045_hp_master_sw_put,
823 .private_value = 0x10,
829 static struct hda_verb cxt5045_init_verbs[] = {
831 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
832 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
834 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
835 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
836 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
837 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
838 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
839 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
840 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
841 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
842 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
843 /* Record selector: Int mic */
844 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
845 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
846 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
847 /* SPDIF route: PCM */
848 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
849 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
851 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
855 static struct hda_verb cxt5045_benq_init_verbs[] = {
857 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
858 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
859 /* Line In,HP, Amp */
860 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
861 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
862 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
863 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
864 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
865 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
866 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
867 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
868 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
869 /* Record selector: Int mic */
870 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
871 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
872 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
873 /* SPDIF route: PCM */
874 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
875 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
877 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
881 static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
882 /* pin sensing on HP jack */
883 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
887 static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
888 /* pin sensing on HP jack */
889 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
893 #ifdef CONFIG_SND_DEBUG
894 /* Test configuration for debugging, modelled after the ALC260 test
897 static struct hda_input_mux cxt5045_test_capture_source = {
902 { "LINE1 pin", 0x2 },
903 { "HP-OUT pin", 0x3 },
908 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
910 /* Output controls */
911 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
912 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
913 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
914 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
915 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
916 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
918 /* Modes for retasking pin widgets */
919 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
920 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
922 /* EAPD Switch Control */
923 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
925 /* Loopback mixer controls */
927 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
928 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
929 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
930 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
931 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
932 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
933 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
934 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
935 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
936 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
938 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
939 .name = "Input Source",
940 .info = conexant_mux_enum_info,
941 .get = conexant_mux_enum_get,
942 .put = conexant_mux_enum_put,
944 /* Audio input controls */
945 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
946 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
947 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
948 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
949 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
950 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
951 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
952 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
953 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
954 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
958 static struct hda_verb cxt5045_test_init_verbs[] = {
959 /* Set connections */
960 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
961 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
962 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
963 /* Enable retasking pins as output, initially without power amp */
964 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
965 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
967 /* Disable digital (SPDIF) pins initially, but users can enable
968 * them via a mixer switch. In the case of SPDIF-out, this initverb
969 * payload also sets the generation to 0, output to be in "consumer"
970 * PCM format, copyright asserted, no pre-emphasis and no validity
973 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
974 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
976 /* Start with output sum widgets muted and their output gains at min */
977 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
978 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
980 /* Unmute retasking pin widget output buffers since the default
981 * state appears to be output. As the pin mode is changed by the
982 * user the pin mode control will take care of enabling the pin's
983 * input/output buffers as needed.
985 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
986 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
988 /* Mute capture amp left and right */
989 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
991 /* Set ADC connection select to match default mixer setting (mic1
994 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
995 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
997 /* Mute all inputs to mixer widget (even unconnected ones) */
998 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
999 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1000 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1001 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1002 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1009 /* initialize jack-sensing, too */
1010 static int cxt5045_init(struct hda_codec *codec)
1012 conexant_init(codec);
1013 cxt5045_hp_automute(codec);
1019 CXT5045_LAPTOP_HPSENSE,
1020 CXT5045_LAPTOP_MICSENSE,
1021 CXT5045_LAPTOP_HPMICSENSE,
1023 CXT5045_LAPTOP_HP530,
1024 #ifdef CONFIG_SND_DEBUG
1030 static const char *cxt5045_models[CXT5045_MODELS] = {
1031 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1032 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1033 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1034 [CXT5045_BENQ] = "benq",
1035 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1036 #ifdef CONFIG_SND_DEBUG
1037 [CXT5045_TEST] = "test",
1041 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1042 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1043 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1044 CXT5045_LAPTOP_HPSENSE),
1045 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1046 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1047 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1048 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1049 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1050 CXT5045_LAPTOP_HPMICSENSE),
1051 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1052 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1053 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1054 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1055 CXT5045_LAPTOP_HPMICSENSE),
1056 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1060 static int patch_cxt5045(struct hda_codec *codec)
1062 struct conexant_spec *spec;
1065 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1070 spec->multiout.max_channels = 2;
1071 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1072 spec->multiout.dac_nids = cxt5045_dac_nids;
1073 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1074 spec->num_adc_nids = 1;
1075 spec->adc_nids = cxt5045_adc_nids;
1076 spec->capsrc_nids = cxt5045_capsrc_nids;
1077 spec->input_mux = &cxt5045_capture_source;
1078 spec->num_mixers = 1;
1079 spec->mixers[0] = cxt5045_mixers;
1080 spec->num_init_verbs = 1;
1081 spec->init_verbs[0] = cxt5045_init_verbs;
1082 spec->spdif_route = 0;
1083 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1084 spec->channel_mode = cxt5045_modes,
1087 codec->patch_ops = conexant_patch_ops;
1089 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1092 switch (board_config) {
1093 case CXT5045_LAPTOP_HPSENSE:
1094 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1095 spec->input_mux = &cxt5045_capture_source;
1096 spec->num_init_verbs = 2;
1097 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1098 spec->mixers[0] = cxt5045_mixers;
1099 codec->patch_ops.init = cxt5045_init;
1101 case CXT5045_LAPTOP_MICSENSE:
1102 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1103 spec->input_mux = &cxt5045_capture_source;
1104 spec->num_init_verbs = 2;
1105 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1106 spec->mixers[0] = cxt5045_mixers;
1107 codec->patch_ops.init = cxt5045_init;
1110 case CXT5045_LAPTOP_HPMICSENSE:
1111 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1112 spec->input_mux = &cxt5045_capture_source;
1113 spec->num_init_verbs = 3;
1114 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1115 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1116 spec->mixers[0] = cxt5045_mixers;
1117 codec->patch_ops.init = cxt5045_init;
1120 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1121 spec->input_mux = &cxt5045_capture_source_benq;
1122 spec->num_init_verbs = 1;
1123 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1124 spec->mixers[0] = cxt5045_mixers;
1125 spec->mixers[1] = cxt5045_benq_mixers;
1126 spec->num_mixers = 2;
1127 codec->patch_ops.init = cxt5045_init;
1129 case CXT5045_LAPTOP_HP530:
1130 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1131 spec->input_mux = &cxt5045_capture_source_hp530;
1132 spec->num_init_verbs = 2;
1133 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1134 spec->mixers[0] = cxt5045_mixers_hp530;
1135 codec->patch_ops.init = cxt5045_init;
1137 #ifdef CONFIG_SND_DEBUG
1139 spec->input_mux = &cxt5045_test_capture_source;
1140 spec->mixers[0] = cxt5045_test_mixer;
1141 spec->init_verbs[0] = cxt5045_test_init_verbs;
1147 switch (codec->subsystem_id >> 16) {
1149 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1150 * Fix max PCM level to 0 dB
1151 * (originall it has 0x2b steps with 0dB offset 0x14)
1153 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1154 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1155 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1156 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1157 (1 << AC_AMPCAP_MUTE_SHIFT));
1165 /* Conexant 5047 specific */
1166 #define CXT5047_SPDIF_OUT 0x11
1168 static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
1169 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1170 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1172 static struct hda_channel_mode cxt5047_modes[1] = {
1176 static struct hda_input_mux cxt5047_toshiba_capture_source = {
1184 /* turn on/off EAPD (+ mute HP) as a master switch */
1185 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1186 struct snd_ctl_elem_value *ucontrol)
1188 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1189 struct conexant_spec *spec = codec->spec;
1192 if (!cxt_eapd_put(kcontrol, ucontrol))
1195 /* toggle internal speakers mute depending of presence of
1196 * the headphone jack
1198 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1199 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1200 HDA_AMP_MUTE, bits);
1201 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1202 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1203 HDA_AMP_MUTE, bits);
1207 /* mute internal speaker if HP is plugged */
1208 static void cxt5047_hp_automute(struct hda_codec *codec)
1210 struct conexant_spec *spec = codec->spec;
1213 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1214 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1216 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1217 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1218 HDA_AMP_MUTE, bits);
1219 /* Mute/Unmute PCM 2 for good measure - some systems need this */
1220 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1221 HDA_AMP_MUTE, bits);
1224 /* mute internal speaker if HP is plugged */
1225 static void cxt5047_hp2_automute(struct hda_codec *codec)
1227 struct conexant_spec *spec = codec->spec;
1230 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1231 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1233 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1234 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1235 HDA_AMP_MUTE, bits);
1236 /* Mute/Unmute PCM 2 for good measure - some systems need this */
1237 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1238 HDA_AMP_MUTE, bits);
1241 /* toggle input of built-in and mic jack appropriately */
1242 static void cxt5047_hp_automic(struct hda_codec *codec)
1244 static struct hda_verb mic_jack_on[] = {
1245 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1246 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1249 static struct hda_verb mic_jack_off[] = {
1250 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1251 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1254 unsigned int present;
1256 present = snd_hda_codec_read(codec, 0x15, 0,
1257 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1259 snd_hda_sequence_write(codec, mic_jack_on);
1261 snd_hda_sequence_write(codec, mic_jack_off);
1264 /* unsolicited event for HP jack sensing */
1265 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1268 switch (res >> 26) {
1269 case CONEXANT_HP_EVENT:
1270 cxt5047_hp_automute(codec);
1272 case CONEXANT_MIC_EVENT:
1273 cxt5047_hp_automic(codec);
1278 /* unsolicited event for HP jack sensing - non-EAPD systems */
1279 static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1284 case CONEXANT_HP_EVENT:
1285 cxt5047_hp2_automute(codec);
1287 case CONEXANT_MIC_EVENT:
1288 cxt5047_hp_automic(codec);
1293 static struct snd_kcontrol_new cxt5047_mixers[] = {
1294 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1295 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1296 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1297 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
1298 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1299 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1300 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1301 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1302 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1303 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1304 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1305 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1306 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1307 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
1312 static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1313 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1314 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1315 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1316 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1317 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1318 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1319 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1320 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1322 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1323 .name = "Master Playback Switch",
1324 .info = cxt_eapd_info,
1325 .get = cxt_eapd_get,
1326 .put = cxt5047_hp_master_sw_put,
1327 .private_value = 0x13,
1333 static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1334 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1335 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1336 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1337 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1338 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1339 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1340 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1342 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1343 .name = "Master Playback Switch",
1344 .info = cxt_eapd_info,
1345 .get = cxt_eapd_get,
1346 .put = cxt5047_hp_master_sw_put,
1347 .private_value = 0x13,
1352 static struct hda_verb cxt5047_init_verbs[] = {
1353 /* Line in, Mic, Built-in Mic */
1354 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1355 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1356 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1358 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1359 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
1360 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1361 /* Record selector: Mic */
1362 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1363 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1364 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1365 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1366 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1367 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1368 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1369 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1370 /* SPDIF route: PCM */
1371 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1372 /* Enable unsolicited events */
1373 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1374 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1378 /* configuration for Toshiba Laptops */
1379 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1380 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1381 /* pin sensing on HP and Mic jacks */
1382 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1383 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1384 /* Speaker routing */
1385 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1389 /* configuration for HP Laptops */
1390 static struct hda_verb cxt5047_hp_init_verbs[] = {
1391 /* pin sensing on HP jack */
1392 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1393 /* 0x13 is actually shared by both HP and speaker;
1394 * setting the connection to 0 (=0x19) makes the master volume control
1395 * working mysteriouslly...
1397 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1398 /* Record selector: Ext Mic */
1399 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1400 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1401 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1402 /* Speaker routing */
1403 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1407 /* Test configuration for debugging, modelled after the ALC260 test
1410 #ifdef CONFIG_SND_DEBUG
1411 static struct hda_input_mux cxt5047_test_capture_source = {
1414 { "LINE1 pin", 0x0 },
1415 { "MIC1 pin", 0x1 },
1416 { "MIC2 pin", 0x2 },
1421 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1423 /* Output only controls */
1424 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1425 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1426 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1427 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1428 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1429 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1431 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1432 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1433 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1434 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1435 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1437 /* Modes for retasking pin widgets */
1438 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1439 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1441 /* EAPD Switch Control */
1442 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1444 /* Loopback mixer controls */
1445 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1446 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1447 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1448 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1449 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1450 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1451 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1452 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1454 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1455 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1456 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1457 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1458 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1459 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1460 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1461 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1463 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1464 .name = "Input Source",
1465 .info = conexant_mux_enum_info,
1466 .get = conexant_mux_enum_get,
1467 .put = conexant_mux_enum_put,
1469 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1470 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1471 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1472 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1473 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1474 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1475 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1476 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1477 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1478 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1483 static struct hda_verb cxt5047_test_init_verbs[] = {
1484 /* Enable retasking pins as output, initially without power amp */
1485 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1486 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1487 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1489 /* Disable digital (SPDIF) pins initially, but users can enable
1490 * them via a mixer switch. In the case of SPDIF-out, this initverb
1491 * payload also sets the generation to 0, output to be in "consumer"
1492 * PCM format, copyright asserted, no pre-emphasis and no validity
1495 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1497 /* Ensure mic1, mic2, line1 pin widgets take input from the
1498 * OUT1 sum bus when acting as an output.
1500 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1501 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1503 /* Start with output sum widgets muted and their output gains at min */
1504 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1505 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1507 /* Unmute retasking pin widget output buffers since the default
1508 * state appears to be output. As the pin mode is changed by the
1509 * user the pin mode control will take care of enabling the pin's
1510 * input/output buffers as needed.
1512 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1513 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1514 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1516 /* Mute capture amp left and right */
1517 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1519 /* Set ADC connection select to match default mixer setting (mic1
1522 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1524 /* Mute all inputs to mixer widget (even unconnected ones) */
1525 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1526 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1530 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1531 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1539 /* initialize jack-sensing, too */
1540 static int cxt5047_hp_init(struct hda_codec *codec)
1542 conexant_init(codec);
1543 cxt5047_hp_automute(codec);
1549 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1550 CXT5047_LAPTOP_HP, /* Some HP laptops */
1551 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1552 #ifdef CONFIG_SND_DEBUG
1558 static const char *cxt5047_models[CXT5047_MODELS] = {
1559 [CXT5047_LAPTOP] = "laptop",
1560 [CXT5047_LAPTOP_HP] = "laptop-hp",
1561 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1562 #ifdef CONFIG_SND_DEBUG
1563 [CXT5047_TEST] = "test",
1567 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1568 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1569 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1571 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1575 static int patch_cxt5047(struct hda_codec *codec)
1577 struct conexant_spec *spec;
1580 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1585 spec->multiout.max_channels = 2;
1586 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1587 spec->multiout.dac_nids = cxt5047_dac_nids;
1588 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1589 spec->num_adc_nids = 1;
1590 spec->adc_nids = cxt5047_adc_nids;
1591 spec->capsrc_nids = cxt5047_capsrc_nids;
1592 spec->num_mixers = 1;
1593 spec->mixers[0] = cxt5047_mixers;
1594 spec->num_init_verbs = 1;
1595 spec->init_verbs[0] = cxt5047_init_verbs;
1596 spec->spdif_route = 0;
1597 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1598 spec->channel_mode = cxt5047_modes,
1600 codec->patch_ops = conexant_patch_ops;
1602 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1605 switch (board_config) {
1606 case CXT5047_LAPTOP:
1607 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
1609 case CXT5047_LAPTOP_HP:
1610 spec->num_init_verbs = 2;
1611 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1612 spec->mixers[0] = cxt5047_hp_mixers;
1613 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1614 codec->patch_ops.init = cxt5047_hp_init;
1616 case CXT5047_LAPTOP_EAPD:
1617 spec->input_mux = &cxt5047_toshiba_capture_source;
1618 spec->num_init_verbs = 2;
1619 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1620 spec->mixers[0] = cxt5047_toshiba_mixers;
1621 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1623 #ifdef CONFIG_SND_DEBUG
1625 spec->input_mux = &cxt5047_test_capture_source;
1626 spec->mixers[0] = cxt5047_test_mixer;
1627 spec->init_verbs[0] = cxt5047_test_init_verbs;
1628 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1631 spec->vmaster_nid = 0x13;
1635 /* Conexant 5051 specific */
1636 static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1637 static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1639 static struct hda_channel_mode cxt5051_modes[1] = {
1643 static void cxt5051_update_speaker(struct hda_codec *codec)
1645 struct conexant_spec *spec = codec->spec;
1646 unsigned int pinctl;
1647 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1648 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1652 /* turn on/off EAPD (+ mute HP) as a master switch */
1653 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1654 struct snd_ctl_elem_value *ucontrol)
1656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1658 if (!cxt_eapd_put(kcontrol, ucontrol))
1660 cxt5051_update_speaker(codec);
1664 /* toggle input of built-in and mic jack appropriately */
1665 static void cxt5051_portb_automic(struct hda_codec *codec)
1667 struct conexant_spec *spec = codec->spec;
1668 unsigned int present;
1670 if (spec->no_auto_mic)
1672 present = snd_hda_codec_read(codec, 0x17, 0,
1673 AC_VERB_GET_PIN_SENSE, 0) &
1674 AC_PINSENSE_PRESENCE;
1675 snd_hda_codec_write(codec, 0x14, 0,
1676 AC_VERB_SET_CONNECT_SEL,
1677 present ? 0x01 : 0x00);
1680 /* switch the current ADC according to the jack state */
1681 static void cxt5051_portc_automic(struct hda_codec *codec)
1683 struct conexant_spec *spec = codec->spec;
1684 unsigned int present;
1687 if (spec->no_auto_mic)
1689 present = snd_hda_codec_read(codec, 0x18, 0,
1690 AC_VERB_GET_PIN_SENSE, 0) &
1691 AC_PINSENSE_PRESENCE;
1693 spec->cur_adc_idx = 1;
1695 spec->cur_adc_idx = 0;
1696 new_adc = spec->adc_nids[spec->cur_adc_idx];
1697 if (spec->cur_adc && spec->cur_adc != new_adc) {
1698 /* stream is running, let's swap the current ADC */
1699 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1700 spec->cur_adc = new_adc;
1701 snd_hda_codec_setup_stream(codec, new_adc,
1702 spec->cur_adc_stream_tag, 0,
1703 spec->cur_adc_format);
1707 /* mute internal speaker if HP is plugged */
1708 static void cxt5051_hp_automute(struct hda_codec *codec)
1710 struct conexant_spec *spec = codec->spec;
1712 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1713 AC_VERB_GET_PIN_SENSE, 0) &
1714 AC_PINSENSE_PRESENCE;
1715 cxt5051_update_speaker(codec);
1718 /* unsolicited event for HP jack sensing */
1719 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1722 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1723 switch (res >> 26) {
1724 case CONEXANT_HP_EVENT:
1725 cxt5051_hp_automute(codec);
1727 case CXT5051_PORTB_EVENT:
1728 cxt5051_portb_automic(codec);
1730 case CXT5051_PORTC_EVENT:
1731 cxt5051_portc_automic(codec);
1734 conexant_report_jack(codec, nid);
1737 static struct snd_kcontrol_new cxt5051_mixers[] = {
1738 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1739 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1740 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1741 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1742 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1743 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1744 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1746 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1747 .name = "Master Playback Switch",
1748 .info = cxt_eapd_info,
1749 .get = cxt_eapd_get,
1750 .put = cxt5051_hp_master_sw_put,
1751 .private_value = 0x1a,
1757 static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1758 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1759 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1760 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1761 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1762 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1764 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1765 .name = "Master Playback Switch",
1766 .info = cxt_eapd_info,
1767 .get = cxt_eapd_get,
1768 .put = cxt5051_hp_master_sw_put,
1769 .private_value = 0x1a,
1775 static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1776 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1777 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1778 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1780 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1781 .name = "Master Playback Switch",
1782 .info = cxt_eapd_info,
1783 .get = cxt_eapd_get,
1784 .put = cxt5051_hp_master_sw_put,
1785 .private_value = 0x1a,
1791 static struct hda_verb cxt5051_init_verbs[] = {
1793 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1794 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1795 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1796 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1797 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1798 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1800 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1801 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1803 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1804 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1806 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1807 /* Record selector: Int mic */
1808 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1809 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1810 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1811 /* SPDIF route: PCM */
1812 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1814 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1815 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1816 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1817 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1821 static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1823 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1824 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1825 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1826 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1828 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1829 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1831 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1832 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1834 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1835 /* Record selector: Int mic */
1836 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1837 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1838 /* SPDIF route: PCM */
1839 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1841 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1842 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1843 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1847 static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1849 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1850 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1851 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1852 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1853 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1854 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1856 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1857 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1859 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1860 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1862 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1863 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1865 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1866 /* Record selector: Int mic */
1867 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1868 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1869 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1870 /* SPDIF route: PCM */
1871 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1873 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1874 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1875 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1876 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1877 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1881 /* initialize jack-sensing, too */
1882 static int cxt5051_init(struct hda_codec *codec)
1884 conexant_init(codec);
1885 conexant_init_jacks(codec);
1886 if (codec->patch_ops.unsol_event) {
1887 cxt5051_hp_automute(codec);
1888 cxt5051_portb_automic(codec);
1889 cxt5051_portc_automic(codec);
1896 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1897 CXT5051_HP, /* no docking */
1898 CXT5051_HP_DV6736, /* HP without mic switch */
1899 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
1903 static const char *cxt5051_models[CXT5051_MODELS] = {
1904 [CXT5051_LAPTOP] = "laptop",
1905 [CXT5051_HP] = "hp",
1906 [CXT5051_HP_DV6736] = "hp-dv6736",
1907 [CXT5051_LENOVO_X200] = "lenovo-x200",
1910 static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1911 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1912 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1914 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1915 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1919 static int patch_cxt5051(struct hda_codec *codec)
1921 struct conexant_spec *spec;
1924 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1929 codec->patch_ops = conexant_patch_ops;
1930 codec->patch_ops.init = cxt5051_init;
1932 spec->multiout.max_channels = 2;
1933 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1934 spec->multiout.dac_nids = cxt5051_dac_nids;
1935 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1936 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1937 spec->adc_nids = cxt5051_adc_nids;
1938 spec->num_mixers = 1;
1939 spec->mixers[0] = cxt5051_mixers;
1940 spec->num_init_verbs = 1;
1941 spec->init_verbs[0] = cxt5051_init_verbs;
1942 spec->spdif_route = 0;
1943 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1944 spec->channel_mode = cxt5051_modes;
1946 spec->cur_adc_idx = 0;
1948 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1950 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1953 switch (board_config) {
1955 spec->mixers[0] = cxt5051_hp_mixers;
1957 case CXT5051_HP_DV6736:
1958 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1959 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1960 spec->no_auto_mic = 1;
1962 case CXT5051_LENOVO_X200:
1963 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1974 static struct hda_codec_preset snd_hda_preset_conexant[] = {
1975 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1976 .patch = patch_cxt5045 },
1977 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1978 .patch = patch_cxt5047 },
1979 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1980 .patch = patch_cxt5051 },
1984 MODULE_ALIAS("snd-hda-codec-id:14f15045");
1985 MODULE_ALIAS("snd-hda-codec-id:14f15047");
1986 MODULE_ALIAS("snd-hda-codec-id:14f15051");
1988 MODULE_LICENSE("GPL");
1989 MODULE_DESCRIPTION("Conexant HD-audio codec");
1991 static struct hda_codec_preset_list conexant_list = {
1992 .preset = snd_hda_preset_conexant,
1993 .owner = THIS_MODULE,
1996 static int __init patch_conexant_init(void)
1998 return snd_hda_add_codec_preset(&conexant_list);
2001 static void __exit patch_conexant_exit(void)
2003 snd_hda_delete_codec_preset(&conexant_list);
2006 module_init(patch_conexant_init)
2007 module_exit(patch_conexant_exit)