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)
59 hda_nid_t pin; /* input pin NID */
60 hda_nid_t adc; /* connected ADC NID */
61 hda_nid_t boost; /* optional boost volume NID */
62 int index; /* corresponding to autocfg.input */
65 struct conexant_spec {
67 const struct snd_kcontrol_new *mixers[5];
69 hda_nid_t vmaster_nid;
71 const struct hda_verb *init_verbs[5]; /* initialization verbs
75 unsigned int num_init_verbs;
78 struct hda_multi_out multiout; /* playback set-up
79 * max_channels, dacs must be set
80 * dig_out_nid and hp_nid are optional
82 unsigned int cur_eapd;
83 unsigned int hp_present;
84 unsigned int auto_mic;
85 int auto_mic_ext; /* imux_pins[] index for ext mic */
86 unsigned int need_dac_fix;
87 hda_nid_t slave_dig_outs[2];
90 unsigned int num_adc_nids;
91 const hda_nid_t *adc_nids;
92 hda_nid_t dig_in_nid; /* digital-in NID; optional */
94 unsigned int cur_adc_idx;
96 unsigned int cur_adc_stream_tag;
97 unsigned int cur_adc_format;
99 const struct hda_pcm_stream *capture_stream;
102 const struct hda_input_mux *input_mux;
103 const hda_nid_t *capsrc_nids;
104 unsigned int cur_mux[3];
107 const struct hda_channel_mode *channel_mode;
108 int num_channel_mode;
110 /* PCM information */
111 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
113 unsigned int spdif_route;
115 /* dynamic controls, init_verbs and input_mux */
116 struct auto_pin_cfg autocfg;
117 struct hda_input_mux private_imux;
118 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
119 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
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 adc_switching:1;
135 unsigned int ext_mic_present;
136 unsigned int recording;
137 void (*capture_prepare)(struct hda_codec *codec);
138 void (*capture_cleanup)(struct hda_codec *codec);
140 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
141 * through the microphone jack.
142 * When the user enables this through a mixer switch, both internal and
143 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
144 * we also allow the bias to be configured through a separate mixer
146 unsigned int dc_enable;
147 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
148 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
150 unsigned int beep_amp;
153 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
154 struct hda_codec *codec,
155 struct snd_pcm_substream *substream)
157 struct conexant_spec *spec = codec->spec;
158 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
162 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
163 struct hda_codec *codec,
164 unsigned int stream_tag,
166 struct snd_pcm_substream *substream)
168 struct conexant_spec *spec = codec->spec;
169 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
174 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
175 struct hda_codec *codec,
176 struct snd_pcm_substream *substream)
178 struct conexant_spec *spec = codec->spec;
179 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
185 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
186 struct hda_codec *codec,
187 struct snd_pcm_substream *substream)
189 struct conexant_spec *spec = codec->spec;
190 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
193 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
194 struct hda_codec *codec,
195 struct snd_pcm_substream *substream)
197 struct conexant_spec *spec = codec->spec;
198 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
201 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
202 struct hda_codec *codec,
203 unsigned int stream_tag,
205 struct snd_pcm_substream *substream)
207 struct conexant_spec *spec = codec->spec;
208 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
216 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
217 struct hda_codec *codec,
218 unsigned int stream_tag,
220 struct snd_pcm_substream *substream)
222 struct conexant_spec *spec = codec->spec;
223 if (spec->capture_prepare)
224 spec->capture_prepare(codec);
225 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
226 stream_tag, 0, format);
230 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
231 struct hda_codec *codec,
232 struct snd_pcm_substream *substream)
234 struct conexant_spec *spec = codec->spec;
235 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
236 if (spec->capture_cleanup)
237 spec->capture_cleanup(codec);
243 static const struct hda_pcm_stream conexant_pcm_analog_playback = {
247 .nid = 0, /* fill later */
249 .open = conexant_playback_pcm_open,
250 .prepare = conexant_playback_pcm_prepare,
251 .cleanup = conexant_playback_pcm_cleanup
255 static const struct hda_pcm_stream conexant_pcm_analog_capture = {
259 .nid = 0, /* fill later */
261 .prepare = conexant_capture_pcm_prepare,
262 .cleanup = conexant_capture_pcm_cleanup
267 static const struct hda_pcm_stream conexant_pcm_digital_playback = {
271 .nid = 0, /* fill later */
273 .open = conexant_dig_playback_pcm_open,
274 .close = conexant_dig_playback_pcm_close,
275 .prepare = conexant_dig_playback_pcm_prepare
279 static const struct hda_pcm_stream conexant_pcm_digital_capture = {
283 /* NID is set in alc_build_pcms */
286 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
287 struct hda_codec *codec,
288 unsigned int stream_tag,
290 struct snd_pcm_substream *substream)
292 struct conexant_spec *spec = codec->spec;
293 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
294 spec->cur_adc_stream_tag = stream_tag;
295 spec->cur_adc_format = format;
296 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
300 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
301 struct hda_codec *codec,
302 struct snd_pcm_substream *substream)
304 struct conexant_spec *spec = codec->spec;
305 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
310 static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
314 .nid = 0, /* fill later */
316 .prepare = cx5051_capture_pcm_prepare,
317 .cleanup = cx5051_capture_pcm_cleanup
321 static int conexant_build_pcms(struct hda_codec *codec)
323 struct conexant_spec *spec = codec->spec;
324 struct hda_pcm *info = spec->pcm_rec;
327 codec->pcm_info = info;
329 info->name = "CONEXANT Analog";
330 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
331 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
332 spec->multiout.max_channels;
333 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
334 spec->multiout.dac_nids[0];
335 if (spec->capture_stream)
336 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
338 if (codec->vendor_id == 0x14f15051)
339 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
340 cx5051_pcm_analog_capture;
342 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
343 conexant_pcm_analog_capture;
344 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
348 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
350 if (spec->multiout.dig_out_nid) {
353 info->name = "Conexant Digital";
354 info->pcm_type = HDA_PCM_TYPE_SPDIF;
355 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
356 conexant_pcm_digital_playback;
357 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
358 spec->multiout.dig_out_nid;
359 if (spec->dig_in_nid) {
360 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
361 conexant_pcm_digital_capture;
362 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
365 if (spec->slave_dig_outs[0])
366 codec->slave_dig_outs = spec->slave_dig_outs;
372 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
373 struct snd_ctl_elem_info *uinfo)
375 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
376 struct conexant_spec *spec = codec->spec;
378 return snd_hda_input_mux_info(spec->input_mux, uinfo);
381 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
382 struct snd_ctl_elem_value *ucontrol)
384 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
385 struct conexant_spec *spec = codec->spec;
386 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
388 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
392 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
393 struct snd_ctl_elem_value *ucontrol)
395 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
396 struct conexant_spec *spec = codec->spec;
397 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
399 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
400 spec->capsrc_nids[adc_idx],
401 &spec->cur_mux[adc_idx]);
404 static int conexant_init_jacks(struct hda_codec *codec)
406 #ifdef CONFIG_SND_HDA_INPUT_JACK
407 struct conexant_spec *spec = codec->spec;
410 for (i = 0; i < spec->num_init_verbs; i++) {
411 const struct hda_verb *hv;
413 hv = spec->init_verbs[i];
416 switch (hv->param ^ AC_USRSP_EN) {
417 case CONEXANT_HP_EVENT:
418 err = snd_hda_input_jack_add(codec, hv->nid,
419 SND_JACK_HEADPHONE, NULL);
420 snd_hda_input_jack_report(codec, hv->nid);
422 case CXT5051_PORTC_EVENT:
423 case CONEXANT_MIC_EVENT:
424 err = snd_hda_input_jack_add(codec, hv->nid,
425 SND_JACK_MICROPHONE, NULL);
426 snd_hda_input_jack_report(codec, hv->nid);
434 #endif /* CONFIG_SND_HDA_INPUT_JACK */
438 static int conexant_init(struct hda_codec *codec)
440 struct conexant_spec *spec = codec->spec;
443 for (i = 0; i < spec->num_init_verbs; i++)
444 snd_hda_sequence_write(codec, spec->init_verbs[i]);
448 static void conexant_free(struct hda_codec *codec)
450 snd_hda_input_jack_free(codec);
451 snd_hda_detach_beep_device(codec);
455 static const struct snd_kcontrol_new cxt_capture_mixers[] = {
457 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
458 .name = "Capture Source",
459 .info = conexant_mux_enum_info,
460 .get = conexant_mux_enum_get,
461 .put = conexant_mux_enum_put
466 #ifdef CONFIG_SND_HDA_INPUT_BEEP
467 /* additional beep mixers; the actual parameters are overwritten at build */
468 static const struct snd_kcontrol_new cxt_beep_mixer[] = {
469 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
470 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
475 static const char * const slave_vols[] = {
476 "Headphone Playback Volume",
477 "Speaker Playback Volume",
478 "Front Playback Volume",
479 "Surround Playback Volume",
480 "CLFE Playback Volume",
484 static const char * const slave_sws[] = {
485 "Headphone Playback Switch",
486 "Speaker Playback Switch",
487 "Front Playback Switch",
488 "Surround Playback Switch",
489 "CLFE Playback Switch",
493 static int conexant_build_controls(struct hda_codec *codec)
495 struct conexant_spec *spec = codec->spec;
499 for (i = 0; i < spec->num_mixers; i++) {
500 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
504 if (spec->multiout.dig_out_nid) {
505 err = snd_hda_create_spdif_out_ctls(codec,
506 spec->multiout.dig_out_nid);
509 err = snd_hda_create_spdif_share_sw(codec,
513 spec->multiout.share_spdif = 1;
515 if (spec->dig_in_nid) {
516 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
521 /* if we have no master control, let's create it */
522 if (spec->vmaster_nid &&
523 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
524 unsigned int vmaster_tlv[4];
525 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
526 HDA_OUTPUT, vmaster_tlv);
527 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
528 vmaster_tlv, slave_vols);
532 if (spec->vmaster_nid &&
533 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
534 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
540 if (spec->input_mux) {
541 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
546 #ifdef CONFIG_SND_HDA_INPUT_BEEP
547 /* create beep controls if needed */
548 if (spec->beep_amp) {
549 const struct snd_kcontrol_new *knew;
550 for (knew = cxt_beep_mixer; knew->name; knew++) {
551 struct snd_kcontrol *kctl;
552 kctl = snd_ctl_new1(knew, codec);
555 kctl->private_value = spec->beep_amp;
556 err = snd_hda_ctl_add(codec, 0, kctl);
566 #ifdef CONFIG_SND_HDA_POWER_SAVE
567 static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
569 snd_hda_shutup_pins(codec);
574 static const struct hda_codec_ops conexant_patch_ops = {
575 .build_controls = conexant_build_controls,
576 .build_pcms = conexant_build_pcms,
577 .init = conexant_init,
578 .free = conexant_free,
579 #ifdef CONFIG_SND_HDA_POWER_SAVE
580 .suspend = conexant_suspend,
582 .reboot_notify = snd_hda_shutup_pins,
585 #ifdef CONFIG_SND_HDA_INPUT_BEEP
586 #define set_beep_amp(spec, nid, idx, dir) \
587 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
589 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
592 static int patch_conexant_auto(struct hda_codec *codec);
595 * the private value = nid | (invert << 8)
598 #define cxt_eapd_info snd_ctl_boolean_mono_info
600 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
601 struct snd_ctl_elem_value *ucontrol)
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 struct conexant_spec *spec = codec->spec;
605 int invert = (kcontrol->private_value >> 8) & 1;
607 ucontrol->value.integer.value[0] = !spec->cur_eapd;
609 ucontrol->value.integer.value[0] = spec->cur_eapd;
614 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
615 struct snd_ctl_elem_value *ucontrol)
617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618 struct conexant_spec *spec = codec->spec;
619 int invert = (kcontrol->private_value >> 8) & 1;
620 hda_nid_t nid = kcontrol->private_value & 0xff;
623 eapd = !!ucontrol->value.integer.value[0];
626 if (eapd == spec->cur_eapd)
629 spec->cur_eapd = eapd;
630 snd_hda_codec_write_cache(codec, nid,
631 0, AC_VERB_SET_EAPD_BTLENABLE,
636 /* controls for test mode */
637 #ifdef CONFIG_SND_DEBUG
639 #define CXT_EAPD_SWITCH(xname, nid, mask) \
640 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
641 .info = cxt_eapd_info, \
642 .get = cxt_eapd_get, \
643 .put = cxt_eapd_put, \
644 .private_value = nid | (mask<<16) }
648 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_info *uinfo)
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct conexant_spec *spec = codec->spec;
653 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
654 spec->num_channel_mode);
657 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
658 struct snd_ctl_elem_value *ucontrol)
660 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
661 struct conexant_spec *spec = codec->spec;
662 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
663 spec->num_channel_mode,
664 spec->multiout.max_channels);
667 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
668 struct snd_ctl_elem_value *ucontrol)
670 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
671 struct conexant_spec *spec = codec->spec;
672 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
673 spec->num_channel_mode,
674 &spec->multiout.max_channels);
675 if (err >= 0 && spec->need_dac_fix)
676 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
680 #define CXT_PIN_MODE(xname, nid, dir) \
681 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
682 .info = conexant_ch_mode_info, \
683 .get = conexant_ch_mode_get, \
684 .put = conexant_ch_mode_put, \
685 .private_value = nid | (dir<<16) }
687 #endif /* CONFIG_SND_DEBUG */
689 /* Conexant 5045 specific */
691 static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
692 static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
693 static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
694 #define CXT5045_SPDIF_OUT 0x18
696 static const struct hda_channel_mode cxt5045_modes[1] = {
700 static const struct hda_input_mux cxt5045_capture_source = {
708 static const struct hda_input_mux cxt5045_capture_source_benq = {
719 static const struct hda_input_mux cxt5045_capture_source_hp530 = {
727 /* turn on/off EAPD (+ mute HP) as a master switch */
728 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
729 struct snd_ctl_elem_value *ucontrol)
731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
732 struct conexant_spec *spec = codec->spec;
735 if (!cxt_eapd_put(kcontrol, ucontrol))
738 /* toggle internal speakers mute depending of presence of
741 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
742 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
745 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
746 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
751 /* bind volumes of both NID 0x10 and 0x11 */
752 static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
753 .ops = &snd_hda_bind_vol,
755 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
756 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
761 /* toggle input of built-in and mic jack appropriately */
762 static void cxt5045_hp_automic(struct hda_codec *codec)
764 static const struct hda_verb mic_jack_on[] = {
765 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
766 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
769 static const struct hda_verb mic_jack_off[] = {
770 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
771 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
774 unsigned int present;
776 present = snd_hda_jack_detect(codec, 0x12);
778 snd_hda_sequence_write(codec, mic_jack_on);
780 snd_hda_sequence_write(codec, mic_jack_off);
784 /* mute internal speaker if HP is plugged */
785 static void cxt5045_hp_automute(struct hda_codec *codec)
787 struct conexant_spec *spec = codec->spec;
790 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
792 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
793 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
797 /* unsolicited event for HP jack sensing */
798 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
803 case CONEXANT_HP_EVENT:
804 cxt5045_hp_automute(codec);
806 case CONEXANT_MIC_EVENT:
807 cxt5045_hp_automic(codec);
813 static const struct snd_kcontrol_new cxt5045_mixers[] = {
814 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
815 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
816 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
817 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
818 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
819 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
820 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
821 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
822 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
823 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
824 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
826 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
827 .name = "Master Playback Switch",
828 .info = cxt_eapd_info,
830 .put = cxt5045_hp_master_sw_put,
831 .private_value = 0x10,
837 static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
838 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
839 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
840 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
841 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
843 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
844 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
845 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
846 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
848 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
849 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
854 static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
855 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
856 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
857 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
858 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
859 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
860 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
861 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
862 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
863 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
864 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
865 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
867 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
868 .name = "Master Playback Switch",
869 .info = cxt_eapd_info,
871 .put = cxt5045_hp_master_sw_put,
872 .private_value = 0x10,
878 static const struct hda_verb cxt5045_init_verbs[] = {
880 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
881 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
883 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
884 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
885 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
886 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
887 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
888 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
889 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
890 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
891 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
892 /* Record selector: Internal mic */
893 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
894 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
895 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
896 /* SPDIF route: PCM */
897 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
898 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
900 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
904 static const struct hda_verb cxt5045_benq_init_verbs[] = {
905 /* Internal Mic, Mic */
906 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
907 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
908 /* Line In,HP, Amp */
909 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
910 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
911 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
912 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
913 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
914 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
915 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
916 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
917 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
918 /* Record selector: Internal mic */
919 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
920 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
921 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
922 /* SPDIF route: PCM */
923 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
924 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
926 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
930 static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
931 /* pin sensing on HP jack */
932 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
936 static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
937 /* pin sensing on HP jack */
938 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
942 #ifdef CONFIG_SND_DEBUG
943 /* Test configuration for debugging, modelled after the ALC260 test
946 static const struct hda_input_mux cxt5045_test_capture_source = {
951 { "LINE1 pin", 0x2 },
952 { "HP-OUT pin", 0x3 },
957 static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
959 /* Output controls */
960 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
961 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
962 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
963 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
964 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
965 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
967 /* Modes for retasking pin widgets */
968 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
969 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
971 /* EAPD Switch Control */
972 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
974 /* Loopback mixer controls */
976 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
977 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
978 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
979 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
980 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
981 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
982 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
983 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
984 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
985 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
987 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
988 .name = "Input Source",
989 .info = conexant_mux_enum_info,
990 .get = conexant_mux_enum_get,
991 .put = conexant_mux_enum_put,
993 /* Audio input controls */
994 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
995 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
996 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
997 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
998 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
999 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1000 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1001 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1002 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1003 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1007 static const struct hda_verb cxt5045_test_init_verbs[] = {
1008 /* Set connections */
1009 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1010 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1011 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1012 /* Enable retasking pins as output, initially without power amp */
1013 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1014 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1016 /* Disable digital (SPDIF) pins initially, but users can enable
1017 * them via a mixer switch. In the case of SPDIF-out, this initverb
1018 * payload also sets the generation to 0, output to be in "consumer"
1019 * PCM format, copyright asserted, no pre-emphasis and no validity
1022 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1023 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1025 /* Start with output sum widgets muted and their output gains at min */
1026 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1027 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1029 /* Unmute retasking pin widget output buffers since the default
1030 * state appears to be output. As the pin mode is changed by the
1031 * user the pin mode control will take care of enabling the pin's
1032 * input/output buffers as needed.
1034 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1035 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1037 /* Mute capture amp left and right */
1038 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1040 /* Set ADC connection select to match default mixer setting (mic1
1043 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1044 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1046 /* Mute all inputs to mixer widget (even unconnected ones) */
1047 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1048 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1049 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1050 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1051 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1058 /* initialize jack-sensing, too */
1059 static int cxt5045_init(struct hda_codec *codec)
1061 conexant_init(codec);
1062 cxt5045_hp_automute(codec);
1068 CXT5045_LAPTOP_HPSENSE,
1069 CXT5045_LAPTOP_MICSENSE,
1070 CXT5045_LAPTOP_HPMICSENSE,
1072 CXT5045_LAPTOP_HP530,
1073 #ifdef CONFIG_SND_DEBUG
1080 static const char * const cxt5045_models[CXT5045_MODELS] = {
1081 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1082 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1083 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1084 [CXT5045_BENQ] = "benq",
1085 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1086 #ifdef CONFIG_SND_DEBUG
1087 [CXT5045_TEST] = "test",
1089 [CXT5045_AUTO] = "auto",
1092 static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1093 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1094 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1095 CXT5045_LAPTOP_HPSENSE),
1096 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1097 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1098 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1099 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1100 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1101 CXT5045_LAPTOP_HPMICSENSE),
1102 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1103 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1104 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1105 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1106 CXT5045_LAPTOP_HPMICSENSE),
1107 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1111 static int patch_cxt5045(struct hda_codec *codec)
1113 struct conexant_spec *spec;
1116 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1119 #if 0 /* use the old method just for safety */
1120 if (board_config < 0)
1121 board_config = CXT5045_AUTO;
1123 if (board_config == CXT5045_AUTO)
1124 return patch_conexant_auto(codec);
1126 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1130 codec->pin_amp_workaround = 1;
1132 spec->multiout.max_channels = 2;
1133 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1134 spec->multiout.dac_nids = cxt5045_dac_nids;
1135 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1136 spec->num_adc_nids = 1;
1137 spec->adc_nids = cxt5045_adc_nids;
1138 spec->capsrc_nids = cxt5045_capsrc_nids;
1139 spec->input_mux = &cxt5045_capture_source;
1140 spec->num_mixers = 1;
1141 spec->mixers[0] = cxt5045_mixers;
1142 spec->num_init_verbs = 1;
1143 spec->init_verbs[0] = cxt5045_init_verbs;
1144 spec->spdif_route = 0;
1145 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1146 spec->channel_mode = cxt5045_modes;
1148 set_beep_amp(spec, 0x16, 0, 1);
1150 codec->patch_ops = conexant_patch_ops;
1152 switch (board_config) {
1153 case CXT5045_LAPTOP_HPSENSE:
1154 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1155 spec->input_mux = &cxt5045_capture_source;
1156 spec->num_init_verbs = 2;
1157 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1158 spec->mixers[0] = cxt5045_mixers;
1159 codec->patch_ops.init = cxt5045_init;
1161 case CXT5045_LAPTOP_MICSENSE:
1162 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1163 spec->input_mux = &cxt5045_capture_source;
1164 spec->num_init_verbs = 2;
1165 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1166 spec->mixers[0] = cxt5045_mixers;
1167 codec->patch_ops.init = cxt5045_init;
1170 case CXT5045_LAPTOP_HPMICSENSE:
1171 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1172 spec->input_mux = &cxt5045_capture_source;
1173 spec->num_init_verbs = 3;
1174 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1175 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1176 spec->mixers[0] = cxt5045_mixers;
1177 codec->patch_ops.init = cxt5045_init;
1180 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1181 spec->input_mux = &cxt5045_capture_source_benq;
1182 spec->num_init_verbs = 1;
1183 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1184 spec->mixers[0] = cxt5045_mixers;
1185 spec->mixers[1] = cxt5045_benq_mixers;
1186 spec->num_mixers = 2;
1187 codec->patch_ops.init = cxt5045_init;
1189 case CXT5045_LAPTOP_HP530:
1190 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1191 spec->input_mux = &cxt5045_capture_source_hp530;
1192 spec->num_init_verbs = 2;
1193 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1194 spec->mixers[0] = cxt5045_mixers_hp530;
1195 codec->patch_ops.init = cxt5045_init;
1197 #ifdef CONFIG_SND_DEBUG
1199 spec->input_mux = &cxt5045_test_capture_source;
1200 spec->mixers[0] = cxt5045_test_mixer;
1201 spec->init_verbs[0] = cxt5045_test_init_verbs;
1207 switch (codec->subsystem_id >> 16) {
1212 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1213 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1214 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1216 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1217 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1218 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1219 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1220 (1 << AC_AMPCAP_MUTE_SHIFT));
1225 snd_hda_attach_beep_device(codec, spec->beep_amp);
1231 /* Conexant 5047 specific */
1232 #define CXT5047_SPDIF_OUT 0x11
1234 static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1235 static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1236 static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1238 static const struct hda_channel_mode cxt5047_modes[1] = {
1242 static const struct hda_input_mux cxt5047_toshiba_capture_source = {
1250 /* turn on/off EAPD (+ mute HP) as a master switch */
1251 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1252 struct snd_ctl_elem_value *ucontrol)
1254 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1255 struct conexant_spec *spec = codec->spec;
1258 if (!cxt_eapd_put(kcontrol, ucontrol))
1261 /* toggle internal speakers mute depending of presence of
1262 * the headphone jack
1264 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1265 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1266 * pin widgets unlike other codecs. In this case, we need to
1267 * set index 0x01 for the volume from the mixer amp 0x19.
1269 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1270 HDA_AMP_MUTE, bits);
1271 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1272 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1273 HDA_AMP_MUTE, bits);
1277 /* mute internal speaker if HP is plugged */
1278 static void cxt5047_hp_automute(struct hda_codec *codec)
1280 struct conexant_spec *spec = codec->spec;
1283 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1285 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1286 /* See the note in cxt5047_hp_master_sw_put */
1287 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1288 HDA_AMP_MUTE, bits);
1291 /* toggle input of built-in and mic jack appropriately */
1292 static void cxt5047_hp_automic(struct hda_codec *codec)
1294 static const struct hda_verb mic_jack_on[] = {
1295 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1296 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1299 static const struct hda_verb mic_jack_off[] = {
1300 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1301 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1304 unsigned int present;
1306 present = snd_hda_jack_detect(codec, 0x15);
1308 snd_hda_sequence_write(codec, mic_jack_on);
1310 snd_hda_sequence_write(codec, mic_jack_off);
1313 /* unsolicited event for HP jack sensing */
1314 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1317 switch (res >> 26) {
1318 case CONEXANT_HP_EVENT:
1319 cxt5047_hp_automute(codec);
1321 case CONEXANT_MIC_EVENT:
1322 cxt5047_hp_automic(codec);
1327 static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1328 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1329 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1330 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1331 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1332 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1333 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1334 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1336 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1337 .name = "Master Playback Switch",
1338 .info = cxt_eapd_info,
1339 .get = cxt_eapd_get,
1340 .put = cxt5047_hp_master_sw_put,
1341 .private_value = 0x13,
1347 static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1348 /* See the note in cxt5047_hp_master_sw_put */
1349 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1350 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1354 static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1355 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1359 static const struct hda_verb cxt5047_init_verbs[] = {
1360 /* Line in, Mic, Built-in Mic */
1361 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1362 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1363 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1365 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1366 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1367 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1368 /* Record selector: Mic */
1369 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1370 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1371 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1372 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1373 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1374 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1375 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1376 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1377 /* SPDIF route: PCM */
1378 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1379 /* Enable unsolicited events */
1380 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1381 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1385 /* configuration for Toshiba Laptops */
1386 static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
1387 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1391 /* Test configuration for debugging, modelled after the ALC260 test
1394 #ifdef CONFIG_SND_DEBUG
1395 static const struct hda_input_mux cxt5047_test_capture_source = {
1398 { "LINE1 pin", 0x0 },
1399 { "MIC1 pin", 0x1 },
1400 { "MIC2 pin", 0x2 },
1405 static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1407 /* Output only controls */
1408 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1409 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1410 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1411 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1412 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1413 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1414 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1415 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1416 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1417 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1418 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1421 /* Modes for retasking pin widgets */
1422 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1423 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1425 /* EAPD Switch Control */
1426 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1428 /* Loopback mixer controls */
1429 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1430 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1431 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1432 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1433 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1434 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1435 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1436 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1438 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1439 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1440 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1441 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1442 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1443 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1444 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1445 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1447 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1448 .name = "Input Source",
1449 .info = conexant_mux_enum_info,
1450 .get = conexant_mux_enum_get,
1451 .put = conexant_mux_enum_put,
1453 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1458 static const struct hda_verb cxt5047_test_init_verbs[] = {
1459 /* Enable retasking pins as output, initially without power amp */
1460 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1461 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1462 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1464 /* Disable digital (SPDIF) pins initially, but users can enable
1465 * them via a mixer switch. In the case of SPDIF-out, this initverb
1466 * payload also sets the generation to 0, output to be in "consumer"
1467 * PCM format, copyright asserted, no pre-emphasis and no validity
1470 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1472 /* Ensure mic1, mic2, line1 pin widgets take input from the
1473 * OUT1 sum bus when acting as an output.
1475 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1476 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1478 /* Start with output sum widgets muted and their output gains at min */
1479 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1480 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1482 /* Unmute retasking pin widget output buffers since the default
1483 * state appears to be output. As the pin mode is changed by the
1484 * user the pin mode control will take care of enabling the pin's
1485 * input/output buffers as needed.
1487 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1488 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1489 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1491 /* Mute capture amp left and right */
1492 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1494 /* Set ADC connection select to match default mixer setting (mic1
1497 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1499 /* Mute all inputs to mixer widget (even unconnected ones) */
1500 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1501 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1502 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1503 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1504 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1505 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1506 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1507 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1514 /* initialize jack-sensing, too */
1515 static int cxt5047_hp_init(struct hda_codec *codec)
1517 conexant_init(codec);
1518 cxt5047_hp_automute(codec);
1524 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1525 CXT5047_LAPTOP_HP, /* Some HP laptops */
1526 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1527 #ifdef CONFIG_SND_DEBUG
1534 static const char * const cxt5047_models[CXT5047_MODELS] = {
1535 [CXT5047_LAPTOP] = "laptop",
1536 [CXT5047_LAPTOP_HP] = "laptop-hp",
1537 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1538 #ifdef CONFIG_SND_DEBUG
1539 [CXT5047_TEST] = "test",
1541 [CXT5047_AUTO] = "auto",
1544 static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1545 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1546 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1548 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1552 static int patch_cxt5047(struct hda_codec *codec)
1554 struct conexant_spec *spec;
1557 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1560 #if 0 /* not enabled as default, as BIOS often broken for this codec */
1561 if (board_config < 0)
1562 board_config = CXT5047_AUTO;
1564 if (board_config == CXT5047_AUTO)
1565 return patch_conexant_auto(codec);
1567 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1571 codec->pin_amp_workaround = 1;
1573 spec->multiout.max_channels = 2;
1574 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1575 spec->multiout.dac_nids = cxt5047_dac_nids;
1576 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1577 spec->num_adc_nids = 1;
1578 spec->adc_nids = cxt5047_adc_nids;
1579 spec->capsrc_nids = cxt5047_capsrc_nids;
1580 spec->num_mixers = 1;
1581 spec->mixers[0] = cxt5047_base_mixers;
1582 spec->num_init_verbs = 1;
1583 spec->init_verbs[0] = cxt5047_init_verbs;
1584 spec->spdif_route = 0;
1585 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1586 spec->channel_mode = cxt5047_modes,
1588 codec->patch_ops = conexant_patch_ops;
1590 switch (board_config) {
1591 case CXT5047_LAPTOP:
1592 spec->num_mixers = 2;
1593 spec->mixers[1] = cxt5047_hp_spk_mixers;
1594 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1596 case CXT5047_LAPTOP_HP:
1597 spec->num_mixers = 2;
1598 spec->mixers[1] = cxt5047_hp_only_mixers;
1599 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1600 codec->patch_ops.init = cxt5047_hp_init;
1602 case CXT5047_LAPTOP_EAPD:
1603 spec->input_mux = &cxt5047_toshiba_capture_source;
1604 spec->num_mixers = 2;
1605 spec->mixers[1] = cxt5047_hp_spk_mixers;
1606 spec->num_init_verbs = 2;
1607 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1608 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1610 #ifdef CONFIG_SND_DEBUG
1612 spec->input_mux = &cxt5047_test_capture_source;
1613 spec->mixers[0] = cxt5047_test_mixer;
1614 spec->init_verbs[0] = cxt5047_test_init_verbs;
1615 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1618 spec->vmaster_nid = 0x13;
1620 switch (codec->subsystem_id >> 16) {
1622 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1623 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1624 * with 0 dB offset 0x17)
1626 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1627 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1628 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1629 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1630 (1 << AC_AMPCAP_MUTE_SHIFT));
1637 /* Conexant 5051 specific */
1638 static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1639 static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1641 static const struct hda_channel_mode cxt5051_modes[1] = {
1645 static void cxt5051_update_speaker(struct hda_codec *codec)
1647 struct conexant_spec *spec = codec->spec;
1648 unsigned int pinctl;
1650 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1651 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1654 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1655 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1657 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1659 snd_hda_codec_write(codec, 0x1b, 0,
1660 AC_VERB_SET_PIN_WIDGET_CONTROL,
1664 /* turn on/off EAPD (+ mute HP) as a master switch */
1665 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1666 struct snd_ctl_elem_value *ucontrol)
1668 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1670 if (!cxt_eapd_put(kcontrol, ucontrol))
1672 cxt5051_update_speaker(codec);
1676 /* toggle input of built-in and mic jack appropriately */
1677 static void cxt5051_portb_automic(struct hda_codec *codec)
1679 struct conexant_spec *spec = codec->spec;
1680 unsigned int present;
1682 if (!(spec->auto_mic & AUTO_MIC_PORTB))
1684 present = snd_hda_jack_detect(codec, 0x17);
1685 snd_hda_codec_write(codec, 0x14, 0,
1686 AC_VERB_SET_CONNECT_SEL,
1687 present ? 0x01 : 0x00);
1690 /* switch the current ADC according to the jack state */
1691 static void cxt5051_portc_automic(struct hda_codec *codec)
1693 struct conexant_spec *spec = codec->spec;
1694 unsigned int present;
1697 if (!(spec->auto_mic & AUTO_MIC_PORTC))
1699 present = snd_hda_jack_detect(codec, 0x18);
1701 spec->cur_adc_idx = 1;
1703 spec->cur_adc_idx = 0;
1704 new_adc = spec->adc_nids[spec->cur_adc_idx];
1705 if (spec->cur_adc && spec->cur_adc != new_adc) {
1706 /* stream is running, let's swap the current ADC */
1707 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1708 spec->cur_adc = new_adc;
1709 snd_hda_codec_setup_stream(codec, new_adc,
1710 spec->cur_adc_stream_tag, 0,
1711 spec->cur_adc_format);
1715 /* mute internal speaker if HP is plugged */
1716 static void cxt5051_hp_automute(struct hda_codec *codec)
1718 struct conexant_spec *spec = codec->spec;
1720 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1721 cxt5051_update_speaker(codec);
1724 /* unsolicited event for HP jack sensing */
1725 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1728 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1729 switch (res >> 26) {
1730 case CONEXANT_HP_EVENT:
1731 cxt5051_hp_automute(codec);
1733 case CXT5051_PORTB_EVENT:
1734 cxt5051_portb_automic(codec);
1736 case CXT5051_PORTC_EVENT:
1737 cxt5051_portc_automic(codec);
1740 snd_hda_input_jack_report(codec, nid);
1743 static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1744 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1746 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1747 .name = "Master Playback Switch",
1748 .info = cxt_eapd_info,
1749 .get = cxt_eapd_get,
1750 .put = cxt5051_hp_master_sw_put,
1751 .private_value = 0x1a,
1756 static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1757 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1758 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1759 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1760 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1761 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1762 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1766 static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1767 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1768 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1769 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1770 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1774 static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1775 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1776 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
1780 static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1781 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1782 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1786 static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1787 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1788 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1789 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1790 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1794 static const struct hda_verb cxt5051_init_verbs[] = {
1796 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1797 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1798 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1799 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1800 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1801 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1803 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1804 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1806 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1807 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1809 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1810 /* Record selector: Internal mic */
1811 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1812 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1813 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1814 /* SPDIF route: PCM */
1815 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1816 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1818 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1819 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1823 static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1825 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1826 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1827 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1828 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1830 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1831 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1833 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1834 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1836 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1837 /* Record selector: Internal mic */
1838 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1839 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1840 /* SPDIF route: PCM */
1841 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1843 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1844 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1848 static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1850 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1851 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1852 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1853 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1854 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1855 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1857 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1858 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1860 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1861 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1863 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1864 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1866 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1867 /* Record selector: Internal mic */
1868 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1869 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1870 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1871 /* SPDIF route: PCM */
1872 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
1873 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1875 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1876 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1877 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1881 static const struct hda_verb cxt5051_f700_init_verbs[] = {
1883 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1884 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1885 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1886 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1888 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1889 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1891 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1892 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1894 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1895 /* Record selector: Internal mic */
1896 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1897 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1898 /* SPDIF route: PCM */
1899 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1901 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1902 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1906 static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1909 snd_hda_codec_write(codec, nid, 0,
1910 AC_VERB_SET_UNSOLICITED_ENABLE,
1911 AC_USRSP_EN | event);
1912 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1913 snd_hda_input_jack_report(codec, nid);
1916 static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1918 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1919 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1923 /* initialize jack-sensing, too */
1924 static int cxt5051_init(struct hda_codec *codec)
1926 struct conexant_spec *spec = codec->spec;
1928 conexant_init(codec);
1929 conexant_init_jacks(codec);
1931 if (spec->auto_mic & AUTO_MIC_PORTB)
1932 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1933 if (spec->auto_mic & AUTO_MIC_PORTC)
1934 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1936 if (codec->patch_ops.unsol_event) {
1937 cxt5051_hp_automute(codec);
1938 cxt5051_portb_automic(codec);
1939 cxt5051_portc_automic(codec);
1946 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1947 CXT5051_HP, /* no docking */
1948 CXT5051_HP_DV6736, /* HP without mic switch */
1949 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1950 CXT5051_F700, /* HP Compaq Presario F700 */
1951 CXT5051_TOSHIBA, /* Toshiba M300 & co */
1952 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
1953 CXT5051_AUTO, /* auto-parser */
1957 static const char *const cxt5051_models[CXT5051_MODELS] = {
1958 [CXT5051_LAPTOP] = "laptop",
1959 [CXT5051_HP] = "hp",
1960 [CXT5051_HP_DV6736] = "hp-dv6736",
1961 [CXT5051_LENOVO_X200] = "lenovo-x200",
1962 [CXT5051_F700] = "hp-700",
1963 [CXT5051_TOSHIBA] = "toshiba",
1964 [CXT5051_IDEAPAD] = "ideapad",
1965 [CXT5051_AUTO] = "auto",
1968 static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1969 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1970 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1971 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1972 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1973 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1975 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1976 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1977 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1981 static int patch_cxt5051(struct hda_codec *codec)
1983 struct conexant_spec *spec;
1986 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1989 #if 0 /* use the old method just for safety */
1990 if (board_config < 0)
1991 board_config = CXT5051_AUTO;
1993 if (board_config == CXT5051_AUTO)
1994 return patch_conexant_auto(codec);
1996 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2000 codec->pin_amp_workaround = 1;
2002 codec->patch_ops = conexant_patch_ops;
2003 codec->patch_ops.init = cxt5051_init;
2005 spec->multiout.max_channels = 2;
2006 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2007 spec->multiout.dac_nids = cxt5051_dac_nids;
2008 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2009 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2010 spec->adc_nids = cxt5051_adc_nids;
2011 spec->num_mixers = 2;
2012 spec->mixers[0] = cxt5051_capture_mixers;
2013 spec->mixers[1] = cxt5051_playback_mixers;
2014 spec->num_init_verbs = 1;
2015 spec->init_verbs[0] = cxt5051_init_verbs;
2016 spec->spdif_route = 0;
2017 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2018 spec->channel_mode = cxt5051_modes;
2020 spec->cur_adc_idx = 0;
2022 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2024 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2026 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
2027 switch (board_config) {
2029 spec->mixers[0] = cxt5051_hp_mixers;
2031 case CXT5051_HP_DV6736:
2032 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2033 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2036 case CXT5051_LENOVO_X200:
2037 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
2038 /* Thinkpad X301 does not have S/PDIF wired and no ability
2039 to use a docking station. */
2040 if (codec->subsystem_id == 0x17aa211f)
2041 spec->multiout.dig_out_nid = 0;
2044 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2045 spec->mixers[0] = cxt5051_f700_mixers;
2048 case CXT5051_TOSHIBA:
2049 spec->mixers[0] = cxt5051_toshiba_mixers;
2050 spec->auto_mic = AUTO_MIC_PORTB;
2052 case CXT5051_IDEAPAD:
2053 spec->init_verbs[spec->num_init_verbs++] =
2054 cxt5051_ideapad_init_verbs;
2060 snd_hda_attach_beep_device(codec, spec->beep_amp);
2065 /* Conexant 5066 specific */
2067 static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2068 static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2069 static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2070 static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
2072 /* OLPC's microphone port is DC coupled for use with external sensors,
2073 * therefore we use a 50% mic bias in order to center the input signal with
2074 * the DC input range of the codec. */
2075 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2077 static const struct hda_channel_mode cxt5066_modes[1] = {
2081 #define HP_PRESENT_PORT_A (1 << 0)
2082 #define HP_PRESENT_PORT_D (1 << 1)
2083 #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2084 #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2086 static void cxt5066_update_speaker(struct hda_codec *codec)
2088 struct conexant_spec *spec = codec->spec;
2089 unsigned int pinctl;
2091 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2092 spec->hp_present, spec->cur_eapd);
2095 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
2096 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2099 /* Port D (HP/LO) */
2100 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2101 if (spec->dell_automute || spec->thinkpad) {
2102 /* Mute if Port A is connected */
2103 if (hp_port_a_present(spec))
2106 /* Thinkpad/Dell doesn't give pin-D status */
2107 if (!hp_port_d_present(spec))
2110 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2114 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2115 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2119 /* turn on/off EAPD (+ mute HP) as a master switch */
2120 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2121 struct snd_ctl_elem_value *ucontrol)
2123 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2125 if (!cxt_eapd_put(kcontrol, ucontrol))
2128 cxt5066_update_speaker(codec);
2132 static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2136 { "50%", PIN_VREF50 },
2137 { "80%", PIN_VREF80 },
2141 static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2143 struct conexant_spec *spec = codec->spec;
2144 /* Even though port F is the DC input, the bias is controlled on port B.
2145 * we also leave that port as an active input (but unselected) in DC mode
2146 * just in case that is necessary to make the bias setting take effect. */
2147 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2148 AC_VERB_SET_PIN_WIDGET_CONTROL,
2149 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2152 /* OLPC defers mic widget control until when capture is started because the
2153 * microphone LED comes on as soon as these settings are put in place. if we
2154 * did this before recording, it would give the false indication that recording
2155 * is happening when it is not. */
2156 static void cxt5066_olpc_select_mic(struct hda_codec *codec)
2158 struct conexant_spec *spec = codec->spec;
2159 if (!spec->recording)
2162 if (spec->dc_enable) {
2163 /* in DC mode we ignore presence detection and just use the jack
2164 * through our special DC port */
2165 const struct hda_verb enable_dc_mode[] = {
2166 /* disble internal mic, port C */
2167 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2169 /* enable DC capture, port F */
2170 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2174 snd_hda_sequence_write(codec, enable_dc_mode);
2175 /* port B input disabled (and bias set) through the following call */
2176 cxt5066_set_olpc_dc_bias(codec);
2180 /* disable DC (port F) */
2181 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2183 /* external mic, port B */
2184 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2185 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
2187 /* internal mic, port C */
2188 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2189 spec->ext_mic_present ? 0 : PIN_VREF80);
2192 /* toggle input of built-in and mic jack appropriately */
2193 static void cxt5066_olpc_automic(struct hda_codec *codec)
2195 struct conexant_spec *spec = codec->spec;
2196 unsigned int present;
2198 if (spec->dc_enable) /* don't do presence detection in DC mode */
2201 present = snd_hda_codec_read(codec, 0x1a, 0,
2202 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2204 snd_printdd("CXT5066: external microphone detected\n");
2206 snd_printdd("CXT5066: external microphone absent\n");
2208 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2210 spec->ext_mic_present = !!present;
2212 cxt5066_olpc_select_mic(codec);
2215 /* toggle input of built-in digital mic and mic jack appropriately */
2216 static void cxt5066_vostro_automic(struct hda_codec *codec)
2218 unsigned int present;
2220 struct hda_verb ext_mic_present[] = {
2221 /* enable external mic, port B */
2222 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2224 /* switch to external mic input */
2225 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2226 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2228 /* disable internal digital mic */
2229 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2232 static const struct hda_verb ext_mic_absent[] = {
2233 /* enable internal mic, port C */
2234 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2236 /* switch to internal mic input */
2237 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2239 /* disable external mic, port B */
2240 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2244 present = snd_hda_jack_detect(codec, 0x1a);
2246 snd_printdd("CXT5066: external microphone detected\n");
2247 snd_hda_sequence_write(codec, ext_mic_present);
2249 snd_printdd("CXT5066: external microphone absent\n");
2250 snd_hda_sequence_write(codec, ext_mic_absent);
2254 /* toggle input of built-in digital mic and mic jack appropriately */
2255 static void cxt5066_ideapad_automic(struct hda_codec *codec)
2257 unsigned int present;
2259 struct hda_verb ext_mic_present[] = {
2260 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2261 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2262 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2265 static const struct hda_verb ext_mic_absent[] = {
2266 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2267 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2268 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2272 present = snd_hda_jack_detect(codec, 0x1b);
2274 snd_printdd("CXT5066: external microphone detected\n");
2275 snd_hda_sequence_write(codec, ext_mic_present);
2277 snd_printdd("CXT5066: external microphone absent\n");
2278 snd_hda_sequence_write(codec, ext_mic_absent);
2283 /* toggle input of built-in digital mic and mic jack appropriately */
2284 static void cxt5066_asus_automic(struct hda_codec *codec)
2286 unsigned int present;
2288 present = snd_hda_jack_detect(codec, 0x1b);
2289 snd_printdd("CXT5066: external microphone present=%d\n", present);
2290 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2295 /* toggle input of built-in digital mic and mic jack appropriately */
2296 static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2298 unsigned int present;
2300 present = snd_hda_jack_detect(codec, 0x1b);
2301 snd_printdd("CXT5066: external microphone present=%d\n", present);
2302 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2307 /* toggle input of built-in digital mic and mic jack appropriately
2308 order is: external mic -> dock mic -> interal mic */
2309 static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2311 unsigned int ext_present, dock_present;
2313 static const struct hda_verb ext_mic_present[] = {
2314 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2315 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2316 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2317 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2318 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2321 static const struct hda_verb dock_mic_present[] = {
2322 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2323 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2324 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2325 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2326 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2329 static const struct hda_verb ext_mic_absent[] = {
2330 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2331 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2332 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2333 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2337 ext_present = snd_hda_jack_detect(codec, 0x1b);
2338 dock_present = snd_hda_jack_detect(codec, 0x1a);
2340 snd_printdd("CXT5066: external microphone detected\n");
2341 snd_hda_sequence_write(codec, ext_mic_present);
2342 } else if (dock_present) {
2343 snd_printdd("CXT5066: dock microphone detected\n");
2344 snd_hda_sequence_write(codec, dock_mic_present);
2346 snd_printdd("CXT5066: external microphone absent\n");
2347 snd_hda_sequence_write(codec, ext_mic_absent);
2351 /* mute internal speaker if HP is plugged */
2352 static void cxt5066_hp_automute(struct hda_codec *codec)
2354 struct conexant_spec *spec = codec->spec;
2355 unsigned int portA, portD;
2358 portA = snd_hda_jack_detect(codec, 0x19);
2361 portD = snd_hda_jack_detect(codec, 0x1c);
2363 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2364 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
2365 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2366 portA, portD, spec->hp_present);
2367 cxt5066_update_speaker(codec);
2370 /* Dispatch the right mic autoswitch function */
2371 static void cxt5066_automic(struct hda_codec *codec)
2373 struct conexant_spec *spec = codec->spec;
2375 if (spec->dell_vostro)
2376 cxt5066_vostro_automic(codec);
2377 else if (spec->ideapad)
2378 cxt5066_ideapad_automic(codec);
2379 else if (spec->thinkpad)
2380 cxt5066_thinkpad_automic(codec);
2381 else if (spec->hp_laptop)
2382 cxt5066_hp_laptop_automic(codec);
2383 else if (spec->asus)
2384 cxt5066_asus_automic(codec);
2387 /* unsolicited event for jack sensing */
2388 static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
2390 struct conexant_spec *spec = codec->spec;
2391 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2392 switch (res >> 26) {
2393 case CONEXANT_HP_EVENT:
2394 cxt5066_hp_automute(codec);
2396 case CONEXANT_MIC_EVENT:
2397 /* ignore mic events in DC mode; we're always using the jack */
2398 if (!spec->dc_enable)
2399 cxt5066_olpc_automic(codec);
2404 /* unsolicited event for jack sensing */
2405 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2407 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2408 switch (res >> 26) {
2409 case CONEXANT_HP_EVENT:
2410 cxt5066_hp_automute(codec);
2412 case CONEXANT_MIC_EVENT:
2413 cxt5066_automic(codec);
2419 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2430 static void cxt5066_set_mic_boost(struct hda_codec *codec)
2432 struct conexant_spec *spec = codec->spec;
2433 snd_hda_codec_write_cache(codec, 0x17, 0,
2434 AC_VERB_SET_AMP_GAIN_MUTE,
2435 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2436 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
2437 if (spec->ideapad || spec->thinkpad) {
2438 /* adjust the internal mic as well...it is not through 0x17 */
2439 snd_hda_codec_write_cache(codec, 0x23, 0,
2440 AC_VERB_SET_AMP_GAIN_MUTE,
2441 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2442 cxt5066_analog_mic_boost.
2443 items[spec->mic_boost].index);
2447 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2448 struct snd_ctl_elem_info *uinfo)
2450 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2453 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2454 struct snd_ctl_elem_value *ucontrol)
2456 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2457 struct conexant_spec *spec = codec->spec;
2458 ucontrol->value.enumerated.item[0] = spec->mic_boost;
2462 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2463 struct snd_ctl_elem_value *ucontrol)
2465 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2466 struct conexant_spec *spec = codec->spec;
2467 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2469 idx = ucontrol->value.enumerated.item[0];
2470 if (idx >= imux->num_items)
2471 idx = imux->num_items - 1;
2473 spec->mic_boost = idx;
2474 if (!spec->dc_enable)
2475 cxt5066_set_mic_boost(codec);
2479 static void cxt5066_enable_dc(struct hda_codec *codec)
2481 const struct hda_verb enable_dc_mode[] = {
2483 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2485 /* switch to DC input */
2486 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2490 /* configure as input source */
2491 snd_hda_sequence_write(codec, enable_dc_mode);
2492 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2495 static void cxt5066_disable_dc(struct hda_codec *codec)
2497 /* reconfigure input source */
2498 cxt5066_set_mic_boost(codec);
2499 /* automic also selects the right mic if we're recording */
2500 cxt5066_olpc_automic(codec);
2503 static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2504 struct snd_ctl_elem_value *ucontrol)
2506 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2507 struct conexant_spec *spec = codec->spec;
2508 ucontrol->value.integer.value[0] = spec->dc_enable;
2512 static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2513 struct snd_ctl_elem_value *ucontrol)
2515 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2516 struct conexant_spec *spec = codec->spec;
2517 int dc_enable = !!ucontrol->value.integer.value[0];
2519 if (dc_enable == spec->dc_enable)
2522 spec->dc_enable = dc_enable;
2524 cxt5066_enable_dc(codec);
2526 cxt5066_disable_dc(codec);
2531 static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2532 struct snd_ctl_elem_info *uinfo)
2534 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2537 static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2538 struct snd_ctl_elem_value *ucontrol)
2540 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2541 struct conexant_spec *spec = codec->spec;
2542 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2546 static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2547 struct snd_ctl_elem_value *ucontrol)
2549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2550 struct conexant_spec *spec = codec->spec;
2551 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2554 idx = ucontrol->value.enumerated.item[0];
2555 if (idx >= imux->num_items)
2556 idx = imux->num_items - 1;
2558 spec->dc_input_bias = idx;
2559 if (spec->dc_enable)
2560 cxt5066_set_olpc_dc_bias(codec);
2564 static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2566 struct conexant_spec *spec = codec->spec;
2567 /* mark as recording and configure the microphone widget so that the
2568 * recording LED comes on. */
2569 spec->recording = 1;
2570 cxt5066_olpc_select_mic(codec);
2573 static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2575 struct conexant_spec *spec = codec->spec;
2576 const struct hda_verb disable_mics[] = {
2577 /* disable external mic, port B */
2578 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2580 /* disble internal mic, port C */
2581 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2583 /* disable DC capture, port F */
2584 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2588 snd_hda_sequence_write(codec, disable_mics);
2589 spec->recording = 0;
2592 static void conexant_check_dig_outs(struct hda_codec *codec,
2593 const hda_nid_t *dig_pins,
2596 struct conexant_spec *spec = codec->spec;
2597 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2600 for (i = 0; i < num_pins; i++, dig_pins++) {
2601 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2602 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2604 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2606 if (spec->slave_dig_outs[0])
2609 nid_loc = spec->slave_dig_outs;
2613 static const struct hda_input_mux cxt5066_capture_source = {
2623 static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2624 .ops = &snd_hda_bind_vol,
2626 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2627 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2632 static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2633 .ops = &snd_hda_bind_sw,
2635 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2636 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2641 static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
2642 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2646 static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2648 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2649 .name = "Master Playback Volume",
2650 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2651 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2652 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2653 .subdevice = HDA_SUBDEV_AMP_FLAG,
2654 .info = snd_hda_mixer_amp_volume_info,
2655 .get = snd_hda_mixer_amp_volume_get,
2656 .put = snd_hda_mixer_amp_volume_put,
2657 .tlv = { .c = snd_hda_mixer_amp_tlv },
2658 /* offset by 28 volume steps to limit minimum gain to -46dB */
2660 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2665 static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2667 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2668 .name = "DC Mode Enable Switch",
2669 .info = snd_ctl_boolean_mono_info,
2670 .get = cxt5066_olpc_dc_get,
2671 .put = cxt5066_olpc_dc_put,
2674 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2675 .name = "DC Input Bias Enum",
2676 .info = cxt5066_olpc_dc_bias_enum_info,
2677 .get = cxt5066_olpc_dc_bias_enum_get,
2678 .put = cxt5066_olpc_dc_bias_enum_put,
2683 static const struct snd_kcontrol_new cxt5066_mixers[] = {
2685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2686 .name = "Master Playback Switch",
2687 .info = cxt_eapd_info,
2688 .get = cxt_eapd_get,
2689 .put = cxt5066_hp_master_sw_put,
2690 .private_value = 0x1d,
2694 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2695 .name = "Analog Mic Boost Capture Enum",
2696 .info = cxt5066_mic_boost_mux_enum_info,
2697 .get = cxt5066_mic_boost_mux_enum_get,
2698 .put = cxt5066_mic_boost_mux_enum_put,
2701 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2702 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2706 static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2708 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2709 .name = "Internal Mic Boost Capture Enum",
2710 .info = cxt5066_mic_boost_mux_enum_info,
2711 .get = cxt5066_mic_boost_mux_enum_get,
2712 .put = cxt5066_mic_boost_mux_enum_put,
2713 .private_value = 0x23 | 0x100,
2718 static const struct hda_verb cxt5066_init_verbs[] = {
2719 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2720 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2721 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2722 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2725 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2726 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2729 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2730 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2732 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2733 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2736 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2738 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2739 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2740 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2741 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2742 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2743 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2745 /* no digital microphone support yet */
2746 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2748 /* Audio input selector */
2749 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2751 /* SPDIF route: PCM */
2752 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2753 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2755 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2756 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2759 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2761 /* not handling these yet */
2762 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2763 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2764 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2765 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2766 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2767 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2768 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2769 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2773 static const struct hda_verb cxt5066_init_verbs_olpc[] = {
2774 /* Port A: headphones */
2775 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2776 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2778 /* Port B: external microphone */
2779 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2781 /* Port C: internal microphone */
2782 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2784 /* Port D: unused */
2785 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2787 /* Port E: unused, but has primary EAPD */
2788 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2789 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2791 /* Port F: external DC input through microphone port */
2792 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2794 /* Port G: internal speakers */
2795 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2796 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2799 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2802 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2804 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2805 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2806 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2807 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2808 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2809 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2810 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2811 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2812 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2813 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2814 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2815 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2817 /* Disable digital microphone port */
2818 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2820 /* Audio input selectors */
2821 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2822 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2825 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2826 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2828 /* enable unsolicited events for Port A and B */
2829 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2830 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2834 static const struct hda_verb cxt5066_init_verbs_vostro[] = {
2835 /* Port A: headphones */
2836 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2837 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2839 /* Port B: external microphone */
2840 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2842 /* Port C: unused */
2843 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2845 /* Port D: unused */
2846 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2848 /* Port E: unused, but has primary EAPD */
2849 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2850 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2852 /* Port F: unused */
2853 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2855 /* Port G: internal speakers */
2856 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2857 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2860 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2863 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2865 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2866 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2867 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2868 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2869 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2870 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2871 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2872 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2873 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2874 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2875 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2876 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2878 /* Digital microphone port */
2879 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2881 /* Audio input selectors */
2882 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2883 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2886 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2887 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2889 /* enable unsolicited events for Port A and B */
2890 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2891 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2895 static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2896 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2897 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2898 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2899 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2902 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2903 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2906 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2907 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2909 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2910 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2913 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2915 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2916 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2917 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2918 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2919 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2920 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2921 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2923 /* Audio input selector */
2924 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2925 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2927 /* SPDIF route: PCM */
2928 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2929 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2931 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2932 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2934 /* internal microphone */
2935 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2938 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2940 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2941 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2945 static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2946 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2947 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2949 /* Port G: internal speakers */
2950 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2951 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2953 /* Port A: HP, Amp */
2954 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2955 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2957 /* Port B: Mic Dock */
2958 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2961 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2963 /* Port D: HP Dock, Amp */
2964 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2965 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2968 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2970 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2971 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2972 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2973 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2974 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2975 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2976 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2978 /* Audio input selector */
2979 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2980 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2982 /* SPDIF route: PCM */
2983 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2984 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2986 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2987 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2989 /* internal microphone */
2990 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2993 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2995 /* enable unsolicited events for Port A, B, C and D */
2996 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2997 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2998 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2999 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3003 static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
3004 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3009 static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
3010 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3011 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3012 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3016 /* initialize jack-sensing, too */
3017 static int cxt5066_init(struct hda_codec *codec)
3019 snd_printdd("CXT5066: init\n");
3020 conexant_init(codec);
3021 if (codec->patch_ops.unsol_event) {
3022 cxt5066_hp_automute(codec);
3023 cxt5066_automic(codec);
3025 cxt5066_set_mic_boost(codec);
3029 static int cxt5066_olpc_init(struct hda_codec *codec)
3031 struct conexant_spec *spec = codec->spec;
3032 snd_printdd("CXT5066: init\n");
3033 conexant_init(codec);
3034 cxt5066_hp_automute(codec);
3035 if (!spec->dc_enable) {
3036 cxt5066_set_mic_boost(codec);
3037 cxt5066_olpc_automic(codec);
3039 cxt5066_enable_dc(codec);
3045 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
3046 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3047 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
3048 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
3049 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
3050 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
3051 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
3052 CXT5066_HP_LAPTOP, /* HP Laptop */
3053 CXT5066_AUTO, /* BIOS auto-parser */
3057 static const char * const cxt5066_models[CXT5066_MODELS] = {
3058 [CXT5066_LAPTOP] = "laptop",
3059 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3060 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
3061 [CXT5066_DELL_VOSTRO] = "dell-vostro",
3062 [CXT5066_IDEAPAD] = "ideapad",
3063 [CXT5066_THINKPAD] = "thinkpad",
3064 [CXT5066_ASUS] = "asus",
3065 [CXT5066_HP_LAPTOP] = "hp-laptop",
3066 [CXT5066_AUTO] = "auto",
3069 static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3070 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
3071 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
3072 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3073 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
3074 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
3075 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3076 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3077 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
3078 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3079 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
3080 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
3081 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
3082 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3083 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
3084 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
3085 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3087 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
3088 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3089 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
3090 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
3091 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3092 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
3093 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
3094 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
3095 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
3099 static int patch_cxt5066(struct hda_codec *codec)
3101 struct conexant_spec *spec;
3104 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3105 cxt5066_models, cxt5066_cfg_tbl);
3106 #if 0 /* use the old method just for safety */
3107 if (board_config < 0)
3108 board_config = CXT5066_AUTO;
3110 if (board_config == CXT5066_AUTO)
3111 return patch_conexant_auto(codec);
3113 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3118 codec->patch_ops = conexant_patch_ops;
3119 codec->patch_ops.init = conexant_init;
3121 spec->dell_automute = 0;
3122 spec->multiout.max_channels = 2;
3123 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3124 spec->multiout.dac_nids = cxt5066_dac_nids;
3125 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3126 ARRAY_SIZE(cxt5066_digout_pin_nids));
3127 spec->num_adc_nids = 1;
3128 spec->adc_nids = cxt5066_adc_nids;
3129 spec->capsrc_nids = cxt5066_capsrc_nids;
3130 spec->input_mux = &cxt5066_capture_source;
3132 spec->port_d_mode = PIN_HP;
3134 spec->num_init_verbs = 1;
3135 spec->init_verbs[0] = cxt5066_init_verbs;
3136 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3137 spec->channel_mode = cxt5066_modes;
3139 spec->cur_adc_idx = 0;
3141 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3143 switch (board_config) {
3145 case CXT5066_LAPTOP:
3146 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3147 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3149 case CXT5066_DELL_LAPTOP:
3150 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3151 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3153 spec->port_d_mode = PIN_OUT;
3154 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3155 spec->num_init_verbs++;
3156 spec->dell_automute = 1;
3159 case CXT5066_HP_LAPTOP:
3160 codec->patch_ops.init = cxt5066_init;
3161 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3162 spec->init_verbs[spec->num_init_verbs] =
3163 cxt5066_init_verbs_hp_laptop;
3164 spec->num_init_verbs++;
3165 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3166 spec->asus = board_config == CXT5066_ASUS;
3167 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3168 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3170 if (board_config == CXT5066_HP_LAPTOP)
3171 spec->multiout.dig_out_nid = 0;
3172 /* input source automatically selected */
3173 spec->input_mux = NULL;
3174 spec->port_d_mode = 0;
3175 spec->mic_boost = 3; /* default 30dB gain */
3178 case CXT5066_OLPC_XO_1_5:
3179 codec->patch_ops.init = cxt5066_olpc_init;
3180 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
3181 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3182 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3183 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
3184 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3185 spec->port_d_mode = 0;
3186 spec->mic_boost = 3; /* default 30dB gain */
3189 spec->multiout.dig_out_nid = 0;
3191 /* input source automatically selected */
3192 spec->input_mux = NULL;
3194 /* our capture hooks which allow us to turn on the microphone LED
3195 * at the right time */
3196 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3197 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
3199 case CXT5066_DELL_VOSTRO:
3200 codec->patch_ops.init = cxt5066_init;
3201 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3202 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3203 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3204 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3205 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
3206 spec->port_d_mode = 0;
3207 spec->dell_vostro = 1;
3208 spec->mic_boost = 3; /* default 30dB gain */
3211 spec->multiout.dig_out_nid = 0;
3213 /* input source automatically selected */
3214 spec->input_mux = NULL;
3216 case CXT5066_IDEAPAD:
3217 codec->patch_ops.init = cxt5066_init;
3218 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3219 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3220 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3221 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3222 spec->port_d_mode = 0;
3224 spec->mic_boost = 2; /* default 20dB gain */
3227 spec->multiout.dig_out_nid = 0;
3229 /* input source automatically selected */
3230 spec->input_mux = NULL;
3232 case CXT5066_THINKPAD:
3233 codec->patch_ops.init = cxt5066_init;
3234 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3235 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3236 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3237 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3239 spec->port_d_mode = PIN_OUT;
3240 spec->mic_boost = 2; /* default 20dB gain */
3243 spec->multiout.dig_out_nid = 0;
3245 /* input source automatically selected */
3246 spec->input_mux = NULL;
3251 snd_hda_attach_beep_device(codec, spec->beep_amp);
3257 * Automatic parser for CX20641 & co
3260 static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3261 struct hda_codec *codec,
3262 unsigned int stream_tag,
3263 unsigned int format,
3264 struct snd_pcm_substream *substream)
3266 struct conexant_spec *spec = codec->spec;
3267 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
3268 if (spec->adc_switching) {
3269 spec->cur_adc = adc;
3270 spec->cur_adc_stream_tag = stream_tag;
3271 spec->cur_adc_format = format;
3273 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3277 static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3278 struct hda_codec *codec,
3279 struct snd_pcm_substream *substream)
3281 struct conexant_spec *spec = codec->spec;
3282 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3287 static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3291 .nid = 0, /* fill later */
3293 .prepare = cx_auto_capture_pcm_prepare,
3294 .cleanup = cx_auto_capture_pcm_cleanup
3298 static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3300 /* get the connection index of @nid in the widget @mux */
3301 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3304 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3307 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3308 for (i = 0; i < nums; i++)
3314 /* get an unassigned DAC from the given list.
3315 * Return the nid if found and reduce the DAC list, or return zero if
3318 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3319 hda_nid_t *dacs, int *num_dacs)
3321 int i, nums = *num_dacs;
3324 for (i = 0; i < nums; i++) {
3325 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3333 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3338 #define MAX_AUTO_DACS 5
3340 /* fill analog DAC list from the widget tree */
3341 static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3343 hda_nid_t nid, end_nid;
3346 end_nid = codec->start_nid + codec->num_nodes;
3347 for (nid = codec->start_nid; nid < end_nid; nid++) {
3348 unsigned int wcaps = get_wcaps(codec, nid);
3349 unsigned int type = get_wcaps_type(wcaps);
3350 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3352 if (nums >= MAX_AUTO_DACS)
3359 /* fill pin_dac_pair list from the pin and dac list */
3360 static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3361 int num_pins, hda_nid_t *dacs, int *rest,
3362 struct pin_dac_pair *filled, int type)
3367 for (i = 0; i < num_pins; i++) {
3368 filled[nums].pin = pins[i];
3369 filled[nums].type = type;
3370 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3376 /* parse analog output paths */
3377 static void cx_auto_parse_output(struct hda_codec *codec)
3379 struct conexant_spec *spec = codec->spec;
3380 struct auto_pin_cfg *cfg = &spec->autocfg;
3381 hda_nid_t dacs[MAX_AUTO_DACS];
3382 int i, j, nums, rest;
3384 rest = fill_cx_auto_dacs(codec, dacs);
3385 /* parse all analog output pins */
3386 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3387 dacs, &rest, spec->dac_info,
3389 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3390 dacs, &rest, spec->dac_info + nums,
3392 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3393 dacs, &rest, spec->dac_info + nums,
3394 AUTO_PIN_SPEAKER_OUT);
3395 spec->dac_info_filled = nums;
3396 /* fill multiout struct */
3397 for (i = 0; i < nums; i++) {
3398 hda_nid_t dac = spec->dac_info[i].dac;
3401 switch (spec->dac_info[i].type) {
3402 case AUTO_PIN_LINE_OUT:
3403 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3404 spec->multiout.num_dacs++;
3406 case AUTO_PIN_HP_OUT:
3407 case AUTO_PIN_SPEAKER_OUT:
3408 if (!spec->multiout.hp_nid) {
3409 spec->multiout.hp_nid = dac;
3412 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3413 if (!spec->multiout.extra_out_nid[j]) {
3414 spec->multiout.extra_out_nid[j] = dac;
3420 spec->multiout.dac_nids = spec->private_dac_nids;
3421 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3423 if (cfg->hp_outs > 0)
3424 spec->auto_mute = 1;
3425 spec->vmaster_nid = spec->private_dac_nids[0];
3428 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3429 hda_nid_t *pins, bool on);
3431 /* auto-mute/unmute speaker and line outs according to headphone jack */
3432 static void cx_auto_hp_automute(struct hda_codec *codec)
3434 struct conexant_spec *spec = codec->spec;
3435 struct auto_pin_cfg *cfg = &spec->autocfg;
3438 if (!spec->auto_mute)
3441 for (i = 0; i < cfg->hp_outs; i++) {
3442 if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3447 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present);
3448 for (i = 0; i < cfg->line_outs; i++) {
3449 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3450 AC_VERB_SET_PIN_WIDGET_CONTROL,
3451 present ? 0 : PIN_OUT);
3453 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present);
3454 for (i = 0; !present && i < cfg->line_outs; i++)
3455 if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3457 for (i = 0; i < cfg->speaker_outs; i++) {
3458 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3459 AC_VERB_SET_PIN_WIDGET_CONTROL,
3460 present ? 0 : PIN_OUT);
3462 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present);
3465 static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3466 struct snd_ctl_elem_info *uinfo)
3468 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3469 struct conexant_spec *spec = codec->spec;
3471 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3474 static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3475 struct snd_ctl_elem_value *ucontrol)
3477 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3478 struct conexant_spec *spec = codec->spec;
3480 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3484 /* look for the route the given pin from mux and return the index;
3485 * if do_select is set, actually select the route.
3487 static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3488 hda_nid_t pin, hda_nid_t *srcp,
3489 bool do_select, int depth)
3491 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3494 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3496 case AC_WID_AUD_SEL:
3497 case AC_WID_AUD_MIX:
3503 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3504 for (i = 0; i < nums; i++)
3505 if (conn[i] == pin) {
3507 snd_hda_codec_write(codec, mux, 0,
3508 AC_VERB_SET_CONNECT_SEL, i);
3516 for (i = 0; i < nums; i++) {
3517 int ret = __select_input_connection(codec, conn[i], pin, srcp,
3521 snd_hda_codec_write(codec, mux, 0,
3522 AC_VERB_SET_CONNECT_SEL, i);
3529 static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3532 __select_input_connection(codec, mux, pin, NULL, true, 0);
3535 static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3538 return __select_input_connection(codec, mux, pin, NULL, false, 0);
3541 static int cx_auto_mux_enum_update(struct hda_codec *codec,
3542 const struct hda_input_mux *imux,
3545 struct conexant_spec *spec = codec->spec;
3548 if (!imux->num_items)
3550 if (idx >= imux->num_items)
3551 idx = imux->num_items - 1;
3552 if (spec->cur_mux[0] == idx)
3554 adc = spec->imux_info[idx].adc;
3555 select_input_connection(codec, spec->imux_info[idx].adc,
3556 spec->imux_info[idx].pin);
3557 if (spec->cur_adc && spec->cur_adc != adc) {
3558 /* stream is running, let's swap the current ADC */
3559 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3560 spec->cur_adc = adc;
3561 snd_hda_codec_setup_stream(codec, adc,
3562 spec->cur_adc_stream_tag, 0,
3563 spec->cur_adc_format);
3565 spec->cur_mux[0] = idx;
3569 static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3570 struct snd_ctl_elem_value *ucontrol)
3572 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3573 struct conexant_spec *spec = codec->spec;
3575 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3576 ucontrol->value.enumerated.item[0]);
3579 static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3581 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3582 .name = "Capture Source",
3583 .info = cx_auto_mux_enum_info,
3584 .get = cx_auto_mux_enum_get,
3585 .put = cx_auto_mux_enum_put
3590 /* automatic switch internal and external mic */
3591 static void cx_auto_automic(struct hda_codec *codec)
3593 struct conexant_spec *spec = codec->spec;
3594 int ext_idx = spec->auto_mic_ext;
3596 if (!spec->auto_mic)
3598 if (snd_hda_jack_detect(codec, spec->imux_info[ext_idx].pin))
3599 cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx);
3601 cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx);
3604 static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3606 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3607 switch (res >> 26) {
3608 case CONEXANT_HP_EVENT:
3609 cx_auto_hp_automute(codec);
3610 snd_hda_input_jack_report(codec, nid);
3612 case CONEXANT_MIC_EVENT:
3613 cx_auto_automic(codec);
3614 snd_hda_input_jack_report(codec, nid);
3619 /* return true if it's an internal-mic pin */
3620 static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3622 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3623 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
3624 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
3627 /* return true if it's an external-mic pin */
3628 static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3630 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3631 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
3632 snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3633 (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
3636 /* check whether the pin config is suitable for auto-mic switching;
3637 * auto-mic is enabled only when one int-mic and one-ext mic exist
3639 static void cx_auto_check_auto_mic(struct hda_codec *codec)
3641 struct conexant_spec *spec = codec->spec;
3643 if (is_ext_mic(codec, spec->imux_info[0].pin) &&
3644 is_int_mic(codec, spec->imux_info[1].pin)) {
3646 spec->auto_mic_ext = 0;
3649 if (is_int_mic(codec, spec->imux_info[0].pin) &&
3650 is_ext_mic(codec, spec->imux_info[1].pin)) {
3652 spec->auto_mic_ext = 1;
3657 static void cx_auto_parse_input(struct hda_codec *codec)
3659 struct conexant_spec *spec = codec->spec;
3660 struct auto_pin_cfg *cfg = &spec->autocfg;
3661 struct hda_input_mux *imux;
3664 imux = &spec->private_imux;
3665 for (i = 0; i < cfg->num_inputs; i++) {
3666 for (j = 0; j < spec->num_adc_nids; j++) {
3667 hda_nid_t adc = spec->adc_nids[j];
3668 int idx = get_input_connection(codec, adc,
3669 cfg->inputs[i].pin);
3672 label = hda_get_autocfg_input_label(codec, cfg, i);
3673 spec->imux_info[imux->num_items].index = i;
3674 spec->imux_info[imux->num_items].boost = 0;
3675 spec->imux_info[imux->num_items].adc = adc;
3676 spec->imux_info[imux->num_items].pin =
3678 snd_hda_add_imux_item(imux, label, idx, NULL);
3683 if (imux->num_items == 2 && cfg->num_inputs == 2)
3684 cx_auto_check_auto_mic(codec);
3685 if (imux->num_items > 1 && !spec->auto_mic) {
3686 for (i = 1; i < imux->num_items; i++) {
3687 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
3688 spec->adc_switching = 1;
3695 /* get digital-input audio widget corresponding to the given pin */
3696 static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3698 hda_nid_t nid, end_nid;
3700 end_nid = codec->start_nid + codec->num_nodes;
3701 for (nid = codec->start_nid; nid < end_nid; nid++) {
3702 unsigned int wcaps = get_wcaps(codec, nid);
3703 unsigned int type = get_wcaps_type(wcaps);
3704 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3705 if (get_connection_index(codec, nid, pin) >= 0)
3712 static void cx_auto_parse_digital(struct hda_codec *codec)
3714 struct conexant_spec *spec = codec->spec;
3715 struct auto_pin_cfg *cfg = &spec->autocfg;
3718 if (cfg->dig_outs &&
3719 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3720 spec->multiout.dig_out_nid = nid;
3721 if (cfg->dig_in_pin)
3722 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3725 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3726 static void cx_auto_parse_beep(struct hda_codec *codec)
3728 struct conexant_spec *spec = codec->spec;
3729 hda_nid_t nid, end_nid;
3731 end_nid = codec->start_nid + codec->num_nodes;
3732 for (nid = codec->start_nid; nid < end_nid; nid++)
3733 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3734 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3739 #define cx_auto_parse_beep(codec)
3742 static int cx_auto_parse_auto_config(struct hda_codec *codec)
3744 struct conexant_spec *spec = codec->spec;
3747 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3751 cx_auto_parse_output(codec);
3752 cx_auto_parse_input(codec);
3753 cx_auto_parse_digital(codec);
3754 cx_auto_parse_beep(codec);
3758 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3759 hda_nid_t *pins, bool on)
3762 for (i = 0; i < num_pins; i++) {
3763 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3764 snd_hda_codec_write(codec, pins[i], 0,
3765 AC_VERB_SET_EAPD_BTLENABLE,
3770 static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3773 int idx = get_connection_index(codec, pin, src);
3775 snd_hda_codec_write(codec, pin, 0,
3776 AC_VERB_SET_CONNECT_SEL, idx);
3779 static void mute_outputs(struct hda_codec *codec, int num_nids,
3780 const hda_nid_t *nids)
3784 for (i = 0; i < num_nids; i++) {
3785 hda_nid_t nid = nids[i];
3786 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3788 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3792 snd_hda_codec_write(codec, nid, 0,
3793 AC_VERB_SET_AMP_GAIN_MUTE, val);
3797 static void cx_auto_init_output(struct hda_codec *codec)
3799 struct conexant_spec *spec = codec->spec;
3800 struct auto_pin_cfg *cfg = &spec->autocfg;
3804 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
3805 for (i = 0; i < cfg->hp_outs; i++)
3806 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3807 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
3808 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3809 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3810 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
3811 if (spec->auto_mute) {
3812 for (i = 0; i < cfg->hp_outs; i++) {
3813 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3814 AC_VERB_SET_UNSOLICITED_ENABLE,
3815 AC_USRSP_EN | CONEXANT_HP_EVENT);
3817 cx_auto_hp_automute(codec);
3819 for (i = 0; i < cfg->line_outs; i++)
3820 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3821 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3822 for (i = 0; i < cfg->speaker_outs; i++)
3823 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3824 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3826 cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins,
3828 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins,
3830 cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins,
3834 for (i = 0; i < spec->dac_info_filled; i++) {
3835 nid = spec->dac_info[i].dac;
3837 nid = spec->multiout.dac_nids[0];
3838 select_connection(codec, spec->dac_info[i].pin, nid);
3842 static void cx_auto_init_input(struct hda_codec *codec)
3844 struct conexant_spec *spec = codec->spec;
3845 struct auto_pin_cfg *cfg = &spec->autocfg;
3848 for (i = 0; i < spec->num_adc_nids; i++) {
3849 hda_nid_t nid = spec->adc_nids[i];
3850 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3852 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
3853 val = AMP_IN_MUTE(0);
3855 val = AMP_IN_UNMUTE(0);
3856 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3860 for (i = 0; i < cfg->num_inputs; i++) {
3862 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3866 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3867 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3870 if (spec->auto_mic) {
3871 int ext_idx = spec->auto_mic_ext;
3872 snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3873 AC_VERB_SET_UNSOLICITED_ENABLE,
3874 AC_USRSP_EN | CONEXANT_MIC_EVENT);
3875 cx_auto_automic(codec);
3877 select_input_connection(codec, spec->imux_info[0].adc,
3878 spec->imux_info[0].pin);
3882 static void cx_auto_init_digital(struct hda_codec *codec)
3884 struct conexant_spec *spec = codec->spec;
3885 struct auto_pin_cfg *cfg = &spec->autocfg;
3887 if (spec->multiout.dig_out_nid)
3888 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3889 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3890 if (spec->dig_in_nid)
3891 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3892 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3895 static int cx_auto_init(struct hda_codec *codec)
3897 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3898 cx_auto_init_output(codec);
3899 cx_auto_init_input(codec);
3900 cx_auto_init_digital(codec);
3904 static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
3905 const char *dir, int cidx,
3906 hda_nid_t nid, int hda_dir, int amp_idx)
3908 static char name[32];
3909 static struct snd_kcontrol_new knew[] = {
3910 HDA_CODEC_VOLUME(name, 0, 0, 0),
3911 HDA_CODEC_MUTE(name, 0, 0, 0),
3913 static const char * const sfx[2] = { "Volume", "Switch" };
3916 for (i = 0; i < 2; i++) {
3917 struct snd_kcontrol *kctl;
3918 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
3920 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3921 knew[i].index = cidx;
3922 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3923 kctl = snd_ctl_new1(&knew[i], codec);
3926 err = snd_hda_ctl_add(codec, nid, kctl);
3929 if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3935 #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
3936 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3938 #define cx_auto_add_pb_volume(codec, nid, str, idx) \
3939 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3941 static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
3942 hda_nid_t pin, const char *name, int idx)
3945 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
3946 if (caps & AC_AMPCAP_NUM_STEPS)
3947 return cx_auto_add_pb_volume(codec, dac, name, idx);
3948 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
3949 if (caps & AC_AMPCAP_NUM_STEPS)
3950 return cx_auto_add_pb_volume(codec, pin, name, idx);
3954 static int cx_auto_build_output_controls(struct hda_codec *codec)
3956 struct conexant_spec *spec = codec->spec;
3958 int num_line = 0, num_hp = 0, num_spk = 0;
3959 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
3961 if (spec->dac_info_filled == 1)
3962 return try_add_pb_volume(codec, spec->dac_info[0].dac,
3963 spec->dac_info[0].pin,
3966 for (i = 0; i < spec->dac_info_filled; i++) {
3969 if (!spec->dac_info[i].dac)
3971 type = spec->dac_info[i].type;
3972 if (type == AUTO_PIN_LINE_OUT)
3973 type = spec->autocfg.line_out_type;
3975 case AUTO_PIN_LINE_OUT:
3977 label = texts[num_line++];
3980 case AUTO_PIN_HP_OUT:
3981 label = "Headphone";
3984 case AUTO_PIN_SPEAKER_OUT:
3989 err = try_add_pb_volume(codec, spec->dac_info[i].dac,
3990 spec->dac_info[i].pin,
3998 static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
3999 const char *label, const char *pfx,
4002 struct conexant_spec *spec = codec->spec;
4005 for (i = 0; i < spec->num_adc_nids; i++) {
4006 hda_nid_t adc_nid = spec->adc_nids[i];
4007 int idx = get_input_connection(codec, adc_nid, nid);
4010 return cx_auto_add_volume_idx(codec, label, pfx,
4011 cidx, adc_nid, HDA_INPUT, idx);
4016 static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4017 const char *label, int cidx)
4019 struct conexant_spec *spec = codec->spec;
4023 nid = spec->imux_info[idx].pin;
4024 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4025 return cx_auto_add_volume(codec, label, " Boost", cidx,
4027 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4031 for (i = 0; i < idx; i++) {
4032 if (spec->imux_info[i].boost == mux)
4033 return 0; /* already present */
4036 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
4037 spec->imux_info[idx].boost = mux;
4038 return cx_auto_add_volume(codec, label, " Boost", 0,
4044 static int cx_auto_build_input_controls(struct hda_codec *codec)
4046 struct conexant_spec *spec = codec->spec;
4047 struct hda_input_mux *imux = &spec->private_imux;
4048 const char *prev_label;
4049 int input_conn[HDA_MAX_NUM_INPUTS];
4051 int multi_connection;
4053 multi_connection = 0;
4054 for (i = 0; i < imux->num_items; i++) {
4055 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4056 spec->imux_info[i].pin);
4057 input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
4058 if (i > 0 && input_conn[i] != input_conn[0])
4059 multi_connection = 1;
4064 for (i = 0; i < imux->num_items; i++) {
4065 hda_nid_t nid = spec->imux_info[i].pin;
4068 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
4069 spec->imux_info[i].index);
4070 if (label == prev_label)
4076 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4080 if (!multi_connection) {
4083 err = cx_auto_add_capture_volume(codec, nid,
4084 "Capture", "", cidx);
4086 err = cx_auto_add_capture_volume(codec, nid,
4087 label, " Capture", cidx);
4093 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4094 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4102 static int cx_auto_build_controls(struct hda_codec *codec)
4106 err = cx_auto_build_output_controls(codec);
4109 err = cx_auto_build_input_controls(codec);
4112 return conexant_build_controls(codec);
4115 static int cx_auto_search_adcs(struct hda_codec *codec)
4117 struct conexant_spec *spec = codec->spec;
4118 hda_nid_t nid, end_nid;
4120 end_nid = codec->start_nid + codec->num_nodes;
4121 for (nid = codec->start_nid; nid < end_nid; nid++) {
4122 unsigned int caps = get_wcaps(codec, nid);
4123 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4125 if (caps & AC_WCAP_DIGITAL)
4127 if (snd_BUG_ON(spec->num_adc_nids >=
4128 ARRAY_SIZE(spec->private_adc_nids)))
4130 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4132 spec->adc_nids = spec->private_adc_nids;
4137 static const struct hda_codec_ops cx_auto_patch_ops = {
4138 .build_controls = cx_auto_build_controls,
4139 .build_pcms = conexant_build_pcms,
4140 .init = cx_auto_init,
4141 .free = conexant_free,
4142 .unsol_event = cx_auto_unsol_event,
4143 #ifdef CONFIG_SND_HDA_POWER_SAVE
4144 .suspend = conexant_suspend,
4146 .reboot_notify = snd_hda_shutup_pins,
4149 static int patch_conexant_auto(struct hda_codec *codec)
4151 struct conexant_spec *spec;
4154 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4157 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4161 codec->pin_amp_workaround = 1;
4162 err = cx_auto_search_adcs(codec);
4165 err = cx_auto_parse_auto_config(codec);
4171 spec->capture_stream = &cx_auto_pcm_analog_capture;
4172 codec->patch_ops = cx_auto_patch_ops;
4174 snd_hda_attach_beep_device(codec, spec->beep_amp);
4181 static const struct hda_codec_preset snd_hda_preset_conexant[] = {
4182 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4183 .patch = patch_cxt5045 },
4184 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4185 .patch = patch_cxt5047 },
4186 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4187 .patch = patch_cxt5051 },
4188 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4189 .patch = patch_cxt5066 },
4190 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4191 .patch = patch_cxt5066 },
4192 { .id = 0x14f15068, .name = "CX20584",
4193 .patch = patch_cxt5066 },
4194 { .id = 0x14f15069, .name = "CX20585",
4195 .patch = patch_cxt5066 },
4196 { .id = 0x14f1506e, .name = "CX20590",
4197 .patch = patch_cxt5066 },
4198 { .id = 0x14f15097, .name = "CX20631",
4199 .patch = patch_conexant_auto },
4200 { .id = 0x14f15098, .name = "CX20632",
4201 .patch = patch_conexant_auto },
4202 { .id = 0x14f150a1, .name = "CX20641",
4203 .patch = patch_conexant_auto },
4204 { .id = 0x14f150a2, .name = "CX20642",
4205 .patch = patch_conexant_auto },
4206 { .id = 0x14f150ab, .name = "CX20651",
4207 .patch = patch_conexant_auto },
4208 { .id = 0x14f150ac, .name = "CX20652",
4209 .patch = patch_conexant_auto },
4210 { .id = 0x14f150b8, .name = "CX20664",
4211 .patch = patch_conexant_auto },
4212 { .id = 0x14f150b9, .name = "CX20665",
4213 .patch = patch_conexant_auto },
4217 MODULE_ALIAS("snd-hda-codec-id:14f15045");
4218 MODULE_ALIAS("snd-hda-codec-id:14f15047");
4219 MODULE_ALIAS("snd-hda-codec-id:14f15051");
4220 MODULE_ALIAS("snd-hda-codec-id:14f15066");
4221 MODULE_ALIAS("snd-hda-codec-id:14f15067");
4222 MODULE_ALIAS("snd-hda-codec-id:14f15068");
4223 MODULE_ALIAS("snd-hda-codec-id:14f15069");
4224 MODULE_ALIAS("snd-hda-codec-id:14f1506e");
4225 MODULE_ALIAS("snd-hda-codec-id:14f15097");
4226 MODULE_ALIAS("snd-hda-codec-id:14f15098");
4227 MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4228 MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4229 MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4230 MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4231 MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4232 MODULE_ALIAS("snd-hda-codec-id:14f150b9");
4234 MODULE_LICENSE("GPL");
4235 MODULE_DESCRIPTION("Conexant HD-audio codec");
4237 static struct hda_codec_preset_list conexant_list = {
4238 .preset = snd_hda_preset_conexant,
4239 .owner = THIS_MODULE,
4242 static int __init patch_conexant_init(void)
4244 return snd_hda_add_codec_preset(&conexant_list);
4247 static void __exit patch_conexant_exit(void)
4249 snd_hda_delete_codec_preset(&conexant_list);
4252 module_init(patch_conexant_init)
4253 module_exit(patch_conexant_exit)