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];
111 unsigned int dell_automute;
112 unsigned int port_d_mode;
113 unsigned char ext_mic_bias;
116 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
117 struct hda_codec *codec,
118 struct snd_pcm_substream *substream)
120 struct conexant_spec *spec = codec->spec;
121 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
125 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
126 struct hda_codec *codec,
127 unsigned int stream_tag,
129 struct snd_pcm_substream *substream)
131 struct conexant_spec *spec = codec->spec;
132 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
137 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
138 struct hda_codec *codec,
139 struct snd_pcm_substream *substream)
141 struct conexant_spec *spec = codec->spec;
142 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
148 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
149 struct hda_codec *codec,
150 struct snd_pcm_substream *substream)
152 struct conexant_spec *spec = codec->spec;
153 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
156 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
157 struct hda_codec *codec,
158 struct snd_pcm_substream *substream)
160 struct conexant_spec *spec = codec->spec;
161 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
164 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
165 struct hda_codec *codec,
166 unsigned int stream_tag,
168 struct snd_pcm_substream *substream)
170 struct conexant_spec *spec = codec->spec;
171 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
179 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
181 unsigned int stream_tag,
183 struct snd_pcm_substream *substream)
185 struct conexant_spec *spec = codec->spec;
186 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
187 stream_tag, 0, format);
191 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
192 struct hda_codec *codec,
193 struct snd_pcm_substream *substream)
195 struct conexant_spec *spec = codec->spec;
196 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
202 static struct hda_pcm_stream conexant_pcm_analog_playback = {
206 .nid = 0, /* fill later */
208 .open = conexant_playback_pcm_open,
209 .prepare = conexant_playback_pcm_prepare,
210 .cleanup = conexant_playback_pcm_cleanup
214 static struct hda_pcm_stream conexant_pcm_analog_capture = {
218 .nid = 0, /* fill later */
220 .prepare = conexant_capture_pcm_prepare,
221 .cleanup = conexant_capture_pcm_cleanup
226 static struct hda_pcm_stream conexant_pcm_digital_playback = {
230 .nid = 0, /* fill later */
232 .open = conexant_dig_playback_pcm_open,
233 .close = conexant_dig_playback_pcm_close,
234 .prepare = conexant_dig_playback_pcm_prepare
238 static struct hda_pcm_stream conexant_pcm_digital_capture = {
242 /* NID is set in alc_build_pcms */
245 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
246 struct hda_codec *codec,
247 unsigned int stream_tag,
249 struct snd_pcm_substream *substream)
251 struct conexant_spec *spec = codec->spec;
252 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
253 spec->cur_adc_stream_tag = stream_tag;
254 spec->cur_adc_format = format;
255 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
259 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
260 struct hda_codec *codec,
261 struct snd_pcm_substream *substream)
263 struct conexant_spec *spec = codec->spec;
264 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
269 static struct hda_pcm_stream cx5051_pcm_analog_capture = {
273 .nid = 0, /* fill later */
275 .prepare = cx5051_capture_pcm_prepare,
276 .cleanup = cx5051_capture_pcm_cleanup
280 static int conexant_build_pcms(struct hda_codec *codec)
282 struct conexant_spec *spec = codec->spec;
283 struct hda_pcm *info = spec->pcm_rec;
286 codec->pcm_info = info;
288 info->name = "CONEXANT Analog";
289 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
290 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
291 spec->multiout.max_channels;
292 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
293 spec->multiout.dac_nids[0];
294 if (codec->vendor_id == 0x14f15051)
295 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
296 cx5051_pcm_analog_capture;
298 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
299 conexant_pcm_analog_capture;
300 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
301 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
303 if (spec->multiout.dig_out_nid) {
306 info->name = "Conexant Digital";
307 info->pcm_type = HDA_PCM_TYPE_SPDIF;
308 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
309 conexant_pcm_digital_playback;
310 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
311 spec->multiout.dig_out_nid;
312 if (spec->dig_in_nid) {
313 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
314 conexant_pcm_digital_capture;
315 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
323 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
324 struct snd_ctl_elem_info *uinfo)
326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327 struct conexant_spec *spec = codec->spec;
329 return snd_hda_input_mux_info(spec->input_mux, uinfo);
332 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
333 struct snd_ctl_elem_value *ucontrol)
335 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
336 struct conexant_spec *spec = codec->spec;
337 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
339 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
343 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
344 struct snd_ctl_elem_value *ucontrol)
346 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
347 struct conexant_spec *spec = codec->spec;
348 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
350 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
351 spec->capsrc_nids[adc_idx],
352 &spec->cur_mux[adc_idx]);
355 #ifdef CONFIG_SND_HDA_INPUT_JACK
356 static void conexant_free_jack_priv(struct snd_jack *jack)
358 struct conexant_jack *jacks = jack->private_data;
363 static int conexant_add_jack(struct hda_codec *codec,
364 hda_nid_t nid, int type)
366 struct conexant_spec *spec;
367 struct conexant_jack *jack;
372 snd_array_init(&spec->jacks, sizeof(*jack), 32);
373 jack = snd_array_new(&spec->jacks);
374 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
382 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
385 jack->jack->private_data = jack;
386 jack->jack->private_free = conexant_free_jack_priv;
390 static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
392 struct conexant_spec *spec = codec->spec;
393 struct conexant_jack *jacks = spec->jacks.list;
397 for (i = 0; i < spec->jacks.used; i++) {
398 if (jacks->nid == nid) {
399 unsigned int present;
400 present = snd_hda_codec_read(codec, nid, 0,
401 AC_VERB_GET_PIN_SENSE, 0) &
402 AC_PINSENSE_PRESENCE;
404 present = (present) ? jacks->type : 0 ;
406 snd_jack_report(jacks->jack,
414 static int conexant_init_jacks(struct hda_codec *codec)
416 struct conexant_spec *spec = codec->spec;
419 for (i = 0; i < spec->num_init_verbs; i++) {
420 const struct hda_verb *hv;
422 hv = spec->init_verbs[i];
425 switch (hv->param ^ AC_USRSP_EN) {
426 case CONEXANT_HP_EVENT:
427 err = conexant_add_jack(codec, hv->nid,
429 conexant_report_jack(codec, hv->nid);
431 case CXT5051_PORTC_EVENT:
432 case CONEXANT_MIC_EVENT:
433 err = conexant_add_jack(codec, hv->nid,
434 SND_JACK_MICROPHONE);
435 conexant_report_jack(codec, hv->nid);
447 static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
451 static inline int conexant_init_jacks(struct hda_codec *codec)
457 static int conexant_init(struct hda_codec *codec)
459 struct conexant_spec *spec = codec->spec;
462 for (i = 0; i < spec->num_init_verbs; i++)
463 snd_hda_sequence_write(codec, spec->init_verbs[i]);
467 static void conexant_free(struct hda_codec *codec)
469 #ifdef CONFIG_SND_HDA_INPUT_JACK
470 struct conexant_spec *spec = codec->spec;
471 if (spec->jacks.list) {
472 struct conexant_jack *jacks = spec->jacks.list;
474 for (i = 0; i < spec->jacks.used; i++, jacks++) {
476 snd_device_free(codec->bus->card, jacks->jack);
478 snd_array_free(&spec->jacks);
484 static struct snd_kcontrol_new cxt_capture_mixers[] = {
486 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
487 .name = "Capture Source",
488 .info = conexant_mux_enum_info,
489 .get = conexant_mux_enum_get,
490 .put = conexant_mux_enum_put
495 static const char *slave_vols[] = {
496 "Headphone Playback Volume",
497 "Speaker Playback Volume",
501 static const char *slave_sws[] = {
502 "Headphone Playback Switch",
503 "Speaker Playback Switch",
507 static int conexant_build_controls(struct hda_codec *codec)
509 struct conexant_spec *spec = codec->spec;
513 for (i = 0; i < spec->num_mixers; i++) {
514 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
518 if (spec->multiout.dig_out_nid) {
519 err = snd_hda_create_spdif_out_ctls(codec,
520 spec->multiout.dig_out_nid);
523 err = snd_hda_create_spdif_share_sw(codec,
527 spec->multiout.share_spdif = 1;
529 if (spec->dig_in_nid) {
530 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
535 /* if we have no master control, let's create it */
536 if (spec->vmaster_nid &&
537 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
538 unsigned int vmaster_tlv[4];
539 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
540 HDA_OUTPUT, vmaster_tlv);
541 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
542 vmaster_tlv, slave_vols);
546 if (spec->vmaster_nid &&
547 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
548 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
554 if (spec->input_mux) {
555 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
563 static struct hda_codec_ops conexant_patch_ops = {
564 .build_controls = conexant_build_controls,
565 .build_pcms = conexant_build_pcms,
566 .init = conexant_init,
567 .free = conexant_free,
572 * the private value = nid | (invert << 8)
575 #define cxt_eapd_info snd_ctl_boolean_mono_info
577 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
578 struct snd_ctl_elem_value *ucontrol)
580 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
581 struct conexant_spec *spec = codec->spec;
582 int invert = (kcontrol->private_value >> 8) & 1;
584 ucontrol->value.integer.value[0] = !spec->cur_eapd;
586 ucontrol->value.integer.value[0] = spec->cur_eapd;
591 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
592 struct snd_ctl_elem_value *ucontrol)
594 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
595 struct conexant_spec *spec = codec->spec;
596 int invert = (kcontrol->private_value >> 8) & 1;
597 hda_nid_t nid = kcontrol->private_value & 0xff;
600 eapd = !!ucontrol->value.integer.value[0];
603 if (eapd == spec->cur_eapd)
606 spec->cur_eapd = eapd;
607 snd_hda_codec_write_cache(codec, nid,
608 0, AC_VERB_SET_EAPD_BTLENABLE,
613 /* controls for test mode */
614 #ifdef CONFIG_SND_DEBUG
616 #define CXT_EAPD_SWITCH(xname, nid, mask) \
617 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
618 .info = cxt_eapd_info, \
619 .get = cxt_eapd_get, \
620 .put = cxt_eapd_put, \
621 .private_value = nid | (mask<<16) }
625 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
626 struct snd_ctl_elem_info *uinfo)
628 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
629 struct conexant_spec *spec = codec->spec;
630 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
631 spec->num_channel_mode);
634 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
635 struct snd_ctl_elem_value *ucontrol)
637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638 struct conexant_spec *spec = codec->spec;
639 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
640 spec->num_channel_mode,
641 spec->multiout.max_channels);
644 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
645 struct snd_ctl_elem_value *ucontrol)
647 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
648 struct conexant_spec *spec = codec->spec;
649 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
650 spec->num_channel_mode,
651 &spec->multiout.max_channels);
652 if (err >= 0 && spec->need_dac_fix)
653 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
657 #define CXT_PIN_MODE(xname, nid, dir) \
658 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
659 .info = conexant_ch_mode_info, \
660 .get = conexant_ch_mode_get, \
661 .put = conexant_ch_mode_put, \
662 .private_value = nid | (dir<<16) }
664 #endif /* CONFIG_SND_DEBUG */
666 /* Conexant 5045 specific */
668 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
669 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
670 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
671 #define CXT5045_SPDIF_OUT 0x18
673 static struct hda_channel_mode cxt5045_modes[1] = {
677 static struct hda_input_mux cxt5045_capture_source = {
685 static struct hda_input_mux cxt5045_capture_source_benq = {
696 static struct hda_input_mux cxt5045_capture_source_hp530 = {
704 /* turn on/off EAPD (+ mute HP) as a master switch */
705 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
706 struct snd_ctl_elem_value *ucontrol)
708 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
709 struct conexant_spec *spec = codec->spec;
712 if (!cxt_eapd_put(kcontrol, ucontrol))
715 /* toggle internal speakers mute depending of presence of
718 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
719 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
722 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
723 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
728 /* bind volumes of both NID 0x10 and 0x11 */
729 static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
730 .ops = &snd_hda_bind_vol,
732 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
733 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
738 /* toggle input of built-in and mic jack appropriately */
739 static void cxt5045_hp_automic(struct hda_codec *codec)
741 static struct hda_verb mic_jack_on[] = {
742 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
743 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
746 static struct hda_verb mic_jack_off[] = {
747 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
748 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
751 unsigned int present;
753 present = snd_hda_codec_read(codec, 0x12, 0,
754 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
756 snd_hda_sequence_write(codec, mic_jack_on);
758 snd_hda_sequence_write(codec, mic_jack_off);
762 /* mute internal speaker if HP is plugged */
763 static void cxt5045_hp_automute(struct hda_codec *codec)
765 struct conexant_spec *spec = codec->spec;
768 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
769 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
771 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
772 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
776 /* unsolicited event for HP jack sensing */
777 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
782 case CONEXANT_HP_EVENT:
783 cxt5045_hp_automute(codec);
785 case CONEXANT_MIC_EVENT:
786 cxt5045_hp_automic(codec);
792 static struct snd_kcontrol_new cxt5045_mixers[] = {
793 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
794 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
795 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
796 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
797 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
798 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
799 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
800 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
801 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
802 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
803 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
805 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
806 .name = "Master Playback Switch",
807 .info = cxt_eapd_info,
809 .put = cxt5045_hp_master_sw_put,
810 .private_value = 0x10,
816 static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
817 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
818 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
819 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
820 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
822 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
823 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
824 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
825 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
827 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
828 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
833 static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
834 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
835 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
836 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
837 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
838 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
839 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
840 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
841 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
842 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
843 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
844 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
846 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
847 .name = "Master Playback Switch",
848 .info = cxt_eapd_info,
850 .put = cxt5045_hp_master_sw_put,
851 .private_value = 0x10,
857 static struct hda_verb cxt5045_init_verbs[] = {
859 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
860 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
862 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
863 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
864 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
865 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
866 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
867 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
868 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
869 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
870 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
871 /* Record selector: Int mic */
872 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
873 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
874 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
875 /* SPDIF route: PCM */
876 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
877 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
879 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
883 static struct hda_verb cxt5045_benq_init_verbs[] = {
885 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
886 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
887 /* Line In,HP, Amp */
888 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
889 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
890 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
891 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
892 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
893 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
894 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
895 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
896 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
897 /* Record selector: Int mic */
898 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
899 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
900 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
901 /* SPDIF route: PCM */
902 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
903 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
905 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
909 static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
910 /* pin sensing on HP jack */
911 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
915 static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
916 /* pin sensing on HP jack */
917 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
921 #ifdef CONFIG_SND_DEBUG
922 /* Test configuration for debugging, modelled after the ALC260 test
925 static struct hda_input_mux cxt5045_test_capture_source = {
930 { "LINE1 pin", 0x2 },
931 { "HP-OUT pin", 0x3 },
936 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
938 /* Output controls */
939 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
940 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
941 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
942 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
943 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
944 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
946 /* Modes for retasking pin widgets */
947 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
948 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
950 /* EAPD Switch Control */
951 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
953 /* Loopback mixer controls */
955 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
956 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
957 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
958 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
959 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
960 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
961 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
962 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
963 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
964 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
966 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
967 .name = "Input Source",
968 .info = conexant_mux_enum_info,
969 .get = conexant_mux_enum_get,
970 .put = conexant_mux_enum_put,
972 /* Audio input controls */
973 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
974 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
975 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
976 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
977 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
978 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
979 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
980 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
981 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
982 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
986 static struct hda_verb cxt5045_test_init_verbs[] = {
987 /* Set connections */
988 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
989 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
990 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
991 /* Enable retasking pins as output, initially without power amp */
992 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
993 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
995 /* Disable digital (SPDIF) pins initially, but users can enable
996 * them via a mixer switch. In the case of SPDIF-out, this initverb
997 * payload also sets the generation to 0, output to be in "consumer"
998 * PCM format, copyright asserted, no pre-emphasis and no validity
1001 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1002 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1004 /* Start with output sum widgets muted and their output gains at min */
1005 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1006 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1008 /* Unmute retasking pin widget output buffers since the default
1009 * state appears to be output. As the pin mode is changed by the
1010 * user the pin mode control will take care of enabling the pin's
1011 * input/output buffers as needed.
1013 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1014 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1016 /* Mute capture amp left and right */
1017 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1019 /* Set ADC connection select to match default mixer setting (mic1
1022 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1023 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1025 /* Mute all inputs to mixer widget (even unconnected ones) */
1026 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1027 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1028 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1029 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1030 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1037 /* initialize jack-sensing, too */
1038 static int cxt5045_init(struct hda_codec *codec)
1040 conexant_init(codec);
1041 cxt5045_hp_automute(codec);
1047 CXT5045_LAPTOP_HPSENSE,
1048 CXT5045_LAPTOP_MICSENSE,
1049 CXT5045_LAPTOP_HPMICSENSE,
1051 CXT5045_LAPTOP_HP530,
1052 #ifdef CONFIG_SND_DEBUG
1058 static const char *cxt5045_models[CXT5045_MODELS] = {
1059 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1060 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1061 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1062 [CXT5045_BENQ] = "benq",
1063 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1064 #ifdef CONFIG_SND_DEBUG
1065 [CXT5045_TEST] = "test",
1069 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1070 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1071 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1072 CXT5045_LAPTOP_HPSENSE),
1073 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1074 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1075 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1076 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1077 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1078 CXT5045_LAPTOP_HPMICSENSE),
1079 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1080 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1081 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1082 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1083 CXT5045_LAPTOP_HPMICSENSE),
1084 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1088 static int patch_cxt5045(struct hda_codec *codec)
1090 struct conexant_spec *spec;
1093 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1097 codec->pin_amp_workaround = 1;
1099 spec->multiout.max_channels = 2;
1100 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1101 spec->multiout.dac_nids = cxt5045_dac_nids;
1102 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1103 spec->num_adc_nids = 1;
1104 spec->adc_nids = cxt5045_adc_nids;
1105 spec->capsrc_nids = cxt5045_capsrc_nids;
1106 spec->input_mux = &cxt5045_capture_source;
1107 spec->num_mixers = 1;
1108 spec->mixers[0] = cxt5045_mixers;
1109 spec->num_init_verbs = 1;
1110 spec->init_verbs[0] = cxt5045_init_verbs;
1111 spec->spdif_route = 0;
1112 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1113 spec->channel_mode = cxt5045_modes,
1116 codec->patch_ops = conexant_patch_ops;
1118 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1121 switch (board_config) {
1122 case CXT5045_LAPTOP_HPSENSE:
1123 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1124 spec->input_mux = &cxt5045_capture_source;
1125 spec->num_init_verbs = 2;
1126 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1127 spec->mixers[0] = cxt5045_mixers;
1128 codec->patch_ops.init = cxt5045_init;
1130 case CXT5045_LAPTOP_MICSENSE:
1131 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1132 spec->input_mux = &cxt5045_capture_source;
1133 spec->num_init_verbs = 2;
1134 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1135 spec->mixers[0] = cxt5045_mixers;
1136 codec->patch_ops.init = cxt5045_init;
1139 case CXT5045_LAPTOP_HPMICSENSE:
1140 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1141 spec->input_mux = &cxt5045_capture_source;
1142 spec->num_init_verbs = 3;
1143 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1144 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1145 spec->mixers[0] = cxt5045_mixers;
1146 codec->patch_ops.init = cxt5045_init;
1149 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1150 spec->input_mux = &cxt5045_capture_source_benq;
1151 spec->num_init_verbs = 1;
1152 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1153 spec->mixers[0] = cxt5045_mixers;
1154 spec->mixers[1] = cxt5045_benq_mixers;
1155 spec->num_mixers = 2;
1156 codec->patch_ops.init = cxt5045_init;
1158 case CXT5045_LAPTOP_HP530:
1159 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1160 spec->input_mux = &cxt5045_capture_source_hp530;
1161 spec->num_init_verbs = 2;
1162 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1163 spec->mixers[0] = cxt5045_mixers_hp530;
1164 codec->patch_ops.init = cxt5045_init;
1166 #ifdef CONFIG_SND_DEBUG
1168 spec->input_mux = &cxt5045_test_capture_source;
1169 spec->mixers[0] = cxt5045_test_mixer;
1170 spec->init_verbs[0] = cxt5045_test_init_verbs;
1176 switch (codec->subsystem_id >> 16) {
1181 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1182 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1183 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1185 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1186 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1187 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1188 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1189 (1 << AC_AMPCAP_MUTE_SHIFT));
1197 /* Conexant 5047 specific */
1198 #define CXT5047_SPDIF_OUT 0x11
1200 static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1201 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1202 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1204 static struct hda_channel_mode cxt5047_modes[1] = {
1208 static struct hda_input_mux cxt5047_toshiba_capture_source = {
1216 /* turn on/off EAPD (+ mute HP) as a master switch */
1217 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1218 struct snd_ctl_elem_value *ucontrol)
1220 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1221 struct conexant_spec *spec = codec->spec;
1224 if (!cxt_eapd_put(kcontrol, ucontrol))
1227 /* toggle internal speakers mute depending of presence of
1228 * the headphone jack
1230 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1231 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1232 * pin widgets unlike other codecs. In this case, we need to
1233 * set index 0x01 for the volume from the mixer amp 0x19.
1235 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1236 HDA_AMP_MUTE, bits);
1237 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1238 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1239 HDA_AMP_MUTE, bits);
1243 /* mute internal speaker if HP is plugged */
1244 static void cxt5047_hp_automute(struct hda_codec *codec)
1246 struct conexant_spec *spec = codec->spec;
1249 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1250 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1252 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1253 /* See the note in cxt5047_hp_master_sw_put */
1254 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1255 HDA_AMP_MUTE, bits);
1258 /* toggle input of built-in and mic jack appropriately */
1259 static void cxt5047_hp_automic(struct hda_codec *codec)
1261 static struct hda_verb mic_jack_on[] = {
1262 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1263 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1266 static struct hda_verb mic_jack_off[] = {
1267 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1268 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1271 unsigned int present;
1273 present = snd_hda_codec_read(codec, 0x15, 0,
1274 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1276 snd_hda_sequence_write(codec, mic_jack_on);
1278 snd_hda_sequence_write(codec, mic_jack_off);
1281 /* unsolicited event for HP jack sensing */
1282 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1285 switch (res >> 26) {
1286 case CONEXANT_HP_EVENT:
1287 cxt5047_hp_automute(codec);
1289 case CONEXANT_MIC_EVENT:
1290 cxt5047_hp_automic(codec);
1295 static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1296 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1297 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1298 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
1299 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1300 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1301 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1302 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1304 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1305 .name = "Master Playback Switch",
1306 .info = cxt_eapd_info,
1307 .get = cxt_eapd_get,
1308 .put = cxt5047_hp_master_sw_put,
1309 .private_value = 0x13,
1315 static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1316 /* See the note in cxt5047_hp_master_sw_put */
1317 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1318 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1322 static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1323 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1327 static struct hda_verb cxt5047_init_verbs[] = {
1328 /* Line in, Mic, Built-in Mic */
1329 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1330 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1331 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1333 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1334 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1335 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1336 /* Record selector: Mic */
1337 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1338 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1339 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1340 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1341 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1342 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1343 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1344 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1345 /* SPDIF route: PCM */
1346 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1347 /* Enable unsolicited events */
1348 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1349 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1353 /* configuration for Toshiba Laptops */
1354 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1355 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1359 /* Test configuration for debugging, modelled after the ALC260 test
1362 #ifdef CONFIG_SND_DEBUG
1363 static struct hda_input_mux cxt5047_test_capture_source = {
1366 { "LINE1 pin", 0x0 },
1367 { "MIC1 pin", 0x1 },
1368 { "MIC2 pin", 0x2 },
1373 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1375 /* Output only controls */
1376 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1377 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1378 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1379 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1380 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1381 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1382 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1383 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1384 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1385 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1386 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1387 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1389 /* Modes for retasking pin widgets */
1390 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1391 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1393 /* EAPD Switch Control */
1394 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1396 /* Loopback mixer controls */
1397 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1398 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1399 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1400 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1401 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1402 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1403 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1404 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1406 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1407 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1408 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1409 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1410 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1411 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1412 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1413 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1415 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1416 .name = "Input Source",
1417 .info = conexant_mux_enum_info,
1418 .get = conexant_mux_enum_get,
1419 .put = conexant_mux_enum_put,
1421 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1422 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1423 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1424 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1425 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1426 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1427 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1428 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1429 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1430 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1435 static struct hda_verb cxt5047_test_init_verbs[] = {
1436 /* Enable retasking pins as output, initially without power amp */
1437 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1438 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1439 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1441 /* Disable digital (SPDIF) pins initially, but users can enable
1442 * them via a mixer switch. In the case of SPDIF-out, this initverb
1443 * payload also sets the generation to 0, output to be in "consumer"
1444 * PCM format, copyright asserted, no pre-emphasis and no validity
1447 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1449 /* Ensure mic1, mic2, line1 pin widgets take input from the
1450 * OUT1 sum bus when acting as an output.
1452 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1453 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1455 /* Start with output sum widgets muted and their output gains at min */
1456 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1457 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1459 /* Unmute retasking pin widget output buffers since the default
1460 * state appears to be output. As the pin mode is changed by the
1461 * user the pin mode control will take care of enabling the pin's
1462 * input/output buffers as needed.
1464 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1465 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1466 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1468 /* Mute capture amp left and right */
1469 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1471 /* Set ADC connection select to match default mixer setting (mic1
1474 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1476 /* Mute all inputs to mixer widget (even unconnected ones) */
1477 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1478 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1479 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1480 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1481 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1482 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1483 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1484 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1491 /* initialize jack-sensing, too */
1492 static int cxt5047_hp_init(struct hda_codec *codec)
1494 conexant_init(codec);
1495 cxt5047_hp_automute(codec);
1501 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1502 CXT5047_LAPTOP_HP, /* Some HP laptops */
1503 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1504 #ifdef CONFIG_SND_DEBUG
1510 static const char *cxt5047_models[CXT5047_MODELS] = {
1511 [CXT5047_LAPTOP] = "laptop",
1512 [CXT5047_LAPTOP_HP] = "laptop-hp",
1513 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1514 #ifdef CONFIG_SND_DEBUG
1515 [CXT5047_TEST] = "test",
1519 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1520 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1521 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1523 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1527 static int patch_cxt5047(struct hda_codec *codec)
1529 struct conexant_spec *spec;
1532 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1536 codec->pin_amp_workaround = 1;
1538 spec->multiout.max_channels = 2;
1539 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1540 spec->multiout.dac_nids = cxt5047_dac_nids;
1541 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1542 spec->num_adc_nids = 1;
1543 spec->adc_nids = cxt5047_adc_nids;
1544 spec->capsrc_nids = cxt5047_capsrc_nids;
1545 spec->num_mixers = 1;
1546 spec->mixers[0] = cxt5047_base_mixers;
1547 spec->num_init_verbs = 1;
1548 spec->init_verbs[0] = cxt5047_init_verbs;
1549 spec->spdif_route = 0;
1550 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1551 spec->channel_mode = cxt5047_modes,
1553 codec->patch_ops = conexant_patch_ops;
1555 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1558 switch (board_config) {
1559 case CXT5047_LAPTOP:
1560 spec->num_mixers = 2;
1561 spec->mixers[1] = cxt5047_hp_spk_mixers;
1562 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1564 case CXT5047_LAPTOP_HP:
1565 spec->num_mixers = 2;
1566 spec->mixers[1] = cxt5047_hp_only_mixers;
1567 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1568 codec->patch_ops.init = cxt5047_hp_init;
1570 case CXT5047_LAPTOP_EAPD:
1571 spec->input_mux = &cxt5047_toshiba_capture_source;
1572 spec->num_mixers = 2;
1573 spec->mixers[1] = cxt5047_hp_spk_mixers;
1574 spec->num_init_verbs = 2;
1575 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1576 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1578 #ifdef CONFIG_SND_DEBUG
1580 spec->input_mux = &cxt5047_test_capture_source;
1581 spec->mixers[0] = cxt5047_test_mixer;
1582 spec->init_verbs[0] = cxt5047_test_init_verbs;
1583 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1586 spec->vmaster_nid = 0x13;
1588 switch (codec->subsystem_id >> 16) {
1590 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1591 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1592 * with 0 dB offset 0x17)
1594 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1595 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1596 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1597 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1598 (1 << AC_AMPCAP_MUTE_SHIFT));
1605 /* Conexant 5051 specific */
1606 static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1607 static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1609 static struct hda_channel_mode cxt5051_modes[1] = {
1613 static void cxt5051_update_speaker(struct hda_codec *codec)
1615 struct conexant_spec *spec = codec->spec;
1616 unsigned int pinctl;
1617 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1618 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1622 /* turn on/off EAPD (+ mute HP) as a master switch */
1623 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1624 struct snd_ctl_elem_value *ucontrol)
1626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1628 if (!cxt_eapd_put(kcontrol, ucontrol))
1630 cxt5051_update_speaker(codec);
1634 /* toggle input of built-in and mic jack appropriately */
1635 static void cxt5051_portb_automic(struct hda_codec *codec)
1637 struct conexant_spec *spec = codec->spec;
1638 unsigned int present;
1640 if (spec->no_auto_mic)
1642 present = snd_hda_codec_read(codec, 0x17, 0,
1643 AC_VERB_GET_PIN_SENSE, 0) &
1644 AC_PINSENSE_PRESENCE;
1645 snd_hda_codec_write(codec, 0x14, 0,
1646 AC_VERB_SET_CONNECT_SEL,
1647 present ? 0x01 : 0x00);
1650 /* switch the current ADC according to the jack state */
1651 static void cxt5051_portc_automic(struct hda_codec *codec)
1653 struct conexant_spec *spec = codec->spec;
1654 unsigned int present;
1657 if (spec->no_auto_mic)
1659 present = snd_hda_codec_read(codec, 0x18, 0,
1660 AC_VERB_GET_PIN_SENSE, 0) &
1661 AC_PINSENSE_PRESENCE;
1663 spec->cur_adc_idx = 1;
1665 spec->cur_adc_idx = 0;
1666 new_adc = spec->adc_nids[spec->cur_adc_idx];
1667 if (spec->cur_adc && spec->cur_adc != new_adc) {
1668 /* stream is running, let's swap the current ADC */
1669 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1670 spec->cur_adc = new_adc;
1671 snd_hda_codec_setup_stream(codec, new_adc,
1672 spec->cur_adc_stream_tag, 0,
1673 spec->cur_adc_format);
1677 /* mute internal speaker if HP is plugged */
1678 static void cxt5051_hp_automute(struct hda_codec *codec)
1680 struct conexant_spec *spec = codec->spec;
1682 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1683 AC_VERB_GET_PIN_SENSE, 0) &
1684 AC_PINSENSE_PRESENCE;
1685 cxt5051_update_speaker(codec);
1688 /* unsolicited event for HP jack sensing */
1689 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1692 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1693 switch (res >> 26) {
1694 case CONEXANT_HP_EVENT:
1695 cxt5051_hp_automute(codec);
1697 case CXT5051_PORTB_EVENT:
1698 cxt5051_portb_automic(codec);
1700 case CXT5051_PORTC_EVENT:
1701 cxt5051_portc_automic(codec);
1704 conexant_report_jack(codec, nid);
1707 static struct snd_kcontrol_new cxt5051_mixers[] = {
1708 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1709 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1710 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1711 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1712 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1713 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1714 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1716 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1717 .name = "Master Playback Switch",
1718 .info = cxt_eapd_info,
1719 .get = cxt_eapd_get,
1720 .put = cxt5051_hp_master_sw_put,
1721 .private_value = 0x1a,
1727 static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1728 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1729 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1730 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1731 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1732 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1734 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1735 .name = "Master Playback Switch",
1736 .info = cxt_eapd_info,
1737 .get = cxt_eapd_get,
1738 .put = cxt5051_hp_master_sw_put,
1739 .private_value = 0x1a,
1745 static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1746 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1747 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1748 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1751 .name = "Master Playback Switch",
1752 .info = cxt_eapd_info,
1753 .get = cxt_eapd_get,
1754 .put = cxt5051_hp_master_sw_put,
1755 .private_value = 0x1a,
1761 static struct hda_verb cxt5051_init_verbs[] = {
1763 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1764 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1765 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1766 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1767 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1768 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1770 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1771 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1773 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1774 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1776 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1777 /* Record selector: Int mic */
1778 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1779 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1780 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1781 /* SPDIF route: PCM */
1782 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1784 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1785 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1786 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1787 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1791 static struct hda_verb cxt5051_hp_dv6736_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_PIN_WIDGET_CONTROL, 0x0},
1796 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1798 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1799 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1801 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1802 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1804 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1805 /* Record selector: Int mic */
1806 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1807 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1808 /* SPDIF route: PCM */
1809 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1811 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1812 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1813 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1817 static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1819 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1820 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1821 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1822 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1823 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1824 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1826 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1827 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1829 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1830 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1832 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1833 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1835 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1836 /* Record selector: Int mic */
1837 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1838 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1839 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
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},
1846 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1847 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1851 /* initialize jack-sensing, too */
1852 static int cxt5051_init(struct hda_codec *codec)
1854 conexant_init(codec);
1855 conexant_init_jacks(codec);
1856 if (codec->patch_ops.unsol_event) {
1857 cxt5051_hp_automute(codec);
1858 cxt5051_portb_automic(codec);
1859 cxt5051_portc_automic(codec);
1866 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1867 CXT5051_HP, /* no docking */
1868 CXT5051_HP_DV6736, /* HP without mic switch */
1869 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
1873 static const char *cxt5051_models[CXT5051_MODELS] = {
1874 [CXT5051_LAPTOP] = "laptop",
1875 [CXT5051_HP] = "hp",
1876 [CXT5051_HP_DV6736] = "hp-dv6736",
1877 [CXT5051_LENOVO_X200] = "lenovo-x200",
1880 static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1881 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1882 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1883 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1885 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1886 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1890 static int patch_cxt5051(struct hda_codec *codec)
1892 struct conexant_spec *spec;
1895 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1899 codec->pin_amp_workaround = 1;
1901 codec->patch_ops = conexant_patch_ops;
1902 codec->patch_ops.init = cxt5051_init;
1904 spec->multiout.max_channels = 2;
1905 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1906 spec->multiout.dac_nids = cxt5051_dac_nids;
1907 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1908 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1909 spec->adc_nids = cxt5051_adc_nids;
1910 spec->num_mixers = 1;
1911 spec->mixers[0] = cxt5051_mixers;
1912 spec->num_init_verbs = 1;
1913 spec->init_verbs[0] = cxt5051_init_verbs;
1914 spec->spdif_route = 0;
1915 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1916 spec->channel_mode = cxt5051_modes;
1918 spec->cur_adc_idx = 0;
1920 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1922 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1925 switch (board_config) {
1927 spec->mixers[0] = cxt5051_hp_mixers;
1929 case CXT5051_HP_DV6736:
1930 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1931 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1932 spec->no_auto_mic = 1;
1934 case CXT5051_LENOVO_X200:
1935 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1942 /* Conexant 5066 specific */
1944 static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1945 static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1946 static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1947 #define CXT5066_SPDIF_OUT 0x21
1949 /* OLPC's microphone port is DC coupled for use with external sensors,
1950 * therefore we use a 50% mic bias in order to center the input signal with
1951 * the DC input range of the codec. */
1952 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1954 static struct hda_channel_mode cxt5066_modes[1] = {
1958 static void cxt5066_update_speaker(struct hda_codec *codec)
1960 struct conexant_spec *spec = codec->spec;
1961 unsigned int pinctl;
1963 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
1967 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
1968 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1971 /* Port D (HP/LO) */
1972 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
1973 ? spec->port_d_mode : 0;
1974 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1978 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1979 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1982 if (spec->dell_automute) {
1983 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
1984 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
1986 snd_hda_codec_write(codec, 0x1c, 0,
1987 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
1991 /* turn on/off EAPD (+ mute HP) as a master switch */
1992 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1993 struct snd_ctl_elem_value *ucontrol)
1995 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1997 if (!cxt_eapd_put(kcontrol, ucontrol))
2000 cxt5066_update_speaker(codec);
2004 /* toggle input of built-in and mic jack appropriately */
2005 static void cxt5066_automic(struct hda_codec *codec)
2007 struct conexant_spec *spec = codec->spec;
2008 struct hda_verb ext_mic_present[] = {
2009 /* enable external mic, port B */
2010 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
2012 /* switch to external mic input */
2013 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2015 /* disable internal mic, port C */
2016 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2019 static struct hda_verb ext_mic_absent[] = {
2020 /* enable internal mic, port C */
2021 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2023 /* switch to internal mic input */
2024 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2026 /* disable external mic, port B */
2027 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2030 unsigned int present;
2032 present = snd_hda_codec_read(codec, 0x1a, 0,
2033 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2035 snd_printdd("CXT5066: external microphone detected\n");
2036 snd_hda_sequence_write(codec, ext_mic_present);
2038 snd_printdd("CXT5066: external microphone absent\n");
2039 snd_hda_sequence_write(codec, ext_mic_absent);
2043 /* mute internal speaker if HP is plugged */
2044 static void cxt5066_hp_automute(struct hda_codec *codec)
2046 struct conexant_spec *spec = codec->spec;
2047 unsigned int portA, portD;
2050 portA = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0)
2051 & AC_PINSENSE_PRESENCE;
2054 portD = (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0)
2055 & AC_PINSENSE_PRESENCE) << 1;
2057 spec->hp_present = !!(portA | portD);
2058 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2059 portA, portD, spec->hp_present);
2060 cxt5066_update_speaker(codec);
2063 /* unsolicited event for jack sensing */
2064 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2066 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2067 switch (res >> 26) {
2068 case CONEXANT_HP_EVENT:
2069 cxt5066_hp_automute(codec);
2071 case CONEXANT_MIC_EVENT:
2072 cxt5066_automic(codec);
2077 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2088 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2089 struct snd_ctl_elem_info *uinfo)
2091 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2094 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2095 struct snd_ctl_elem_value *ucontrol)
2097 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2100 val = snd_hda_codec_read(codec, 0x17, 0,
2101 AC_VERB_GET_AMP_GAIN_MUTE, AC_AMP_GET_OUTPUT);
2103 ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
2107 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2108 struct snd_ctl_elem_value *ucontrol)
2110 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2111 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2114 if (!imux->num_items)
2116 idx = ucontrol->value.enumerated.item[0];
2117 if (idx >= imux->num_items)
2118 idx = imux->num_items - 1;
2120 snd_hda_codec_write_cache(codec, 0x17, 0,
2121 AC_VERB_SET_AMP_GAIN_MUTE,
2122 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2123 imux->items[idx].index);
2128 static struct hda_input_mux cxt5066_capture_source = {
2138 static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2139 .ops = &snd_hda_bind_vol,
2141 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2142 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2147 static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2148 .ops = &snd_hda_bind_sw,
2150 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2151 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2156 static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2157 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2161 static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2163 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2164 .name = "Master Playback Volume",
2165 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2166 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2167 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2168 .info = snd_hda_mixer_amp_volume_info,
2169 .get = snd_hda_mixer_amp_volume_get,
2170 .put = snd_hda_mixer_amp_volume_put,
2171 .tlv = { .c = snd_hda_mixer_amp_tlv },
2172 /* offset by 28 volume steps to limit minimum gain to -46dB */
2174 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2179 static struct snd_kcontrol_new cxt5066_mixers[] = {
2181 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2182 .name = "Master Playback Switch",
2183 .info = cxt_eapd_info,
2184 .get = cxt_eapd_get,
2185 .put = cxt5066_hp_master_sw_put,
2186 .private_value = 0x1d,
2190 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2191 .name = "Analog Mic Boost Capture Enum",
2192 .info = cxt5066_mic_boost_mux_enum_info,
2193 .get = cxt5066_mic_boost_mux_enum_get,
2194 .put = cxt5066_mic_boost_mux_enum_put,
2197 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2198 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2202 static struct hda_verb cxt5066_init_verbs[] = {
2203 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2204 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2205 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2206 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2209 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2210 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2213 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2214 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2216 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2217 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2220 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2222 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2223 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2224 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2225 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2226 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2227 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2229 /* no digital microphone support yet */
2230 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2232 /* Audio input selector */
2233 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2235 /* SPDIF route: PCM */
2236 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2237 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2239 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2240 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2243 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2245 /* not handling these yet */
2246 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2247 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2248 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2249 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2250 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2251 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2252 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2253 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2257 static struct hda_verb cxt5066_init_verbs_olpc[] = {
2258 /* Port A: headphones */
2259 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2260 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2262 /* Port B: external microphone */
2263 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, CXT5066_OLPC_EXT_MIC_BIAS},
2265 /* Port C: internal microphone */
2266 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2268 /* Port D: unused */
2269 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2271 /* Port E: unused, but has primary EAPD */
2272 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2273 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2275 /* Port F: unused */
2276 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2278 /* Port G: internal speakers */
2279 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2280 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2283 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2286 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2288 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2289 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2290 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2291 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2292 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2293 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2294 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2295 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2296 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2297 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2298 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2299 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2301 /* Disable digital microphone port */
2302 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2304 /* Audio input selectors */
2305 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2306 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2309 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2310 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2312 /* enable unsolicited events for Port A and B */
2313 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2314 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2318 static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2319 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2323 /* initialize jack-sensing, too */
2324 static int cxt5066_init(struct hda_codec *codec)
2326 snd_printdd("CXT5066: init\n");
2327 conexant_init(codec);
2328 if (codec->patch_ops.unsol_event) {
2329 cxt5066_hp_automute(codec);
2330 cxt5066_automic(codec);
2336 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2337 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2338 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
2342 static const char *cxt5066_models[CXT5066_MODELS] = {
2343 [CXT5066_LAPTOP] = "laptop",
2344 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2345 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
2348 static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2349 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2351 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2352 CXT5066_DELL_LAPTOP),
2353 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
2354 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
2355 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
2359 static int patch_cxt5066(struct hda_codec *codec)
2361 struct conexant_spec *spec;
2364 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2369 codec->patch_ops = conexant_patch_ops;
2370 codec->patch_ops.init = cxt5066_init;
2372 spec->dell_automute = 0;
2373 spec->multiout.max_channels = 2;
2374 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2375 spec->multiout.dac_nids = cxt5066_dac_nids;
2376 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
2377 spec->num_adc_nids = 1;
2378 spec->adc_nids = cxt5066_adc_nids;
2379 spec->capsrc_nids = cxt5066_capsrc_nids;
2380 spec->input_mux = &cxt5066_capture_source;
2382 spec->port_d_mode = PIN_HP;
2383 spec->ext_mic_bias = PIN_VREF80;
2385 spec->num_init_verbs = 1;
2386 spec->init_verbs[0] = cxt5066_init_verbs;
2387 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2388 spec->channel_mode = cxt5066_modes;
2390 spec->cur_adc_idx = 0;
2392 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2393 cxt5066_models, cxt5066_cfg_tbl);
2394 switch (board_config) {
2396 case CXT5066_LAPTOP:
2397 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2398 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2400 case CXT5066_DELL_LAPTOP:
2401 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2402 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2404 spec->port_d_mode = PIN_OUT;
2405 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
2406 spec->num_init_verbs++;
2407 spec->dell_automute = 1;
2409 case CXT5066_OLPC_XO_1_5:
2410 codec->patch_ops.unsol_event = cxt5066_unsol_event;
2411 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
2412 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2413 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2414 spec->port_d_mode = 0;
2415 spec->ext_mic_bias = CXT5066_OLPC_EXT_MIC_BIAS;
2418 spec->multiout.dig_out_nid = 0;
2420 /* input source automatically selected */
2421 spec->input_mux = NULL;
2431 static struct hda_codec_preset snd_hda_preset_conexant[] = {
2432 { .id = 0x14f15045, .name = "CX20549 (Venice)",
2433 .patch = patch_cxt5045 },
2434 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
2435 .patch = patch_cxt5047 },
2436 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
2437 .patch = patch_cxt5051 },
2438 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
2439 .patch = patch_cxt5066 },
2443 MODULE_ALIAS("snd-hda-codec-id:14f15045");
2444 MODULE_ALIAS("snd-hda-codec-id:14f15047");
2445 MODULE_ALIAS("snd-hda-codec-id:14f15051");
2446 MODULE_ALIAS("snd-hda-codec-id:14f15066");
2448 MODULE_LICENSE("GPL");
2449 MODULE_DESCRIPTION("Conexant HD-audio codec");
2451 static struct hda_codec_preset_list conexant_list = {
2452 .preset = snd_hda_preset_conexant,
2453 .owner = THIS_MODULE,
2456 static int __init patch_conexant_init(void)
2458 return snd_hda_add_codec_preset(&conexant_list);
2461 static void __exit patch_conexant_exit(void)
2463 snd_hda_delete_codec_preset(&conexant_list);
2466 module_init(patch_conexant_init)
2467 module_exit(patch_conexant_exit)