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 <linux/module.h>
28 #include <sound/core.h>
29 #include <sound/jack.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
35 #define CXT_PIN_DIR_IN 0x00
36 #define CXT_PIN_DIR_OUT 0x01
37 #define CXT_PIN_DIR_INOUT 0x02
38 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
39 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
41 #define CONEXANT_HP_EVENT 0x37
42 #define CONEXANT_MIC_EVENT 0x38
43 #define CONEXANT_LINE_EVENT 0x39
45 /* Conexant 5051 specific */
47 #define CXT5051_SPDIF_OUT 0x12
48 #define CXT5051_PORTB_EVENT 0x38
49 #define CXT5051_PORTC_EVENT 0x39
51 #define AUTO_MIC_PORTB (1 << 1)
52 #define AUTO_MIC_PORTC (1 << 2)
61 hda_nid_t pin; /* input pin NID */
62 hda_nid_t adc; /* connected ADC NID */
63 hda_nid_t boost; /* optional boost volume NID */
64 int index; /* corresponding to autocfg.input */
67 struct conexant_spec {
69 const struct snd_kcontrol_new *mixers[5];
71 hda_nid_t vmaster_nid;
73 const struct hda_verb *init_verbs[5]; /* initialization verbs
77 unsigned int num_init_verbs;
80 struct hda_multi_out multiout; /* playback set-up
81 * max_channels, dacs must be set
82 * dig_out_nid and hp_nid are optional
84 unsigned int cur_eapd;
85 unsigned int hp_present;
86 unsigned int line_present;
87 unsigned int auto_mic;
88 int auto_mic_ext; /* imux_pins[] index for ext mic */
89 int auto_mic_dock; /* imux_pins[] index for dock mic */
90 int auto_mic_int; /* imux_pins[] index for int mic */
91 unsigned int need_dac_fix;
92 hda_nid_t slave_dig_outs[2];
95 unsigned int num_adc_nids;
96 const hda_nid_t *adc_nids;
97 hda_nid_t dig_in_nid; /* digital-in NID; optional */
99 unsigned int cur_adc_idx;
101 unsigned int cur_adc_stream_tag;
102 unsigned int cur_adc_format;
104 const struct hda_pcm_stream *capture_stream;
107 const struct hda_input_mux *input_mux;
108 const hda_nid_t *capsrc_nids;
109 unsigned int cur_mux[3];
112 const struct hda_channel_mode *channel_mode;
113 int num_channel_mode;
115 /* PCM information */
116 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
118 unsigned int spdif_route;
120 /* dynamic controls, init_verbs and input_mux */
121 struct auto_pin_cfg autocfg;
122 struct hda_input_mux private_imux;
123 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
124 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
125 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
126 struct pin_dac_pair dac_info[8];
129 unsigned int port_d_mode;
130 unsigned int auto_mute:1; /* used in auto-parser */
131 unsigned int detect_line:1; /* Line-out detection enabled */
132 unsigned int automute_lines:1; /* automute line-out as well */
133 unsigned int automute_hp_lo:1; /* both HP and LO available */
134 unsigned int dell_automute:1;
135 unsigned int dell_vostro:1;
136 unsigned int ideapad:1;
137 unsigned int thinkpad:1;
138 unsigned int hp_laptop:1;
140 unsigned int pin_eapd_ctrls:1;
141 unsigned int single_adc_amp:1;
142 unsigned int fixup_stereo_dmic:1;
144 unsigned int adc_switching:1;
146 unsigned int ext_mic_present;
147 unsigned int recording;
148 void (*capture_prepare)(struct hda_codec *codec);
149 void (*capture_cleanup)(struct hda_codec *codec);
151 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
152 * through the microphone jack.
153 * When the user enables this through a mixer switch, both internal and
154 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
155 * we also allow the bias to be configured through a separate mixer
157 unsigned int dc_enable;
158 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
159 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
161 unsigned int beep_amp;
163 /* extra EAPD pins */
164 unsigned int num_eapds;
168 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
169 struct hda_codec *codec,
170 struct snd_pcm_substream *substream)
172 struct conexant_spec *spec = codec->spec;
173 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
177 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
178 struct hda_codec *codec,
179 unsigned int stream_tag,
181 struct snd_pcm_substream *substream)
183 struct conexant_spec *spec = codec->spec;
184 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
189 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
190 struct hda_codec *codec,
191 struct snd_pcm_substream *substream)
193 struct conexant_spec *spec = codec->spec;
194 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
200 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
201 struct hda_codec *codec,
202 struct snd_pcm_substream *substream)
204 struct conexant_spec *spec = codec->spec;
205 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
208 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
209 struct hda_codec *codec,
210 struct snd_pcm_substream *substream)
212 struct conexant_spec *spec = codec->spec;
213 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
216 static int conexant_dig_playback_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 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
231 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
232 struct hda_codec *codec,
233 unsigned int stream_tag,
235 struct snd_pcm_substream *substream)
237 struct conexant_spec *spec = codec->spec;
238 if (spec->capture_prepare)
239 spec->capture_prepare(codec);
240 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
241 stream_tag, 0, format);
245 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
246 struct hda_codec *codec,
247 struct snd_pcm_substream *substream)
249 struct conexant_spec *spec = codec->spec;
250 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
251 if (spec->capture_cleanup)
252 spec->capture_cleanup(codec);
258 static const struct hda_pcm_stream conexant_pcm_analog_playback = {
262 .nid = 0, /* fill later */
264 .open = conexant_playback_pcm_open,
265 .prepare = conexant_playback_pcm_prepare,
266 .cleanup = conexant_playback_pcm_cleanup
270 static const struct hda_pcm_stream conexant_pcm_analog_capture = {
274 .nid = 0, /* fill later */
276 .prepare = conexant_capture_pcm_prepare,
277 .cleanup = conexant_capture_pcm_cleanup
282 static const struct hda_pcm_stream conexant_pcm_digital_playback = {
286 .nid = 0, /* fill later */
288 .open = conexant_dig_playback_pcm_open,
289 .close = conexant_dig_playback_pcm_close,
290 .prepare = conexant_dig_playback_pcm_prepare
294 static const struct hda_pcm_stream conexant_pcm_digital_capture = {
298 /* NID is set in alc_build_pcms */
301 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
302 struct hda_codec *codec,
303 unsigned int stream_tag,
305 struct snd_pcm_substream *substream)
307 struct conexant_spec *spec = codec->spec;
308 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
309 spec->cur_adc_stream_tag = stream_tag;
310 spec->cur_adc_format = format;
311 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
315 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
316 struct hda_codec *codec,
317 struct snd_pcm_substream *substream)
319 struct conexant_spec *spec = codec->spec;
320 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
325 static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
329 .nid = 0, /* fill later */
331 .prepare = cx5051_capture_pcm_prepare,
332 .cleanup = cx5051_capture_pcm_cleanup
336 static int conexant_build_pcms(struct hda_codec *codec)
338 struct conexant_spec *spec = codec->spec;
339 struct hda_pcm *info = spec->pcm_rec;
342 codec->pcm_info = info;
344 info->name = "CONEXANT Analog";
345 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
346 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
347 spec->multiout.max_channels;
348 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
349 spec->multiout.dac_nids[0];
350 if (spec->capture_stream)
351 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
353 if (codec->vendor_id == 0x14f15051)
354 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
355 cx5051_pcm_analog_capture;
357 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
358 conexant_pcm_analog_capture;
359 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
363 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
365 if (spec->multiout.dig_out_nid) {
368 info->name = "Conexant Digital";
369 info->pcm_type = HDA_PCM_TYPE_SPDIF;
370 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
371 conexant_pcm_digital_playback;
372 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
373 spec->multiout.dig_out_nid;
374 if (spec->dig_in_nid) {
375 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
376 conexant_pcm_digital_capture;
377 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
380 if (spec->slave_dig_outs[0])
381 codec->slave_dig_outs = spec->slave_dig_outs;
387 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
388 struct snd_ctl_elem_info *uinfo)
390 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
391 struct conexant_spec *spec = codec->spec;
393 return snd_hda_input_mux_info(spec->input_mux, uinfo);
396 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
397 struct snd_ctl_elem_value *ucontrol)
399 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
400 struct conexant_spec *spec = codec->spec;
401 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
403 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
407 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
408 struct snd_ctl_elem_value *ucontrol)
410 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
411 struct conexant_spec *spec = codec->spec;
412 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
414 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
415 spec->capsrc_nids[adc_idx],
416 &spec->cur_mux[adc_idx]);
419 static int conexant_init_jacks(struct hda_codec *codec)
421 #ifdef CONFIG_SND_HDA_INPUT_JACK
422 struct conexant_spec *spec = codec->spec;
425 for (i = 0; i < spec->num_init_verbs; i++) {
426 const struct hda_verb *hv;
428 hv = spec->init_verbs[i];
431 switch (hv->param ^ AC_USRSP_EN) {
432 case CONEXANT_HP_EVENT:
433 err = snd_hda_input_jack_add(codec, hv->nid,
434 SND_JACK_HEADPHONE, NULL);
435 snd_hda_input_jack_report(codec, hv->nid);
437 case CXT5051_PORTC_EVENT:
438 case CONEXANT_MIC_EVENT:
439 err = snd_hda_input_jack_add(codec, hv->nid,
440 SND_JACK_MICROPHONE, NULL);
441 snd_hda_input_jack_report(codec, hv->nid);
449 #endif /* CONFIG_SND_HDA_INPUT_JACK */
453 static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
454 unsigned int power_state)
456 if (power_state == AC_PWRST_D3)
458 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
460 /* partial workaround for "azx_get_response timeout" */
461 if (power_state == AC_PWRST_D0)
463 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
466 static int conexant_init(struct hda_codec *codec)
468 struct conexant_spec *spec = codec->spec;
471 for (i = 0; i < spec->num_init_verbs; i++)
472 snd_hda_sequence_write(codec, spec->init_verbs[i]);
476 static void conexant_free(struct hda_codec *codec)
478 snd_hda_input_jack_free(codec);
479 snd_hda_detach_beep_device(codec);
483 static const struct snd_kcontrol_new cxt_capture_mixers[] = {
485 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
486 .name = "Capture Source",
487 .info = conexant_mux_enum_info,
488 .get = conexant_mux_enum_get,
489 .put = conexant_mux_enum_put
494 #ifdef CONFIG_SND_HDA_INPUT_BEEP
495 /* additional beep mixers; the actual parameters are overwritten at build */
496 static const struct snd_kcontrol_new cxt_beep_mixer[] = {
497 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
498 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
503 static const char * const slave_vols[] = {
504 "Headphone Playback Volume",
505 "Speaker Playback Volume",
506 "Front Playback Volume",
507 "Surround Playback Volume",
508 "CLFE Playback Volume",
512 static const char * const slave_sws[] = {
513 "Headphone Playback Switch",
514 "Speaker Playback Switch",
515 "Front Playback Switch",
516 "Surround Playback Switch",
517 "CLFE Playback Switch",
521 static int conexant_build_controls(struct hda_codec *codec)
523 struct conexant_spec *spec = codec->spec;
527 for (i = 0; i < spec->num_mixers; i++) {
528 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
532 if (spec->multiout.dig_out_nid) {
533 err = snd_hda_create_spdif_out_ctls(codec,
534 spec->multiout.dig_out_nid,
535 spec->multiout.dig_out_nid);
538 err = snd_hda_create_spdif_share_sw(codec,
542 spec->multiout.share_spdif = 1;
544 if (spec->dig_in_nid) {
545 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
550 /* if we have no master control, let's create it */
551 if (spec->vmaster_nid &&
552 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
553 unsigned int vmaster_tlv[4];
554 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
555 HDA_OUTPUT, vmaster_tlv);
556 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
557 vmaster_tlv, slave_vols);
561 if (spec->vmaster_nid &&
562 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
563 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
569 if (spec->input_mux) {
570 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
575 #ifdef CONFIG_SND_HDA_INPUT_BEEP
576 /* create beep controls if needed */
577 if (spec->beep_amp) {
578 const struct snd_kcontrol_new *knew;
579 for (knew = cxt_beep_mixer; knew->name; knew++) {
580 struct snd_kcontrol *kctl;
581 kctl = snd_ctl_new1(knew, codec);
584 kctl->private_value = spec->beep_amp;
585 err = snd_hda_ctl_add(codec, 0, kctl);
595 static const struct hda_codec_ops conexant_patch_ops = {
596 .build_controls = conexant_build_controls,
597 .build_pcms = conexant_build_pcms,
598 .init = conexant_init,
599 .free = conexant_free,
600 .set_power_state = conexant_set_power,
603 #ifdef CONFIG_SND_HDA_INPUT_BEEP
604 #define set_beep_amp(spec, nid, idx, dir) \
605 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
607 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
610 static int patch_conexant_auto(struct hda_codec *codec);
613 * the private value = nid | (invert << 8)
616 #define cxt_eapd_info snd_ctl_boolean_mono_info
618 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
619 struct snd_ctl_elem_value *ucontrol)
621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
622 struct conexant_spec *spec = codec->spec;
623 int invert = (kcontrol->private_value >> 8) & 1;
625 ucontrol->value.integer.value[0] = !spec->cur_eapd;
627 ucontrol->value.integer.value[0] = spec->cur_eapd;
632 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_value *ucontrol)
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct conexant_spec *spec = codec->spec;
637 int invert = (kcontrol->private_value >> 8) & 1;
638 hda_nid_t nid = kcontrol->private_value & 0xff;
641 eapd = !!ucontrol->value.integer.value[0];
644 if (eapd == spec->cur_eapd)
647 spec->cur_eapd = eapd;
648 snd_hda_codec_write_cache(codec, nid,
649 0, AC_VERB_SET_EAPD_BTLENABLE,
654 /* controls for test mode */
655 #ifdef CONFIG_SND_DEBUG
657 #define CXT_EAPD_SWITCH(xname, nid, mask) \
658 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
659 .info = cxt_eapd_info, \
660 .get = cxt_eapd_get, \
661 .put = cxt_eapd_put, \
662 .private_value = nid | (mask<<16) }
666 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_info *uinfo)
669 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670 struct conexant_spec *spec = codec->spec;
671 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
672 spec->num_channel_mode);
675 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
676 struct snd_ctl_elem_value *ucontrol)
678 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
679 struct conexant_spec *spec = codec->spec;
680 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
681 spec->num_channel_mode,
682 spec->multiout.max_channels);
685 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
686 struct snd_ctl_elem_value *ucontrol)
688 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
689 struct conexant_spec *spec = codec->spec;
690 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
691 spec->num_channel_mode,
692 &spec->multiout.max_channels);
693 if (err >= 0 && spec->need_dac_fix)
694 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
698 #define CXT_PIN_MODE(xname, nid, dir) \
699 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
700 .info = conexant_ch_mode_info, \
701 .get = conexant_ch_mode_get, \
702 .put = conexant_ch_mode_put, \
703 .private_value = nid | (dir<<16) }
705 #endif /* CONFIG_SND_DEBUG */
707 /* Conexant 5045 specific */
709 static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
710 static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
711 static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
712 #define CXT5045_SPDIF_OUT 0x18
714 static const struct hda_channel_mode cxt5045_modes[1] = {
718 static const struct hda_input_mux cxt5045_capture_source = {
726 static const struct hda_input_mux cxt5045_capture_source_benq = {
737 static const struct hda_input_mux cxt5045_capture_source_hp530 = {
745 /* turn on/off EAPD (+ mute HP) as a master switch */
746 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
747 struct snd_ctl_elem_value *ucontrol)
749 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
750 struct conexant_spec *spec = codec->spec;
753 if (!cxt_eapd_put(kcontrol, ucontrol))
756 /* toggle internal speakers mute depending of presence of
759 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
760 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
763 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
764 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
769 /* bind volumes of both NID 0x10 and 0x11 */
770 static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
771 .ops = &snd_hda_bind_vol,
773 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
774 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
779 /* toggle input of built-in and mic jack appropriately */
780 static void cxt5045_hp_automic(struct hda_codec *codec)
782 static const struct hda_verb mic_jack_on[] = {
783 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
784 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
787 static const struct hda_verb mic_jack_off[] = {
788 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
789 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
792 unsigned int present;
794 present = snd_hda_jack_detect(codec, 0x12);
796 snd_hda_sequence_write(codec, mic_jack_on);
798 snd_hda_sequence_write(codec, mic_jack_off);
802 /* mute internal speaker if HP is plugged */
803 static void cxt5045_hp_automute(struct hda_codec *codec)
805 struct conexant_spec *spec = codec->spec;
808 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
810 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
811 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
815 /* unsolicited event for HP jack sensing */
816 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
821 case CONEXANT_HP_EVENT:
822 cxt5045_hp_automute(codec);
824 case CONEXANT_MIC_EVENT:
825 cxt5045_hp_automic(codec);
831 static const struct snd_kcontrol_new cxt5045_mixers[] = {
832 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
833 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
834 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
835 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
836 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
837 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
838 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
839 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
840 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
841 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
842 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
844 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
845 .name = "Master Playback Switch",
846 .info = cxt_eapd_info,
848 .put = cxt5045_hp_master_sw_put,
849 .private_value = 0x10,
855 static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
856 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
857 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
858 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
859 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
861 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
862 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
863 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
864 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
866 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
867 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
872 static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
873 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
874 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
875 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
876 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
877 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
878 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
879 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
880 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
881 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
882 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
883 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
885 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
886 .name = "Master Playback Switch",
887 .info = cxt_eapd_info,
889 .put = cxt5045_hp_master_sw_put,
890 .private_value = 0x10,
896 static const struct hda_verb cxt5045_init_verbs[] = {
898 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
899 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
901 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
902 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
903 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
904 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
905 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
906 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
907 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
908 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
909 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
910 /* Record selector: Internal mic */
911 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
912 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
913 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
914 /* SPDIF route: PCM */
915 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
916 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
918 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
922 static const struct hda_verb cxt5045_benq_init_verbs[] = {
923 /* Internal Mic, Mic */
924 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
925 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
926 /* Line In,HP, Amp */
927 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
928 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
929 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
930 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
931 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
932 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
933 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
934 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
935 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
936 /* Record selector: Internal mic */
937 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
938 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
939 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
940 /* SPDIF route: PCM */
941 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
942 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
944 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
948 static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
949 /* pin sensing on HP jack */
950 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
954 static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
955 /* pin sensing on HP jack */
956 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
960 #ifdef CONFIG_SND_DEBUG
961 /* Test configuration for debugging, modelled after the ALC260 test
964 static const struct hda_input_mux cxt5045_test_capture_source = {
969 { "LINE1 pin", 0x2 },
970 { "HP-OUT pin", 0x3 },
975 static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
977 /* Output controls */
978 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
979 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
980 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
981 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
982 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
983 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
985 /* Modes for retasking pin widgets */
986 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
987 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
989 /* EAPD Switch Control */
990 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
992 /* Loopback mixer controls */
994 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
995 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
996 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
997 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
998 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
999 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1000 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1001 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1002 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1003 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
1005 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1006 .name = "Input Source",
1007 .info = conexant_mux_enum_info,
1008 .get = conexant_mux_enum_get,
1009 .put = conexant_mux_enum_put,
1011 /* Audio input controls */
1012 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1013 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1014 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1015 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1016 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1017 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1018 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1019 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1020 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1021 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1025 static const struct hda_verb cxt5045_test_init_verbs[] = {
1026 /* Set connections */
1027 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1028 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1029 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1030 /* Enable retasking pins as output, initially without power amp */
1031 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1032 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1034 /* Disable digital (SPDIF) pins initially, but users can enable
1035 * them via a mixer switch. In the case of SPDIF-out, this initverb
1036 * payload also sets the generation to 0, output to be in "consumer"
1037 * PCM format, copyright asserted, no pre-emphasis and no validity
1040 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1041 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1043 /* Start with output sum widgets muted and their output gains at min */
1044 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1045 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1047 /* Unmute retasking pin widget output buffers since the default
1048 * state appears to be output. As the pin mode is changed by the
1049 * user the pin mode control will take care of enabling the pin's
1050 * input/output buffers as needed.
1052 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1053 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1055 /* Mute capture amp left and right */
1056 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1058 /* Set ADC connection select to match default mixer setting (mic1
1061 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1062 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1064 /* Mute all inputs to mixer widget (even unconnected ones) */
1065 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1066 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1067 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1068 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1069 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1076 /* initialize jack-sensing, too */
1077 static int cxt5045_init(struct hda_codec *codec)
1079 conexant_init(codec);
1080 cxt5045_hp_automute(codec);
1086 CXT5045_LAPTOP_HPSENSE,
1087 CXT5045_LAPTOP_MICSENSE,
1088 CXT5045_LAPTOP_HPMICSENSE,
1090 CXT5045_LAPTOP_HP530,
1091 #ifdef CONFIG_SND_DEBUG
1098 static const char * const cxt5045_models[CXT5045_MODELS] = {
1099 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1100 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1101 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1102 [CXT5045_BENQ] = "benq",
1103 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1104 #ifdef CONFIG_SND_DEBUG
1105 [CXT5045_TEST] = "test",
1107 [CXT5045_AUTO] = "auto",
1110 static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1111 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1112 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1113 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1114 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1115 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1116 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1117 CXT5045_LAPTOP_HPMICSENSE),
1118 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1119 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1120 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1121 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1122 CXT5045_LAPTOP_HPMICSENSE),
1123 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1127 static int patch_cxt5045(struct hda_codec *codec)
1129 struct conexant_spec *spec;
1132 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1135 if (board_config < 0)
1136 board_config = CXT5045_AUTO; /* model=auto as default */
1137 if (board_config == CXT5045_AUTO)
1138 return patch_conexant_auto(codec);
1140 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1144 codec->pin_amp_workaround = 1;
1146 spec->multiout.max_channels = 2;
1147 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1148 spec->multiout.dac_nids = cxt5045_dac_nids;
1149 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1150 spec->num_adc_nids = 1;
1151 spec->adc_nids = cxt5045_adc_nids;
1152 spec->capsrc_nids = cxt5045_capsrc_nids;
1153 spec->input_mux = &cxt5045_capture_source;
1154 spec->num_mixers = 1;
1155 spec->mixers[0] = cxt5045_mixers;
1156 spec->num_init_verbs = 1;
1157 spec->init_verbs[0] = cxt5045_init_verbs;
1158 spec->spdif_route = 0;
1159 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1160 spec->channel_mode = cxt5045_modes;
1162 set_beep_amp(spec, 0x16, 0, 1);
1164 codec->patch_ops = conexant_patch_ops;
1166 switch (board_config) {
1167 case CXT5045_LAPTOP_HPSENSE:
1168 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1169 spec->input_mux = &cxt5045_capture_source;
1170 spec->num_init_verbs = 2;
1171 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1172 spec->mixers[0] = cxt5045_mixers;
1173 codec->patch_ops.init = cxt5045_init;
1175 case CXT5045_LAPTOP_MICSENSE:
1176 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1177 spec->input_mux = &cxt5045_capture_source;
1178 spec->num_init_verbs = 2;
1179 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1180 spec->mixers[0] = cxt5045_mixers;
1181 codec->patch_ops.init = cxt5045_init;
1184 case CXT5045_LAPTOP_HPMICSENSE:
1185 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1186 spec->input_mux = &cxt5045_capture_source;
1187 spec->num_init_verbs = 3;
1188 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1189 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1190 spec->mixers[0] = cxt5045_mixers;
1191 codec->patch_ops.init = cxt5045_init;
1194 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1195 spec->input_mux = &cxt5045_capture_source_benq;
1196 spec->num_init_verbs = 1;
1197 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1198 spec->mixers[0] = cxt5045_mixers;
1199 spec->mixers[1] = cxt5045_benq_mixers;
1200 spec->num_mixers = 2;
1201 codec->patch_ops.init = cxt5045_init;
1203 case CXT5045_LAPTOP_HP530:
1204 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1205 spec->input_mux = &cxt5045_capture_source_hp530;
1206 spec->num_init_verbs = 2;
1207 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1208 spec->mixers[0] = cxt5045_mixers_hp530;
1209 codec->patch_ops.init = cxt5045_init;
1211 #ifdef CONFIG_SND_DEBUG
1213 spec->input_mux = &cxt5045_test_capture_source;
1214 spec->mixers[0] = cxt5045_test_mixer;
1215 spec->init_verbs[0] = cxt5045_test_init_verbs;
1221 switch (codec->subsystem_id >> 16) {
1226 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1227 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1228 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1230 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1231 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1232 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1233 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1234 (1 << AC_AMPCAP_MUTE_SHIFT));
1239 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
1245 /* Conexant 5047 specific */
1246 #define CXT5047_SPDIF_OUT 0x11
1248 static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1249 static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1250 static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1252 static const struct hda_channel_mode cxt5047_modes[1] = {
1256 static const struct hda_input_mux cxt5047_toshiba_capture_source = {
1264 /* turn on/off EAPD (+ mute HP) as a master switch */
1265 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1266 struct snd_ctl_elem_value *ucontrol)
1268 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1269 struct conexant_spec *spec = codec->spec;
1272 if (!cxt_eapd_put(kcontrol, ucontrol))
1275 /* toggle internal speakers mute depending of presence of
1276 * the headphone jack
1278 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1279 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1280 * pin widgets unlike other codecs. In this case, we need to
1281 * set index 0x01 for the volume from the mixer amp 0x19.
1283 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1284 HDA_AMP_MUTE, bits);
1285 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1286 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1287 HDA_AMP_MUTE, bits);
1291 /* mute internal speaker if HP is plugged */
1292 static void cxt5047_hp_automute(struct hda_codec *codec)
1294 struct conexant_spec *spec = codec->spec;
1297 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1299 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1300 /* See the note in cxt5047_hp_master_sw_put */
1301 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1302 HDA_AMP_MUTE, bits);
1305 /* toggle input of built-in and mic jack appropriately */
1306 static void cxt5047_hp_automic(struct hda_codec *codec)
1308 static const struct hda_verb mic_jack_on[] = {
1309 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1310 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1313 static const struct hda_verb mic_jack_off[] = {
1314 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1315 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1318 unsigned int present;
1320 present = snd_hda_jack_detect(codec, 0x15);
1322 snd_hda_sequence_write(codec, mic_jack_on);
1324 snd_hda_sequence_write(codec, mic_jack_off);
1327 /* unsolicited event for HP jack sensing */
1328 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1331 switch (res >> 26) {
1332 case CONEXANT_HP_EVENT:
1333 cxt5047_hp_automute(codec);
1335 case CONEXANT_MIC_EVENT:
1336 cxt5047_hp_automic(codec);
1341 static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1342 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1343 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1344 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1345 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1346 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1347 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1348 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1350 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1351 .name = "Master Playback Switch",
1352 .info = cxt_eapd_info,
1353 .get = cxt_eapd_get,
1354 .put = cxt5047_hp_master_sw_put,
1355 .private_value = 0x13,
1361 static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1362 /* See the note in cxt5047_hp_master_sw_put */
1363 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1364 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1368 static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1369 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1373 static const struct hda_verb cxt5047_init_verbs[] = {
1374 /* Line in, Mic, Built-in Mic */
1375 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1376 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1377 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1379 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1380 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1381 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1382 /* Record selector: Mic */
1383 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1384 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1385 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1386 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1387 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1388 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1389 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1390 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1391 /* SPDIF route: PCM */
1392 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1393 /* Enable unsolicited events */
1394 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1395 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1399 /* configuration for Toshiba Laptops */
1400 static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
1401 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1405 /* Test configuration for debugging, modelled after the ALC260 test
1408 #ifdef CONFIG_SND_DEBUG
1409 static const struct hda_input_mux cxt5047_test_capture_source = {
1412 { "LINE1 pin", 0x0 },
1413 { "MIC1 pin", 0x1 },
1414 { "MIC2 pin", 0x2 },
1419 static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1421 /* Output only controls */
1422 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1423 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1424 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1425 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1426 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1427 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1428 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1429 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1431 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1432 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1433 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1435 /* Modes for retasking pin widgets */
1436 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1437 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1439 /* EAPD Switch Control */
1440 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1442 /* Loopback mixer controls */
1443 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1444 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1445 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1446 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1447 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1448 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1449 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1450 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1452 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1453 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1454 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1455 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1456 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1457 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1458 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1459 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1462 .name = "Input Source",
1463 .info = conexant_mux_enum_info,
1464 .get = conexant_mux_enum_get,
1465 .put = conexant_mux_enum_put,
1467 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1472 static const struct hda_verb cxt5047_test_init_verbs[] = {
1473 /* Enable retasking pins as output, initially without power amp */
1474 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1475 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1476 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1478 /* Disable digital (SPDIF) pins initially, but users can enable
1479 * them via a mixer switch. In the case of SPDIF-out, this initverb
1480 * payload also sets the generation to 0, output to be in "consumer"
1481 * PCM format, copyright asserted, no pre-emphasis and no validity
1484 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1486 /* Ensure mic1, mic2, line1 pin widgets take input from the
1487 * OUT1 sum bus when acting as an output.
1489 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1490 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1492 /* Start with output sum widgets muted and their output gains at min */
1493 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1494 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1496 /* Unmute retasking pin widget output buffers since the default
1497 * state appears to be output. As the pin mode is changed by the
1498 * user the pin mode control will take care of enabling the pin's
1499 * input/output buffers as needed.
1501 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1502 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1503 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1505 /* Mute capture amp left and right */
1506 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1508 /* Set ADC connection select to match default mixer setting (mic1
1511 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1513 /* Mute all inputs to mixer widget (even unconnected ones) */
1514 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1515 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1516 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1517 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1518 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1519 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1520 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1521 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1528 /* initialize jack-sensing, too */
1529 static int cxt5047_hp_init(struct hda_codec *codec)
1531 conexant_init(codec);
1532 cxt5047_hp_automute(codec);
1538 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1539 CXT5047_LAPTOP_HP, /* Some HP laptops */
1540 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1541 #ifdef CONFIG_SND_DEBUG
1548 static const char * const cxt5047_models[CXT5047_MODELS] = {
1549 [CXT5047_LAPTOP] = "laptop",
1550 [CXT5047_LAPTOP_HP] = "laptop-hp",
1551 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1552 #ifdef CONFIG_SND_DEBUG
1553 [CXT5047_TEST] = "test",
1555 [CXT5047_AUTO] = "auto",
1558 static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1559 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1560 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1562 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1566 static int patch_cxt5047(struct hda_codec *codec)
1568 struct conexant_spec *spec;
1571 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1574 if (board_config < 0)
1575 board_config = CXT5047_AUTO; /* model=auto as default */
1576 if (board_config == CXT5047_AUTO)
1577 return patch_conexant_auto(codec);
1579 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1583 codec->pin_amp_workaround = 1;
1585 spec->multiout.max_channels = 2;
1586 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1587 spec->multiout.dac_nids = cxt5047_dac_nids;
1588 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1589 spec->num_adc_nids = 1;
1590 spec->adc_nids = cxt5047_adc_nids;
1591 spec->capsrc_nids = cxt5047_capsrc_nids;
1592 spec->num_mixers = 1;
1593 spec->mixers[0] = cxt5047_base_mixers;
1594 spec->num_init_verbs = 1;
1595 spec->init_verbs[0] = cxt5047_init_verbs;
1596 spec->spdif_route = 0;
1597 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1598 spec->channel_mode = cxt5047_modes,
1600 codec->patch_ops = conexant_patch_ops;
1602 switch (board_config) {
1603 case CXT5047_LAPTOP:
1604 spec->num_mixers = 2;
1605 spec->mixers[1] = cxt5047_hp_spk_mixers;
1606 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1608 case CXT5047_LAPTOP_HP:
1609 spec->num_mixers = 2;
1610 spec->mixers[1] = cxt5047_hp_only_mixers;
1611 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1612 codec->patch_ops.init = cxt5047_hp_init;
1614 case CXT5047_LAPTOP_EAPD:
1615 spec->input_mux = &cxt5047_toshiba_capture_source;
1616 spec->num_mixers = 2;
1617 spec->mixers[1] = cxt5047_hp_spk_mixers;
1618 spec->num_init_verbs = 2;
1619 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1620 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1622 #ifdef CONFIG_SND_DEBUG
1624 spec->input_mux = &cxt5047_test_capture_source;
1625 spec->mixers[0] = cxt5047_test_mixer;
1626 spec->init_verbs[0] = cxt5047_test_init_verbs;
1627 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1630 spec->vmaster_nid = 0x13;
1632 switch (codec->subsystem_id >> 16) {
1634 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1635 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1636 * with 0 dB offset 0x17)
1638 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1639 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1640 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1641 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1642 (1 << AC_AMPCAP_MUTE_SHIFT));
1649 /* Conexant 5051 specific */
1650 static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1651 static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1653 static const struct hda_channel_mode cxt5051_modes[1] = {
1657 static void cxt5051_update_speaker(struct hda_codec *codec)
1659 struct conexant_spec *spec = codec->spec;
1660 unsigned int pinctl;
1662 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1663 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1666 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1667 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1669 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1671 snd_hda_codec_write(codec, 0x1b, 0,
1672 AC_VERB_SET_PIN_WIDGET_CONTROL,
1676 /* turn on/off EAPD (+ mute HP) as a master switch */
1677 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1678 struct snd_ctl_elem_value *ucontrol)
1680 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1682 if (!cxt_eapd_put(kcontrol, ucontrol))
1684 cxt5051_update_speaker(codec);
1688 /* toggle input of built-in and mic jack appropriately */
1689 static void cxt5051_portb_automic(struct hda_codec *codec)
1691 struct conexant_spec *spec = codec->spec;
1692 unsigned int present;
1694 if (!(spec->auto_mic & AUTO_MIC_PORTB))
1696 present = snd_hda_jack_detect(codec, 0x17);
1697 snd_hda_codec_write(codec, 0x14, 0,
1698 AC_VERB_SET_CONNECT_SEL,
1699 present ? 0x01 : 0x00);
1702 /* switch the current ADC according to the jack state */
1703 static void cxt5051_portc_automic(struct hda_codec *codec)
1705 struct conexant_spec *spec = codec->spec;
1706 unsigned int present;
1709 if (!(spec->auto_mic & AUTO_MIC_PORTC))
1711 present = snd_hda_jack_detect(codec, 0x18);
1713 spec->cur_adc_idx = 1;
1715 spec->cur_adc_idx = 0;
1716 new_adc = spec->adc_nids[spec->cur_adc_idx];
1717 if (spec->cur_adc && spec->cur_adc != new_adc) {
1718 /* stream is running, let's swap the current ADC */
1719 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1720 spec->cur_adc = new_adc;
1721 snd_hda_codec_setup_stream(codec, new_adc,
1722 spec->cur_adc_stream_tag, 0,
1723 spec->cur_adc_format);
1727 /* mute internal speaker if HP is plugged */
1728 static void cxt5051_hp_automute(struct hda_codec *codec)
1730 struct conexant_spec *spec = codec->spec;
1732 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1733 cxt5051_update_speaker(codec);
1736 /* unsolicited event for HP jack sensing */
1737 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1740 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1741 switch (res >> 26) {
1742 case CONEXANT_HP_EVENT:
1743 cxt5051_hp_automute(codec);
1745 case CXT5051_PORTB_EVENT:
1746 cxt5051_portb_automic(codec);
1748 case CXT5051_PORTC_EVENT:
1749 cxt5051_portc_automic(codec);
1752 snd_hda_input_jack_report(codec, nid);
1755 static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1756 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1758 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1759 .name = "Master Playback Switch",
1760 .info = cxt_eapd_info,
1761 .get = cxt_eapd_get,
1762 .put = cxt5051_hp_master_sw_put,
1763 .private_value = 0x1a,
1768 static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1769 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1770 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1771 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1772 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1773 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1774 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1778 static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1779 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1780 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1781 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1782 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1786 static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1787 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1788 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
1792 static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1793 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1794 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1798 static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1799 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1800 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1801 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1802 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1806 static const struct hda_verb cxt5051_init_verbs[] = {
1808 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1809 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1810 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1811 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1812 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1813 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1815 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1816 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1818 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1819 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1821 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1822 /* Record selector: Internal mic */
1823 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1824 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1825 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1826 /* SPDIF route: PCM */
1827 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1828 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1830 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1831 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1835 static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1837 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1838 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1839 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1840 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1842 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1843 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1845 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1846 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1848 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1849 /* Record selector: Internal mic */
1850 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1851 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1852 /* SPDIF route: PCM */
1853 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1855 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1856 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1860 static const struct hda_verb cxt5051_f700_init_verbs[] = {
1862 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1863 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1864 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1865 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1867 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1868 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1870 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1871 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1873 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1874 /* Record selector: Internal mic */
1875 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1876 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1877 /* SPDIF route: PCM */
1878 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1880 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1881 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1885 static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1888 snd_hda_codec_write(codec, nid, 0,
1889 AC_VERB_SET_UNSOLICITED_ENABLE,
1890 AC_USRSP_EN | event);
1893 static void cxt5051_init_mic_jack(struct hda_codec *codec, hda_nid_t nid)
1895 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1896 snd_hda_input_jack_report(codec, nid);
1899 static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1901 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1902 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1906 /* initialize jack-sensing, too */
1907 static int cxt5051_init(struct hda_codec *codec)
1909 struct conexant_spec *spec = codec->spec;
1911 conexant_init(codec);
1913 if (spec->auto_mic & AUTO_MIC_PORTB)
1914 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1915 if (spec->auto_mic & AUTO_MIC_PORTC)
1916 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1918 if (codec->patch_ops.unsol_event) {
1919 cxt5051_hp_automute(codec);
1920 cxt5051_portb_automic(codec);
1921 cxt5051_portc_automic(codec);
1928 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1929 CXT5051_HP, /* no docking */
1930 CXT5051_HP_DV6736, /* HP without mic switch */
1931 CXT5051_F700, /* HP Compaq Presario F700 */
1932 CXT5051_TOSHIBA, /* Toshiba M300 & co */
1933 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
1934 CXT5051_AUTO, /* auto-parser */
1938 static const char *const cxt5051_models[CXT5051_MODELS] = {
1939 [CXT5051_LAPTOP] = "laptop",
1940 [CXT5051_HP] = "hp",
1941 [CXT5051_HP_DV6736] = "hp-dv6736",
1942 [CXT5051_F700] = "hp-700",
1943 [CXT5051_TOSHIBA] = "toshiba",
1944 [CXT5051_IDEAPAD] = "ideapad",
1945 [CXT5051_AUTO] = "auto",
1948 static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1949 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1950 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1951 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1952 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1953 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1955 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1956 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1960 static int patch_cxt5051(struct hda_codec *codec)
1962 struct conexant_spec *spec;
1965 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1968 if (board_config < 0)
1969 board_config = CXT5051_AUTO; /* model=auto as default */
1970 if (board_config == CXT5051_AUTO)
1971 return patch_conexant_auto(codec);
1973 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1977 codec->pin_amp_workaround = 1;
1979 codec->patch_ops = conexant_patch_ops;
1980 codec->patch_ops.init = cxt5051_init;
1982 spec->multiout.max_channels = 2;
1983 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1984 spec->multiout.dac_nids = cxt5051_dac_nids;
1985 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1986 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1987 spec->adc_nids = cxt5051_adc_nids;
1988 spec->num_mixers = 2;
1989 spec->mixers[0] = cxt5051_capture_mixers;
1990 spec->mixers[1] = cxt5051_playback_mixers;
1991 spec->num_init_verbs = 1;
1992 spec->init_verbs[0] = cxt5051_init_verbs;
1993 spec->spdif_route = 0;
1994 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1995 spec->channel_mode = cxt5051_modes;
1997 spec->cur_adc_idx = 0;
1999 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2001 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2003 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
2004 switch (board_config) {
2006 spec->mixers[0] = cxt5051_hp_mixers;
2008 case CXT5051_HP_DV6736:
2009 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2010 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2014 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2015 spec->mixers[0] = cxt5051_f700_mixers;
2018 case CXT5051_TOSHIBA:
2019 spec->mixers[0] = cxt5051_toshiba_mixers;
2020 spec->auto_mic = AUTO_MIC_PORTB;
2022 case CXT5051_IDEAPAD:
2023 spec->init_verbs[spec->num_init_verbs++] =
2024 cxt5051_ideapad_init_verbs;
2030 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
2032 conexant_init_jacks(codec);
2033 if (spec->auto_mic & AUTO_MIC_PORTB)
2034 cxt5051_init_mic_jack(codec, 0x17);
2035 if (spec->auto_mic & AUTO_MIC_PORTC)
2036 cxt5051_init_mic_jack(codec, 0x18);
2041 /* Conexant 5066 specific */
2043 static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2044 static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2045 static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2046 static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
2048 /* OLPC's microphone port is DC coupled for use with external sensors,
2049 * therefore we use a 50% mic bias in order to center the input signal with
2050 * the DC input range of the codec. */
2051 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2053 static const struct hda_channel_mode cxt5066_modes[1] = {
2057 #define HP_PRESENT_PORT_A (1 << 0)
2058 #define HP_PRESENT_PORT_D (1 << 1)
2059 #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2060 #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2062 static void cxt5066_update_speaker(struct hda_codec *codec)
2064 struct conexant_spec *spec = codec->spec;
2065 unsigned int pinctl;
2067 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2068 spec->hp_present, spec->cur_eapd);
2071 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
2072 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2075 /* Port D (HP/LO) */
2076 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2077 if (spec->dell_automute || spec->thinkpad) {
2078 /* Mute if Port A is connected */
2079 if (hp_port_a_present(spec))
2082 /* Thinkpad/Dell doesn't give pin-D status */
2083 if (!hp_port_d_present(spec))
2086 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2090 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2091 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2095 /* turn on/off EAPD (+ mute HP) as a master switch */
2096 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2097 struct snd_ctl_elem_value *ucontrol)
2099 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2101 if (!cxt_eapd_put(kcontrol, ucontrol))
2104 cxt5066_update_speaker(codec);
2108 static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2112 { "50%", PIN_VREF50 },
2113 { "80%", PIN_VREF80 },
2117 static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2119 struct conexant_spec *spec = codec->spec;
2120 /* Even though port F is the DC input, the bias is controlled on port B.
2121 * we also leave that port as an active input (but unselected) in DC mode
2122 * just in case that is necessary to make the bias setting take effect. */
2123 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2124 AC_VERB_SET_PIN_WIDGET_CONTROL,
2125 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2128 /* OLPC defers mic widget control until when capture is started because the
2129 * microphone LED comes on as soon as these settings are put in place. if we
2130 * did this before recording, it would give the false indication that recording
2131 * is happening when it is not. */
2132 static void cxt5066_olpc_select_mic(struct hda_codec *codec)
2134 struct conexant_spec *spec = codec->spec;
2135 if (!spec->recording)
2138 if (spec->dc_enable) {
2139 /* in DC mode we ignore presence detection and just use the jack
2140 * through our special DC port */
2141 const struct hda_verb enable_dc_mode[] = {
2142 /* disble internal mic, port C */
2143 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2145 /* enable DC capture, port F */
2146 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2150 snd_hda_sequence_write(codec, enable_dc_mode);
2151 /* port B input disabled (and bias set) through the following call */
2152 cxt5066_set_olpc_dc_bias(codec);
2156 /* disable DC (port F) */
2157 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2159 /* external mic, port B */
2160 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2161 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
2163 /* internal mic, port C */
2164 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2165 spec->ext_mic_present ? 0 : PIN_VREF80);
2168 /* toggle input of built-in and mic jack appropriately */
2169 static void cxt5066_olpc_automic(struct hda_codec *codec)
2171 struct conexant_spec *spec = codec->spec;
2172 unsigned int present;
2174 if (spec->dc_enable) /* don't do presence detection in DC mode */
2177 present = snd_hda_codec_read(codec, 0x1a, 0,
2178 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2180 snd_printdd("CXT5066: external microphone detected\n");
2182 snd_printdd("CXT5066: external microphone absent\n");
2184 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2186 spec->ext_mic_present = !!present;
2188 cxt5066_olpc_select_mic(codec);
2191 /* toggle input of built-in digital mic and mic jack appropriately */
2192 static void cxt5066_vostro_automic(struct hda_codec *codec)
2194 unsigned int present;
2196 struct hda_verb ext_mic_present[] = {
2197 /* enable external mic, port B */
2198 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2200 /* switch to external mic input */
2201 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2202 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2204 /* disable internal digital mic */
2205 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2208 static const struct hda_verb ext_mic_absent[] = {
2209 /* enable internal mic, port C */
2210 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2212 /* switch to internal mic input */
2213 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2215 /* disable external mic, port B */
2216 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2220 present = snd_hda_jack_detect(codec, 0x1a);
2222 snd_printdd("CXT5066: external microphone detected\n");
2223 snd_hda_sequence_write(codec, ext_mic_present);
2225 snd_printdd("CXT5066: external microphone absent\n");
2226 snd_hda_sequence_write(codec, ext_mic_absent);
2230 /* toggle input of built-in digital mic and mic jack appropriately */
2231 static void cxt5066_ideapad_automic(struct hda_codec *codec)
2233 unsigned int present;
2235 struct hda_verb ext_mic_present[] = {
2236 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2237 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2238 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2241 static const struct hda_verb ext_mic_absent[] = {
2242 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2243 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2244 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2248 present = snd_hda_jack_detect(codec, 0x1b);
2250 snd_printdd("CXT5066: external microphone detected\n");
2251 snd_hda_sequence_write(codec, ext_mic_present);
2253 snd_printdd("CXT5066: external microphone absent\n");
2254 snd_hda_sequence_write(codec, ext_mic_absent);
2259 /* toggle input of built-in digital mic and mic jack appropriately */
2260 static void cxt5066_asus_automic(struct hda_codec *codec)
2262 unsigned int present;
2264 present = snd_hda_jack_detect(codec, 0x1b);
2265 snd_printdd("CXT5066: external microphone present=%d\n", present);
2266 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2271 /* toggle input of built-in digital mic and mic jack appropriately */
2272 static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2274 unsigned int present;
2276 present = snd_hda_jack_detect(codec, 0x1b);
2277 snd_printdd("CXT5066: external microphone present=%d\n", present);
2278 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2283 /* toggle input of built-in digital mic and mic jack appropriately
2284 order is: external mic -> dock mic -> interal mic */
2285 static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2287 unsigned int ext_present, dock_present;
2289 static const struct hda_verb ext_mic_present[] = {
2290 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2291 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2292 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2293 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2294 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2297 static const struct hda_verb dock_mic_present[] = {
2298 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2299 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2300 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2301 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2302 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2305 static const struct hda_verb ext_mic_absent[] = {
2306 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2307 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2308 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2309 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2313 ext_present = snd_hda_jack_detect(codec, 0x1b);
2314 dock_present = snd_hda_jack_detect(codec, 0x1a);
2316 snd_printdd("CXT5066: external microphone detected\n");
2317 snd_hda_sequence_write(codec, ext_mic_present);
2318 } else if (dock_present) {
2319 snd_printdd("CXT5066: dock microphone detected\n");
2320 snd_hda_sequence_write(codec, dock_mic_present);
2322 snd_printdd("CXT5066: external microphone absent\n");
2323 snd_hda_sequence_write(codec, ext_mic_absent);
2327 /* mute internal speaker if HP is plugged */
2328 static void cxt5066_hp_automute(struct hda_codec *codec)
2330 struct conexant_spec *spec = codec->spec;
2331 unsigned int portA, portD;
2334 portA = snd_hda_jack_detect(codec, 0x19);
2337 portD = snd_hda_jack_detect(codec, 0x1c);
2339 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2340 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
2341 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2342 portA, portD, spec->hp_present);
2343 cxt5066_update_speaker(codec);
2346 /* Dispatch the right mic autoswitch function */
2347 static void cxt5066_automic(struct hda_codec *codec)
2349 struct conexant_spec *spec = codec->spec;
2351 if (spec->dell_vostro)
2352 cxt5066_vostro_automic(codec);
2353 else if (spec->ideapad)
2354 cxt5066_ideapad_automic(codec);
2355 else if (spec->thinkpad)
2356 cxt5066_thinkpad_automic(codec);
2357 else if (spec->hp_laptop)
2358 cxt5066_hp_laptop_automic(codec);
2359 else if (spec->asus)
2360 cxt5066_asus_automic(codec);
2363 /* unsolicited event for jack sensing */
2364 static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
2366 struct conexant_spec *spec = codec->spec;
2367 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2368 switch (res >> 26) {
2369 case CONEXANT_HP_EVENT:
2370 cxt5066_hp_automute(codec);
2372 case CONEXANT_MIC_EVENT:
2373 /* ignore mic events in DC mode; we're always using the jack */
2374 if (!spec->dc_enable)
2375 cxt5066_olpc_automic(codec);
2380 /* unsolicited event for jack sensing */
2381 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2383 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2384 switch (res >> 26) {
2385 case CONEXANT_HP_EVENT:
2386 cxt5066_hp_automute(codec);
2388 case CONEXANT_MIC_EVENT:
2389 cxt5066_automic(codec);
2395 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2406 static void cxt5066_set_mic_boost(struct hda_codec *codec)
2408 struct conexant_spec *spec = codec->spec;
2409 snd_hda_codec_write_cache(codec, 0x17, 0,
2410 AC_VERB_SET_AMP_GAIN_MUTE,
2411 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2412 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
2413 if (spec->ideapad || spec->thinkpad) {
2414 /* adjust the internal mic as well...it is not through 0x17 */
2415 snd_hda_codec_write_cache(codec, 0x23, 0,
2416 AC_VERB_SET_AMP_GAIN_MUTE,
2417 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2418 cxt5066_analog_mic_boost.
2419 items[spec->mic_boost].index);
2423 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2424 struct snd_ctl_elem_info *uinfo)
2426 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2429 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2430 struct snd_ctl_elem_value *ucontrol)
2432 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2433 struct conexant_spec *spec = codec->spec;
2434 ucontrol->value.enumerated.item[0] = spec->mic_boost;
2438 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2439 struct snd_ctl_elem_value *ucontrol)
2441 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2442 struct conexant_spec *spec = codec->spec;
2443 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2445 idx = ucontrol->value.enumerated.item[0];
2446 if (idx >= imux->num_items)
2447 idx = imux->num_items - 1;
2449 spec->mic_boost = idx;
2450 if (!spec->dc_enable)
2451 cxt5066_set_mic_boost(codec);
2455 static void cxt5066_enable_dc(struct hda_codec *codec)
2457 const struct hda_verb enable_dc_mode[] = {
2459 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2461 /* switch to DC input */
2462 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2466 /* configure as input source */
2467 snd_hda_sequence_write(codec, enable_dc_mode);
2468 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2471 static void cxt5066_disable_dc(struct hda_codec *codec)
2473 /* reconfigure input source */
2474 cxt5066_set_mic_boost(codec);
2475 /* automic also selects the right mic if we're recording */
2476 cxt5066_olpc_automic(codec);
2479 static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2480 struct snd_ctl_elem_value *ucontrol)
2482 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2483 struct conexant_spec *spec = codec->spec;
2484 ucontrol->value.integer.value[0] = spec->dc_enable;
2488 static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2489 struct snd_ctl_elem_value *ucontrol)
2491 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2492 struct conexant_spec *spec = codec->spec;
2493 int dc_enable = !!ucontrol->value.integer.value[0];
2495 if (dc_enable == spec->dc_enable)
2498 spec->dc_enable = dc_enable;
2500 cxt5066_enable_dc(codec);
2502 cxt5066_disable_dc(codec);
2507 static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2508 struct snd_ctl_elem_info *uinfo)
2510 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2513 static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2514 struct snd_ctl_elem_value *ucontrol)
2516 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2517 struct conexant_spec *spec = codec->spec;
2518 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2522 static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2523 struct snd_ctl_elem_value *ucontrol)
2525 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2526 struct conexant_spec *spec = codec->spec;
2527 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2530 idx = ucontrol->value.enumerated.item[0];
2531 if (idx >= imux->num_items)
2532 idx = imux->num_items - 1;
2534 spec->dc_input_bias = idx;
2535 if (spec->dc_enable)
2536 cxt5066_set_olpc_dc_bias(codec);
2540 static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2542 struct conexant_spec *spec = codec->spec;
2543 /* mark as recording and configure the microphone widget so that the
2544 * recording LED comes on. */
2545 spec->recording = 1;
2546 cxt5066_olpc_select_mic(codec);
2549 static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2551 struct conexant_spec *spec = codec->spec;
2552 const struct hda_verb disable_mics[] = {
2553 /* disable external mic, port B */
2554 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2556 /* disble internal mic, port C */
2557 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2559 /* disable DC capture, port F */
2560 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2564 snd_hda_sequence_write(codec, disable_mics);
2565 spec->recording = 0;
2568 static void conexant_check_dig_outs(struct hda_codec *codec,
2569 const hda_nid_t *dig_pins,
2572 struct conexant_spec *spec = codec->spec;
2573 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2576 for (i = 0; i < num_pins; i++, dig_pins++) {
2577 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2578 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2580 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2582 if (spec->slave_dig_outs[0])
2585 nid_loc = spec->slave_dig_outs;
2589 static const struct hda_input_mux cxt5066_capture_source = {
2599 static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2600 .ops = &snd_hda_bind_vol,
2602 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2603 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2608 static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2609 .ops = &snd_hda_bind_sw,
2611 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2612 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2617 static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
2618 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2622 static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2625 .name = "Master Playback Volume",
2626 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2627 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2628 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2629 .subdevice = HDA_SUBDEV_AMP_FLAG,
2630 .info = snd_hda_mixer_amp_volume_info,
2631 .get = snd_hda_mixer_amp_volume_get,
2632 .put = snd_hda_mixer_amp_volume_put,
2633 .tlv = { .c = snd_hda_mixer_amp_tlv },
2634 /* offset by 28 volume steps to limit minimum gain to -46dB */
2636 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2641 static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2643 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2644 .name = "DC Mode Enable Switch",
2645 .info = snd_ctl_boolean_mono_info,
2646 .get = cxt5066_olpc_dc_get,
2647 .put = cxt5066_olpc_dc_put,
2650 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2651 .name = "DC Input Bias Enum",
2652 .info = cxt5066_olpc_dc_bias_enum_info,
2653 .get = cxt5066_olpc_dc_bias_enum_get,
2654 .put = cxt5066_olpc_dc_bias_enum_put,
2659 static const struct snd_kcontrol_new cxt5066_mixers[] = {
2661 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2662 .name = "Master Playback Switch",
2663 .info = cxt_eapd_info,
2664 .get = cxt_eapd_get,
2665 .put = cxt5066_hp_master_sw_put,
2666 .private_value = 0x1d,
2670 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2671 .name = "Analog Mic Boost Capture Enum",
2672 .info = cxt5066_mic_boost_mux_enum_info,
2673 .get = cxt5066_mic_boost_mux_enum_get,
2674 .put = cxt5066_mic_boost_mux_enum_put,
2677 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2678 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2682 static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2684 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2685 .name = "Internal Mic Boost Capture Enum",
2686 .info = cxt5066_mic_boost_mux_enum_info,
2687 .get = cxt5066_mic_boost_mux_enum_get,
2688 .put = cxt5066_mic_boost_mux_enum_put,
2689 .private_value = 0x23 | 0x100,
2694 static const struct hda_verb cxt5066_init_verbs[] = {
2695 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2696 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2697 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2698 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2701 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2702 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2705 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2706 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2708 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2709 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2712 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2714 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2715 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2716 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2717 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2718 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2719 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2721 /* no digital microphone support yet */
2722 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2724 /* Audio input selector */
2725 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2727 /* SPDIF route: PCM */
2728 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2729 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2731 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2732 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2735 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2737 /* not handling these yet */
2738 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2739 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2740 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2741 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2742 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2743 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2744 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2745 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2749 static const struct hda_verb cxt5066_init_verbs_olpc[] = {
2750 /* Port A: headphones */
2751 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2752 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2754 /* Port B: external microphone */
2755 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2757 /* Port C: internal microphone */
2758 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2760 /* Port D: unused */
2761 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2763 /* Port E: unused, but has primary EAPD */
2764 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2765 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2767 /* Port F: external DC input through microphone port */
2768 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2770 /* Port G: internal speakers */
2771 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2772 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2775 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2778 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2780 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2781 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2782 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2783 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2784 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2785 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2786 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2787 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2788 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2789 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2790 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2791 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2793 /* Disable digital microphone port */
2794 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2796 /* Audio input selectors */
2797 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2798 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2801 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2802 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2804 /* enable unsolicited events for Port A and B */
2805 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2806 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2810 static const struct hda_verb cxt5066_init_verbs_vostro[] = {
2811 /* Port A: headphones */
2812 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2813 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2815 /* Port B: external microphone */
2816 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2818 /* Port C: unused */
2819 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2821 /* Port D: unused */
2822 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2824 /* Port E: unused, but has primary EAPD */
2825 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2826 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2828 /* Port F: unused */
2829 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2831 /* Port G: internal speakers */
2832 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2833 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2836 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2839 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2841 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2842 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2843 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2844 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2845 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2846 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2847 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2848 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2849 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2850 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2851 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2852 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2854 /* Digital microphone port */
2855 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2857 /* Audio input selectors */
2858 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2859 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2862 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2863 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2865 /* enable unsolicited events for Port A and B */
2866 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2867 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2871 static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2872 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2873 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2874 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2875 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2878 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2879 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2882 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2883 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2885 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2886 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2889 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2891 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2892 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2893 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2894 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2895 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2896 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2897 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2899 /* Audio input selector */
2900 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2901 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2903 /* SPDIF route: PCM */
2904 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2905 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2907 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2908 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2910 /* internal microphone */
2911 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2914 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2916 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2917 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2921 static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2922 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2923 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2925 /* Port G: internal speakers */
2926 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2927 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2929 /* Port A: HP, Amp */
2930 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2931 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2933 /* Port B: Mic Dock */
2934 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2937 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2939 /* Port D: HP Dock, Amp */
2940 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2941 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2944 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2946 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2947 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2948 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2949 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2950 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2951 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2952 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2954 /* Audio input selector */
2955 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2956 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2958 /* SPDIF route: PCM */
2959 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2960 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2962 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2963 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2965 /* internal microphone */
2966 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2969 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2971 /* enable unsolicited events for Port A, B, C and D */
2972 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2973 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2974 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2975 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2979 static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2980 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2985 static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2986 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2987 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2988 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2992 /* initialize jack-sensing, too */
2993 static int cxt5066_init(struct hda_codec *codec)
2995 snd_printdd("CXT5066: init\n");
2996 conexant_init(codec);
2997 if (codec->patch_ops.unsol_event) {
2998 cxt5066_hp_automute(codec);
2999 cxt5066_automic(codec);
3001 cxt5066_set_mic_boost(codec);
3005 static int cxt5066_olpc_init(struct hda_codec *codec)
3007 struct conexant_spec *spec = codec->spec;
3008 snd_printdd("CXT5066: init\n");
3009 conexant_init(codec);
3010 cxt5066_hp_automute(codec);
3011 if (!spec->dc_enable) {
3012 cxt5066_set_mic_boost(codec);
3013 cxt5066_olpc_automic(codec);
3015 cxt5066_enable_dc(codec);
3021 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
3022 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3023 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
3024 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
3025 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
3026 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
3027 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
3028 CXT5066_HP_LAPTOP, /* HP Laptop */
3029 CXT5066_AUTO, /* BIOS auto-parser */
3033 static const char * const cxt5066_models[CXT5066_MODELS] = {
3034 [CXT5066_LAPTOP] = "laptop",
3035 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3036 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
3037 [CXT5066_DELL_VOSTRO] = "dell-vostro",
3038 [CXT5066_IDEAPAD] = "ideapad",
3039 [CXT5066_THINKPAD] = "thinkpad",
3040 [CXT5066_ASUS] = "asus",
3041 [CXT5066_HP_LAPTOP] = "hp-laptop",
3042 [CXT5066_AUTO] = "auto",
3045 static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3046 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
3047 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
3048 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
3049 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3050 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
3051 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3052 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3053 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
3054 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3055 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
3056 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
3057 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
3058 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3059 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
3060 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3062 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
3063 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3064 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
3065 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
3066 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3067 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
3068 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
3069 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
3070 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
3071 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
3072 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
3073 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
3074 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
3078 static int patch_cxt5066(struct hda_codec *codec)
3080 struct conexant_spec *spec;
3083 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3084 cxt5066_models, cxt5066_cfg_tbl);
3085 if (board_config < 0)
3086 board_config = CXT5066_AUTO; /* model=auto as default */
3087 if (board_config == CXT5066_AUTO)
3088 return patch_conexant_auto(codec);
3090 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3095 codec->patch_ops = conexant_patch_ops;
3096 codec->patch_ops.init = conexant_init;
3098 spec->dell_automute = 0;
3099 spec->multiout.max_channels = 2;
3100 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3101 spec->multiout.dac_nids = cxt5066_dac_nids;
3102 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3103 ARRAY_SIZE(cxt5066_digout_pin_nids));
3104 spec->num_adc_nids = 1;
3105 spec->adc_nids = cxt5066_adc_nids;
3106 spec->capsrc_nids = cxt5066_capsrc_nids;
3107 spec->input_mux = &cxt5066_capture_source;
3109 spec->port_d_mode = PIN_HP;
3111 spec->num_init_verbs = 1;
3112 spec->init_verbs[0] = cxt5066_init_verbs;
3113 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3114 spec->channel_mode = cxt5066_modes;
3116 spec->cur_adc_idx = 0;
3118 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3120 switch (board_config) {
3122 case CXT5066_LAPTOP:
3123 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3124 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3126 case CXT5066_DELL_LAPTOP:
3127 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3128 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3130 spec->port_d_mode = PIN_OUT;
3131 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3132 spec->num_init_verbs++;
3133 spec->dell_automute = 1;
3136 case CXT5066_HP_LAPTOP:
3137 codec->patch_ops.init = cxt5066_init;
3138 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3139 spec->init_verbs[spec->num_init_verbs] =
3140 cxt5066_init_verbs_hp_laptop;
3141 spec->num_init_verbs++;
3142 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3143 spec->asus = board_config == CXT5066_ASUS;
3144 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3145 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3147 if (board_config == CXT5066_HP_LAPTOP)
3148 spec->multiout.dig_out_nid = 0;
3149 /* input source automatically selected */
3150 spec->input_mux = NULL;
3151 spec->port_d_mode = 0;
3152 spec->mic_boost = 3; /* default 30dB gain */
3155 case CXT5066_OLPC_XO_1_5:
3156 codec->patch_ops.init = cxt5066_olpc_init;
3157 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
3158 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3159 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3160 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
3161 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3162 spec->port_d_mode = 0;
3163 spec->mic_boost = 3; /* default 30dB gain */
3166 spec->multiout.dig_out_nid = 0;
3168 /* input source automatically selected */
3169 spec->input_mux = NULL;
3171 /* our capture hooks which allow us to turn on the microphone LED
3172 * at the right time */
3173 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3174 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
3176 case CXT5066_DELL_VOSTRO:
3177 codec->patch_ops.init = cxt5066_init;
3178 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3179 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3180 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3181 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3182 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
3183 spec->port_d_mode = 0;
3184 spec->dell_vostro = 1;
3185 spec->mic_boost = 3; /* default 30dB gain */
3188 spec->multiout.dig_out_nid = 0;
3190 /* input source automatically selected */
3191 spec->input_mux = NULL;
3193 case CXT5066_IDEAPAD:
3194 codec->patch_ops.init = cxt5066_init;
3195 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3196 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3197 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3198 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3199 spec->port_d_mode = 0;
3201 spec->mic_boost = 2; /* default 20dB gain */
3204 spec->multiout.dig_out_nid = 0;
3206 /* input source automatically selected */
3207 spec->input_mux = NULL;
3209 case CXT5066_THINKPAD:
3210 codec->patch_ops.init = cxt5066_init;
3211 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3212 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3213 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3214 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3216 spec->port_d_mode = PIN_OUT;
3217 spec->mic_boost = 2; /* default 20dB gain */
3220 spec->multiout.dig_out_nid = 0;
3222 /* input source automatically selected */
3223 spec->input_mux = NULL;
3228 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
3234 * Automatic parser for CX20641 & co
3237 static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3238 struct hda_codec *codec,
3239 unsigned int stream_tag,
3240 unsigned int format,
3241 struct snd_pcm_substream *substream)
3243 struct conexant_spec *spec = codec->spec;
3244 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
3245 if (spec->adc_switching) {
3246 spec->cur_adc = adc;
3247 spec->cur_adc_stream_tag = stream_tag;
3248 spec->cur_adc_format = format;
3250 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3254 static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3255 struct hda_codec *codec,
3256 struct snd_pcm_substream *substream)
3258 struct conexant_spec *spec = codec->spec;
3259 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3264 static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3268 .nid = 0, /* fill later */
3270 .prepare = cx_auto_capture_pcm_prepare,
3271 .cleanup = cx_auto_capture_pcm_cleanup
3275 static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3277 #define get_connection_index(codec, mux, nid)\
3278 snd_hda_get_conn_index(codec, mux, nid, 0)
3280 /* get an unassigned DAC from the given list.
3281 * Return the nid if found and reduce the DAC list, or return zero if
3284 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3285 hda_nid_t *dacs, int *num_dacs)
3287 int i, nums = *num_dacs;
3290 for (i = 0; i < nums; i++) {
3291 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3299 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3304 #define MAX_AUTO_DACS 5
3306 #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3308 /* fill analog DAC list from the widget tree */
3309 static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3311 hda_nid_t nid, end_nid;
3314 end_nid = codec->start_nid + codec->num_nodes;
3315 for (nid = codec->start_nid; nid < end_nid; nid++) {
3316 unsigned int wcaps = get_wcaps(codec, nid);
3317 unsigned int type = get_wcaps_type(wcaps);
3318 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3320 if (nums >= MAX_AUTO_DACS)
3327 /* fill pin_dac_pair list from the pin and dac list */
3328 static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3329 int num_pins, hda_nid_t *dacs, int *rest,
3330 struct pin_dac_pair *filled, int nums,
3333 int i, start = nums;
3335 for (i = 0; i < num_pins; i++, nums++) {
3336 filled[nums].pin = pins[i];
3337 filled[nums].type = type;
3338 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3339 if (filled[nums].dac)
3341 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3342 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3345 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
3346 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
3349 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
3354 /* parse analog output paths */
3355 static void cx_auto_parse_output(struct hda_codec *codec)
3357 struct conexant_spec *spec = codec->spec;
3358 struct auto_pin_cfg *cfg = &spec->autocfg;
3359 hda_nid_t dacs[MAX_AUTO_DACS];
3360 int i, j, nums, rest;
3362 rest = fill_cx_auto_dacs(codec, dacs);
3363 /* parse all analog output pins */
3364 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3365 dacs, &rest, spec->dac_info, 0,
3367 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3368 dacs, &rest, spec->dac_info, nums,
3370 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3371 dacs, &rest, spec->dac_info, nums,
3372 AUTO_PIN_SPEAKER_OUT);
3373 spec->dac_info_filled = nums;
3374 /* fill multiout struct */
3375 for (i = 0; i < nums; i++) {
3376 hda_nid_t dac = spec->dac_info[i].dac;
3377 if (!dac || (dac & DAC_SLAVE_FLAG))
3379 switch (spec->dac_info[i].type) {
3380 case AUTO_PIN_LINE_OUT:
3381 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3382 spec->multiout.num_dacs++;
3384 case AUTO_PIN_HP_OUT:
3385 case AUTO_PIN_SPEAKER_OUT:
3386 if (!spec->multiout.hp_nid) {
3387 spec->multiout.hp_nid = dac;
3390 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3391 if (!spec->multiout.extra_out_nid[j]) {
3392 spec->multiout.extra_out_nid[j] = dac;
3398 spec->multiout.dac_nids = spec->private_dac_nids;
3399 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3401 for (i = 0; i < cfg->hp_outs; i++) {
3402 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3403 spec->auto_mute = 1;
3407 if (spec->auto_mute &&
3408 cfg->line_out_pins[0] &&
3409 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
3410 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3411 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3412 for (i = 0; i < cfg->line_outs; i++) {
3413 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3414 spec->detect_line = 1;
3418 spec->automute_lines = spec->detect_line;
3421 spec->vmaster_nid = spec->private_dac_nids[0];
3424 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3425 hda_nid_t *pins, bool on);
3427 static void do_automute(struct hda_codec *codec, int num_pins,
3428 hda_nid_t *pins, bool on)
3430 struct conexant_spec *spec = codec->spec;
3432 for (i = 0; i < num_pins; i++)
3433 snd_hda_codec_write(codec, pins[i], 0,
3434 AC_VERB_SET_PIN_WIDGET_CONTROL,
3436 if (spec->pin_eapd_ctrls)
3437 cx_auto_turn_eapd(codec, num_pins, pins, on);
3440 static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3444 for (i = 0; i < num_pins; i++) {
3445 hda_nid_t nid = pins[i];
3446 if (!nid || !is_jack_detectable(codec, nid))
3448 snd_hda_input_jack_report(codec, nid);
3449 present |= snd_hda_jack_detect(codec, nid);
3454 /* auto-mute/unmute speaker and line outs according to headphone jack */
3455 static void cx_auto_update_speakers(struct hda_codec *codec)
3457 struct conexant_spec *spec = codec->spec;
3458 struct auto_pin_cfg *cfg = &spec->autocfg;
3461 /* turn on HP EAPD when HP jacks are present */
3462 if (spec->pin_eapd_ctrls) {
3463 if (spec->auto_mute)
3464 on = spec->hp_present;
3465 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3468 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3469 if (spec->auto_mute)
3470 on = !(spec->hp_present ||
3471 (spec->detect_line && spec->line_present));
3472 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
3474 /* toggle line-out mutes if needed, too */
3475 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3476 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3477 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3479 if (spec->auto_mute) {
3480 /* mute LO in auto-mode when HP jack is present */
3481 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3482 spec->automute_lines)
3483 on = !spec->hp_present;
3487 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
3490 static void cx_auto_hp_automute(struct hda_codec *codec)
3492 struct conexant_spec *spec = codec->spec;
3493 struct auto_pin_cfg *cfg = &spec->autocfg;
3495 if (!spec->auto_mute)
3497 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3498 cx_auto_update_speakers(codec);
3501 static void cx_auto_line_automute(struct hda_codec *codec)
3503 struct conexant_spec *spec = codec->spec;
3504 struct auto_pin_cfg *cfg = &spec->autocfg;
3506 if (!spec->auto_mute || !spec->detect_line)
3508 spec->line_present = detect_jacks(codec, cfg->line_outs,
3509 cfg->line_out_pins);
3510 cx_auto_update_speakers(codec);
3513 static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3514 struct snd_ctl_elem_info *uinfo)
3516 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3517 struct conexant_spec *spec = codec->spec;
3518 static const char * const texts2[] = {
3519 "Disabled", "Enabled"
3521 static const char * const texts3[] = {
3522 "Disabled", "Speaker Only", "Line-Out+Speaker"
3524 const char * const *texts;
3526 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3528 if (spec->automute_hp_lo) {
3529 uinfo->value.enumerated.items = 3;
3532 uinfo->value.enumerated.items = 2;
3535 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3536 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3537 strcpy(uinfo->value.enumerated.name,
3538 texts[uinfo->value.enumerated.item]);
3542 static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3543 struct snd_ctl_elem_value *ucontrol)
3545 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3546 struct conexant_spec *spec = codec->spec;
3548 if (!spec->auto_mute)
3550 else if (!spec->automute_lines)
3554 ucontrol->value.enumerated.item[0] = val;
3558 static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3559 struct snd_ctl_elem_value *ucontrol)
3561 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3562 struct conexant_spec *spec = codec->spec;
3564 switch (ucontrol->value.enumerated.item[0]) {
3566 if (!spec->auto_mute)
3568 spec->auto_mute = 0;
3571 if (spec->auto_mute && !spec->automute_lines)
3573 spec->auto_mute = 1;
3574 spec->automute_lines = 0;
3577 if (!spec->automute_hp_lo)
3579 if (spec->auto_mute && spec->automute_lines)
3581 spec->auto_mute = 1;
3582 spec->automute_lines = 1;
3587 cx_auto_update_speakers(codec);
3591 static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3593 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3594 .name = "Auto-Mute Mode",
3595 .info = cx_automute_mode_info,
3596 .get = cx_automute_mode_get,
3597 .put = cx_automute_mode_put,
3602 static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3603 struct snd_ctl_elem_info *uinfo)
3605 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3606 struct conexant_spec *spec = codec->spec;
3608 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3611 static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3612 struct snd_ctl_elem_value *ucontrol)
3614 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3615 struct conexant_spec *spec = codec->spec;
3617 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3621 /* look for the route the given pin from mux and return the index;
3622 * if do_select is set, actually select the route.
3624 static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3625 hda_nid_t pin, hda_nid_t *srcp,
3626 bool do_select, int depth)
3628 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3631 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3633 case AC_WID_AUD_SEL:
3634 case AC_WID_AUD_MIX:
3640 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3641 for (i = 0; i < nums; i++)
3642 if (conn[i] == pin) {
3644 snd_hda_codec_write(codec, mux, 0,
3645 AC_VERB_SET_CONNECT_SEL, i);
3653 for (i = 0; i < nums; i++) {
3654 int ret = __select_input_connection(codec, conn[i], pin, srcp,
3658 snd_hda_codec_write(codec, mux, 0,
3659 AC_VERB_SET_CONNECT_SEL, i);
3666 static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3669 __select_input_connection(codec, mux, pin, NULL, true, 0);
3672 static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3675 return __select_input_connection(codec, mux, pin, NULL, false, 0);
3678 static int cx_auto_mux_enum_update(struct hda_codec *codec,
3679 const struct hda_input_mux *imux,
3682 struct conexant_spec *spec = codec->spec;
3686 if (!imux->num_items)
3688 if (idx >= imux->num_items)
3689 idx = imux->num_items - 1;
3690 if (spec->cur_mux[0] == idx)
3692 adc = spec->imux_info[idx].adc;
3693 select_input_connection(codec, spec->imux_info[idx].adc,
3694 spec->imux_info[idx].pin);
3695 if (spec->cur_adc && spec->cur_adc != adc) {
3696 /* stream is running, let's swap the current ADC */
3697 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3698 spec->cur_adc = adc;
3699 snd_hda_codec_setup_stream(codec, adc,
3700 spec->cur_adc_stream_tag, 0,
3701 spec->cur_adc_format);
3703 spec->cur_mux[0] = idx;
3707 static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3708 struct snd_ctl_elem_value *ucontrol)
3710 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3711 struct conexant_spec *spec = codec->spec;
3713 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3714 ucontrol->value.enumerated.item[0]);
3717 static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3720 .name = "Capture Source",
3721 .info = cx_auto_mux_enum_info,
3722 .get = cx_auto_mux_enum_get,
3723 .put = cx_auto_mux_enum_put
3728 static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3730 struct conexant_spec *spec = codec->spec;
3733 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3735 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3739 /* automatic switch internal and external mic */
3740 static void cx_auto_automic(struct hda_codec *codec)
3742 struct conexant_spec *spec = codec->spec;
3744 if (!spec->auto_mic)
3746 if (!select_automic(codec, spec->auto_mic_ext, true))
3747 if (!select_automic(codec, spec->auto_mic_dock, true))
3748 select_automic(codec, spec->auto_mic_int, false);
3751 static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3753 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3754 switch (res >> 26) {
3755 case CONEXANT_HP_EVENT:
3756 cx_auto_hp_automute(codec);
3758 case CONEXANT_LINE_EVENT:
3759 cx_auto_line_automute(codec);
3761 case CONEXANT_MIC_EVENT:
3762 cx_auto_automic(codec);
3763 snd_hda_input_jack_report(codec, nid);
3768 /* check whether the pin config is suitable for auto-mic switching;
3769 * auto-mic is enabled only when one int-mic and one ext- and/or
3770 * one dock-mic exist
3772 static void cx_auto_check_auto_mic(struct hda_codec *codec)
3774 struct conexant_spec *spec = codec->spec;
3775 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3778 for (i = 0; i < ARRAY_SIZE(pset); i++)
3780 for (i = 0; i < spec->private_imux.num_items; i++) {
3781 hda_nid_t pin = spec->imux_info[i].pin;
3782 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3784 attr = snd_hda_get_input_pin_attr(def_conf);
3785 if (attr == INPUT_PIN_ATTR_UNUSED)
3786 return; /* invalid entry */
3787 if (attr > INPUT_PIN_ATTR_NORMAL)
3788 attr = INPUT_PIN_ATTR_NORMAL;
3789 if (attr != INPUT_PIN_ATTR_INT &&
3790 !is_jack_detectable(codec, pin))
3791 return; /* non-detectable pin */
3792 type = get_defcfg_device(def_conf);
3793 if (type != AC_JACK_MIC_IN &&
3794 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3795 return; /* no valid input type */
3796 if (pset[attr] >= 0)
3797 return; /* already occupied */
3800 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3801 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3802 return; /* no input to switch*/
3804 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3805 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3806 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
3809 static void cx_auto_parse_input(struct hda_codec *codec)
3811 struct conexant_spec *spec = codec->spec;
3812 struct auto_pin_cfg *cfg = &spec->autocfg;
3813 struct hda_input_mux *imux;
3816 imux = &spec->private_imux;
3817 for (i = 0; i < cfg->num_inputs; i++) {
3818 for (j = 0; j < spec->num_adc_nids; j++) {
3819 hda_nid_t adc = spec->adc_nids[j];
3820 int idx = get_input_connection(codec, adc,
3821 cfg->inputs[i].pin);
3824 label = hda_get_autocfg_input_label(codec, cfg, i);
3825 spec->imux_info[imux->num_items].index = i;
3826 spec->imux_info[imux->num_items].boost = 0;
3827 spec->imux_info[imux->num_items].adc = adc;
3828 spec->imux_info[imux->num_items].pin =
3830 snd_hda_add_imux_item(imux, label, idx, NULL);
3835 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
3836 cx_auto_check_auto_mic(codec);
3837 if (imux->num_items > 1) {
3838 for (i = 1; i < imux->num_items; i++) {
3839 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
3840 spec->adc_switching = 1;
3847 /* get digital-input audio widget corresponding to the given pin */
3848 static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3850 hda_nid_t nid, end_nid;
3852 end_nid = codec->start_nid + codec->num_nodes;
3853 for (nid = codec->start_nid; nid < end_nid; nid++) {
3854 unsigned int wcaps = get_wcaps(codec, nid);
3855 unsigned int type = get_wcaps_type(wcaps);
3856 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3857 if (get_connection_index(codec, nid, pin) >= 0)
3864 static void cx_auto_parse_digital(struct hda_codec *codec)
3866 struct conexant_spec *spec = codec->spec;
3867 struct auto_pin_cfg *cfg = &spec->autocfg;
3870 if (cfg->dig_outs &&
3871 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3872 spec->multiout.dig_out_nid = nid;
3873 if (cfg->dig_in_pin)
3874 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3877 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3878 static void cx_auto_parse_beep(struct hda_codec *codec)
3880 struct conexant_spec *spec = codec->spec;
3881 hda_nid_t nid, end_nid;
3883 end_nid = codec->start_nid + codec->num_nodes;
3884 for (nid = codec->start_nid; nid < end_nid; nid++)
3885 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3886 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3891 #define cx_auto_parse_beep(codec)
3895 static void cx_auto_parse_eapd(struct hda_codec *codec)
3897 struct conexant_spec *spec = codec->spec;
3898 hda_nid_t nid, end_nid;
3900 end_nid = codec->start_nid + codec->num_nodes;
3901 for (nid = codec->start_nid; nid < end_nid; nid++) {
3902 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3904 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3906 spec->eapds[spec->num_eapds++] = nid;
3907 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3911 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3912 * it's a new chip, where EAPDs are supposed to be associated to
3913 * pins, and we can control EAPD per pin.
3914 * OTOH, if only one or two EAPDs are found, it's an old chip,
3915 * thus it might control over all pins.
3917 spec->pin_eapd_ctrls = spec->num_eapds > 2;
3920 static int cx_auto_parse_auto_config(struct hda_codec *codec)
3922 struct conexant_spec *spec = codec->spec;
3925 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3929 cx_auto_parse_output(codec);
3930 cx_auto_parse_input(codec);
3931 cx_auto_parse_digital(codec);
3932 cx_auto_parse_beep(codec);
3933 cx_auto_parse_eapd(codec);
3937 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3938 hda_nid_t *pins, bool on)
3941 for (i = 0; i < num_pins; i++) {
3942 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3943 snd_hda_codec_write(codec, pins[i], 0,
3944 AC_VERB_SET_EAPD_BTLENABLE,
3949 static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3952 int idx = get_connection_index(codec, pin, src);
3954 snd_hda_codec_write(codec, pin, 0,
3955 AC_VERB_SET_CONNECT_SEL, idx);
3958 static void mute_outputs(struct hda_codec *codec, int num_nids,
3959 const hda_nid_t *nids)
3963 for (i = 0; i < num_nids; i++) {
3964 hda_nid_t nid = nids[i];
3965 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3967 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3971 snd_hda_codec_write(codec, nid, 0,
3972 AC_VERB_SET_AMP_GAIN_MUTE, val);
3976 static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3977 hda_nid_t *pins, unsigned int tag)
3980 for (i = 0; i < num_pins; i++)
3981 snd_hda_codec_write(codec, pins[i], 0,
3982 AC_VERB_SET_UNSOLICITED_ENABLE,
3986 static void cx_auto_init_output(struct hda_codec *codec)
3988 struct conexant_spec *spec = codec->spec;
3989 struct auto_pin_cfg *cfg = &spec->autocfg;
3993 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
3994 for (i = 0; i < cfg->hp_outs; i++) {
3995 unsigned int val = PIN_OUT;
3996 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
3998 val |= AC_PINCTL_HP_EN;
3999 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
4000 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
4002 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
4003 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
4004 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
4005 for (i = 0; i < spec->dac_info_filled; i++) {
4006 nid = spec->dac_info[i].dac;
4008 nid = spec->multiout.dac_nids[0];
4009 else if (nid & DAC_SLAVE_FLAG)
4010 nid &= ~DAC_SLAVE_FLAG;
4011 select_connection(codec, spec->dac_info[i].pin, nid);
4013 if (spec->auto_mute) {
4014 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
4016 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
4018 if (spec->detect_line) {
4019 enable_unsol_pins(codec, cfg->line_outs,
4021 CONEXANT_LINE_EVENT);
4022 spec->line_present =
4023 detect_jacks(codec, cfg->line_outs,
4024 cfg->line_out_pins);
4027 cx_auto_update_speakers(codec);
4028 /* turn on all EAPDs if no individual EAPD control is available */
4029 if (!spec->pin_eapd_ctrls)
4030 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
4033 static void cx_auto_init_input(struct hda_codec *codec)
4035 struct conexant_spec *spec = codec->spec;
4036 struct auto_pin_cfg *cfg = &spec->autocfg;
4039 for (i = 0; i < spec->num_adc_nids; i++) {
4040 hda_nid_t nid = spec->adc_nids[i];
4041 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4043 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4044 val = AMP_IN_MUTE(0);
4046 val = AMP_IN_UNMUTE(0);
4047 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4051 for (i = 0; i < cfg->num_inputs; i++) {
4053 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4057 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4058 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4061 if (spec->auto_mic) {
4062 if (spec->auto_mic_ext >= 0) {
4063 snd_hda_codec_write(codec,
4064 cfg->inputs[spec->auto_mic_ext].pin, 0,
4065 AC_VERB_SET_UNSOLICITED_ENABLE,
4066 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4068 if (spec->auto_mic_dock >= 0) {
4069 snd_hda_codec_write(codec,
4070 cfg->inputs[spec->auto_mic_dock].pin, 0,
4071 AC_VERB_SET_UNSOLICITED_ENABLE,
4072 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4074 cx_auto_automic(codec);
4076 select_input_connection(codec, spec->imux_info[0].adc,
4077 spec->imux_info[0].pin);
4081 static void cx_auto_init_digital(struct hda_codec *codec)
4083 struct conexant_spec *spec = codec->spec;
4084 struct auto_pin_cfg *cfg = &spec->autocfg;
4086 if (spec->multiout.dig_out_nid)
4087 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4088 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4089 if (spec->dig_in_nid)
4090 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4091 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4094 static int cx_auto_init(struct hda_codec *codec)
4096 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4097 cx_auto_init_output(codec);
4098 cx_auto_init_input(codec);
4099 cx_auto_init_digital(codec);
4103 static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
4104 const char *dir, int cidx,
4105 hda_nid_t nid, int hda_dir, int amp_idx, int chs)
4107 static char name[44];
4108 static struct snd_kcontrol_new knew[] = {
4109 HDA_CODEC_VOLUME(name, 0, 0, 0),
4110 HDA_CODEC_MUTE(name, 0, 0, 0),
4112 static const char * const sfx[2] = { "Volume", "Switch" };
4115 for (i = 0; i < 2; i++) {
4116 struct snd_kcontrol *kctl;
4117 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
4119 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4120 knew[i].index = cidx;
4121 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4122 kctl = snd_ctl_new1(&knew[i], codec);
4125 err = snd_hda_ctl_add(codec, nid, kctl);
4128 if (!(query_amp_caps(codec, nid, hda_dir) &
4129 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
4135 #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4136 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
4138 #define cx_auto_add_pb_volume(codec, nid, str, idx) \
4139 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4141 static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4142 hda_nid_t pin, const char *name, int idx)
4145 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4146 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4147 if (caps & AC_AMPCAP_NUM_STEPS)
4148 return cx_auto_add_pb_volume(codec, dac, name, idx);
4150 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4151 if (caps & AC_AMPCAP_NUM_STEPS)
4152 return cx_auto_add_pb_volume(codec, pin, name, idx);
4156 static int cx_auto_build_output_controls(struct hda_codec *codec)
4158 struct conexant_spec *spec = codec->spec;
4160 int num_line = 0, num_hp = 0, num_spk = 0;
4161 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
4163 if (spec->dac_info_filled == 1)
4164 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4165 spec->dac_info[0].pin,
4168 for (i = 0; i < spec->dac_info_filled; i++) {
4171 hda_nid_t dac = spec->dac_info[i].dac;
4172 type = spec->dac_info[i].type;
4173 if (type == AUTO_PIN_LINE_OUT)
4174 type = spec->autocfg.line_out_type;
4176 case AUTO_PIN_LINE_OUT:
4178 label = texts[num_line++];
4181 case AUTO_PIN_HP_OUT:
4182 label = "Headphone";
4185 case AUTO_PIN_SPEAKER_OUT:
4190 err = try_add_pb_volume(codec, dac,
4191 spec->dac_info[i].pin,
4197 if (spec->auto_mute) {
4198 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4206 /* Returns zero if this is a normal stereo channel, and non-zero if it should
4207 be split in two independent channels.
4208 dest_label must be at least 44 characters. */
4209 static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
4210 char *dest_label, int nid)
4212 struct conexant_spec *spec = codec->spec;
4215 if (!spec->fixup_stereo_dmic)
4218 for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
4220 if (spec->autocfg.inputs[i].pin != nid)
4223 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
4225 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4226 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
4229 /* Finally found the inverted internal mic! */
4230 snprintf(dest_label, 44, "Inverted %s", label);
4236 static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4237 const char *label, const char *pfx,
4240 struct conexant_spec *spec = codec->spec;
4243 for (i = 0; i < spec->num_adc_nids; i++) {
4244 char rightch_label[44];
4245 hda_nid_t adc_nid = spec->adc_nids[i];
4246 int idx = get_input_connection(codec, adc_nid, nid);
4249 if (spec->single_adc_amp)
4252 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4253 /* Make two independent kcontrols for left and right */
4254 int err = cx_auto_add_volume_idx(codec, label, pfx,
4255 cidx, adc_nid, HDA_INPUT, idx, 1);
4258 return cx_auto_add_volume_idx(codec, rightch_label, pfx,
4259 cidx, adc_nid, HDA_INPUT, idx, 2);
4261 return cx_auto_add_volume_idx(codec, label, pfx,
4262 cidx, adc_nid, HDA_INPUT, idx, 3);
4267 static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4268 const char *label, int cidx)
4270 struct conexant_spec *spec = codec->spec;
4274 nid = spec->imux_info[idx].pin;
4275 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4276 char rightch_label[44];
4277 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4278 int err = cx_auto_add_volume_idx(codec, label, " Boost",
4279 cidx, nid, HDA_INPUT, 0, 1);
4282 return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
4283 cidx, nid, HDA_INPUT, 0, 2);
4285 return cx_auto_add_volume(codec, label, " Boost", cidx,
4288 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4292 for (i = 0; i < idx; i++) {
4293 if (spec->imux_info[i].boost == mux)
4294 return 0; /* already present */
4297 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
4298 spec->imux_info[idx].boost = mux;
4299 return cx_auto_add_volume(codec, label, " Boost", 0,
4305 static int cx_auto_build_input_controls(struct hda_codec *codec)
4307 struct conexant_spec *spec = codec->spec;
4308 struct hda_input_mux *imux = &spec->private_imux;
4309 const char *prev_label;
4310 int input_conn[HDA_MAX_NUM_INPUTS];
4311 int i, j, err, cidx;
4312 int multi_connection;
4314 if (!imux->num_items)
4317 multi_connection = 0;
4318 for (i = 0; i < imux->num_items; i++) {
4319 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4320 spec->imux_info[i].pin);
4323 input_conn[i] = spec->imux_info[i].adc;
4324 if (!spec->single_adc_amp)
4325 input_conn[i] |= cidx << 8;
4326 if (i > 0 && input_conn[i] != input_conn[0])
4327 multi_connection = 1;
4332 for (i = 0; i < imux->num_items; i++) {
4333 hda_nid_t nid = spec->imux_info[i].pin;
4336 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
4337 spec->imux_info[i].index);
4338 if (label == prev_label)
4344 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4348 if (!multi_connection) {
4351 err = cx_auto_add_capture_volume(codec, nid,
4352 "Capture", "", cidx);
4354 bool dup_found = false;
4355 for (j = 0; j < i; j++) {
4356 if (input_conn[j] == input_conn[i]) {
4363 err = cx_auto_add_capture_volume(codec, nid,
4364 label, " Capture", cidx);
4370 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4371 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4379 static int cx_auto_build_controls(struct hda_codec *codec)
4383 err = cx_auto_build_output_controls(codec);
4386 err = cx_auto_build_input_controls(codec);
4389 return conexant_build_controls(codec);
4392 static int cx_auto_search_adcs(struct hda_codec *codec)
4394 struct conexant_spec *spec = codec->spec;
4395 hda_nid_t nid, end_nid;
4397 end_nid = codec->start_nid + codec->num_nodes;
4398 for (nid = codec->start_nid; nid < end_nid; nid++) {
4399 unsigned int caps = get_wcaps(codec, nid);
4400 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4402 if (caps & AC_WCAP_DIGITAL)
4404 if (snd_BUG_ON(spec->num_adc_nids >=
4405 ARRAY_SIZE(spec->private_adc_nids)))
4407 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4409 spec->adc_nids = spec->private_adc_nids;
4414 static const struct hda_codec_ops cx_auto_patch_ops = {
4415 .build_controls = cx_auto_build_controls,
4416 .build_pcms = conexant_build_pcms,
4417 .init = cx_auto_init,
4418 .free = conexant_free,
4419 .unsol_event = cx_auto_unsol_event,
4430 static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4432 for (; cfg->nid; cfg++)
4433 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4438 CXT_PINCFG_LENOVO_X200,
4439 CXT_PINCFG_LENOVO_TP410,
4440 CXT_FIXUP_STEREO_DMIC,
4443 static void apply_fixup(struct hda_codec *codec,
4444 const struct snd_pci_quirk *quirk,
4445 const struct cxt_pincfg **table)
4447 struct conexant_spec *spec = codec->spec;
4449 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
4452 if (table[quirk->value]) {
4453 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4455 apply_pincfg(codec, table[quirk->value]);
4457 if (quirk->value == CXT_FIXUP_STEREO_DMIC) {
4458 snd_printdd(KERN_INFO "hda_codec: applying internal mic workaround for %s\n",
4460 spec->fixup_stereo_dmic = 1;
4464 /* ThinkPad X200 & co with cxt5051 */
4465 static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4466 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4467 { 0x17, 0x21a11000 }, /* dock-mic */
4468 { 0x19, 0x2121103f }, /* dock-HP */
4472 /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
4473 static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = {
4474 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
4475 { 0x1a, 0x21a190f0 }, /* dock-mic */
4476 { 0x1c, 0x212140ff }, /* dock-HP */
4480 static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
4481 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
4482 [CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410,
4483 [CXT_FIXUP_STEREO_DMIC] = NULL,
4486 static const struct snd_pci_quirk cxt5051_fixups[] = {
4487 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4491 static const struct snd_pci_quirk cxt5066_fixups[] = {
4492 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
4493 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
4494 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
4495 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4496 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
4497 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
4498 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
4499 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
4500 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
4504 /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4505 * can be created (bko#42825)
4507 static void add_cx5051_fake_mutes(struct hda_codec *codec)
4509 static hda_nid_t out_nids[] = {
4514 for (p = out_nids; *p; p++)
4515 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4516 AC_AMPCAP_MIN_MUTE |
4517 query_amp_caps(codec, *p, HDA_OUTPUT));
4520 static int patch_conexant_auto(struct hda_codec *codec)
4522 struct conexant_spec *spec;
4525 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4528 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4532 codec->pin_amp_workaround = 1;
4534 switch (codec->vendor_id) {
4536 spec->single_adc_amp = 1;
4539 add_cx5051_fake_mutes(codec);
4540 apply_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl);
4543 apply_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl);
4547 err = cx_auto_search_adcs(codec);
4550 err = cx_auto_parse_auto_config(codec);
4556 spec->capture_stream = &cx_auto_pcm_analog_capture;
4557 codec->patch_ops = cx_auto_patch_ops;
4559 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
4566 static const struct hda_codec_preset snd_hda_preset_conexant[] = {
4567 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4568 .patch = patch_cxt5045 },
4569 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4570 .patch = patch_cxt5047 },
4571 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4572 .patch = patch_cxt5051 },
4573 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4574 .patch = patch_cxt5066 },
4575 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4576 .patch = patch_cxt5066 },
4577 { .id = 0x14f15068, .name = "CX20584",
4578 .patch = patch_cxt5066 },
4579 { .id = 0x14f15069, .name = "CX20585",
4580 .patch = patch_cxt5066 },
4581 { .id = 0x14f1506c, .name = "CX20588",
4582 .patch = patch_cxt5066 },
4583 { .id = 0x14f1506e, .name = "CX20590",
4584 .patch = patch_cxt5066 },
4585 { .id = 0x14f15097, .name = "CX20631",
4586 .patch = patch_conexant_auto },
4587 { .id = 0x14f15098, .name = "CX20632",
4588 .patch = patch_conexant_auto },
4589 { .id = 0x14f150a1, .name = "CX20641",
4590 .patch = patch_conexant_auto },
4591 { .id = 0x14f150a2, .name = "CX20642",
4592 .patch = patch_conexant_auto },
4593 { .id = 0x14f150ab, .name = "CX20651",
4594 .patch = patch_conexant_auto },
4595 { .id = 0x14f150ac, .name = "CX20652",
4596 .patch = patch_conexant_auto },
4597 { .id = 0x14f150b8, .name = "CX20664",
4598 .patch = patch_conexant_auto },
4599 { .id = 0x14f150b9, .name = "CX20665",
4600 .patch = patch_conexant_auto },
4601 { .id = 0x14f1510f, .name = "CX20751/2",
4602 .patch = patch_conexant_auto },
4603 { .id = 0x14f15110, .name = "CX20751/2",
4604 .patch = patch_conexant_auto },
4605 { .id = 0x14f15111, .name = "CX20753/4",
4606 .patch = patch_conexant_auto },
4607 { .id = 0x14f15113, .name = "CX20755",
4608 .patch = patch_conexant_auto },
4609 { .id = 0x14f15114, .name = "CX20756",
4610 .patch = patch_conexant_auto },
4611 { .id = 0x14f15115, .name = "CX20757",
4612 .patch = patch_conexant_auto },
4616 MODULE_ALIAS("snd-hda-codec-id:14f15045");
4617 MODULE_ALIAS("snd-hda-codec-id:14f15047");
4618 MODULE_ALIAS("snd-hda-codec-id:14f15051");
4619 MODULE_ALIAS("snd-hda-codec-id:14f15066");
4620 MODULE_ALIAS("snd-hda-codec-id:14f15067");
4621 MODULE_ALIAS("snd-hda-codec-id:14f15068");
4622 MODULE_ALIAS("snd-hda-codec-id:14f15069");
4623 MODULE_ALIAS("snd-hda-codec-id:14f1506c");
4624 MODULE_ALIAS("snd-hda-codec-id:14f1506e");
4625 MODULE_ALIAS("snd-hda-codec-id:14f15097");
4626 MODULE_ALIAS("snd-hda-codec-id:14f15098");
4627 MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4628 MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4629 MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4630 MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4631 MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4632 MODULE_ALIAS("snd-hda-codec-id:14f150b9");
4633 MODULE_ALIAS("snd-hda-codec-id:14f1510f");
4634 MODULE_ALIAS("snd-hda-codec-id:14f15110");
4635 MODULE_ALIAS("snd-hda-codec-id:14f15111");
4636 MODULE_ALIAS("snd-hda-codec-id:14f15113");
4637 MODULE_ALIAS("snd-hda-codec-id:14f15114");
4638 MODULE_ALIAS("snd-hda-codec-id:14f15115");
4640 MODULE_LICENSE("GPL");
4641 MODULE_DESCRIPTION("Conexant HD-audio codec");
4643 static struct hda_codec_preset_list conexant_list = {
4644 .preset = snd_hda_preset_conexant,
4645 .owner = THIS_MODULE,
4648 static int __init patch_conexant_init(void)
4650 return snd_hda_add_codec_preset(&conexant_list);
4653 static void __exit patch_conexant_exit(void)
4655 snd_hda_delete_codec_preset(&conexant_list);
4658 module_init(patch_conexant_init)
4659 module_exit(patch_conexant_exit)