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"
34 #define CXT_PIN_DIR_IN 0x00
35 #define CXT_PIN_DIR_OUT 0x01
36 #define CXT_PIN_DIR_INOUT 0x02
37 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
38 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
40 #define CONEXANT_HP_EVENT 0x37
41 #define CONEXANT_MIC_EVENT 0x38
43 /* Conexant 5051 specific */
45 #define CXT5051_SPDIF_OUT 0x12
46 #define CXT5051_PORTB_EVENT 0x38
47 #define CXT5051_PORTC_EVENT 0x39
49 #define AUTO_MIC_PORTB (1 << 1)
50 #define AUTO_MIC_PORTC (1 << 2)
52 struct conexant_jack {
56 struct snd_jack *jack;
66 struct conexant_spec {
68 struct snd_kcontrol_new *mixers[5];
70 hda_nid_t vmaster_nid;
72 const struct hda_verb *init_verbs[5]; /* initialization verbs
76 unsigned int num_init_verbs;
79 struct hda_multi_out multiout; /* playback set-up
80 * max_channels, dacs must be set
81 * dig_out_nid and hp_nid are optional
83 unsigned int cur_eapd;
84 unsigned int hp_present;
85 unsigned int auto_mic;
86 int auto_mic_ext; /* autocfg.inputs[] index for ext mic */
87 unsigned int need_dac_fix;
88 hda_nid_t slave_dig_outs[2];
91 unsigned int num_adc_nids;
93 hda_nid_t dig_in_nid; /* digital-in NID; optional */
95 unsigned int cur_adc_idx;
97 unsigned int cur_adc_stream_tag;
98 unsigned int cur_adc_format;
101 const struct hda_input_mux *input_mux;
102 hda_nid_t *capsrc_nids;
103 unsigned int cur_mux[3];
106 const struct hda_channel_mode *channel_mode;
107 int num_channel_mode;
109 /* PCM information */
110 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
112 unsigned int spdif_route;
115 struct snd_array jacks;
117 /* dynamic controls, init_verbs and input_mux */
118 struct auto_pin_cfg autocfg;
119 struct hda_input_mux private_imux;
120 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
121 struct pin_dac_pair dac_info[8];
124 unsigned int port_d_mode;
125 unsigned int auto_mute:1; /* used in auto-parser */
126 unsigned int dell_automute:1;
127 unsigned int dell_vostro:1;
128 unsigned int ideapad:1;
129 unsigned int thinkpad:1;
130 unsigned int hp_laptop:1;
133 unsigned int ext_mic_present;
134 unsigned int recording;
135 void (*capture_prepare)(struct hda_codec *codec);
136 void (*capture_cleanup)(struct hda_codec *codec);
138 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
139 * through the microphone jack.
140 * When the user enables this through a mixer switch, both internal and
141 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
142 * we also allow the bias to be configured through a separate mixer
144 unsigned int dc_enable;
145 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
146 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
148 unsigned int beep_amp;
151 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
152 struct hda_codec *codec,
153 struct snd_pcm_substream *substream)
155 struct conexant_spec *spec = codec->spec;
156 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
160 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
161 struct hda_codec *codec,
162 unsigned int stream_tag,
164 struct snd_pcm_substream *substream)
166 struct conexant_spec *spec = codec->spec;
167 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
172 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
173 struct hda_codec *codec,
174 struct snd_pcm_substream *substream)
176 struct conexant_spec *spec = codec->spec;
177 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
183 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
184 struct hda_codec *codec,
185 struct snd_pcm_substream *substream)
187 struct conexant_spec *spec = codec->spec;
188 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
191 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
192 struct hda_codec *codec,
193 struct snd_pcm_substream *substream)
195 struct conexant_spec *spec = codec->spec;
196 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
199 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
200 struct hda_codec *codec,
201 unsigned int stream_tag,
203 struct snd_pcm_substream *substream)
205 struct conexant_spec *spec = codec->spec;
206 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
214 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
215 struct hda_codec *codec,
216 unsigned int stream_tag,
218 struct snd_pcm_substream *substream)
220 struct conexant_spec *spec = codec->spec;
221 if (spec->capture_prepare)
222 spec->capture_prepare(codec);
223 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
224 stream_tag, 0, format);
228 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
229 struct hda_codec *codec,
230 struct snd_pcm_substream *substream)
232 struct conexant_spec *spec = codec->spec;
233 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
234 if (spec->capture_cleanup)
235 spec->capture_cleanup(codec);
241 static struct hda_pcm_stream conexant_pcm_analog_playback = {
245 .nid = 0, /* fill later */
247 .open = conexant_playback_pcm_open,
248 .prepare = conexant_playback_pcm_prepare,
249 .cleanup = conexant_playback_pcm_cleanup
253 static struct hda_pcm_stream conexant_pcm_analog_capture = {
257 .nid = 0, /* fill later */
259 .prepare = conexant_capture_pcm_prepare,
260 .cleanup = conexant_capture_pcm_cleanup
265 static struct hda_pcm_stream conexant_pcm_digital_playback = {
269 .nid = 0, /* fill later */
271 .open = conexant_dig_playback_pcm_open,
272 .close = conexant_dig_playback_pcm_close,
273 .prepare = conexant_dig_playback_pcm_prepare
277 static struct hda_pcm_stream conexant_pcm_digital_capture = {
281 /* NID is set in alc_build_pcms */
284 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
285 struct hda_codec *codec,
286 unsigned int stream_tag,
288 struct snd_pcm_substream *substream)
290 struct conexant_spec *spec = codec->spec;
291 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
292 spec->cur_adc_stream_tag = stream_tag;
293 spec->cur_adc_format = format;
294 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
298 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
299 struct hda_codec *codec,
300 struct snd_pcm_substream *substream)
302 struct conexant_spec *spec = codec->spec;
303 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
308 static struct hda_pcm_stream cx5051_pcm_analog_capture = {
312 .nid = 0, /* fill later */
314 .prepare = cx5051_capture_pcm_prepare,
315 .cleanup = cx5051_capture_pcm_cleanup
319 static int conexant_build_pcms(struct hda_codec *codec)
321 struct conexant_spec *spec = codec->spec;
322 struct hda_pcm *info = spec->pcm_rec;
325 codec->pcm_info = info;
327 info->name = "CONEXANT Analog";
328 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
330 spec->multiout.max_channels;
331 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
332 spec->multiout.dac_nids[0];
333 if (codec->vendor_id == 0x14f15051)
334 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
335 cx5051_pcm_analog_capture;
337 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
338 conexant_pcm_analog_capture;
339 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
340 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
342 if (spec->multiout.dig_out_nid) {
345 info->name = "Conexant Digital";
346 info->pcm_type = HDA_PCM_TYPE_SPDIF;
347 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
348 conexant_pcm_digital_playback;
349 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
350 spec->multiout.dig_out_nid;
351 if (spec->dig_in_nid) {
352 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
353 conexant_pcm_digital_capture;
354 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
357 if (spec->slave_dig_outs[0])
358 codec->slave_dig_outs = spec->slave_dig_outs;
364 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
365 struct snd_ctl_elem_info *uinfo)
367 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
368 struct conexant_spec *spec = codec->spec;
370 return snd_hda_input_mux_info(spec->input_mux, uinfo);
373 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
374 struct snd_ctl_elem_value *ucontrol)
376 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377 struct conexant_spec *spec = codec->spec;
378 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
380 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
384 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
385 struct snd_ctl_elem_value *ucontrol)
387 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
388 struct conexant_spec *spec = codec->spec;
389 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
391 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
392 spec->capsrc_nids[adc_idx],
393 &spec->cur_mux[adc_idx]);
396 #ifdef CONFIG_SND_HDA_INPUT_JACK
397 static void conexant_free_jack_priv(struct snd_jack *jack)
399 struct conexant_jack *jacks = jack->private_data;
404 static int conexant_add_jack(struct hda_codec *codec,
405 hda_nid_t nid, int type)
407 struct conexant_spec *spec;
408 struct conexant_jack *jack;
413 snd_array_init(&spec->jacks, sizeof(*jack), 32);
414 jack = snd_array_new(&spec->jacks);
415 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
423 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
426 jack->jack->private_data = jack;
427 jack->jack->private_free = conexant_free_jack_priv;
431 static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
433 struct conexant_spec *spec = codec->spec;
434 struct conexant_jack *jacks = spec->jacks.list;
438 for (i = 0; i < spec->jacks.used; i++) {
439 if (jacks->nid == nid) {
440 unsigned int present;
441 present = snd_hda_jack_detect(codec, nid);
443 present = (present) ? jacks->type : 0 ;
445 snd_jack_report(jacks->jack,
453 static int conexant_init_jacks(struct hda_codec *codec)
455 struct conexant_spec *spec = codec->spec;
458 for (i = 0; i < spec->num_init_verbs; i++) {
459 const struct hda_verb *hv;
461 hv = spec->init_verbs[i];
464 switch (hv->param ^ AC_USRSP_EN) {
465 case CONEXANT_HP_EVENT:
466 err = conexant_add_jack(codec, hv->nid,
468 conexant_report_jack(codec, hv->nid);
470 case CXT5051_PORTC_EVENT:
471 case CONEXANT_MIC_EVENT:
472 err = conexant_add_jack(codec, hv->nid,
473 SND_JACK_MICROPHONE);
474 conexant_report_jack(codec, hv->nid);
486 static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
490 static inline int conexant_init_jacks(struct hda_codec *codec)
496 static int conexant_init(struct hda_codec *codec)
498 struct conexant_spec *spec = codec->spec;
501 for (i = 0; i < spec->num_init_verbs; i++)
502 snd_hda_sequence_write(codec, spec->init_verbs[i]);
506 static void conexant_free(struct hda_codec *codec)
508 #ifdef CONFIG_SND_HDA_INPUT_JACK
509 struct conexant_spec *spec = codec->spec;
510 if (spec->jacks.list) {
511 struct conexant_jack *jacks = spec->jacks.list;
513 for (i = 0; i < spec->jacks.used; i++, jacks++) {
515 snd_device_free(codec->bus->card, jacks->jack);
517 snd_array_free(&spec->jacks);
520 snd_hda_detach_beep_device(codec);
524 static struct snd_kcontrol_new cxt_capture_mixers[] = {
526 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
527 .name = "Capture Source",
528 .info = conexant_mux_enum_info,
529 .get = conexant_mux_enum_get,
530 .put = conexant_mux_enum_put
535 #ifdef CONFIG_SND_HDA_INPUT_BEEP
536 /* additional beep mixers; the actual parameters are overwritten at build */
537 static struct snd_kcontrol_new cxt_beep_mixer[] = {
538 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
539 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
544 static const char * const slave_vols[] = {
545 "Headphone Playback Volume",
546 "Speaker Playback Volume",
550 static const char * const slave_sws[] = {
551 "Headphone Playback Switch",
552 "Speaker Playback Switch",
556 static int conexant_build_controls(struct hda_codec *codec)
558 struct conexant_spec *spec = codec->spec;
562 for (i = 0; i < spec->num_mixers; i++) {
563 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
567 if (spec->multiout.dig_out_nid) {
568 err = snd_hda_create_spdif_out_ctls(codec,
569 spec->multiout.dig_out_nid);
572 err = snd_hda_create_spdif_share_sw(codec,
576 spec->multiout.share_spdif = 1;
578 if (spec->dig_in_nid) {
579 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
584 /* if we have no master control, let's create it */
585 if (spec->vmaster_nid &&
586 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
587 unsigned int vmaster_tlv[4];
588 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
589 HDA_OUTPUT, vmaster_tlv);
590 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
591 vmaster_tlv, slave_vols);
595 if (spec->vmaster_nid &&
596 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
597 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
603 if (spec->input_mux) {
604 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
609 #ifdef CONFIG_SND_HDA_INPUT_BEEP
610 /* create beep controls if needed */
611 if (spec->beep_amp) {
612 struct snd_kcontrol_new *knew;
613 for (knew = cxt_beep_mixer; knew->name; knew++) {
614 struct snd_kcontrol *kctl;
615 kctl = snd_ctl_new1(knew, codec);
618 kctl->private_value = spec->beep_amp;
619 err = snd_hda_ctl_add(codec, 0, kctl);
629 #ifdef CONFIG_SND_HDA_POWER_SAVE
630 static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
632 snd_hda_shutup_pins(codec);
637 static struct hda_codec_ops conexant_patch_ops = {
638 .build_controls = conexant_build_controls,
639 .build_pcms = conexant_build_pcms,
640 .init = conexant_init,
641 .free = conexant_free,
642 #ifdef CONFIG_SND_HDA_POWER_SAVE
643 .suspend = conexant_suspend,
645 .reboot_notify = snd_hda_shutup_pins,
648 #ifdef CONFIG_SND_HDA_INPUT_BEEP
649 #define set_beep_amp(spec, nid, idx, dir) \
650 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
652 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
657 * the private value = nid | (invert << 8)
660 #define cxt_eapd_info snd_ctl_boolean_mono_info
662 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
663 struct snd_ctl_elem_value *ucontrol)
665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
666 struct conexant_spec *spec = codec->spec;
667 int invert = (kcontrol->private_value >> 8) & 1;
669 ucontrol->value.integer.value[0] = !spec->cur_eapd;
671 ucontrol->value.integer.value[0] = spec->cur_eapd;
676 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
677 struct snd_ctl_elem_value *ucontrol)
679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
680 struct conexant_spec *spec = codec->spec;
681 int invert = (kcontrol->private_value >> 8) & 1;
682 hda_nid_t nid = kcontrol->private_value & 0xff;
685 eapd = !!ucontrol->value.integer.value[0];
688 if (eapd == spec->cur_eapd)
691 spec->cur_eapd = eapd;
692 snd_hda_codec_write_cache(codec, nid,
693 0, AC_VERB_SET_EAPD_BTLENABLE,
698 /* controls for test mode */
699 #ifdef CONFIG_SND_DEBUG
701 #define CXT_EAPD_SWITCH(xname, nid, mask) \
702 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
703 .info = cxt_eapd_info, \
704 .get = cxt_eapd_get, \
705 .put = cxt_eapd_put, \
706 .private_value = nid | (mask<<16) }
710 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
711 struct snd_ctl_elem_info *uinfo)
713 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
714 struct conexant_spec *spec = codec->spec;
715 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
716 spec->num_channel_mode);
719 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
720 struct snd_ctl_elem_value *ucontrol)
722 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
723 struct conexant_spec *spec = codec->spec;
724 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
725 spec->num_channel_mode,
726 spec->multiout.max_channels);
729 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
730 struct snd_ctl_elem_value *ucontrol)
732 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
733 struct conexant_spec *spec = codec->spec;
734 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
735 spec->num_channel_mode,
736 &spec->multiout.max_channels);
737 if (err >= 0 && spec->need_dac_fix)
738 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
742 #define CXT_PIN_MODE(xname, nid, dir) \
743 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
744 .info = conexant_ch_mode_info, \
745 .get = conexant_ch_mode_get, \
746 .put = conexant_ch_mode_put, \
747 .private_value = nid | (dir<<16) }
749 #endif /* CONFIG_SND_DEBUG */
751 /* Conexant 5045 specific */
753 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
754 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
755 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
756 #define CXT5045_SPDIF_OUT 0x18
758 static struct hda_channel_mode cxt5045_modes[1] = {
762 static struct hda_input_mux cxt5045_capture_source = {
770 static struct hda_input_mux cxt5045_capture_source_benq = {
781 static struct hda_input_mux cxt5045_capture_source_hp530 = {
789 /* turn on/off EAPD (+ mute HP) as a master switch */
790 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
791 struct snd_ctl_elem_value *ucontrol)
793 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
794 struct conexant_spec *spec = codec->spec;
797 if (!cxt_eapd_put(kcontrol, ucontrol))
800 /* toggle internal speakers mute depending of presence of
803 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
804 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
807 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
808 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
813 /* bind volumes of both NID 0x10 and 0x11 */
814 static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
815 .ops = &snd_hda_bind_vol,
817 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
818 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
823 /* toggle input of built-in and mic jack appropriately */
824 static void cxt5045_hp_automic(struct hda_codec *codec)
826 static struct hda_verb mic_jack_on[] = {
827 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
828 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
831 static struct hda_verb mic_jack_off[] = {
832 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
833 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
836 unsigned int present;
838 present = snd_hda_jack_detect(codec, 0x12);
840 snd_hda_sequence_write(codec, mic_jack_on);
842 snd_hda_sequence_write(codec, mic_jack_off);
846 /* mute internal speaker if HP is plugged */
847 static void cxt5045_hp_automute(struct hda_codec *codec)
849 struct conexant_spec *spec = codec->spec;
852 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
854 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
855 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
859 /* unsolicited event for HP jack sensing */
860 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
865 case CONEXANT_HP_EVENT:
866 cxt5045_hp_automute(codec);
868 case CONEXANT_MIC_EVENT:
869 cxt5045_hp_automic(codec);
875 static struct snd_kcontrol_new cxt5045_mixers[] = {
876 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
877 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
878 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
879 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
880 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
881 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
882 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
883 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
884 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
885 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
886 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
888 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
889 .name = "Master Playback Switch",
890 .info = cxt_eapd_info,
892 .put = cxt5045_hp_master_sw_put,
893 .private_value = 0x10,
899 static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
900 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
901 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
902 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
903 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
905 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
906 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
907 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
908 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
910 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
911 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
916 static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
917 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
918 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
919 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
920 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
921 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
922 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
923 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
924 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
925 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
926 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
927 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
929 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
930 .name = "Master Playback Switch",
931 .info = cxt_eapd_info,
933 .put = cxt5045_hp_master_sw_put,
934 .private_value = 0x10,
940 static struct hda_verb cxt5045_init_verbs[] = {
942 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
943 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
945 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
946 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
947 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
948 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
949 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
950 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
951 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
952 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
953 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
954 /* Record selector: Internal mic */
955 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
956 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
957 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
958 /* SPDIF route: PCM */
959 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
960 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
962 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
966 static struct hda_verb cxt5045_benq_init_verbs[] = {
967 /* Internal Mic, Mic */
968 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
969 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
970 /* Line In,HP, Amp */
971 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
972 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
973 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
974 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
975 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
976 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
977 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
978 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
979 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
980 /* Record selector: Internal mic */
981 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
982 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
983 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
984 /* SPDIF route: PCM */
985 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
986 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
988 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
992 static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
993 /* pin sensing on HP jack */
994 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
998 static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
999 /* pin sensing on HP jack */
1000 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1004 #ifdef CONFIG_SND_DEBUG
1005 /* Test configuration for debugging, modelled after the ALC260 test
1008 static struct hda_input_mux cxt5045_test_capture_source = {
1012 { "MIC1 pin", 0x1 },
1013 { "LINE1 pin", 0x2 },
1014 { "HP-OUT pin", 0x3 },
1019 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
1021 /* Output controls */
1022 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1023 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1024 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1025 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1026 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1027 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1029 /* Modes for retasking pin widgets */
1030 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
1031 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
1033 /* EAPD Switch Control */
1034 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
1036 /* Loopback mixer controls */
1038 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
1039 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
1040 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
1041 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
1042 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
1043 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1044 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1045 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1046 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1047 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
1049 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1050 .name = "Input Source",
1051 .info = conexant_mux_enum_info,
1052 .get = conexant_mux_enum_get,
1053 .put = conexant_mux_enum_put,
1055 /* Audio input controls */
1056 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1057 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1058 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1059 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1060 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1061 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1062 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1063 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1064 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1065 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1069 static struct hda_verb cxt5045_test_init_verbs[] = {
1070 /* Set connections */
1071 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1072 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1073 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1074 /* Enable retasking pins as output, initially without power amp */
1075 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1076 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1078 /* Disable digital (SPDIF) pins initially, but users can enable
1079 * them via a mixer switch. In the case of SPDIF-out, this initverb
1080 * payload also sets the generation to 0, output to be in "consumer"
1081 * PCM format, copyright asserted, no pre-emphasis and no validity
1084 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1085 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1087 /* Start with output sum widgets muted and their output gains at min */
1088 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1089 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1091 /* Unmute retasking pin widget output buffers since the default
1092 * state appears to be output. As the pin mode is changed by the
1093 * user the pin mode control will take care of enabling the pin's
1094 * input/output buffers as needed.
1096 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1097 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1099 /* Mute capture amp left and right */
1100 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1102 /* Set ADC connection select to match default mixer setting (mic1
1105 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1106 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1108 /* Mute all inputs to mixer widget (even unconnected ones) */
1109 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1110 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1111 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1112 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1113 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1120 /* initialize jack-sensing, too */
1121 static int cxt5045_init(struct hda_codec *codec)
1123 conexant_init(codec);
1124 cxt5045_hp_automute(codec);
1130 CXT5045_LAPTOP_HPSENSE,
1131 CXT5045_LAPTOP_MICSENSE,
1132 CXT5045_LAPTOP_HPMICSENSE,
1134 CXT5045_LAPTOP_HP530,
1135 #ifdef CONFIG_SND_DEBUG
1141 static const char * const cxt5045_models[CXT5045_MODELS] = {
1142 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1143 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1144 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1145 [CXT5045_BENQ] = "benq",
1146 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1147 #ifdef CONFIG_SND_DEBUG
1148 [CXT5045_TEST] = "test",
1152 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1153 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1154 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1155 CXT5045_LAPTOP_HPSENSE),
1156 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1157 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1158 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1159 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1160 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1161 CXT5045_LAPTOP_HPMICSENSE),
1162 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1163 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1164 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1165 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1166 CXT5045_LAPTOP_HPMICSENSE),
1167 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1171 static int patch_cxt5045(struct hda_codec *codec)
1173 struct conexant_spec *spec;
1176 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1180 codec->pin_amp_workaround = 1;
1182 spec->multiout.max_channels = 2;
1183 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1184 spec->multiout.dac_nids = cxt5045_dac_nids;
1185 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1186 spec->num_adc_nids = 1;
1187 spec->adc_nids = cxt5045_adc_nids;
1188 spec->capsrc_nids = cxt5045_capsrc_nids;
1189 spec->input_mux = &cxt5045_capture_source;
1190 spec->num_mixers = 1;
1191 spec->mixers[0] = cxt5045_mixers;
1192 spec->num_init_verbs = 1;
1193 spec->init_verbs[0] = cxt5045_init_verbs;
1194 spec->spdif_route = 0;
1195 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1196 spec->channel_mode = cxt5045_modes;
1198 set_beep_amp(spec, 0x16, 0, 1);
1200 codec->patch_ops = conexant_patch_ops;
1202 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1205 switch (board_config) {
1206 case CXT5045_LAPTOP_HPSENSE:
1207 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1208 spec->input_mux = &cxt5045_capture_source;
1209 spec->num_init_verbs = 2;
1210 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1211 spec->mixers[0] = cxt5045_mixers;
1212 codec->patch_ops.init = cxt5045_init;
1214 case CXT5045_LAPTOP_MICSENSE:
1215 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1216 spec->input_mux = &cxt5045_capture_source;
1217 spec->num_init_verbs = 2;
1218 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1219 spec->mixers[0] = cxt5045_mixers;
1220 codec->patch_ops.init = cxt5045_init;
1223 case CXT5045_LAPTOP_HPMICSENSE:
1224 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1225 spec->input_mux = &cxt5045_capture_source;
1226 spec->num_init_verbs = 3;
1227 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1228 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1229 spec->mixers[0] = cxt5045_mixers;
1230 codec->patch_ops.init = cxt5045_init;
1233 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1234 spec->input_mux = &cxt5045_capture_source_benq;
1235 spec->num_init_verbs = 1;
1236 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1237 spec->mixers[0] = cxt5045_mixers;
1238 spec->mixers[1] = cxt5045_benq_mixers;
1239 spec->num_mixers = 2;
1240 codec->patch_ops.init = cxt5045_init;
1242 case CXT5045_LAPTOP_HP530:
1243 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1244 spec->input_mux = &cxt5045_capture_source_hp530;
1245 spec->num_init_verbs = 2;
1246 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1247 spec->mixers[0] = cxt5045_mixers_hp530;
1248 codec->patch_ops.init = cxt5045_init;
1250 #ifdef CONFIG_SND_DEBUG
1252 spec->input_mux = &cxt5045_test_capture_source;
1253 spec->mixers[0] = cxt5045_test_mixer;
1254 spec->init_verbs[0] = cxt5045_test_init_verbs;
1260 switch (codec->subsystem_id >> 16) {
1265 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1266 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1267 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1269 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1270 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1271 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1272 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1273 (1 << AC_AMPCAP_MUTE_SHIFT));
1278 snd_hda_attach_beep_device(codec, spec->beep_amp);
1284 /* Conexant 5047 specific */
1285 #define CXT5047_SPDIF_OUT 0x11
1287 static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1288 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1289 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1291 static struct hda_channel_mode cxt5047_modes[1] = {
1295 static struct hda_input_mux cxt5047_toshiba_capture_source = {
1303 /* turn on/off EAPD (+ mute HP) as a master switch */
1304 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1305 struct snd_ctl_elem_value *ucontrol)
1307 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1308 struct conexant_spec *spec = codec->spec;
1311 if (!cxt_eapd_put(kcontrol, ucontrol))
1314 /* toggle internal speakers mute depending of presence of
1315 * the headphone jack
1317 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1318 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1319 * pin widgets unlike other codecs. In this case, we need to
1320 * set index 0x01 for the volume from the mixer amp 0x19.
1322 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1323 HDA_AMP_MUTE, bits);
1324 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1325 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1326 HDA_AMP_MUTE, bits);
1330 /* mute internal speaker if HP is plugged */
1331 static void cxt5047_hp_automute(struct hda_codec *codec)
1333 struct conexant_spec *spec = codec->spec;
1336 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1338 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1339 /* See the note in cxt5047_hp_master_sw_put */
1340 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1341 HDA_AMP_MUTE, bits);
1344 /* toggle input of built-in and mic jack appropriately */
1345 static void cxt5047_hp_automic(struct hda_codec *codec)
1347 static struct hda_verb mic_jack_on[] = {
1348 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1349 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1352 static struct hda_verb mic_jack_off[] = {
1353 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1354 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1357 unsigned int present;
1359 present = snd_hda_jack_detect(codec, 0x15);
1361 snd_hda_sequence_write(codec, mic_jack_on);
1363 snd_hda_sequence_write(codec, mic_jack_off);
1366 /* unsolicited event for HP jack sensing */
1367 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1370 switch (res >> 26) {
1371 case CONEXANT_HP_EVENT:
1372 cxt5047_hp_automute(codec);
1374 case CONEXANT_MIC_EVENT:
1375 cxt5047_hp_automic(codec);
1380 static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1381 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1382 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1383 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1384 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1385 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1386 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1387 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1389 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1390 .name = "Master Playback Switch",
1391 .info = cxt_eapd_info,
1392 .get = cxt_eapd_get,
1393 .put = cxt5047_hp_master_sw_put,
1394 .private_value = 0x13,
1400 static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1401 /* See the note in cxt5047_hp_master_sw_put */
1402 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1403 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1407 static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1408 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1412 static struct hda_verb cxt5047_init_verbs[] = {
1413 /* Line in, Mic, Built-in Mic */
1414 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1415 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1416 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1418 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1419 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1420 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1421 /* Record selector: Mic */
1422 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1423 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1424 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1425 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1426 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1427 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1428 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1429 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1430 /* SPDIF route: PCM */
1431 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1432 /* Enable unsolicited events */
1433 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1434 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1438 /* configuration for Toshiba Laptops */
1439 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1440 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1444 /* Test configuration for debugging, modelled after the ALC260 test
1447 #ifdef CONFIG_SND_DEBUG
1448 static struct hda_input_mux cxt5047_test_capture_source = {
1451 { "LINE1 pin", 0x0 },
1452 { "MIC1 pin", 0x1 },
1453 { "MIC2 pin", 0x2 },
1458 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1460 /* Output only controls */
1461 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1462 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1463 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1464 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1465 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1466 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1467 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1468 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1469 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1470 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1471 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1472 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1474 /* Modes for retasking pin widgets */
1475 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1476 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1478 /* EAPD Switch Control */
1479 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1481 /* Loopback mixer controls */
1482 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1483 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1484 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1485 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1486 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1487 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1488 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1489 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1491 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1492 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1493 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1494 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1495 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1496 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1497 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1498 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1500 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1501 .name = "Input Source",
1502 .info = conexant_mux_enum_info,
1503 .get = conexant_mux_enum_get,
1504 .put = conexant_mux_enum_put,
1506 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1511 static struct hda_verb cxt5047_test_init_verbs[] = {
1512 /* Enable retasking pins as output, initially without power amp */
1513 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1514 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1515 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1517 /* Disable digital (SPDIF) pins initially, but users can enable
1518 * them via a mixer switch. In the case of SPDIF-out, this initverb
1519 * payload also sets the generation to 0, output to be in "consumer"
1520 * PCM format, copyright asserted, no pre-emphasis and no validity
1523 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1525 /* Ensure mic1, mic2, line1 pin widgets take input from the
1526 * OUT1 sum bus when acting as an output.
1528 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1529 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1531 /* Start with output sum widgets muted and their output gains at min */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1533 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1535 /* Unmute retasking pin widget output buffers since the default
1536 * state appears to be output. As the pin mode is changed by the
1537 * user the pin mode control will take care of enabling the pin's
1538 * input/output buffers as needed.
1540 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1541 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1542 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1544 /* Mute capture amp left and right */
1545 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1547 /* Set ADC connection select to match default mixer setting (mic1
1550 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1552 /* Mute all inputs to mixer widget (even unconnected ones) */
1553 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1554 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1555 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1556 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1557 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1558 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1559 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1560 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1567 /* initialize jack-sensing, too */
1568 static int cxt5047_hp_init(struct hda_codec *codec)
1570 conexant_init(codec);
1571 cxt5047_hp_automute(codec);
1577 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1578 CXT5047_LAPTOP_HP, /* Some HP laptops */
1579 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1580 #ifdef CONFIG_SND_DEBUG
1586 static const char * const cxt5047_models[CXT5047_MODELS] = {
1587 [CXT5047_LAPTOP] = "laptop",
1588 [CXT5047_LAPTOP_HP] = "laptop-hp",
1589 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1590 #ifdef CONFIG_SND_DEBUG
1591 [CXT5047_TEST] = "test",
1595 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1596 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1597 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1599 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1603 static int patch_cxt5047(struct hda_codec *codec)
1605 struct conexant_spec *spec;
1608 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1612 codec->pin_amp_workaround = 1;
1614 spec->multiout.max_channels = 2;
1615 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1616 spec->multiout.dac_nids = cxt5047_dac_nids;
1617 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1618 spec->num_adc_nids = 1;
1619 spec->adc_nids = cxt5047_adc_nids;
1620 spec->capsrc_nids = cxt5047_capsrc_nids;
1621 spec->num_mixers = 1;
1622 spec->mixers[0] = cxt5047_base_mixers;
1623 spec->num_init_verbs = 1;
1624 spec->init_verbs[0] = cxt5047_init_verbs;
1625 spec->spdif_route = 0;
1626 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1627 spec->channel_mode = cxt5047_modes,
1629 codec->patch_ops = conexant_patch_ops;
1631 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1634 switch (board_config) {
1635 case CXT5047_LAPTOP:
1636 spec->num_mixers = 2;
1637 spec->mixers[1] = cxt5047_hp_spk_mixers;
1638 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1640 case CXT5047_LAPTOP_HP:
1641 spec->num_mixers = 2;
1642 spec->mixers[1] = cxt5047_hp_only_mixers;
1643 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1644 codec->patch_ops.init = cxt5047_hp_init;
1646 case CXT5047_LAPTOP_EAPD:
1647 spec->input_mux = &cxt5047_toshiba_capture_source;
1648 spec->num_mixers = 2;
1649 spec->mixers[1] = cxt5047_hp_spk_mixers;
1650 spec->num_init_verbs = 2;
1651 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1652 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1654 #ifdef CONFIG_SND_DEBUG
1656 spec->input_mux = &cxt5047_test_capture_source;
1657 spec->mixers[0] = cxt5047_test_mixer;
1658 spec->init_verbs[0] = cxt5047_test_init_verbs;
1659 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1662 spec->vmaster_nid = 0x13;
1664 switch (codec->subsystem_id >> 16) {
1666 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1667 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1668 * with 0 dB offset 0x17)
1670 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1671 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1672 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1673 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1674 (1 << AC_AMPCAP_MUTE_SHIFT));
1681 /* Conexant 5051 specific */
1682 static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1683 static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1685 static struct hda_channel_mode cxt5051_modes[1] = {
1689 static void cxt5051_update_speaker(struct hda_codec *codec)
1691 struct conexant_spec *spec = codec->spec;
1692 unsigned int pinctl;
1694 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1695 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1698 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1699 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1701 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1703 snd_hda_codec_write(codec, 0x1b, 0,
1704 AC_VERB_SET_PIN_WIDGET_CONTROL,
1708 /* turn on/off EAPD (+ mute HP) as a master switch */
1709 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1710 struct snd_ctl_elem_value *ucontrol)
1712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1714 if (!cxt_eapd_put(kcontrol, ucontrol))
1716 cxt5051_update_speaker(codec);
1720 /* toggle input of built-in and mic jack appropriately */
1721 static void cxt5051_portb_automic(struct hda_codec *codec)
1723 struct conexant_spec *spec = codec->spec;
1724 unsigned int present;
1726 if (!(spec->auto_mic & AUTO_MIC_PORTB))
1728 present = snd_hda_jack_detect(codec, 0x17);
1729 snd_hda_codec_write(codec, 0x14, 0,
1730 AC_VERB_SET_CONNECT_SEL,
1731 present ? 0x01 : 0x00);
1734 /* switch the current ADC according to the jack state */
1735 static void cxt5051_portc_automic(struct hda_codec *codec)
1737 struct conexant_spec *spec = codec->spec;
1738 unsigned int present;
1741 if (!(spec->auto_mic & AUTO_MIC_PORTC))
1743 present = snd_hda_jack_detect(codec, 0x18);
1745 spec->cur_adc_idx = 1;
1747 spec->cur_adc_idx = 0;
1748 new_adc = spec->adc_nids[spec->cur_adc_idx];
1749 if (spec->cur_adc && spec->cur_adc != new_adc) {
1750 /* stream is running, let's swap the current ADC */
1751 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1752 spec->cur_adc = new_adc;
1753 snd_hda_codec_setup_stream(codec, new_adc,
1754 spec->cur_adc_stream_tag, 0,
1755 spec->cur_adc_format);
1759 /* mute internal speaker if HP is plugged */
1760 static void cxt5051_hp_automute(struct hda_codec *codec)
1762 struct conexant_spec *spec = codec->spec;
1764 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1765 cxt5051_update_speaker(codec);
1768 /* unsolicited event for HP jack sensing */
1769 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1772 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1773 switch (res >> 26) {
1774 case CONEXANT_HP_EVENT:
1775 cxt5051_hp_automute(codec);
1777 case CXT5051_PORTB_EVENT:
1778 cxt5051_portb_automic(codec);
1780 case CXT5051_PORTC_EVENT:
1781 cxt5051_portc_automic(codec);
1784 conexant_report_jack(codec, nid);
1787 static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1788 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1790 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1791 .name = "Master Playback Switch",
1792 .info = cxt_eapd_info,
1793 .get = cxt_eapd_get,
1794 .put = cxt5051_hp_master_sw_put,
1795 .private_value = 0x1a,
1800 static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1801 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1802 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1803 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1804 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1805 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1806 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1810 static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1811 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1812 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1813 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1814 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1818 static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1819 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1820 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
1824 static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1825 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1826 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1830 static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1831 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1832 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1833 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1834 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1838 static struct hda_verb cxt5051_init_verbs[] = {
1840 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1841 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1842 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1843 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1844 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1845 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1847 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1848 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1850 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1851 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1853 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1854 /* Record selector: Internal mic */
1855 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1856 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1857 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1858 /* SPDIF route: PCM */
1859 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1860 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1862 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1863 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1867 static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1869 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1870 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1871 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1872 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1874 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1875 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1877 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1878 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1880 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1881 /* Record selector: Internal mic */
1882 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1883 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1884 /* SPDIF route: PCM */
1885 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1887 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1888 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1892 static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1894 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1895 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1896 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1897 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1898 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1899 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1901 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1902 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1904 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1905 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1907 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1908 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1910 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1911 /* Record selector: Internal mic */
1912 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1913 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1914 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1915 /* SPDIF route: PCM */
1916 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
1917 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1919 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1920 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1921 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1925 static struct hda_verb cxt5051_f700_init_verbs[] = {
1927 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1928 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1929 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1930 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1932 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1933 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1935 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1936 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1938 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1939 /* Record selector: Internal mic */
1940 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1941 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1942 /* SPDIF route: PCM */
1943 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1945 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1946 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1950 static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1953 snd_hda_codec_write(codec, nid, 0,
1954 AC_VERB_SET_UNSOLICITED_ENABLE,
1955 AC_USRSP_EN | event);
1956 #ifdef CONFIG_SND_HDA_INPUT_JACK
1957 conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
1958 conexant_report_jack(codec, nid);
1962 static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1964 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1965 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1969 /* initialize jack-sensing, too */
1970 static int cxt5051_init(struct hda_codec *codec)
1972 struct conexant_spec *spec = codec->spec;
1974 conexant_init(codec);
1975 conexant_init_jacks(codec);
1977 if (spec->auto_mic & AUTO_MIC_PORTB)
1978 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1979 if (spec->auto_mic & AUTO_MIC_PORTC)
1980 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1982 if (codec->patch_ops.unsol_event) {
1983 cxt5051_hp_automute(codec);
1984 cxt5051_portb_automic(codec);
1985 cxt5051_portc_automic(codec);
1992 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1993 CXT5051_HP, /* no docking */
1994 CXT5051_HP_DV6736, /* HP without mic switch */
1995 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1996 CXT5051_F700, /* HP Compaq Presario F700 */
1997 CXT5051_TOSHIBA, /* Toshiba M300 & co */
1998 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
2002 static const char *const cxt5051_models[CXT5051_MODELS] = {
2003 [CXT5051_LAPTOP] = "laptop",
2004 [CXT5051_HP] = "hp",
2005 [CXT5051_HP_DV6736] = "hp-dv6736",
2006 [CXT5051_LENOVO_X200] = "lenovo-x200",
2007 [CXT5051_F700] = "hp-700",
2008 [CXT5051_TOSHIBA] = "toshiba",
2009 [CXT5051_IDEAPAD] = "ideapad",
2012 static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
2013 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
2014 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
2015 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
2016 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
2017 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2019 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
2020 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
2021 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
2025 static int patch_cxt5051(struct hda_codec *codec)
2027 struct conexant_spec *spec;
2030 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2034 codec->pin_amp_workaround = 1;
2036 codec->patch_ops = conexant_patch_ops;
2037 codec->patch_ops.init = cxt5051_init;
2039 spec->multiout.max_channels = 2;
2040 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2041 spec->multiout.dac_nids = cxt5051_dac_nids;
2042 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2043 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2044 spec->adc_nids = cxt5051_adc_nids;
2045 spec->num_mixers = 2;
2046 spec->mixers[0] = cxt5051_capture_mixers;
2047 spec->mixers[1] = cxt5051_playback_mixers;
2048 spec->num_init_verbs = 1;
2049 spec->init_verbs[0] = cxt5051_init_verbs;
2050 spec->spdif_route = 0;
2051 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2052 spec->channel_mode = cxt5051_modes;
2054 spec->cur_adc_idx = 0;
2056 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2058 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2060 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
2063 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
2064 switch (board_config) {
2066 spec->mixers[0] = cxt5051_hp_mixers;
2068 case CXT5051_HP_DV6736:
2069 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2070 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2073 case CXT5051_LENOVO_X200:
2074 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
2075 /* Thinkpad X301 does not have S/PDIF wired and no ability
2076 to use a docking station. */
2077 if (codec->subsystem_id == 0x17aa211f)
2078 spec->multiout.dig_out_nid = 0;
2081 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2082 spec->mixers[0] = cxt5051_f700_mixers;
2085 case CXT5051_TOSHIBA:
2086 spec->mixers[0] = cxt5051_toshiba_mixers;
2087 spec->auto_mic = AUTO_MIC_PORTB;
2089 case CXT5051_IDEAPAD:
2090 spec->init_verbs[spec->num_init_verbs++] =
2091 cxt5051_ideapad_init_verbs;
2097 snd_hda_attach_beep_device(codec, spec->beep_amp);
2102 /* Conexant 5066 specific */
2104 static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2105 static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2106 static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2107 static hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
2109 /* OLPC's microphone port is DC coupled for use with external sensors,
2110 * therefore we use a 50% mic bias in order to center the input signal with
2111 * the DC input range of the codec. */
2112 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2114 static struct hda_channel_mode cxt5066_modes[1] = {
2118 #define HP_PRESENT_PORT_A (1 << 0)
2119 #define HP_PRESENT_PORT_D (1 << 1)
2120 #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2121 #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2123 static void cxt5066_update_speaker(struct hda_codec *codec)
2125 struct conexant_spec *spec = codec->spec;
2126 unsigned int pinctl;
2128 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2129 spec->hp_present, spec->cur_eapd);
2132 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
2133 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2136 /* Port D (HP/LO) */
2137 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2138 if (spec->dell_automute || spec->thinkpad) {
2139 /* Mute if Port A is connected */
2140 if (hp_port_a_present(spec))
2143 /* Thinkpad/Dell doesn't give pin-D status */
2144 if (!hp_port_d_present(spec))
2147 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2151 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2152 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2156 /* turn on/off EAPD (+ mute HP) as a master switch */
2157 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2158 struct snd_ctl_elem_value *ucontrol)
2160 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2162 if (!cxt_eapd_put(kcontrol, ucontrol))
2165 cxt5066_update_speaker(codec);
2169 static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2173 { "50%", PIN_VREF50 },
2174 { "80%", PIN_VREF80 },
2178 static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2180 struct conexant_spec *spec = codec->spec;
2181 /* Even though port F is the DC input, the bias is controlled on port B.
2182 * we also leave that port as an active input (but unselected) in DC mode
2183 * just in case that is necessary to make the bias setting take effect. */
2184 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2185 AC_VERB_SET_PIN_WIDGET_CONTROL,
2186 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2189 /* OLPC defers mic widget control until when capture is started because the
2190 * microphone LED comes on as soon as these settings are put in place. if we
2191 * did this before recording, it would give the false indication that recording
2192 * is happening when it is not. */
2193 static void cxt5066_olpc_select_mic(struct hda_codec *codec)
2195 struct conexant_spec *spec = codec->spec;
2196 if (!spec->recording)
2199 if (spec->dc_enable) {
2200 /* in DC mode we ignore presence detection and just use the jack
2201 * through our special DC port */
2202 const struct hda_verb enable_dc_mode[] = {
2203 /* disble internal mic, port C */
2204 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2206 /* enable DC capture, port F */
2207 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2211 snd_hda_sequence_write(codec, enable_dc_mode);
2212 /* port B input disabled (and bias set) through the following call */
2213 cxt5066_set_olpc_dc_bias(codec);
2217 /* disable DC (port F) */
2218 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2220 /* external mic, port B */
2221 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2222 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
2224 /* internal mic, port C */
2225 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2226 spec->ext_mic_present ? 0 : PIN_VREF80);
2229 /* toggle input of built-in and mic jack appropriately */
2230 static void cxt5066_olpc_automic(struct hda_codec *codec)
2232 struct conexant_spec *spec = codec->spec;
2233 unsigned int present;
2235 if (spec->dc_enable) /* don't do presence detection in DC mode */
2238 present = snd_hda_codec_read(codec, 0x1a, 0,
2239 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2241 snd_printdd("CXT5066: external microphone detected\n");
2243 snd_printdd("CXT5066: external microphone absent\n");
2245 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2247 spec->ext_mic_present = !!present;
2249 cxt5066_olpc_select_mic(codec);
2252 /* toggle input of built-in digital mic and mic jack appropriately */
2253 static void cxt5066_vostro_automic(struct hda_codec *codec)
2255 unsigned int present;
2257 struct hda_verb ext_mic_present[] = {
2258 /* enable external mic, port B */
2259 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2261 /* switch to external mic input */
2262 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2263 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2265 /* disable internal digital mic */
2266 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2269 static struct hda_verb ext_mic_absent[] = {
2270 /* enable internal mic, port C */
2271 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2273 /* switch to internal mic input */
2274 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2276 /* disable external mic, port B */
2277 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2281 present = snd_hda_jack_detect(codec, 0x1a);
2283 snd_printdd("CXT5066: external microphone detected\n");
2284 snd_hda_sequence_write(codec, ext_mic_present);
2286 snd_printdd("CXT5066: external microphone absent\n");
2287 snd_hda_sequence_write(codec, ext_mic_absent);
2291 /* toggle input of built-in digital mic and mic jack appropriately */
2292 static void cxt5066_ideapad_automic(struct hda_codec *codec)
2294 unsigned int present;
2296 struct hda_verb ext_mic_present[] = {
2297 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2298 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2299 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2302 static struct hda_verb ext_mic_absent[] = {
2303 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2304 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2305 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2309 present = snd_hda_jack_detect(codec, 0x1b);
2311 snd_printdd("CXT5066: external microphone detected\n");
2312 snd_hda_sequence_write(codec, ext_mic_present);
2314 snd_printdd("CXT5066: external microphone absent\n");
2315 snd_hda_sequence_write(codec, ext_mic_absent);
2320 /* toggle input of built-in digital mic and mic jack appropriately */
2321 static void cxt5066_asus_automic(struct hda_codec *codec)
2323 unsigned int present;
2325 present = snd_hda_jack_detect(codec, 0x1b);
2326 snd_printdd("CXT5066: external microphone present=%d\n", present);
2327 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2332 /* toggle input of built-in digital mic and mic jack appropriately */
2333 static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2335 unsigned int present;
2337 present = snd_hda_jack_detect(codec, 0x1b);
2338 snd_printdd("CXT5066: external microphone present=%d\n", present);
2339 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2344 /* toggle input of built-in digital mic and mic jack appropriately
2345 order is: external mic -> dock mic -> interal mic */
2346 static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2348 unsigned int ext_present, dock_present;
2350 static struct hda_verb ext_mic_present[] = {
2351 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2352 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2353 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2354 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2355 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2358 static struct hda_verb dock_mic_present[] = {
2359 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2360 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2361 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2362 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2363 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2366 static struct hda_verb ext_mic_absent[] = {
2367 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2368 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2369 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2370 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2374 ext_present = snd_hda_jack_detect(codec, 0x1b);
2375 dock_present = snd_hda_jack_detect(codec, 0x1a);
2377 snd_printdd("CXT5066: external microphone detected\n");
2378 snd_hda_sequence_write(codec, ext_mic_present);
2379 } else if (dock_present) {
2380 snd_printdd("CXT5066: dock microphone detected\n");
2381 snd_hda_sequence_write(codec, dock_mic_present);
2383 snd_printdd("CXT5066: external microphone absent\n");
2384 snd_hda_sequence_write(codec, ext_mic_absent);
2388 /* mute internal speaker if HP is plugged */
2389 static void cxt5066_hp_automute(struct hda_codec *codec)
2391 struct conexant_spec *spec = codec->spec;
2392 unsigned int portA, portD;
2395 portA = snd_hda_jack_detect(codec, 0x19);
2398 portD = snd_hda_jack_detect(codec, 0x1c);
2400 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2401 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
2402 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2403 portA, portD, spec->hp_present);
2404 cxt5066_update_speaker(codec);
2407 /* Dispatch the right mic autoswitch function */
2408 static void cxt5066_automic(struct hda_codec *codec)
2410 struct conexant_spec *spec = codec->spec;
2412 if (spec->dell_vostro)
2413 cxt5066_vostro_automic(codec);
2414 else if (spec->ideapad)
2415 cxt5066_ideapad_automic(codec);
2416 else if (spec->thinkpad)
2417 cxt5066_thinkpad_automic(codec);
2418 else if (spec->hp_laptop)
2419 cxt5066_hp_laptop_automic(codec);
2420 else if (spec->asus)
2421 cxt5066_asus_automic(codec);
2424 /* unsolicited event for jack sensing */
2425 static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
2427 struct conexant_spec *spec = codec->spec;
2428 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2429 switch (res >> 26) {
2430 case CONEXANT_HP_EVENT:
2431 cxt5066_hp_automute(codec);
2433 case CONEXANT_MIC_EVENT:
2434 /* ignore mic events in DC mode; we're always using the jack */
2435 if (!spec->dc_enable)
2436 cxt5066_olpc_automic(codec);
2441 /* unsolicited event for jack sensing */
2442 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2444 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2445 switch (res >> 26) {
2446 case CONEXANT_HP_EVENT:
2447 cxt5066_hp_automute(codec);
2449 case CONEXANT_MIC_EVENT:
2450 cxt5066_automic(codec);
2456 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2467 static void cxt5066_set_mic_boost(struct hda_codec *codec)
2469 struct conexant_spec *spec = codec->spec;
2470 snd_hda_codec_write_cache(codec, 0x17, 0,
2471 AC_VERB_SET_AMP_GAIN_MUTE,
2472 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2473 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
2474 if (spec->ideapad || spec->thinkpad) {
2475 /* adjust the internal mic as well...it is not through 0x17 */
2476 snd_hda_codec_write_cache(codec, 0x23, 0,
2477 AC_VERB_SET_AMP_GAIN_MUTE,
2478 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2479 cxt5066_analog_mic_boost.
2480 items[spec->mic_boost].index);
2484 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2485 struct snd_ctl_elem_info *uinfo)
2487 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2490 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2491 struct snd_ctl_elem_value *ucontrol)
2493 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2494 struct conexant_spec *spec = codec->spec;
2495 ucontrol->value.enumerated.item[0] = spec->mic_boost;
2499 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2500 struct snd_ctl_elem_value *ucontrol)
2502 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2503 struct conexant_spec *spec = codec->spec;
2504 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2506 idx = ucontrol->value.enumerated.item[0];
2507 if (idx >= imux->num_items)
2508 idx = imux->num_items - 1;
2510 spec->mic_boost = idx;
2511 if (!spec->dc_enable)
2512 cxt5066_set_mic_boost(codec);
2516 static void cxt5066_enable_dc(struct hda_codec *codec)
2518 const struct hda_verb enable_dc_mode[] = {
2520 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2522 /* switch to DC input */
2523 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2527 /* configure as input source */
2528 snd_hda_sequence_write(codec, enable_dc_mode);
2529 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2532 static void cxt5066_disable_dc(struct hda_codec *codec)
2534 /* reconfigure input source */
2535 cxt5066_set_mic_boost(codec);
2536 /* automic also selects the right mic if we're recording */
2537 cxt5066_olpc_automic(codec);
2540 static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2541 struct snd_ctl_elem_value *ucontrol)
2543 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2544 struct conexant_spec *spec = codec->spec;
2545 ucontrol->value.integer.value[0] = spec->dc_enable;
2549 static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2550 struct snd_ctl_elem_value *ucontrol)
2552 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2553 struct conexant_spec *spec = codec->spec;
2554 int dc_enable = !!ucontrol->value.integer.value[0];
2556 if (dc_enable == spec->dc_enable)
2559 spec->dc_enable = dc_enable;
2561 cxt5066_enable_dc(codec);
2563 cxt5066_disable_dc(codec);
2568 static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2569 struct snd_ctl_elem_info *uinfo)
2571 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2574 static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2575 struct snd_ctl_elem_value *ucontrol)
2577 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2578 struct conexant_spec *spec = codec->spec;
2579 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2583 static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2584 struct snd_ctl_elem_value *ucontrol)
2586 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2587 struct conexant_spec *spec = codec->spec;
2588 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2591 idx = ucontrol->value.enumerated.item[0];
2592 if (idx >= imux->num_items)
2593 idx = imux->num_items - 1;
2595 spec->dc_input_bias = idx;
2596 if (spec->dc_enable)
2597 cxt5066_set_olpc_dc_bias(codec);
2601 static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2603 struct conexant_spec *spec = codec->spec;
2604 /* mark as recording and configure the microphone widget so that the
2605 * recording LED comes on. */
2606 spec->recording = 1;
2607 cxt5066_olpc_select_mic(codec);
2610 static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2612 struct conexant_spec *spec = codec->spec;
2613 const struct hda_verb disable_mics[] = {
2614 /* disable external mic, port B */
2615 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2617 /* disble internal mic, port C */
2618 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2620 /* disable DC capture, port F */
2621 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2625 snd_hda_sequence_write(codec, disable_mics);
2626 spec->recording = 0;
2629 static void conexant_check_dig_outs(struct hda_codec *codec,
2630 hda_nid_t *dig_pins,
2633 struct conexant_spec *spec = codec->spec;
2634 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2637 for (i = 0; i < num_pins; i++, dig_pins++) {
2638 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2639 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2641 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2643 if (spec->slave_dig_outs[0])
2646 nid_loc = spec->slave_dig_outs;
2650 static struct hda_input_mux cxt5066_capture_source = {
2660 static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2661 .ops = &snd_hda_bind_vol,
2663 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2664 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2669 static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2670 .ops = &snd_hda_bind_sw,
2672 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2673 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2678 static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2679 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2683 static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2686 .name = "Master Playback Volume",
2687 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2688 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2689 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2690 .subdevice = HDA_SUBDEV_AMP_FLAG,
2691 .info = snd_hda_mixer_amp_volume_info,
2692 .get = snd_hda_mixer_amp_volume_get,
2693 .put = snd_hda_mixer_amp_volume_put,
2694 .tlv = { .c = snd_hda_mixer_amp_tlv },
2695 /* offset by 28 volume steps to limit minimum gain to -46dB */
2697 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2702 static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2704 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2705 .name = "DC Mode Enable Switch",
2706 .info = snd_ctl_boolean_mono_info,
2707 .get = cxt5066_olpc_dc_get,
2708 .put = cxt5066_olpc_dc_put,
2711 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2712 .name = "DC Input Bias Enum",
2713 .info = cxt5066_olpc_dc_bias_enum_info,
2714 .get = cxt5066_olpc_dc_bias_enum_get,
2715 .put = cxt5066_olpc_dc_bias_enum_put,
2720 static struct snd_kcontrol_new cxt5066_mixers[] = {
2722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2723 .name = "Master Playback Switch",
2724 .info = cxt_eapd_info,
2725 .get = cxt_eapd_get,
2726 .put = cxt5066_hp_master_sw_put,
2727 .private_value = 0x1d,
2731 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2732 .name = "Analog Mic Boost Capture Enum",
2733 .info = cxt5066_mic_boost_mux_enum_info,
2734 .get = cxt5066_mic_boost_mux_enum_get,
2735 .put = cxt5066_mic_boost_mux_enum_put,
2738 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2739 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2743 static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2745 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2746 .name = "Internal Mic Boost Capture Enum",
2747 .info = cxt5066_mic_boost_mux_enum_info,
2748 .get = cxt5066_mic_boost_mux_enum_get,
2749 .put = cxt5066_mic_boost_mux_enum_put,
2750 .private_value = 0x23 | 0x100,
2755 static struct hda_verb cxt5066_init_verbs[] = {
2756 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2757 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2758 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2759 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2762 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2763 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2766 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2767 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2769 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2770 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2773 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2775 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2776 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2777 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2778 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2779 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2780 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2782 /* no digital microphone support yet */
2783 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2785 /* Audio input selector */
2786 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2788 /* SPDIF route: PCM */
2789 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2790 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2792 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2793 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2796 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2798 /* not handling these yet */
2799 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2800 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2801 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2802 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2803 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2804 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2805 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2806 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2810 static struct hda_verb cxt5066_init_verbs_olpc[] = {
2811 /* Port A: headphones */
2812 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2813 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2815 /* Port B: external microphone */
2816 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2818 /* Port C: internal microphone */
2819 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2821 /* Port D: unused */
2822 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2824 /* Port E: unused, but has primary EAPD */
2825 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2826 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2828 /* Port F: external DC input through microphone port */
2829 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2831 /* Port G: internal speakers */
2832 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2833 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2836 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2839 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2841 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2842 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2843 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2844 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2845 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2846 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2847 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2848 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2849 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2850 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2851 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2852 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2854 /* Disable digital microphone port */
2855 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2857 /* Audio input selectors */
2858 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2859 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2862 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2863 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2865 /* enable unsolicited events for Port A and B */
2866 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2867 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2871 static struct hda_verb cxt5066_init_verbs_vostro[] = {
2872 /* Port A: headphones */
2873 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2874 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2876 /* Port B: external microphone */
2877 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2879 /* Port C: unused */
2880 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2882 /* Port D: unused */
2883 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2885 /* Port E: unused, but has primary EAPD */
2886 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2887 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2889 /* Port F: unused */
2890 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2892 /* Port G: internal speakers */
2893 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2894 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2897 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2900 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2902 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2903 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2904 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2905 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2906 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2907 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2908 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2909 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2910 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2911 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2912 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2913 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2915 /* Digital microphone port */
2916 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2918 /* Audio input selectors */
2919 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2920 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2923 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2924 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2926 /* enable unsolicited events for Port A and B */
2927 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2928 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2932 static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2933 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2934 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2935 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2936 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2939 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2940 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2943 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2944 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2946 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2947 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2950 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2952 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2953 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2954 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2955 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2956 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2957 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2958 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2960 /* Audio input selector */
2961 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2962 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2964 /* SPDIF route: PCM */
2965 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2966 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2968 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2969 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2971 /* internal microphone */
2972 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2975 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2977 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2978 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2982 static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2983 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2984 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2986 /* Port G: internal speakers */
2987 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2988 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2990 /* Port A: HP, Amp */
2991 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2992 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2994 /* Port B: Mic Dock */
2995 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2998 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3000 /* Port D: HP Dock, Amp */
3001 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3002 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
3005 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3007 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
3008 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
3009 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3010 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
3011 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3012 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3013 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
3015 /* Audio input selector */
3016 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
3017 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
3019 /* SPDIF route: PCM */
3020 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
3021 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
3023 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3024 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3026 /* internal microphone */
3027 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
3030 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
3032 /* enable unsolicited events for Port A, B, C and D */
3033 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3034 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3035 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3036 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3040 static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
3041 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3046 static struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
3047 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3048 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3049 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3053 /* initialize jack-sensing, too */
3054 static int cxt5066_init(struct hda_codec *codec)
3056 snd_printdd("CXT5066: init\n");
3057 conexant_init(codec);
3058 if (codec->patch_ops.unsol_event) {
3059 cxt5066_hp_automute(codec);
3060 cxt5066_automic(codec);
3062 cxt5066_set_mic_boost(codec);
3066 static int cxt5066_olpc_init(struct hda_codec *codec)
3068 struct conexant_spec *spec = codec->spec;
3069 snd_printdd("CXT5066: init\n");
3070 conexant_init(codec);
3071 cxt5066_hp_automute(codec);
3072 if (!spec->dc_enable) {
3073 cxt5066_set_mic_boost(codec);
3074 cxt5066_olpc_automic(codec);
3076 cxt5066_enable_dc(codec);
3082 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
3083 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3084 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
3085 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
3086 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
3087 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
3088 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
3089 CXT5066_HP_LAPTOP, /* HP Laptop */
3093 static const char * const cxt5066_models[CXT5066_MODELS] = {
3094 [CXT5066_LAPTOP] = "laptop",
3095 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3096 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
3097 [CXT5066_DELL_VOSTRO] = "dell-vostro",
3098 [CXT5066_IDEAPAD] = "ideapad",
3099 [CXT5066_THINKPAD] = "thinkpad",
3100 [CXT5066_ASUS] = "asus",
3101 [CXT5066_HP_LAPTOP] = "hp-laptop",
3104 static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3105 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
3106 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
3107 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3108 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
3109 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
3110 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3111 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3112 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
3113 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
3114 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
3115 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3116 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
3117 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
3118 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3120 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
3121 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3122 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
3123 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
3124 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3125 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
3126 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
3130 static int patch_cxt5066(struct hda_codec *codec)
3132 struct conexant_spec *spec;
3135 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3140 codec->patch_ops = conexant_patch_ops;
3141 codec->patch_ops.init = conexant_init;
3143 spec->dell_automute = 0;
3144 spec->multiout.max_channels = 2;
3145 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3146 spec->multiout.dac_nids = cxt5066_dac_nids;
3147 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3148 ARRAY_SIZE(cxt5066_digout_pin_nids));
3149 spec->num_adc_nids = 1;
3150 spec->adc_nids = cxt5066_adc_nids;
3151 spec->capsrc_nids = cxt5066_capsrc_nids;
3152 spec->input_mux = &cxt5066_capture_source;
3154 spec->port_d_mode = PIN_HP;
3156 spec->num_init_verbs = 1;
3157 spec->init_verbs[0] = cxt5066_init_verbs;
3158 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3159 spec->channel_mode = cxt5066_modes;
3161 spec->cur_adc_idx = 0;
3163 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3165 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3166 cxt5066_models, cxt5066_cfg_tbl);
3167 switch (board_config) {
3169 case CXT5066_LAPTOP:
3170 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3171 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3173 case CXT5066_DELL_LAPTOP:
3174 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3175 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3177 spec->port_d_mode = PIN_OUT;
3178 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3179 spec->num_init_verbs++;
3180 spec->dell_automute = 1;
3183 case CXT5066_HP_LAPTOP:
3184 codec->patch_ops.init = cxt5066_init;
3185 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3186 spec->init_verbs[spec->num_init_verbs] =
3187 cxt5066_init_verbs_hp_laptop;
3188 spec->num_init_verbs++;
3189 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3190 spec->asus = board_config == CXT5066_ASUS;
3191 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3192 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3194 if (board_config == CXT5066_HP_LAPTOP)
3195 spec->multiout.dig_out_nid = 0;
3196 /* input source automatically selected */
3197 spec->input_mux = NULL;
3198 spec->port_d_mode = 0;
3199 spec->mic_boost = 3; /* default 30dB gain */
3202 case CXT5066_OLPC_XO_1_5:
3203 codec->patch_ops.init = cxt5066_olpc_init;
3204 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
3205 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3206 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3207 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
3208 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3209 spec->port_d_mode = 0;
3210 spec->mic_boost = 3; /* default 30dB gain */
3213 spec->multiout.dig_out_nid = 0;
3215 /* input source automatically selected */
3216 spec->input_mux = NULL;
3218 /* our capture hooks which allow us to turn on the microphone LED
3219 * at the right time */
3220 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3221 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
3223 case CXT5066_DELL_VOSTRO:
3224 codec->patch_ops.init = cxt5066_init;
3225 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3226 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3227 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3228 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3229 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
3230 spec->port_d_mode = 0;
3231 spec->dell_vostro = 1;
3232 spec->mic_boost = 3; /* default 30dB gain */
3235 spec->multiout.dig_out_nid = 0;
3237 /* input source automatically selected */
3238 spec->input_mux = NULL;
3240 case CXT5066_IDEAPAD:
3241 codec->patch_ops.init = cxt5066_init;
3242 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3243 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3244 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3245 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3246 spec->port_d_mode = 0;
3248 spec->mic_boost = 2; /* default 20dB gain */
3251 spec->multiout.dig_out_nid = 0;
3253 /* input source automatically selected */
3254 spec->input_mux = NULL;
3256 case CXT5066_THINKPAD:
3257 codec->patch_ops.init = cxt5066_init;
3258 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3259 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3260 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3261 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3263 spec->port_d_mode = PIN_OUT;
3264 spec->mic_boost = 2; /* default 20dB gain */
3267 spec->multiout.dig_out_nid = 0;
3269 /* input source automatically selected */
3270 spec->input_mux = NULL;
3275 snd_hda_attach_beep_device(codec, spec->beep_amp);
3281 * Automatic parser for CX20641 & co
3284 static hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3286 /* get the connection index of @nid in the widget @mux */
3287 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3290 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3293 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3294 for (i = 0; i < nums; i++)
3300 /* get an unassigned DAC from the given list.
3301 * Return the nid if found and reduce the DAC list, or return zero if
3304 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3305 hda_nid_t *dacs, int *num_dacs)
3307 int i, nums = *num_dacs;
3310 for (i = 0; i < nums; i++) {
3311 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3319 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3324 #define MAX_AUTO_DACS 5
3326 /* fill analog DAC list from the widget tree */
3327 static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3329 hda_nid_t nid, end_nid;
3332 end_nid = codec->start_nid + codec->num_nodes;
3333 for (nid = codec->start_nid; nid < end_nid; nid++) {
3334 unsigned int wcaps = get_wcaps(codec, nid);
3335 unsigned int type = get_wcaps_type(wcaps);
3336 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3338 if (nums >= MAX_AUTO_DACS)
3345 /* fill pin_dac_pair list from the pin and dac list */
3346 static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3347 int num_pins, hda_nid_t *dacs, int *rest,
3348 struct pin_dac_pair *filled, int type)
3353 for (i = 0; i < num_pins; i++) {
3354 filled[nums].pin = pins[i];
3355 filled[nums].type = type;
3356 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3362 /* parse analog output paths */
3363 static void cx_auto_parse_output(struct hda_codec *codec)
3365 struct conexant_spec *spec = codec->spec;
3366 struct auto_pin_cfg *cfg = &spec->autocfg;
3367 hda_nid_t dacs[MAX_AUTO_DACS];
3368 int i, j, nums, rest;
3370 rest = fill_cx_auto_dacs(codec, dacs);
3371 /* parse all analog output pins */
3372 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3373 dacs, &rest, spec->dac_info,
3375 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3376 dacs, &rest, spec->dac_info + nums,
3378 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3379 dacs, &rest, spec->dac_info + nums,
3380 AUTO_PIN_SPEAKER_OUT);
3381 spec->dac_info_filled = nums;
3382 /* fill multiout struct */
3383 for (i = 0; i < nums; i++) {
3384 hda_nid_t dac = spec->dac_info[i].dac;
3387 switch (spec->dac_info[i].type) {
3388 case AUTO_PIN_LINE_OUT:
3389 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3390 spec->multiout.num_dacs++;
3392 case AUTO_PIN_HP_OUT:
3393 case AUTO_PIN_SPEAKER_OUT:
3394 if (!spec->multiout.hp_nid) {
3395 spec->multiout.hp_nid = dac;
3398 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3399 if (!spec->multiout.extra_out_nid[j]) {
3400 spec->multiout.extra_out_nid[j] = dac;
3406 spec->multiout.dac_nids = spec->private_dac_nids;
3407 spec->multiout.max_channels = nums * 2;
3409 if (cfg->hp_outs > 0)
3410 spec->auto_mute = 1;
3411 spec->vmaster_nid = spec->private_dac_nids[0];
3414 /* auto-mute/unmute speaker and line outs according to headphone jack */
3415 static void cx_auto_hp_automute(struct hda_codec *codec)
3417 struct conexant_spec *spec = codec->spec;
3418 struct auto_pin_cfg *cfg = &spec->autocfg;
3421 if (!spec->auto_mute)
3424 for (i = 0; i < cfg->hp_outs; i++) {
3425 if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3430 for (i = 0; i < cfg->line_outs; i++) {
3431 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3432 AC_VERB_SET_PIN_WIDGET_CONTROL,
3433 present ? 0 : PIN_OUT);
3435 for (i = 0; !present && i < cfg->line_outs; i++)
3436 if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3438 for (i = 0; i < cfg->speaker_outs; i++) {
3439 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3440 AC_VERB_SET_PIN_WIDGET_CONTROL,
3441 present ? 0 : PIN_OUT);
3445 /* automatic switch internal and external mic */
3446 static void cx_auto_automic(struct hda_codec *codec)
3448 struct conexant_spec *spec = codec->spec;
3449 struct auto_pin_cfg *cfg = &spec->autocfg;
3450 struct hda_input_mux *imux = &spec->private_imux;
3451 int ext_idx = spec->auto_mic_ext;
3453 if (!spec->auto_mic)
3455 if (snd_hda_jack_detect(codec, cfg->inputs[ext_idx].pin)) {
3456 snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3457 AC_VERB_SET_CONNECT_SEL,
3458 imux->items[ext_idx].index);
3460 snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3461 AC_VERB_SET_CONNECT_SEL,
3462 imux->items[!ext_idx].index);
3466 static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3468 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3469 switch (res >> 26) {
3470 case CONEXANT_HP_EVENT:
3471 cx_auto_hp_automute(codec);
3472 conexant_report_jack(codec, nid);
3474 case CONEXANT_MIC_EVENT:
3475 cx_auto_automic(codec);
3476 conexant_report_jack(codec, nid);
3481 /* return true if it's an internal-mic pin */
3482 static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3484 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3485 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
3486 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
3489 /* return true if it's an external-mic pin */
3490 static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3492 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3493 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
3494 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3495 (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
3498 /* check whether the pin config is suitable for auto-mic switching;
3499 * auto-mic is enabled only when one int-mic and one-ext mic exist
3501 static void cx_auto_check_auto_mic(struct hda_codec *codec)
3503 struct conexant_spec *spec = codec->spec;
3504 struct auto_pin_cfg *cfg = &spec->autocfg;
3506 if (is_ext_mic(codec, cfg->inputs[0].pin) &&
3507 is_int_mic(codec, cfg->inputs[1].pin)) {
3509 spec->auto_mic_ext = 1;
3512 if (is_int_mic(codec, cfg->inputs[1].pin) &&
3513 is_ext_mic(codec, cfg->inputs[0].pin)) {
3515 spec->auto_mic_ext = 0;
3520 static void cx_auto_parse_input(struct hda_codec *codec)
3522 struct conexant_spec *spec = codec->spec;
3523 struct auto_pin_cfg *cfg = &spec->autocfg;
3524 struct hda_input_mux *imux;
3527 imux = &spec->private_imux;
3528 for (i = 0; i < cfg->num_inputs; i++) {
3529 int idx = get_connection_index(codec, spec->adc_nids[0],
3530 cfg->inputs[i].pin);
3533 label = hda_get_autocfg_input_label(codec, cfg, i);
3534 snd_hda_add_imux_item(imux, label, idx, NULL);
3537 if (imux->num_items == 2 && cfg->num_inputs == 2)
3538 cx_auto_check_auto_mic(codec);
3539 if (imux->num_items > 1 && !spec->auto_mic)
3540 spec->input_mux = imux;
3543 /* get digital-input audio widget corresponding to the given pin */
3544 static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3546 hda_nid_t nid, end_nid;
3548 end_nid = codec->start_nid + codec->num_nodes;
3549 for (nid = codec->start_nid; nid < end_nid; nid++) {
3550 unsigned int wcaps = get_wcaps(codec, nid);
3551 unsigned int type = get_wcaps_type(wcaps);
3552 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3553 if (get_connection_index(codec, nid, pin) >= 0)
3560 static void cx_auto_parse_digital(struct hda_codec *codec)
3562 struct conexant_spec *spec = codec->spec;
3563 struct auto_pin_cfg *cfg = &spec->autocfg;
3566 if (cfg->dig_outs &&
3567 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3568 spec->multiout.dig_out_nid = nid;
3569 if (cfg->dig_in_pin)
3570 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3573 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3574 static void cx_auto_parse_beep(struct hda_codec *codec)
3576 struct conexant_spec *spec = codec->spec;
3577 hda_nid_t nid, end_nid;
3579 end_nid = codec->start_nid + codec->num_nodes;
3580 for (nid = codec->start_nid; nid < end_nid; nid++)
3581 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3582 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3587 #define cx_auto_parse_beep(codec)
3590 static int cx_auto_parse_auto_config(struct hda_codec *codec)
3592 struct conexant_spec *spec = codec->spec;
3595 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3599 cx_auto_parse_output(codec);
3600 cx_auto_parse_input(codec);
3601 cx_auto_parse_digital(codec);
3602 cx_auto_parse_beep(codec);
3606 static void cx_auto_turn_on_eapd(struct hda_codec *codec, int num_pins,
3610 for (i = 0; i < num_pins; i++) {
3611 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3612 snd_hda_codec_write(codec, pins[i], 0,
3613 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3617 static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3620 int idx = get_connection_index(codec, pin, src);
3622 snd_hda_codec_write(codec, pin, 0,
3623 AC_VERB_SET_CONNECT_SEL, idx);
3626 static void cx_auto_init_output(struct hda_codec *codec)
3628 struct conexant_spec *spec = codec->spec;
3629 struct auto_pin_cfg *cfg = &spec->autocfg;
3633 for (i = 0; i < spec->multiout.num_dacs; i++)
3634 snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
3635 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3637 for (i = 0; i < cfg->hp_outs; i++)
3638 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3639 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
3640 if (spec->auto_mute) {
3641 for (i = 0; i < cfg->hp_outs; i++) {
3642 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3643 AC_VERB_SET_UNSOLICITED_ENABLE,
3644 AC_USRSP_EN | CONEXANT_HP_EVENT);
3646 cx_auto_hp_automute(codec);
3648 for (i = 0; i < cfg->line_outs; i++)
3649 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3650 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3651 for (i = 0; i < cfg->speaker_outs; i++)
3652 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3653 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3656 for (i = 0; i < spec->dac_info_filled; i++) {
3657 nid = spec->dac_info[i].dac;
3659 nid = spec->multiout.dac_nids[0];
3660 select_connection(codec, spec->dac_info[i].pin, nid);
3664 cx_auto_turn_on_eapd(codec, cfg->line_outs, cfg->line_out_pins);
3665 cx_auto_turn_on_eapd(codec, cfg->hp_outs, cfg->hp_pins);
3666 cx_auto_turn_on_eapd(codec, cfg->speaker_outs, cfg->speaker_pins);
3669 static void cx_auto_init_input(struct hda_codec *codec)
3671 struct conexant_spec *spec = codec->spec;
3672 struct auto_pin_cfg *cfg = &spec->autocfg;
3675 for (i = 0; i < spec->num_adc_nids; i++)
3676 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3677 AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0));
3679 for (i = 0; i < cfg->num_inputs; i++) {
3681 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3685 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3686 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3689 if (spec->auto_mic) {
3690 int ext_idx = spec->auto_mic_ext;
3691 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3692 AC_VERB_SET_UNSOLICITED_ENABLE,
3693 AC_USRSP_EN | CONEXANT_MIC_EVENT);
3694 cx_auto_automic(codec);
3696 for (i = 0; i < spec->num_adc_nids; i++) {
3697 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3698 AC_VERB_SET_CONNECT_SEL,
3699 spec->private_imux.items[0].index);
3704 static void cx_auto_init_digital(struct hda_codec *codec)
3706 struct conexant_spec *spec = codec->spec;
3707 struct auto_pin_cfg *cfg = &spec->autocfg;
3709 if (spec->multiout.dig_out_nid)
3710 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3711 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3712 if (spec->dig_in_nid)
3713 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3714 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3717 static int cx_auto_init(struct hda_codec *codec)
3719 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3720 cx_auto_init_output(codec);
3721 cx_auto_init_input(codec);
3722 cx_auto_init_digital(codec);
3726 static int cx_auto_add_volume(struct hda_codec *codec, const char *basename,
3727 const char *dir, int cidx,
3728 hda_nid_t nid, int hda_dir)
3730 static char name[32];
3731 static struct snd_kcontrol_new knew[] = {
3732 HDA_CODEC_VOLUME(name, 0, 0, 0),
3733 HDA_CODEC_MUTE(name, 0, 0, 0),
3735 static char *sfx[2] = { "Volume", "Switch" };
3738 for (i = 0; i < 2; i++) {
3739 struct snd_kcontrol *kctl;
3740 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, hda_dir);
3741 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3742 knew[i].index = cidx;
3743 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3744 kctl = snd_ctl_new1(&knew[i], codec);
3747 err = snd_hda_ctl_add(codec, nid, kctl);
3750 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3756 #define cx_auto_add_pb_volume(codec, nid, str, idx) \
3757 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3759 static int cx_auto_build_output_controls(struct hda_codec *codec)
3761 struct conexant_spec *spec = codec->spec;
3763 int num_line = 0, num_hp = 0, num_spk = 0;
3764 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
3766 if (spec->dac_info_filled == 1)
3767 return cx_auto_add_pb_volume(codec, spec->dac_info[0].dac,
3769 for (i = 0; i < spec->dac_info_filled; i++) {
3772 if (!spec->dac_info[i].dac)
3774 type = spec->dac_info[i].type;
3775 if (type == AUTO_PIN_LINE_OUT)
3776 type = spec->autocfg.line_out_type;
3778 case AUTO_PIN_LINE_OUT:
3780 label = texts[num_line++];
3783 case AUTO_PIN_HP_OUT:
3784 label = "Headphone";
3787 case AUTO_PIN_SPEAKER_OUT:
3792 err = cx_auto_add_pb_volume(codec, spec->dac_info[i].dac,
3800 static int cx_auto_build_input_controls(struct hda_codec *codec)
3802 struct conexant_spec *spec = codec->spec;
3803 struct auto_pin_cfg *cfg = &spec->autocfg;
3804 static const char *prev_label;
3807 err = cx_auto_add_volume(codec, "Capture", "", 0, spec->adc_nids[0],
3813 for (i = 0; i < cfg->num_inputs; i++) {
3814 hda_nid_t nid = cfg->inputs[i].pin;
3816 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3818 label = hda_get_autocfg_input_label(codec, cfg, i);
3819 if (label == prev_label)
3824 err = cx_auto_add_volume(codec, label, " Capture", cidx,
3832 static int cx_auto_build_controls(struct hda_codec *codec)
3836 err = cx_auto_build_output_controls(codec);
3839 err = cx_auto_build_input_controls(codec);
3842 return conexant_build_controls(codec);
3845 static struct hda_codec_ops cx_auto_patch_ops = {
3846 .build_controls = cx_auto_build_controls,
3847 .build_pcms = conexant_build_pcms,
3848 .init = cx_auto_init,
3849 .free = conexant_free,
3850 .unsol_event = cx_auto_unsol_event,
3851 #ifdef CONFIG_SND_HDA_POWER_SAVE
3852 .suspend = conexant_suspend,
3854 .reboot_notify = snd_hda_shutup_pins,
3857 static int patch_conexant_auto(struct hda_codec *codec)
3859 struct conexant_spec *spec;
3862 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3866 spec->adc_nids = cx_auto_adc_nids;
3867 spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids);
3868 spec->capsrc_nids = spec->adc_nids;
3869 err = cx_auto_parse_auto_config(codec);
3875 codec->patch_ops = cx_auto_patch_ops;
3877 snd_hda_attach_beep_device(codec, spec->beep_amp);
3884 static struct hda_codec_preset snd_hda_preset_conexant[] = {
3885 { .id = 0x14f15045, .name = "CX20549 (Venice)",
3886 .patch = patch_cxt5045 },
3887 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3888 .patch = patch_cxt5047 },
3889 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3890 .patch = patch_cxt5051 },
3891 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
3892 .patch = patch_cxt5066 },
3893 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3894 .patch = patch_cxt5066 },
3895 { .id = 0x14f15068, .name = "CX20584",
3896 .patch = patch_cxt5066 },
3897 { .id = 0x14f15069, .name = "CX20585",
3898 .patch = patch_cxt5066 },
3899 { .id = 0x14f15097, .name = "CX20631",
3900 .patch = patch_conexant_auto },
3901 { .id = 0x14f15098, .name = "CX20632",
3902 .patch = patch_conexant_auto },
3903 { .id = 0x14f150a1, .name = "CX20641",
3904 .patch = patch_conexant_auto },
3905 { .id = 0x14f150a2, .name = "CX20642",
3906 .patch = patch_conexant_auto },
3907 { .id = 0x14f150ab, .name = "CX20651",
3908 .patch = patch_conexant_auto },
3909 { .id = 0x14f150ac, .name = "CX20652",
3910 .patch = patch_conexant_auto },
3911 { .id = 0x14f150b8, .name = "CX20664",
3912 .patch = patch_conexant_auto },
3913 { .id = 0x14f150b9, .name = "CX20665",
3914 .patch = patch_conexant_auto },
3918 MODULE_ALIAS("snd-hda-codec-id:14f15045");
3919 MODULE_ALIAS("snd-hda-codec-id:14f15047");
3920 MODULE_ALIAS("snd-hda-codec-id:14f15051");
3921 MODULE_ALIAS("snd-hda-codec-id:14f15066");
3922 MODULE_ALIAS("snd-hda-codec-id:14f15067");
3923 MODULE_ALIAS("snd-hda-codec-id:14f15068");
3924 MODULE_ALIAS("snd-hda-codec-id:14f15069");
3925 MODULE_ALIAS("snd-hda-codec-id:14f15097");
3926 MODULE_ALIAS("snd-hda-codec-id:14f15098");
3927 MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3928 MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3929 MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3930 MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3931 MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3932 MODULE_ALIAS("snd-hda-codec-id:14f150b9");
3934 MODULE_LICENSE("GPL");
3935 MODULE_DESCRIPTION("Conexant HD-audio codec");
3937 static struct hda_codec_preset_list conexant_list = {
3938 .preset = snd_hda_preset_conexant,
3939 .owner = THIS_MODULE,
3942 static int __init patch_conexant_init(void)
3944 return snd_hda_add_codec_preset(&conexant_list);
3947 static void __exit patch_conexant_exit(void)
3949 snd_hda_delete_codec_preset(&conexant_list);
3952 module_init(patch_conexant_init)
3953 module_exit(patch_conexant_exit)