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"
33 #include "hda_auto_parser.h"
37 #define CXT_PIN_DIR_IN 0x00
38 #define CXT_PIN_DIR_OUT 0x01
39 #define CXT_PIN_DIR_INOUT 0x02
40 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
41 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
43 #define CONEXANT_HP_EVENT 0x37
44 #define CONEXANT_MIC_EVENT 0x38
45 #define CONEXANT_LINE_EVENT 0x39
47 /* Conexant 5051 specific */
49 #define CXT5051_SPDIF_OUT 0x12
50 #define CXT5051_PORTB_EVENT 0x38
51 #define CXT5051_PORTC_EVENT 0x39
53 #define AUTO_MIC_PORTB (1 << 1)
54 #define AUTO_MIC_PORTC (1 << 2)
63 hda_nid_t pin; /* input pin NID */
64 hda_nid_t adc; /* connected ADC NID */
65 hda_nid_t boost; /* optional boost volume NID */
66 int index; /* corresponding to autocfg.input */
69 struct conexant_spec {
70 struct hda_gen_spec gen;
72 const struct snd_kcontrol_new *mixers[5];
74 hda_nid_t vmaster_nid;
75 struct hda_vmaster_mute_hook vmaster_mute;
76 bool vmaster_mute_led;
78 const struct hda_verb *init_verbs[5]; /* initialization verbs
82 unsigned int num_init_verbs;
85 struct hda_multi_out multiout; /* playback set-up
86 * max_channels, dacs must be set
87 * dig_out_nid and hp_nid are optional
89 unsigned int cur_eapd;
90 unsigned int hp_present;
91 unsigned int line_present;
92 unsigned int auto_mic;
93 int auto_mic_ext; /* imux_pins[] index for ext mic */
94 int auto_mic_dock; /* imux_pins[] index for dock mic */
95 int auto_mic_int; /* imux_pins[] index for int mic */
96 unsigned int need_dac_fix;
97 hda_nid_t slave_dig_outs[2];
100 unsigned int num_adc_nids;
101 const hda_nid_t *adc_nids;
102 hda_nid_t dig_in_nid; /* digital-in NID; optional */
104 unsigned int cur_adc_idx;
106 unsigned int cur_adc_stream_tag;
107 unsigned int cur_adc_format;
109 const struct hda_pcm_stream *capture_stream;
112 const struct hda_input_mux *input_mux;
113 const hda_nid_t *capsrc_nids;
114 unsigned int cur_mux[3];
117 const struct hda_channel_mode *channel_mode;
118 int num_channel_mode;
120 /* PCM information */
121 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
123 unsigned int spdif_route;
125 /* dynamic controls, init_verbs and input_mux */
126 struct auto_pin_cfg autocfg;
127 struct hda_input_mux private_imux;
128 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
129 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
130 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
131 struct pin_dac_pair dac_info[8];
134 unsigned int port_d_mode;
135 unsigned int auto_mute:1; /* used in auto-parser */
136 unsigned int detect_line:1; /* Line-out detection enabled */
137 unsigned int automute_lines:1; /* automute line-out as well */
138 unsigned int automute_hp_lo:1; /* both HP and LO available */
139 unsigned int dell_automute:1;
140 unsigned int dell_vostro:1;
141 unsigned int ideapad:1;
142 unsigned int thinkpad:1;
143 unsigned int hp_laptop:1;
145 unsigned int pin_eapd_ctrls:1;
146 unsigned int fixup_stereo_dmic:1;
148 unsigned int adc_switching:1;
150 unsigned int ext_mic_present;
151 unsigned int recording;
152 void (*capture_prepare)(struct hda_codec *codec);
153 void (*capture_cleanup)(struct hda_codec *codec);
155 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
156 * through the microphone jack.
157 * When the user enables this through a mixer switch, both internal and
158 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
159 * we also allow the bias to be configured through a separate mixer
161 unsigned int dc_enable;
162 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
163 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
165 unsigned int beep_amp;
167 /* extra EAPD pins */
168 unsigned int num_eapds;
172 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
173 struct hda_codec *codec,
174 struct snd_pcm_substream *substream)
176 struct conexant_spec *spec = codec->spec;
177 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
181 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
182 struct hda_codec *codec,
183 unsigned int stream_tag,
185 struct snd_pcm_substream *substream)
187 struct conexant_spec *spec = codec->spec;
188 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
193 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
194 struct hda_codec *codec,
195 struct snd_pcm_substream *substream)
197 struct conexant_spec *spec = codec->spec;
198 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
204 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
205 struct hda_codec *codec,
206 struct snd_pcm_substream *substream)
208 struct conexant_spec *spec = codec->spec;
209 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
212 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
213 struct hda_codec *codec,
214 struct snd_pcm_substream *substream)
216 struct conexant_spec *spec = codec->spec;
217 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
220 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
221 struct hda_codec *codec,
222 unsigned int stream_tag,
224 struct snd_pcm_substream *substream)
226 struct conexant_spec *spec = codec->spec;
227 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
235 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
236 struct hda_codec *codec,
237 unsigned int stream_tag,
239 struct snd_pcm_substream *substream)
241 struct conexant_spec *spec = codec->spec;
242 if (spec->capture_prepare)
243 spec->capture_prepare(codec);
244 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
245 stream_tag, 0, format);
249 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
250 struct hda_codec *codec,
251 struct snd_pcm_substream *substream)
253 struct conexant_spec *spec = codec->spec;
254 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
255 if (spec->capture_cleanup)
256 spec->capture_cleanup(codec);
262 static const struct hda_pcm_stream conexant_pcm_analog_playback = {
266 .nid = 0, /* fill later */
268 .open = conexant_playback_pcm_open,
269 .prepare = conexant_playback_pcm_prepare,
270 .cleanup = conexant_playback_pcm_cleanup
274 static const struct hda_pcm_stream conexant_pcm_analog_capture = {
278 .nid = 0, /* fill later */
280 .prepare = conexant_capture_pcm_prepare,
281 .cleanup = conexant_capture_pcm_cleanup
286 static const struct hda_pcm_stream conexant_pcm_digital_playback = {
290 .nid = 0, /* fill later */
292 .open = conexant_dig_playback_pcm_open,
293 .close = conexant_dig_playback_pcm_close,
294 .prepare = conexant_dig_playback_pcm_prepare
298 static const struct hda_pcm_stream conexant_pcm_digital_capture = {
302 /* NID is set in alc_build_pcms */
305 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
306 struct hda_codec *codec,
307 unsigned int stream_tag,
309 struct snd_pcm_substream *substream)
311 struct conexant_spec *spec = codec->spec;
312 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
313 spec->cur_adc_stream_tag = stream_tag;
314 spec->cur_adc_format = format;
315 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
319 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
320 struct hda_codec *codec,
321 struct snd_pcm_substream *substream)
323 struct conexant_spec *spec = codec->spec;
324 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
329 static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
333 .nid = 0, /* fill later */
335 .prepare = cx5051_capture_pcm_prepare,
336 .cleanup = cx5051_capture_pcm_cleanup
340 static bool is_2_1_speaker(struct conexant_spec *spec);
342 static int conexant_build_pcms(struct hda_codec *codec)
344 struct conexant_spec *spec = codec->spec;
345 struct hda_pcm *info = spec->pcm_rec;
348 codec->pcm_info = info;
350 info->name = "CONEXANT Analog";
351 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
352 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
353 spec->multiout.max_channels;
354 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
355 spec->multiout.dac_nids[0];
356 if (is_2_1_speaker(spec))
357 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
359 if (spec->capture_stream)
360 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
362 if (codec->vendor_id == 0x14f15051)
363 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
364 cx5051_pcm_analog_capture;
366 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
367 conexant_pcm_analog_capture;
368 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
372 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
374 if (spec->multiout.dig_out_nid) {
377 info->name = "Conexant Digital";
378 info->pcm_type = HDA_PCM_TYPE_SPDIF;
379 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
380 conexant_pcm_digital_playback;
381 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
382 spec->multiout.dig_out_nid;
383 if (spec->dig_in_nid) {
384 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
385 conexant_pcm_digital_capture;
386 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
389 if (spec->slave_dig_outs[0])
390 codec->slave_dig_outs = spec->slave_dig_outs;
396 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
397 struct snd_ctl_elem_info *uinfo)
399 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
400 struct conexant_spec *spec = codec->spec;
402 return snd_hda_input_mux_info(spec->input_mux, uinfo);
405 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
406 struct snd_ctl_elem_value *ucontrol)
408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
409 struct conexant_spec *spec = codec->spec;
410 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
412 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
416 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
417 struct snd_ctl_elem_value *ucontrol)
419 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
420 struct conexant_spec *spec = codec->spec;
421 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
423 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
424 spec->capsrc_nids[adc_idx],
425 &spec->cur_mux[adc_idx]);
428 static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
429 unsigned int power_state)
431 if (power_state == AC_PWRST_D3)
433 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
435 /* partial workaround for "azx_get_response timeout" */
436 if (power_state == AC_PWRST_D0)
438 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
441 static int conexant_init(struct hda_codec *codec)
443 struct conexant_spec *spec = codec->spec;
446 for (i = 0; i < spec->num_init_verbs; i++)
447 snd_hda_sequence_write(codec, spec->init_verbs[i]);
451 static void conexant_free(struct hda_codec *codec)
453 struct conexant_spec *spec = codec->spec;
454 snd_hda_gen_free(&spec->gen);
455 snd_hda_detach_beep_device(codec);
459 static const struct snd_kcontrol_new cxt_capture_mixers[] = {
461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
462 .name = "Capture Source",
463 .info = conexant_mux_enum_info,
464 .get = conexant_mux_enum_get,
465 .put = conexant_mux_enum_put
470 #ifdef CONFIG_SND_HDA_INPUT_BEEP
471 /* additional beep mixers; the actual parameters are overwritten at build */
472 static const struct snd_kcontrol_new cxt_beep_mixer[] = {
473 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
474 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
479 static const char * const slave_pfxs[] = {
480 "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
484 static int conexant_build_controls(struct hda_codec *codec)
486 struct conexant_spec *spec = codec->spec;
490 for (i = 0; i < spec->num_mixers; i++) {
491 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
495 if (spec->multiout.dig_out_nid) {
496 err = snd_hda_create_spdif_out_ctls(codec,
497 spec->multiout.dig_out_nid,
498 spec->multiout.dig_out_nid);
501 err = snd_hda_create_spdif_share_sw(codec,
505 spec->multiout.share_spdif = 1;
507 if (spec->dig_in_nid) {
508 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
513 /* if we have no master control, let's create it */
514 if (spec->vmaster_nid &&
515 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
516 unsigned int vmaster_tlv[4];
517 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
518 HDA_OUTPUT, vmaster_tlv);
519 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
520 vmaster_tlv, slave_pfxs,
525 if (spec->vmaster_nid &&
526 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
527 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
529 "Playback Switch", true,
530 &spec->vmaster_mute.sw_kctl);
535 if (spec->input_mux) {
536 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
541 #ifdef CONFIG_SND_HDA_INPUT_BEEP
542 /* create beep controls if needed */
543 if (spec->beep_amp) {
544 const struct snd_kcontrol_new *knew;
545 for (knew = cxt_beep_mixer; knew->name; knew++) {
546 struct snd_kcontrol *kctl;
547 kctl = snd_ctl_new1(knew, codec);
550 kctl->private_value = spec->beep_amp;
551 err = snd_hda_ctl_add(codec, 0, kctl);
562 static int conexant_suspend(struct hda_codec *codec)
564 snd_hda_shutup_pins(codec);
569 static const struct hda_codec_ops conexant_patch_ops = {
570 .build_controls = conexant_build_controls,
571 .build_pcms = conexant_build_pcms,
572 .init = conexant_init,
573 .free = conexant_free,
574 .set_power_state = conexant_set_power,
576 .suspend = conexant_suspend,
578 .reboot_notify = snd_hda_shutup_pins,
581 #ifdef CONFIG_SND_HDA_INPUT_BEEP
582 #define set_beep_amp(spec, nid, idx, dir) \
583 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
585 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
588 static int patch_conexant_auto(struct hda_codec *codec);
591 * the private value = nid | (invert << 8)
594 #define cxt_eapd_info snd_ctl_boolean_mono_info
596 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
597 struct snd_ctl_elem_value *ucontrol)
599 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
600 struct conexant_spec *spec = codec->spec;
601 int invert = (kcontrol->private_value >> 8) & 1;
603 ucontrol->value.integer.value[0] = !spec->cur_eapd;
605 ucontrol->value.integer.value[0] = spec->cur_eapd;
610 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
611 struct snd_ctl_elem_value *ucontrol)
613 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
614 struct conexant_spec *spec = codec->spec;
615 int invert = (kcontrol->private_value >> 8) & 1;
616 hda_nid_t nid = kcontrol->private_value & 0xff;
619 eapd = !!ucontrol->value.integer.value[0];
622 if (eapd == spec->cur_eapd)
625 spec->cur_eapd = eapd;
626 snd_hda_codec_write_cache(codec, nid,
627 0, AC_VERB_SET_EAPD_BTLENABLE,
632 /* controls for test mode */
633 #ifdef CONFIG_SND_DEBUG
635 #define CXT_EAPD_SWITCH(xname, nid, mask) \
636 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
637 .info = cxt_eapd_info, \
638 .get = cxt_eapd_get, \
639 .put = cxt_eapd_put, \
640 .private_value = nid | (mask<<16) }
644 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
645 struct snd_ctl_elem_info *uinfo)
647 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
648 struct conexant_spec *spec = codec->spec;
649 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
650 spec->num_channel_mode);
653 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
654 struct snd_ctl_elem_value *ucontrol)
656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
657 struct conexant_spec *spec = codec->spec;
658 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
659 spec->num_channel_mode,
660 spec->multiout.max_channels);
663 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
664 struct snd_ctl_elem_value *ucontrol)
666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
667 struct conexant_spec *spec = codec->spec;
668 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
669 spec->num_channel_mode,
670 &spec->multiout.max_channels);
671 if (err >= 0 && spec->need_dac_fix)
672 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
676 #define CXT_PIN_MODE(xname, nid, dir) \
677 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
678 .info = conexant_ch_mode_info, \
679 .get = conexant_ch_mode_get, \
680 .put = conexant_ch_mode_put, \
681 .private_value = nid | (dir<<16) }
683 #endif /* CONFIG_SND_DEBUG */
685 /* Conexant 5045 specific */
687 static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
688 static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
689 static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
690 #define CXT5045_SPDIF_OUT 0x18
692 static const struct hda_channel_mode cxt5045_modes[1] = {
696 static const struct hda_input_mux cxt5045_capture_source = {
699 { "Internal Mic", 0x1 },
704 static const struct hda_input_mux cxt5045_capture_source_benq = {
707 { "Internal Mic", 0x1 },
714 static const struct hda_input_mux cxt5045_capture_source_hp530 = {
718 { "Internal Mic", 0x2 },
722 /* turn on/off EAPD (+ mute HP) as a master switch */
723 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
724 struct snd_ctl_elem_value *ucontrol)
726 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
727 struct conexant_spec *spec = codec->spec;
730 if (!cxt_eapd_put(kcontrol, ucontrol))
733 /* toggle internal speakers mute depending of presence of
736 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
737 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
740 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
741 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
746 /* bind volumes of both NID 0x10 and 0x11 */
747 static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
748 .ops = &snd_hda_bind_vol,
750 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
751 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
756 /* toggle input of built-in and mic jack appropriately */
757 static void cxt5045_hp_automic(struct hda_codec *codec)
759 static const struct hda_verb mic_jack_on[] = {
760 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
761 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
764 static const struct hda_verb mic_jack_off[] = {
765 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
766 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
769 unsigned int present;
771 present = snd_hda_jack_detect(codec, 0x12);
773 snd_hda_sequence_write(codec, mic_jack_on);
775 snd_hda_sequence_write(codec, mic_jack_off);
779 /* mute internal speaker if HP is plugged */
780 static void cxt5045_hp_automute(struct hda_codec *codec)
782 struct conexant_spec *spec = codec->spec;
785 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
787 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
788 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
792 /* unsolicited event for HP jack sensing */
793 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
798 case CONEXANT_HP_EVENT:
799 cxt5045_hp_automute(codec);
801 case CONEXANT_MIC_EVENT:
802 cxt5045_hp_automic(codec);
808 static const struct snd_kcontrol_new cxt5045_mixers[] = {
809 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
810 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
811 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
812 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
813 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
814 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
815 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
816 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
817 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
819 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
820 .name = "Master Playback Switch",
821 .info = cxt_eapd_info,
823 .put = cxt5045_hp_master_sw_put,
824 .private_value = 0x10,
830 static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
831 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
832 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
837 static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
838 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
839 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
840 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
841 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
842 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
843 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
844 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
845 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
846 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
848 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
849 .name = "Master Playback Switch",
850 .info = cxt_eapd_info,
852 .put = cxt5045_hp_master_sw_put,
853 .private_value = 0x10,
859 static const struct hda_verb cxt5045_init_verbs[] = {
861 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
862 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
864 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
865 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
866 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
867 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
868 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
869 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
870 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
871 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
872 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
873 /* Record selector: Internal mic */
874 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
875 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
876 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
877 /* SPDIF route: PCM */
878 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
879 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
881 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
885 static const struct hda_verb cxt5045_benq_init_verbs[] = {
886 /* Internal Mic, Mic */
887 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
888 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
889 /* Line In,HP, Amp */
890 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
891 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
892 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
893 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
894 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
895 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
896 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
897 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
898 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
899 /* Record selector: Internal mic */
900 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
901 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
902 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
903 /* SPDIF route: PCM */
904 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
905 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
907 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
911 static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
912 /* pin sensing on HP jack */
913 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
917 static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
918 /* pin sensing on HP jack */
919 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
923 #ifdef CONFIG_SND_DEBUG
924 /* Test configuration for debugging, modelled after the ALC260 test
927 static const struct hda_input_mux cxt5045_test_capture_source = {
932 { "LINE1 pin", 0x2 },
933 { "HP-OUT pin", 0x3 },
938 static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
940 /* Output controls */
941 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
942 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
943 HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
944 HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
945 HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
946 HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
948 /* Modes for retasking pin widgets */
949 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
950 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
952 /* EAPD Switch Control */
953 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
955 /* Loopback mixer controls */
957 HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
958 HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
959 HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
960 HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
961 HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
962 HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
963 HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
964 HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
965 HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
966 HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
968 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
969 .name = "Input Source",
970 .info = conexant_mux_enum_info,
971 .get = conexant_mux_enum_get,
972 .put = conexant_mux_enum_put,
974 /* Audio input controls */
975 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
976 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
980 static const struct hda_verb cxt5045_test_init_verbs[] = {
981 /* Set connections */
982 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
983 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
984 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
985 /* Enable retasking pins as output, initially without power amp */
986 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
987 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
989 /* Disable digital (SPDIF) pins initially, but users can enable
990 * them via a mixer switch. In the case of SPDIF-out, this initverb
991 * payload also sets the generation to 0, output to be in "consumer"
992 * PCM format, copyright asserted, no pre-emphasis and no validity
995 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
996 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
998 /* Unmute retasking pin widget output buffers since the default
999 * state appears to be output. As the pin mode is changed by the
1000 * user the pin mode control will take care of enabling the pin's
1001 * input/output buffers as needed.
1003 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1004 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1006 /* Mute capture amp left and right */
1007 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1009 /* Set ADC connection select to match default mixer setting (mic1
1012 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1013 {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
1015 /* Mute all inputs to mixer widget (even unconnected ones) */
1016 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
1017 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1018 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1019 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1020 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1027 /* initialize jack-sensing, too */
1028 static int cxt5045_init(struct hda_codec *codec)
1030 conexant_init(codec);
1031 cxt5045_hp_automute(codec);
1037 CXT5045_LAPTOP_HPSENSE,
1038 CXT5045_LAPTOP_MICSENSE,
1039 CXT5045_LAPTOP_HPMICSENSE,
1041 CXT5045_LAPTOP_HP530,
1042 #ifdef CONFIG_SND_DEBUG
1049 static const char * const cxt5045_models[CXT5045_MODELS] = {
1050 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1051 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1052 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1053 [CXT5045_BENQ] = "benq",
1054 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1055 #ifdef CONFIG_SND_DEBUG
1056 [CXT5045_TEST] = "test",
1058 [CXT5045_AUTO] = "auto",
1061 static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1062 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1063 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1064 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1065 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1066 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1067 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1068 CXT5045_LAPTOP_HPMICSENSE),
1069 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1070 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1071 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1072 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1073 CXT5045_LAPTOP_HPMICSENSE),
1074 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1078 static int patch_cxt5045(struct hda_codec *codec)
1080 struct conexant_spec *spec;
1083 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1086 if (board_config < 0)
1087 board_config = CXT5045_AUTO; /* model=auto as default */
1088 if (board_config == CXT5045_AUTO)
1089 return patch_conexant_auto(codec);
1091 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1095 codec->single_adc_amp = 1;
1097 spec->multiout.max_channels = 2;
1098 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1099 spec->multiout.dac_nids = cxt5045_dac_nids;
1100 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1101 spec->num_adc_nids = 1;
1102 spec->adc_nids = cxt5045_adc_nids;
1103 spec->capsrc_nids = cxt5045_capsrc_nids;
1104 spec->input_mux = &cxt5045_capture_source;
1105 spec->num_mixers = 1;
1106 spec->mixers[0] = cxt5045_mixers;
1107 spec->num_init_verbs = 1;
1108 spec->init_verbs[0] = cxt5045_init_verbs;
1109 spec->spdif_route = 0;
1110 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1111 spec->channel_mode = cxt5045_modes;
1113 set_beep_amp(spec, 0x16, 0, 1);
1115 codec->patch_ops = conexant_patch_ops;
1117 switch (board_config) {
1118 case CXT5045_LAPTOP_HPSENSE:
1119 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1120 spec->input_mux = &cxt5045_capture_source;
1121 spec->num_init_verbs = 2;
1122 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1123 spec->mixers[0] = cxt5045_mixers;
1124 codec->patch_ops.init = cxt5045_init;
1126 case CXT5045_LAPTOP_MICSENSE:
1127 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1128 spec->input_mux = &cxt5045_capture_source;
1129 spec->num_init_verbs = 2;
1130 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1131 spec->mixers[0] = cxt5045_mixers;
1132 codec->patch_ops.init = cxt5045_init;
1135 case CXT5045_LAPTOP_HPMICSENSE:
1136 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1137 spec->input_mux = &cxt5045_capture_source;
1138 spec->num_init_verbs = 3;
1139 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1140 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1141 spec->mixers[0] = cxt5045_mixers;
1142 codec->patch_ops.init = cxt5045_init;
1145 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1146 spec->input_mux = &cxt5045_capture_source_benq;
1147 spec->num_init_verbs = 1;
1148 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1149 spec->mixers[0] = cxt5045_mixers;
1150 spec->mixers[1] = cxt5045_benq_mixers;
1151 spec->num_mixers = 2;
1152 codec->patch_ops.init = cxt5045_init;
1154 case CXT5045_LAPTOP_HP530:
1155 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1156 spec->input_mux = &cxt5045_capture_source_hp530;
1157 spec->num_init_verbs = 2;
1158 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1159 spec->mixers[0] = cxt5045_mixers_hp530;
1160 codec->patch_ops.init = cxt5045_init;
1162 #ifdef CONFIG_SND_DEBUG
1164 spec->input_mux = &cxt5045_test_capture_source;
1165 spec->mixers[0] = cxt5045_test_mixer;
1166 spec->init_verbs[0] = cxt5045_test_init_verbs;
1172 switch (codec->subsystem_id >> 16) {
1177 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1178 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1179 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1181 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1182 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1183 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1184 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1185 (1 << AC_AMPCAP_MUTE_SHIFT));
1190 snd_hda_attach_beep_device(codec, spec->beep_amp);
1196 /* Conexant 5047 specific */
1197 #define CXT5047_SPDIF_OUT 0x11
1199 static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1200 static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1201 static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1203 static const struct hda_channel_mode cxt5047_modes[1] = {
1207 static const struct hda_input_mux cxt5047_toshiba_capture_source = {
1215 /* turn on/off EAPD (+ mute HP) as a master switch */
1216 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1217 struct snd_ctl_elem_value *ucontrol)
1219 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1220 struct conexant_spec *spec = codec->spec;
1223 if (!cxt_eapd_put(kcontrol, ucontrol))
1226 /* toggle internal speakers mute depending of presence of
1227 * the headphone jack
1229 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1230 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1231 * pin widgets unlike other codecs. In this case, we need to
1232 * set index 0x01 for the volume from the mixer amp 0x19.
1234 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1235 HDA_AMP_MUTE, bits);
1236 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1237 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1238 HDA_AMP_MUTE, bits);
1242 /* mute internal speaker if HP is plugged */
1243 static void cxt5047_hp_automute(struct hda_codec *codec)
1245 struct conexant_spec *spec = codec->spec;
1248 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1250 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1251 /* See the note in cxt5047_hp_master_sw_put */
1252 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1253 HDA_AMP_MUTE, bits);
1256 /* toggle input of built-in and mic jack appropriately */
1257 static void cxt5047_hp_automic(struct hda_codec *codec)
1259 static const struct hda_verb mic_jack_on[] = {
1260 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1261 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1264 static const struct hda_verb mic_jack_off[] = {
1265 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1266 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1269 unsigned int present;
1271 present = snd_hda_jack_detect(codec, 0x15);
1273 snd_hda_sequence_write(codec, mic_jack_on);
1275 snd_hda_sequence_write(codec, mic_jack_off);
1278 /* unsolicited event for HP jack sensing */
1279 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1282 switch (res >> 26) {
1283 case CONEXANT_HP_EVENT:
1284 cxt5047_hp_automute(codec);
1286 case CONEXANT_MIC_EVENT:
1287 cxt5047_hp_automic(codec);
1292 static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1293 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1294 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1295 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1296 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1297 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1298 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1299 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1301 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1302 .name = "Master Playback Switch",
1303 .info = cxt_eapd_info,
1304 .get = cxt_eapd_get,
1305 .put = cxt5047_hp_master_sw_put,
1306 .private_value = 0x13,
1312 static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1313 /* See the note in cxt5047_hp_master_sw_put */
1314 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1315 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1319 static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1320 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1324 static const struct hda_verb cxt5047_init_verbs[] = {
1325 /* Line in, Mic, Built-in Mic */
1326 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1327 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1328 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1330 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1331 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1332 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1333 /* Record selector: Mic */
1334 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1335 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1336 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1337 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1338 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1339 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1340 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1341 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1342 /* SPDIF route: PCM */
1343 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1344 /* Enable unsolicited events */
1345 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1346 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1350 /* configuration for Toshiba Laptops */
1351 static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
1352 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1356 /* Test configuration for debugging, modelled after the ALC260 test
1359 #ifdef CONFIG_SND_DEBUG
1360 static const struct hda_input_mux cxt5047_test_capture_source = {
1363 { "LINE1 pin", 0x0 },
1364 { "MIC1 pin", 0x1 },
1365 { "MIC2 pin", 0x2 },
1370 static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1372 /* Output only controls */
1373 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1374 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1375 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1376 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1377 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1378 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1379 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1380 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1381 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1382 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1383 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1384 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1386 /* Modes for retasking pin widgets */
1387 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1388 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1390 /* EAPD Switch Control */
1391 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1393 /* Loopback mixer controls */
1394 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1395 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1396 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1397 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1398 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1399 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1400 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1401 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1403 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1404 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1405 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1406 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1407 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1408 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1409 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1410 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1412 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1413 .name = "Input Source",
1414 .info = conexant_mux_enum_info,
1415 .get = conexant_mux_enum_get,
1416 .put = conexant_mux_enum_put,
1418 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1423 static const struct hda_verb cxt5047_test_init_verbs[] = {
1424 /* Enable retasking pins as output, initially without power amp */
1425 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1426 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1427 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1429 /* Disable digital (SPDIF) pins initially, but users can enable
1430 * them via a mixer switch. In the case of SPDIF-out, this initverb
1431 * payload also sets the generation to 0, output to be in "consumer"
1432 * PCM format, copyright asserted, no pre-emphasis and no validity
1435 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1437 /* Ensure mic1, mic2, line1 pin widgets take input from the
1438 * OUT1 sum bus when acting as an output.
1440 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1441 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1443 /* Start with output sum widgets muted and their output gains at min */
1444 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1445 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1447 /* Unmute retasking pin widget output buffers since the default
1448 * state appears to be output. As the pin mode is changed by the
1449 * user the pin mode control will take care of enabling the pin's
1450 * input/output buffers as needed.
1452 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1453 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1454 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1456 /* Mute capture amp left and right */
1457 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1459 /* Set ADC connection select to match default mixer setting (mic1
1462 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1464 /* Mute all inputs to mixer widget (even unconnected ones) */
1465 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1466 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1467 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1468 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1469 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1470 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1471 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1472 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1479 /* initialize jack-sensing, too */
1480 static int cxt5047_hp_init(struct hda_codec *codec)
1482 conexant_init(codec);
1483 cxt5047_hp_automute(codec);
1489 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1490 CXT5047_LAPTOP_HP, /* Some HP laptops */
1491 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1492 #ifdef CONFIG_SND_DEBUG
1499 static const char * const cxt5047_models[CXT5047_MODELS] = {
1500 [CXT5047_LAPTOP] = "laptop",
1501 [CXT5047_LAPTOP_HP] = "laptop-hp",
1502 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1503 #ifdef CONFIG_SND_DEBUG
1504 [CXT5047_TEST] = "test",
1506 [CXT5047_AUTO] = "auto",
1509 static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1510 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1511 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1513 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1517 static int patch_cxt5047(struct hda_codec *codec)
1519 struct conexant_spec *spec;
1522 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1525 if (board_config < 0)
1526 board_config = CXT5047_AUTO; /* model=auto as default */
1527 if (board_config == CXT5047_AUTO)
1528 return patch_conexant_auto(codec);
1530 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1534 codec->pin_amp_workaround = 1;
1536 spec->multiout.max_channels = 2;
1537 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1538 spec->multiout.dac_nids = cxt5047_dac_nids;
1539 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1540 spec->num_adc_nids = 1;
1541 spec->adc_nids = cxt5047_adc_nids;
1542 spec->capsrc_nids = cxt5047_capsrc_nids;
1543 spec->num_mixers = 1;
1544 spec->mixers[0] = cxt5047_base_mixers;
1545 spec->num_init_verbs = 1;
1546 spec->init_verbs[0] = cxt5047_init_verbs;
1547 spec->spdif_route = 0;
1548 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1549 spec->channel_mode = cxt5047_modes,
1551 codec->patch_ops = conexant_patch_ops;
1553 switch (board_config) {
1554 case CXT5047_LAPTOP:
1555 spec->num_mixers = 2;
1556 spec->mixers[1] = cxt5047_hp_spk_mixers;
1557 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1559 case CXT5047_LAPTOP_HP:
1560 spec->num_mixers = 2;
1561 spec->mixers[1] = cxt5047_hp_only_mixers;
1562 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1563 codec->patch_ops.init = cxt5047_hp_init;
1565 case CXT5047_LAPTOP_EAPD:
1566 spec->input_mux = &cxt5047_toshiba_capture_source;
1567 spec->num_mixers = 2;
1568 spec->mixers[1] = cxt5047_hp_spk_mixers;
1569 spec->num_init_verbs = 2;
1570 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1571 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1573 #ifdef CONFIG_SND_DEBUG
1575 spec->input_mux = &cxt5047_test_capture_source;
1576 spec->mixers[0] = cxt5047_test_mixer;
1577 spec->init_verbs[0] = cxt5047_test_init_verbs;
1578 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1581 spec->vmaster_nid = 0x13;
1583 switch (codec->subsystem_id >> 16) {
1585 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1586 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1587 * with 0 dB offset 0x17)
1589 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1590 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1591 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1592 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1593 (1 << AC_AMPCAP_MUTE_SHIFT));
1600 /* Conexant 5051 specific */
1601 static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1602 static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1604 static const struct hda_channel_mode cxt5051_modes[1] = {
1608 static void cxt5051_update_speaker(struct hda_codec *codec)
1610 struct conexant_spec *spec = codec->spec;
1611 unsigned int pinctl;
1613 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1614 snd_hda_set_pin_ctl(codec, 0x16, pinctl);
1616 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1617 snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
1618 /* on ideapad there is an additional speaker (subwoofer) to mute */
1620 snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
1623 /* turn on/off EAPD (+ mute HP) as a master switch */
1624 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1625 struct snd_ctl_elem_value *ucontrol)
1627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1629 if (!cxt_eapd_put(kcontrol, ucontrol))
1631 cxt5051_update_speaker(codec);
1635 /* toggle input of built-in and mic jack appropriately */
1636 static void cxt5051_portb_automic(struct hda_codec *codec)
1638 struct conexant_spec *spec = codec->spec;
1639 unsigned int present;
1641 if (!(spec->auto_mic & AUTO_MIC_PORTB))
1643 present = snd_hda_jack_detect(codec, 0x17);
1644 snd_hda_codec_write(codec, 0x14, 0,
1645 AC_VERB_SET_CONNECT_SEL,
1646 present ? 0x01 : 0x00);
1649 /* switch the current ADC according to the jack state */
1650 static void cxt5051_portc_automic(struct hda_codec *codec)
1652 struct conexant_spec *spec = codec->spec;
1653 unsigned int present;
1656 if (!(spec->auto_mic & AUTO_MIC_PORTC))
1658 present = snd_hda_jack_detect(codec, 0x18);
1660 spec->cur_adc_idx = 1;
1662 spec->cur_adc_idx = 0;
1663 new_adc = spec->adc_nids[spec->cur_adc_idx];
1664 if (spec->cur_adc && spec->cur_adc != new_adc) {
1665 /* stream is running, let's swap the current ADC */
1666 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1667 spec->cur_adc = new_adc;
1668 snd_hda_codec_setup_stream(codec, new_adc,
1669 spec->cur_adc_stream_tag, 0,
1670 spec->cur_adc_format);
1674 /* mute internal speaker if HP is plugged */
1675 static void cxt5051_hp_automute(struct hda_codec *codec)
1677 struct conexant_spec *spec = codec->spec;
1679 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1680 cxt5051_update_speaker(codec);
1683 /* unsolicited event for HP jack sensing */
1684 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1687 switch (res >> 26) {
1688 case CONEXANT_HP_EVENT:
1689 cxt5051_hp_automute(codec);
1691 case CXT5051_PORTB_EVENT:
1692 cxt5051_portb_automic(codec);
1694 case CXT5051_PORTC_EVENT:
1695 cxt5051_portc_automic(codec);
1700 static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1701 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1703 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1704 .name = "Master Playback Switch",
1705 .info = cxt_eapd_info,
1706 .get = cxt_eapd_get,
1707 .put = cxt5051_hp_master_sw_put,
1708 .private_value = 0x1a,
1713 static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1714 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1715 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1716 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1717 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1718 HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1719 HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
1723 static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1724 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1725 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1726 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1727 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1731 static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1732 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1733 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
1737 static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1738 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1739 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1743 static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1744 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1745 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1746 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1747 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1751 static const struct hda_verb cxt5051_init_verbs[] = {
1753 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1754 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1755 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1756 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1757 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1758 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1760 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1761 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1763 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1764 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1766 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1767 /* Record selector: Internal mic */
1768 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1769 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1770 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1771 /* SPDIF route: PCM */
1772 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1773 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1775 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1776 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1780 static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1782 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1783 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1784 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1785 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1787 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1788 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1790 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1791 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1793 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1794 /* Record selector: Internal mic */
1795 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1796 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1797 /* SPDIF route: PCM */
1798 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1800 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1801 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1805 static const struct hda_verb cxt5051_f700_init_verbs[] = {
1807 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1808 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1809 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1810 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1812 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1813 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1815 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1816 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1818 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1819 /* Record selector: Internal mic */
1820 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1821 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1822 /* SPDIF route: PCM */
1823 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1825 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1826 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1830 static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1833 snd_hda_codec_write(codec, nid, 0,
1834 AC_VERB_SET_UNSOLICITED_ENABLE,
1835 AC_USRSP_EN | event);
1838 static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1840 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1841 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1845 /* initialize jack-sensing, too */
1846 static int cxt5051_init(struct hda_codec *codec)
1848 struct conexant_spec *spec = codec->spec;
1850 conexant_init(codec);
1852 if (spec->auto_mic & AUTO_MIC_PORTB)
1853 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1854 if (spec->auto_mic & AUTO_MIC_PORTC)
1855 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1857 if (codec->patch_ops.unsol_event) {
1858 cxt5051_hp_automute(codec);
1859 cxt5051_portb_automic(codec);
1860 cxt5051_portc_automic(codec);
1867 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1868 CXT5051_HP, /* no docking */
1869 CXT5051_HP_DV6736, /* HP without mic switch */
1870 CXT5051_F700, /* HP Compaq Presario F700 */
1871 CXT5051_TOSHIBA, /* Toshiba M300 & co */
1872 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
1873 CXT5051_AUTO, /* auto-parser */
1877 static const char *const cxt5051_models[CXT5051_MODELS] = {
1878 [CXT5051_LAPTOP] = "laptop",
1879 [CXT5051_HP] = "hp",
1880 [CXT5051_HP_DV6736] = "hp-dv6736",
1881 [CXT5051_F700] = "hp-700",
1882 [CXT5051_TOSHIBA] = "toshiba",
1883 [CXT5051_IDEAPAD] = "ideapad",
1884 [CXT5051_AUTO] = "auto",
1887 static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1888 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1889 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1890 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1891 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1892 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1894 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1895 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1899 static int patch_cxt5051(struct hda_codec *codec)
1901 struct conexant_spec *spec;
1904 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1907 if (board_config < 0)
1908 board_config = CXT5051_AUTO; /* model=auto as default */
1909 if (board_config == CXT5051_AUTO)
1910 return patch_conexant_auto(codec);
1912 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1916 codec->pin_amp_workaround = 1;
1918 codec->patch_ops = conexant_patch_ops;
1919 codec->patch_ops.init = cxt5051_init;
1921 spec->multiout.max_channels = 2;
1922 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1923 spec->multiout.dac_nids = cxt5051_dac_nids;
1924 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1925 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1926 spec->adc_nids = cxt5051_adc_nids;
1927 spec->num_mixers = 2;
1928 spec->mixers[0] = cxt5051_capture_mixers;
1929 spec->mixers[1] = cxt5051_playback_mixers;
1930 spec->num_init_verbs = 1;
1931 spec->init_verbs[0] = cxt5051_init_verbs;
1932 spec->spdif_route = 0;
1933 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1934 spec->channel_mode = cxt5051_modes;
1936 spec->cur_adc_idx = 0;
1938 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1940 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1942 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
1943 switch (board_config) {
1945 spec->mixers[0] = cxt5051_hp_mixers;
1947 case CXT5051_HP_DV6736:
1948 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1949 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1953 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1954 spec->mixers[0] = cxt5051_f700_mixers;
1957 case CXT5051_TOSHIBA:
1958 spec->mixers[0] = cxt5051_toshiba_mixers;
1959 spec->auto_mic = AUTO_MIC_PORTB;
1961 case CXT5051_IDEAPAD:
1962 spec->init_verbs[spec->num_init_verbs++] =
1963 cxt5051_ideapad_init_verbs;
1969 snd_hda_attach_beep_device(codec, spec->beep_amp);
1974 /* Conexant 5066 specific */
1976 static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1977 static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1978 static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1979 static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
1981 /* OLPC's microphone port is DC coupled for use with external sensors,
1982 * therefore we use a 50% mic bias in order to center the input signal with
1983 * the DC input range of the codec. */
1984 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1986 static const struct hda_channel_mode cxt5066_modes[1] = {
1990 #define HP_PRESENT_PORT_A (1 << 0)
1991 #define HP_PRESENT_PORT_D (1 << 1)
1992 #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1993 #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1995 static void cxt5066_update_speaker(struct hda_codec *codec)
1997 struct conexant_spec *spec = codec->spec;
1998 unsigned int pinctl;
2000 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2001 spec->hp_present, spec->cur_eapd);
2004 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
2005 snd_hda_set_pin_ctl(codec, 0x19, pinctl);
2007 /* Port D (HP/LO) */
2008 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2009 if (spec->dell_automute || spec->thinkpad) {
2010 /* Mute if Port A is connected */
2011 if (hp_port_a_present(spec))
2014 /* Thinkpad/Dell doesn't give pin-D status */
2015 if (!hp_port_d_present(spec))
2018 snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
2021 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2022 snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
2025 /* turn on/off EAPD (+ mute HP) as a master switch */
2026 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2027 struct snd_ctl_elem_value *ucontrol)
2029 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2031 if (!cxt_eapd_put(kcontrol, ucontrol))
2034 cxt5066_update_speaker(codec);
2038 static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2042 { "50%", PIN_VREF50 },
2043 { "80%", PIN_VREF80 },
2047 static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2049 struct conexant_spec *spec = codec->spec;
2050 /* Even though port F is the DC input, the bias is controlled on port B.
2051 * we also leave that port as an active input (but unselected) in DC mode
2052 * just in case that is necessary to make the bias setting take effect. */
2053 return snd_hda_set_pin_ctl_cache(codec, 0x1a,
2054 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2057 /* OLPC defers mic widget control until when capture is started because the
2058 * microphone LED comes on as soon as these settings are put in place. if we
2059 * did this before recording, it would give the false indication that recording
2060 * is happening when it is not. */
2061 static void cxt5066_olpc_select_mic(struct hda_codec *codec)
2063 struct conexant_spec *spec = codec->spec;
2064 if (!spec->recording)
2067 if (spec->dc_enable) {
2068 /* in DC mode we ignore presence detection and just use the jack
2069 * through our special DC port */
2070 const struct hda_verb enable_dc_mode[] = {
2071 /* disble internal mic, port C */
2072 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2074 /* enable DC capture, port F */
2075 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2079 snd_hda_sequence_write(codec, enable_dc_mode);
2080 /* port B input disabled (and bias set) through the following call */
2081 cxt5066_set_olpc_dc_bias(codec);
2085 /* disable DC (port F) */
2086 snd_hda_set_pin_ctl(codec, 0x1e, 0);
2088 /* external mic, port B */
2089 snd_hda_set_pin_ctl(codec, 0x1a,
2090 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
2092 /* internal mic, port C */
2093 snd_hda_set_pin_ctl(codec, 0x1b,
2094 spec->ext_mic_present ? 0 : PIN_VREF80);
2097 /* toggle input of built-in and mic jack appropriately */
2098 static void cxt5066_olpc_automic(struct hda_codec *codec)
2100 struct conexant_spec *spec = codec->spec;
2101 unsigned int present;
2103 if (spec->dc_enable) /* don't do presence detection in DC mode */
2106 present = snd_hda_codec_read(codec, 0x1a, 0,
2107 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2109 snd_printdd("CXT5066: external microphone detected\n");
2111 snd_printdd("CXT5066: external microphone absent\n");
2113 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2115 spec->ext_mic_present = !!present;
2117 cxt5066_olpc_select_mic(codec);
2120 /* toggle input of built-in digital mic and mic jack appropriately */
2121 static void cxt5066_vostro_automic(struct hda_codec *codec)
2123 unsigned int present;
2125 struct hda_verb ext_mic_present[] = {
2126 /* enable external mic, port B */
2127 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2129 /* switch to external mic input */
2130 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2131 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2133 /* disable internal digital mic */
2134 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2137 static const struct hda_verb ext_mic_absent[] = {
2138 /* enable internal mic, port C */
2139 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2141 /* switch to internal mic input */
2142 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2144 /* disable external mic, port B */
2145 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2149 present = snd_hda_jack_detect(codec, 0x1a);
2151 snd_printdd("CXT5066: external microphone detected\n");
2152 snd_hda_sequence_write(codec, ext_mic_present);
2154 snd_printdd("CXT5066: external microphone absent\n");
2155 snd_hda_sequence_write(codec, ext_mic_absent);
2159 /* toggle input of built-in digital mic and mic jack appropriately */
2160 static void cxt5066_ideapad_automic(struct hda_codec *codec)
2162 unsigned int present;
2164 struct hda_verb ext_mic_present[] = {
2165 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2166 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2167 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2170 static const struct hda_verb ext_mic_absent[] = {
2171 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2172 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2173 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2177 present = snd_hda_jack_detect(codec, 0x1b);
2179 snd_printdd("CXT5066: external microphone detected\n");
2180 snd_hda_sequence_write(codec, ext_mic_present);
2182 snd_printdd("CXT5066: external microphone absent\n");
2183 snd_hda_sequence_write(codec, ext_mic_absent);
2188 /* toggle input of built-in digital mic and mic jack appropriately */
2189 static void cxt5066_asus_automic(struct hda_codec *codec)
2191 unsigned int present;
2193 present = snd_hda_jack_detect(codec, 0x1b);
2194 snd_printdd("CXT5066: external microphone present=%d\n", present);
2195 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2200 /* toggle input of built-in digital mic and mic jack appropriately */
2201 static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2203 unsigned int present;
2205 present = snd_hda_jack_detect(codec, 0x1b);
2206 snd_printdd("CXT5066: external microphone present=%d\n", present);
2207 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2212 /* toggle input of built-in digital mic and mic jack appropriately
2213 order is: external mic -> dock mic -> interal mic */
2214 static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2216 unsigned int ext_present, dock_present;
2218 static const struct hda_verb ext_mic_present[] = {
2219 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2220 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2221 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2222 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2223 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2226 static const struct hda_verb dock_mic_present[] = {
2227 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2228 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2229 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2230 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2231 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2234 static const struct hda_verb ext_mic_absent[] = {
2235 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2236 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2237 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2238 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2242 ext_present = snd_hda_jack_detect(codec, 0x1b);
2243 dock_present = snd_hda_jack_detect(codec, 0x1a);
2245 snd_printdd("CXT5066: external microphone detected\n");
2246 snd_hda_sequence_write(codec, ext_mic_present);
2247 } else if (dock_present) {
2248 snd_printdd("CXT5066: dock microphone detected\n");
2249 snd_hda_sequence_write(codec, dock_mic_present);
2251 snd_printdd("CXT5066: external microphone absent\n");
2252 snd_hda_sequence_write(codec, ext_mic_absent);
2256 /* mute internal speaker if HP is plugged */
2257 static void cxt5066_hp_automute(struct hda_codec *codec)
2259 struct conexant_spec *spec = codec->spec;
2260 unsigned int portA, portD;
2263 portA = snd_hda_jack_detect(codec, 0x19);
2266 portD = snd_hda_jack_detect(codec, 0x1c);
2268 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2269 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
2270 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2271 portA, portD, spec->hp_present);
2272 cxt5066_update_speaker(codec);
2275 /* Dispatch the right mic autoswitch function */
2276 static void cxt5066_automic(struct hda_codec *codec)
2278 struct conexant_spec *spec = codec->spec;
2280 if (spec->dell_vostro)
2281 cxt5066_vostro_automic(codec);
2282 else if (spec->ideapad)
2283 cxt5066_ideapad_automic(codec);
2284 else if (spec->thinkpad)
2285 cxt5066_thinkpad_automic(codec);
2286 else if (spec->hp_laptop)
2287 cxt5066_hp_laptop_automic(codec);
2288 else if (spec->asus)
2289 cxt5066_asus_automic(codec);
2292 /* unsolicited event for jack sensing */
2293 static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
2295 struct conexant_spec *spec = codec->spec;
2296 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2297 switch (res >> 26) {
2298 case CONEXANT_HP_EVENT:
2299 cxt5066_hp_automute(codec);
2301 case CONEXANT_MIC_EVENT:
2302 /* ignore mic events in DC mode; we're always using the jack */
2303 if (!spec->dc_enable)
2304 cxt5066_olpc_automic(codec);
2309 /* unsolicited event for jack sensing */
2310 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2312 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2313 switch (res >> 26) {
2314 case CONEXANT_HP_EVENT:
2315 cxt5066_hp_automute(codec);
2317 case CONEXANT_MIC_EVENT:
2318 cxt5066_automic(codec);
2324 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2335 static void cxt5066_set_mic_boost(struct hda_codec *codec)
2337 struct conexant_spec *spec = codec->spec;
2338 snd_hda_codec_write_cache(codec, 0x17, 0,
2339 AC_VERB_SET_AMP_GAIN_MUTE,
2340 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2341 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
2342 if (spec->ideapad || spec->thinkpad) {
2343 /* adjust the internal mic as well...it is not through 0x17 */
2344 snd_hda_codec_write_cache(codec, 0x23, 0,
2345 AC_VERB_SET_AMP_GAIN_MUTE,
2346 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2347 cxt5066_analog_mic_boost.
2348 items[spec->mic_boost].index);
2352 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2353 struct snd_ctl_elem_info *uinfo)
2355 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2358 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2359 struct snd_ctl_elem_value *ucontrol)
2361 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2362 struct conexant_spec *spec = codec->spec;
2363 ucontrol->value.enumerated.item[0] = spec->mic_boost;
2367 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2368 struct snd_ctl_elem_value *ucontrol)
2370 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2371 struct conexant_spec *spec = codec->spec;
2372 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2374 idx = ucontrol->value.enumerated.item[0];
2375 if (idx >= imux->num_items)
2376 idx = imux->num_items - 1;
2378 spec->mic_boost = idx;
2379 if (!spec->dc_enable)
2380 cxt5066_set_mic_boost(codec);
2384 static void cxt5066_enable_dc(struct hda_codec *codec)
2386 const struct hda_verb enable_dc_mode[] = {
2388 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2390 /* switch to DC input */
2391 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2395 /* configure as input source */
2396 snd_hda_sequence_write(codec, enable_dc_mode);
2397 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2400 static void cxt5066_disable_dc(struct hda_codec *codec)
2402 /* reconfigure input source */
2403 cxt5066_set_mic_boost(codec);
2404 /* automic also selects the right mic if we're recording */
2405 cxt5066_olpc_automic(codec);
2408 static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2409 struct snd_ctl_elem_value *ucontrol)
2411 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2412 struct conexant_spec *spec = codec->spec;
2413 ucontrol->value.integer.value[0] = spec->dc_enable;
2417 static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2418 struct snd_ctl_elem_value *ucontrol)
2420 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2421 struct conexant_spec *spec = codec->spec;
2422 int dc_enable = !!ucontrol->value.integer.value[0];
2424 if (dc_enable == spec->dc_enable)
2427 spec->dc_enable = dc_enable;
2429 cxt5066_enable_dc(codec);
2431 cxt5066_disable_dc(codec);
2436 static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2437 struct snd_ctl_elem_info *uinfo)
2439 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2442 static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2443 struct snd_ctl_elem_value *ucontrol)
2445 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2446 struct conexant_spec *spec = codec->spec;
2447 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2451 static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2452 struct snd_ctl_elem_value *ucontrol)
2454 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2455 struct conexant_spec *spec = codec->spec;
2456 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2459 idx = ucontrol->value.enumerated.item[0];
2460 if (idx >= imux->num_items)
2461 idx = imux->num_items - 1;
2463 spec->dc_input_bias = idx;
2464 if (spec->dc_enable)
2465 cxt5066_set_olpc_dc_bias(codec);
2469 static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2471 struct conexant_spec *spec = codec->spec;
2472 /* mark as recording and configure the microphone widget so that the
2473 * recording LED comes on. */
2474 spec->recording = 1;
2475 cxt5066_olpc_select_mic(codec);
2478 static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2480 struct conexant_spec *spec = codec->spec;
2481 const struct hda_verb disable_mics[] = {
2482 /* disable external mic, port B */
2483 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2485 /* disble internal mic, port C */
2486 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2488 /* disable DC capture, port F */
2489 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2493 snd_hda_sequence_write(codec, disable_mics);
2494 spec->recording = 0;
2497 static void conexant_check_dig_outs(struct hda_codec *codec,
2498 const hda_nid_t *dig_pins,
2501 struct conexant_spec *spec = codec->spec;
2502 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2505 for (i = 0; i < num_pins; i++, dig_pins++) {
2506 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2507 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2509 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2511 if (spec->slave_dig_outs[0])
2514 nid_loc = spec->slave_dig_outs;
2518 static const struct hda_input_mux cxt5066_capture_source = {
2528 static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2529 .ops = &snd_hda_bind_vol,
2531 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2532 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2537 static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2538 .ops = &snd_hda_bind_sw,
2540 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2541 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2546 static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
2547 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2551 static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2553 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2554 .name = "Master Playback Volume",
2555 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2556 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2557 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2558 .subdevice = HDA_SUBDEV_AMP_FLAG,
2559 .info = snd_hda_mixer_amp_volume_info,
2560 .get = snd_hda_mixer_amp_volume_get,
2561 .put = snd_hda_mixer_amp_volume_put,
2562 .tlv = { .c = snd_hda_mixer_amp_tlv },
2563 /* offset by 28 volume steps to limit minimum gain to -46dB */
2565 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2570 static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2572 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2573 .name = "DC Mode Enable Switch",
2574 .info = snd_ctl_boolean_mono_info,
2575 .get = cxt5066_olpc_dc_get,
2576 .put = cxt5066_olpc_dc_put,
2579 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2580 .name = "DC Input Bias Enum",
2581 .info = cxt5066_olpc_dc_bias_enum_info,
2582 .get = cxt5066_olpc_dc_bias_enum_get,
2583 .put = cxt5066_olpc_dc_bias_enum_put,
2588 static const struct snd_kcontrol_new cxt5066_mixers[] = {
2590 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2591 .name = "Master Playback Switch",
2592 .info = cxt_eapd_info,
2593 .get = cxt_eapd_get,
2594 .put = cxt5066_hp_master_sw_put,
2595 .private_value = 0x1d,
2599 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2600 .name = "Analog Mic Boost Capture Enum",
2601 .info = cxt5066_mic_boost_mux_enum_info,
2602 .get = cxt5066_mic_boost_mux_enum_get,
2603 .put = cxt5066_mic_boost_mux_enum_put,
2606 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2607 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2611 static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2613 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2614 .name = "Internal Mic Boost Capture Enum",
2615 .info = cxt5066_mic_boost_mux_enum_info,
2616 .get = cxt5066_mic_boost_mux_enum_get,
2617 .put = cxt5066_mic_boost_mux_enum_put,
2618 .private_value = 0x23 | 0x100,
2623 static const struct hda_verb cxt5066_init_verbs[] = {
2624 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2625 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2626 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2627 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2630 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2631 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2634 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2635 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2637 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2638 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2641 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2643 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2644 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2645 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2646 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2647 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2648 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2650 /* no digital microphone support yet */
2651 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2653 /* Audio input selector */
2654 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2656 /* SPDIF route: PCM */
2657 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2658 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2660 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2661 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2664 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2666 /* not handling these yet */
2667 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2668 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2669 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2670 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2671 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2672 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2673 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2674 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2678 static const struct hda_verb cxt5066_init_verbs_olpc[] = {
2679 /* Port A: headphones */
2680 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2681 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2683 /* Port B: external microphone */
2684 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2686 /* Port C: internal microphone */
2687 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2689 /* Port D: unused */
2690 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2692 /* Port E: unused, but has primary EAPD */
2693 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2694 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2696 /* Port F: external DC input through microphone port */
2697 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2699 /* Port G: internal speakers */
2700 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2701 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2704 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2707 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2709 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2710 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2711 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2712 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2713 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2714 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2715 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2716 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2717 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2718 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2719 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2720 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2722 /* Disable digital microphone port */
2723 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2725 /* Audio input selectors */
2726 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2727 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2730 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2731 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2733 /* enable unsolicited events for Port A and B */
2734 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2735 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2739 static const struct hda_verb cxt5066_init_verbs_vostro[] = {
2740 /* Port A: headphones */
2741 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2742 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2744 /* Port B: external microphone */
2745 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2747 /* Port C: unused */
2748 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2750 /* Port D: unused */
2751 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2753 /* Port E: unused, but has primary EAPD */
2754 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2755 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2757 /* Port F: unused */
2758 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2760 /* Port G: internal speakers */
2761 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2762 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2765 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2768 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2770 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2771 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2772 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2773 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2774 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2775 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2776 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2777 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2778 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2779 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2780 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2781 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2783 /* Digital microphone port */
2784 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2786 /* Audio input selectors */
2787 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2788 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2791 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2792 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2794 /* enable unsolicited events for Port A and B */
2795 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2796 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2800 static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2801 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2802 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2803 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2804 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2807 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2808 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2811 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2812 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2814 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2815 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2818 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2820 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2821 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2822 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2823 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2824 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2825 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2826 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2828 /* Audio input selector */
2829 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2830 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2832 /* SPDIF route: PCM */
2833 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2834 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2836 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2837 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2839 /* internal microphone */
2840 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2843 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2845 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2846 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2850 static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2851 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2852 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2854 /* Port G: internal speakers */
2855 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2856 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2858 /* Port A: HP, Amp */
2859 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2860 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2862 /* Port B: Mic Dock */
2863 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2866 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2868 /* Port D: HP Dock, Amp */
2869 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2870 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2873 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2875 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2876 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2877 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2878 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2879 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2880 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2881 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2883 /* Audio input selector */
2884 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2885 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2887 /* SPDIF route: PCM */
2888 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2889 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2891 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2892 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2894 /* internal microphone */
2895 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2898 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2900 /* enable unsolicited events for Port A, B, C and D */
2901 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2902 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2903 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2904 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2908 static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2909 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2914 static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2915 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
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 /* initialize jack-sensing, too */
2922 static int cxt5066_init(struct hda_codec *codec)
2924 snd_printdd("CXT5066: init\n");
2925 conexant_init(codec);
2926 if (codec->patch_ops.unsol_event) {
2927 cxt5066_hp_automute(codec);
2928 cxt5066_automic(codec);
2930 cxt5066_set_mic_boost(codec);
2934 static int cxt5066_olpc_init(struct hda_codec *codec)
2936 struct conexant_spec *spec = codec->spec;
2937 snd_printdd("CXT5066: init\n");
2938 conexant_init(codec);
2939 cxt5066_hp_automute(codec);
2940 if (!spec->dc_enable) {
2941 cxt5066_set_mic_boost(codec);
2942 cxt5066_olpc_automic(codec);
2944 cxt5066_enable_dc(codec);
2950 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2951 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2952 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
2953 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
2954 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
2955 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
2956 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
2957 CXT5066_HP_LAPTOP, /* HP Laptop */
2958 CXT5066_AUTO, /* BIOS auto-parser */
2962 static const char * const cxt5066_models[CXT5066_MODELS] = {
2963 [CXT5066_LAPTOP] = "laptop",
2964 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2965 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
2966 [CXT5066_DELL_VOSTRO] = "dell-vostro",
2967 [CXT5066_IDEAPAD] = "ideapad",
2968 [CXT5066_THINKPAD] = "thinkpad",
2969 [CXT5066_ASUS] = "asus",
2970 [CXT5066_HP_LAPTOP] = "hp-laptop",
2971 [CXT5066_AUTO] = "auto",
2974 static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2975 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
2976 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
2977 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
2978 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
2979 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
2980 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2981 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
2982 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
2983 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
2984 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
2985 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
2986 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
2987 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
2988 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2990 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
2991 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
2992 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
2993 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
2994 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
2995 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
2996 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
2997 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
3001 static int patch_cxt5066(struct hda_codec *codec)
3003 struct conexant_spec *spec;
3006 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3007 cxt5066_models, cxt5066_cfg_tbl);
3008 if (board_config < 0)
3009 board_config = CXT5066_AUTO; /* model=auto as default */
3010 if (board_config == CXT5066_AUTO)
3011 return patch_conexant_auto(codec);
3013 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3018 codec->patch_ops = conexant_patch_ops;
3019 codec->patch_ops.init = conexant_init;
3021 spec->dell_automute = 0;
3022 spec->multiout.max_channels = 2;
3023 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3024 spec->multiout.dac_nids = cxt5066_dac_nids;
3025 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3026 ARRAY_SIZE(cxt5066_digout_pin_nids));
3027 spec->num_adc_nids = 1;
3028 spec->adc_nids = cxt5066_adc_nids;
3029 spec->capsrc_nids = cxt5066_capsrc_nids;
3030 spec->input_mux = &cxt5066_capture_source;
3032 spec->port_d_mode = PIN_HP;
3034 spec->num_init_verbs = 1;
3035 spec->init_verbs[0] = cxt5066_init_verbs;
3036 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3037 spec->channel_mode = cxt5066_modes;
3039 spec->cur_adc_idx = 0;
3041 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3043 switch (board_config) {
3045 case CXT5066_LAPTOP:
3046 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3047 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3049 case CXT5066_DELL_LAPTOP:
3050 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3051 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3053 spec->port_d_mode = PIN_OUT;
3054 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3055 spec->num_init_verbs++;
3056 spec->dell_automute = 1;
3059 case CXT5066_HP_LAPTOP:
3060 codec->patch_ops.init = cxt5066_init;
3061 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3062 spec->init_verbs[spec->num_init_verbs] =
3063 cxt5066_init_verbs_hp_laptop;
3064 spec->num_init_verbs++;
3065 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3066 spec->asus = board_config == CXT5066_ASUS;
3067 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3068 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3070 if (board_config == CXT5066_HP_LAPTOP)
3071 spec->multiout.dig_out_nid = 0;
3072 /* input source automatically selected */
3073 spec->input_mux = NULL;
3074 spec->port_d_mode = 0;
3075 spec->mic_boost = 3; /* default 30dB gain */
3078 case CXT5066_OLPC_XO_1_5:
3079 codec->patch_ops.init = cxt5066_olpc_init;
3080 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
3081 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3082 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3083 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
3084 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3085 spec->port_d_mode = 0;
3086 spec->mic_boost = 3; /* default 30dB gain */
3089 spec->multiout.dig_out_nid = 0;
3091 /* input source automatically selected */
3092 spec->input_mux = NULL;
3094 /* our capture hooks which allow us to turn on the microphone LED
3095 * at the right time */
3096 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3097 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
3099 case CXT5066_DELL_VOSTRO:
3100 codec->patch_ops.init = cxt5066_init;
3101 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3102 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3103 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3104 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3105 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
3106 spec->port_d_mode = 0;
3107 spec->dell_vostro = 1;
3108 spec->mic_boost = 3; /* default 30dB gain */
3111 spec->multiout.dig_out_nid = 0;
3113 /* input source automatically selected */
3114 spec->input_mux = NULL;
3116 case CXT5066_IDEAPAD:
3117 codec->patch_ops.init = cxt5066_init;
3118 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3119 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3120 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3121 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3122 spec->port_d_mode = 0;
3124 spec->mic_boost = 2; /* default 20dB gain */
3127 spec->multiout.dig_out_nid = 0;
3129 /* input source automatically selected */
3130 spec->input_mux = NULL;
3132 case CXT5066_THINKPAD:
3133 codec->patch_ops.init = cxt5066_init;
3134 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3135 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3136 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3137 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3139 spec->port_d_mode = PIN_OUT;
3140 spec->mic_boost = 2; /* default 20dB gain */
3143 spec->multiout.dig_out_nid = 0;
3145 /* input source automatically selected */
3146 spec->input_mux = NULL;
3151 snd_hda_attach_beep_device(codec, spec->beep_amp);
3157 * Automatic parser for CX20641 & co
3160 static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3161 struct hda_codec *codec,
3162 unsigned int stream_tag,
3163 unsigned int format,
3164 struct snd_pcm_substream *substream)
3166 struct conexant_spec *spec = codec->spec;
3167 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
3168 if (spec->adc_switching) {
3169 spec->cur_adc = adc;
3170 spec->cur_adc_stream_tag = stream_tag;
3171 spec->cur_adc_format = format;
3173 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3177 static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3178 struct hda_codec *codec,
3179 struct snd_pcm_substream *substream)
3181 struct conexant_spec *spec = codec->spec;
3182 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3187 static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3191 .nid = 0, /* fill later */
3193 .prepare = cx_auto_capture_pcm_prepare,
3194 .cleanup = cx_auto_capture_pcm_cleanup
3198 static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3200 #define get_connection_index(codec, mux, nid)\
3201 snd_hda_get_conn_index(codec, mux, nid, 0)
3203 /* get an unassigned DAC from the given list.
3204 * Return the nid if found and reduce the DAC list, or return zero if
3207 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3208 hda_nid_t *dacs, int *num_dacs)
3210 int i, nums = *num_dacs;
3213 for (i = 0; i < nums; i++) {
3214 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3222 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3227 #define MAX_AUTO_DACS 5
3229 #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3231 /* fill analog DAC list from the widget tree */
3232 static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3234 hda_nid_t nid, end_nid;
3237 end_nid = codec->start_nid + codec->num_nodes;
3238 for (nid = codec->start_nid; nid < end_nid; nid++) {
3239 unsigned int wcaps = get_wcaps(codec, nid);
3240 unsigned int type = get_wcaps_type(wcaps);
3241 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3243 if (nums >= MAX_AUTO_DACS)
3250 /* fill pin_dac_pair list from the pin and dac list */
3251 static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3252 int num_pins, hda_nid_t *dacs, int *rest,
3253 struct pin_dac_pair *filled, int nums,
3256 int i, start = nums;
3258 for (i = 0; i < num_pins; i++, nums++) {
3259 filled[nums].pin = pins[i];
3260 filled[nums].type = type;
3261 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3262 if (filled[nums].dac)
3264 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3265 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3268 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
3269 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
3272 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
3277 /* parse analog output paths */
3278 static void cx_auto_parse_output(struct hda_codec *codec)
3280 struct conexant_spec *spec = codec->spec;
3281 struct auto_pin_cfg *cfg = &spec->autocfg;
3282 hda_nid_t dacs[MAX_AUTO_DACS];
3283 int i, j, nums, rest;
3285 rest = fill_cx_auto_dacs(codec, dacs);
3286 /* parse all analog output pins */
3287 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3288 dacs, &rest, spec->dac_info, 0,
3290 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3291 dacs, &rest, spec->dac_info, nums,
3293 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3294 dacs, &rest, spec->dac_info, nums,
3295 AUTO_PIN_SPEAKER_OUT);
3296 spec->dac_info_filled = nums;
3297 /* fill multiout struct */
3298 for (i = 0; i < nums; i++) {
3299 hda_nid_t dac = spec->dac_info[i].dac;
3300 if (!dac || (dac & DAC_SLAVE_FLAG))
3302 switch (spec->dac_info[i].type) {
3303 case AUTO_PIN_LINE_OUT:
3304 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3305 spec->multiout.num_dacs++;
3307 case AUTO_PIN_HP_OUT:
3308 case AUTO_PIN_SPEAKER_OUT:
3309 if (!spec->multiout.hp_nid) {
3310 spec->multiout.hp_nid = dac;
3313 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3314 if (!spec->multiout.extra_out_nid[j]) {
3315 spec->multiout.extra_out_nid[j] = dac;
3321 spec->multiout.dac_nids = spec->private_dac_nids;
3322 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3324 for (i = 0; i < cfg->hp_outs; i++) {
3325 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3326 spec->auto_mute = 1;
3330 if (spec->auto_mute &&
3331 cfg->line_out_pins[0] &&
3332 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
3333 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3334 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3335 for (i = 0; i < cfg->line_outs; i++) {
3336 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3337 spec->detect_line = 1;
3341 spec->automute_lines = spec->detect_line;
3344 spec->vmaster_nid = spec->private_dac_nids[0];
3347 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3348 hda_nid_t *pins, bool on);
3350 static void do_automute(struct hda_codec *codec, int num_pins,
3351 hda_nid_t *pins, bool on)
3353 struct conexant_spec *spec = codec->spec;
3355 for (i = 0; i < num_pins; i++)
3356 snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0);
3357 if (spec->pin_eapd_ctrls)
3358 cx_auto_turn_eapd(codec, num_pins, pins, on);
3361 static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3365 for (i = 0; i < num_pins; i++) {
3366 hda_nid_t nid = pins[i];
3367 if (!nid || !is_jack_detectable(codec, nid))
3369 present |= snd_hda_jack_detect(codec, nid);
3374 /* auto-mute/unmute speaker and line outs according to headphone jack */
3375 static void cx_auto_update_speakers(struct hda_codec *codec)
3377 struct conexant_spec *spec = codec->spec;
3378 struct auto_pin_cfg *cfg = &spec->autocfg;
3381 /* turn on HP EAPD when HP jacks are present */
3382 if (spec->pin_eapd_ctrls) {
3383 if (spec->auto_mute)
3384 on = spec->hp_present;
3385 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3388 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3389 if (spec->auto_mute)
3390 on = !(spec->hp_present ||
3391 (spec->detect_line && spec->line_present));
3392 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
3394 /* toggle line-out mutes if needed, too */
3395 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3396 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3397 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3399 if (spec->auto_mute) {
3400 /* mute LO in auto-mode when HP jack is present */
3401 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3402 spec->automute_lines)
3403 on = !spec->hp_present;
3407 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
3410 static void cx_auto_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3412 struct conexant_spec *spec = codec->spec;
3413 struct auto_pin_cfg *cfg = &spec->autocfg;
3415 if (!spec->auto_mute)
3417 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3418 cx_auto_update_speakers(codec);
3421 static void cx_auto_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3423 struct conexant_spec *spec = codec->spec;
3424 struct auto_pin_cfg *cfg = &spec->autocfg;
3426 if (!spec->auto_mute || !spec->detect_line)
3428 spec->line_present = detect_jacks(codec, cfg->line_outs,
3429 cfg->line_out_pins);
3430 cx_auto_update_speakers(codec);
3433 static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3434 struct snd_ctl_elem_info *uinfo)
3436 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3437 struct conexant_spec *spec = codec->spec;
3438 static const char * const texts3[] = {
3439 "Disabled", "Speaker Only", "Line Out+Speaker"
3442 if (spec->automute_hp_lo)
3443 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
3444 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
3447 static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3448 struct snd_ctl_elem_value *ucontrol)
3450 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3451 struct conexant_spec *spec = codec->spec;
3453 if (!spec->auto_mute)
3455 else if (!spec->automute_lines)
3459 ucontrol->value.enumerated.item[0] = val;
3463 static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3464 struct snd_ctl_elem_value *ucontrol)
3466 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3467 struct conexant_spec *spec = codec->spec;
3469 switch (ucontrol->value.enumerated.item[0]) {
3471 if (!spec->auto_mute)
3473 spec->auto_mute = 0;
3476 if (spec->auto_mute && !spec->automute_lines)
3478 spec->auto_mute = 1;
3479 spec->automute_lines = 0;
3482 if (!spec->automute_hp_lo)
3484 if (spec->auto_mute && spec->automute_lines)
3486 spec->auto_mute = 1;
3487 spec->automute_lines = 1;
3492 cx_auto_update_speakers(codec);
3496 static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3498 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3499 .name = "Auto-Mute Mode",
3500 .info = cx_automute_mode_info,
3501 .get = cx_automute_mode_get,
3502 .put = cx_automute_mode_put,
3507 static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3508 struct snd_ctl_elem_info *uinfo)
3510 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3511 struct conexant_spec *spec = codec->spec;
3513 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3516 static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3517 struct snd_ctl_elem_value *ucontrol)
3519 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3520 struct conexant_spec *spec = codec->spec;
3522 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3526 /* look for the route the given pin from mux and return the index;
3527 * if do_select is set, actually select the route.
3529 static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3530 hda_nid_t pin, hda_nid_t *srcp,
3531 bool do_select, int depth)
3533 struct conexant_spec *spec = codec->spec;
3534 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3535 int startidx, i, nums;
3537 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3539 case AC_WID_AUD_SEL:
3540 case AC_WID_AUD_MIX:
3546 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3547 for (i = 0; i < nums; i++)
3548 if (conn[i] == pin) {
3550 snd_hda_codec_write(codec, mux, 0,
3551 AC_VERB_SET_CONNECT_SEL, i);
3560 /* Try to rotate around connections to avoid one boost controlling
3561 another input path as well */
3563 for (i = 0; i < spec->private_imux.num_items; i++)
3564 if (spec->imux_info[i].pin == pin) {
3569 for (i = 0; i < nums; i++) {
3570 int j = (i + startidx) % nums;
3571 int ret = __select_input_connection(codec, conn[j], pin, srcp,
3575 snd_hda_codec_write(codec, mux, 0,
3576 AC_VERB_SET_CONNECT_SEL, j);
3583 static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3586 __select_input_connection(codec, mux, pin, NULL, true, 0);
3589 static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3592 return __select_input_connection(codec, mux, pin, NULL, false, 0);
3595 static int cx_auto_mux_enum_update(struct hda_codec *codec,
3596 const struct hda_input_mux *imux,
3599 struct conexant_spec *spec = codec->spec;
3603 if (!imux->num_items)
3605 if (idx >= imux->num_items)
3606 idx = imux->num_items - 1;
3607 if (spec->cur_mux[0] == idx)
3609 adc = spec->imux_info[idx].adc;
3610 select_input_connection(codec, spec->imux_info[idx].adc,
3611 spec->imux_info[idx].pin);
3612 if (spec->cur_adc && spec->cur_adc != adc) {
3613 /* stream is running, let's swap the current ADC */
3614 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3615 spec->cur_adc = adc;
3616 snd_hda_codec_setup_stream(codec, adc,
3617 spec->cur_adc_stream_tag, 0,
3618 spec->cur_adc_format);
3620 spec->cur_mux[0] = idx;
3624 static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3625 struct snd_ctl_elem_value *ucontrol)
3627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3628 struct conexant_spec *spec = codec->spec;
3630 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3631 ucontrol->value.enumerated.item[0]);
3634 static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3636 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3637 .name = "Capture Source",
3638 .info = cx_auto_mux_enum_info,
3639 .get = cx_auto_mux_enum_get,
3640 .put = cx_auto_mux_enum_put
3645 static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3647 struct conexant_spec *spec = codec->spec;
3650 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3652 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3656 /* automatic switch internal and external mic */
3657 static void cx_auto_automic(struct hda_codec *codec, struct hda_jack_tbl *jack)
3659 struct conexant_spec *spec = codec->spec;
3661 if (!spec->auto_mic)
3663 if (!select_automic(codec, spec->auto_mic_ext, true))
3664 if (!select_automic(codec, spec->auto_mic_dock, true))
3665 select_automic(codec, spec->auto_mic_int, false);
3668 /* check whether the pin config is suitable for auto-mic switching;
3669 * auto-mic is enabled only when one int-mic and one ext- and/or
3670 * one dock-mic exist
3672 static void cx_auto_check_auto_mic(struct hda_codec *codec)
3674 struct conexant_spec *spec = codec->spec;
3675 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3678 for (i = 0; i < ARRAY_SIZE(pset); i++)
3680 for (i = 0; i < spec->private_imux.num_items; i++) {
3681 hda_nid_t pin = spec->imux_info[i].pin;
3682 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3684 attr = snd_hda_get_input_pin_attr(def_conf);
3685 if (attr == INPUT_PIN_ATTR_UNUSED)
3686 return; /* invalid entry */
3687 if (attr > INPUT_PIN_ATTR_NORMAL)
3688 attr = INPUT_PIN_ATTR_NORMAL;
3689 if (attr != INPUT_PIN_ATTR_INT &&
3690 !is_jack_detectable(codec, pin))
3691 return; /* non-detectable pin */
3692 type = get_defcfg_device(def_conf);
3693 if (type != AC_JACK_MIC_IN &&
3694 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3695 return; /* no valid input type */
3696 if (pset[attr] >= 0)
3697 return; /* already occupied */
3700 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3701 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3702 return; /* no input to switch*/
3704 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3705 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3706 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
3709 static void cx_auto_parse_input(struct hda_codec *codec)
3711 struct conexant_spec *spec = codec->spec;
3712 struct auto_pin_cfg *cfg = &spec->autocfg;
3713 struct hda_input_mux *imux;
3716 imux = &spec->private_imux;
3717 for (i = 0; i < cfg->num_inputs; i++) {
3718 for (j = 0; j < spec->num_adc_nids; j++) {
3719 hda_nid_t adc = spec->adc_nids[j];
3720 int idx = get_input_connection(codec, adc,
3721 cfg->inputs[i].pin);
3724 label = hda_get_autocfg_input_label(codec, cfg, i);
3725 spec->imux_info[imux->num_items].index = i;
3726 spec->imux_info[imux->num_items].boost = 0;
3727 spec->imux_info[imux->num_items].adc = adc;
3728 spec->imux_info[imux->num_items].pin =
3730 snd_hda_add_imux_item(imux, label, idx, NULL);
3735 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
3736 cx_auto_check_auto_mic(codec);
3737 if (imux->num_items > 1) {
3738 for (i = 1; i < imux->num_items; i++) {
3739 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
3740 spec->adc_switching = 1;
3747 /* get digital-input audio widget corresponding to the given pin */
3748 static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3750 hda_nid_t nid, end_nid;
3752 end_nid = codec->start_nid + codec->num_nodes;
3753 for (nid = codec->start_nid; nid < end_nid; nid++) {
3754 unsigned int wcaps = get_wcaps(codec, nid);
3755 unsigned int type = get_wcaps_type(wcaps);
3756 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3757 if (get_connection_index(codec, nid, pin) >= 0)
3764 static void cx_auto_parse_digital(struct hda_codec *codec)
3766 struct conexant_spec *spec = codec->spec;
3767 struct auto_pin_cfg *cfg = &spec->autocfg;
3770 if (cfg->dig_outs &&
3771 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3772 spec->multiout.dig_out_nid = nid;
3773 if (cfg->dig_in_pin)
3774 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3777 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3778 static void cx_auto_parse_beep(struct hda_codec *codec)
3780 struct conexant_spec *spec = codec->spec;
3781 hda_nid_t nid, end_nid;
3783 end_nid = codec->start_nid + codec->num_nodes;
3784 for (nid = codec->start_nid; nid < end_nid; nid++)
3785 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3786 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3791 #define cx_auto_parse_beep(codec)
3795 static void cx_auto_parse_eapd(struct hda_codec *codec)
3797 struct conexant_spec *spec = codec->spec;
3798 hda_nid_t nid, end_nid;
3800 end_nid = codec->start_nid + codec->num_nodes;
3801 for (nid = codec->start_nid; nid < end_nid; nid++) {
3802 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3804 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3806 spec->eapds[spec->num_eapds++] = nid;
3807 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3811 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3812 * it's a new chip, where EAPDs are supposed to be associated to
3813 * pins, and we can control EAPD per pin.
3814 * OTOH, if only one or two EAPDs are found, it's an old chip,
3815 * thus it might control over all pins.
3817 spec->pin_eapd_ctrls = spec->num_eapds > 2;
3820 static int cx_auto_parse_auto_config(struct hda_codec *codec)
3822 struct conexant_spec *spec = codec->spec;
3825 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3829 cx_auto_parse_output(codec);
3830 cx_auto_parse_input(codec);
3831 cx_auto_parse_digital(codec);
3832 cx_auto_parse_beep(codec);
3833 cx_auto_parse_eapd(codec);
3837 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3838 hda_nid_t *pins, bool on)
3841 for (i = 0; i < num_pins; i++) {
3842 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3843 snd_hda_codec_write(codec, pins[i], 0,
3844 AC_VERB_SET_EAPD_BTLENABLE,
3849 static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3852 int idx = get_connection_index(codec, pin, src);
3854 snd_hda_codec_write(codec, pin, 0,
3855 AC_VERB_SET_CONNECT_SEL, idx);
3858 static void mute_outputs(struct hda_codec *codec, int num_nids,
3859 const hda_nid_t *nids)
3863 for (i = 0; i < num_nids; i++) {
3864 hda_nid_t nid = nids[i];
3865 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3867 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3871 snd_hda_codec_write(codec, nid, 0,
3872 AC_VERB_SET_AMP_GAIN_MUTE, val);
3876 static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3877 hda_nid_t *pins, unsigned int action,
3878 hda_jack_callback cb)
3881 for (i = 0; i < num_pins; i++)
3882 snd_hda_jack_detect_enable_callback(codec, pins[i], action, cb);
3885 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3888 for (i = 0; i < nums; i++)
3894 /* is the given NID found in any of autocfg items? */
3895 static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3899 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3900 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3901 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3902 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3904 for (i = 0; i < cfg->num_inputs; i++)
3905 if (cfg->inputs[i].pin == nid)
3907 if (cfg->dig_in_pin == nid)
3912 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3913 * invalid unsol tags by some reason
3915 static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3917 struct conexant_spec *spec = codec->spec;
3918 struct auto_pin_cfg *cfg = &spec->autocfg;
3921 for (i = 0; i < codec->init_pins.used; i++) {
3922 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3923 if (!found_in_autocfg(cfg, pin->nid))
3924 snd_hda_codec_write(codec, pin->nid, 0,
3925 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3929 /* turn on/off EAPD according to Master switch */
3930 static void cx_auto_vmaster_hook(void *private_data, int enabled)
3932 struct hda_codec *codec = private_data;
3933 struct conexant_spec *spec = codec->spec;
3935 if (enabled && spec->pin_eapd_ctrls) {
3936 cx_auto_update_speakers(codec);
3939 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3942 static void cx_auto_init_output(struct hda_codec *codec)
3944 struct conexant_spec *spec = codec->spec;
3945 struct auto_pin_cfg *cfg = &spec->autocfg;
3949 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
3950 for (i = 0; i < cfg->hp_outs; i++) {
3951 unsigned int val = PIN_OUT;
3952 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
3954 val |= AC_PINCTL_HP_EN;
3955 snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val);
3957 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3958 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3959 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
3960 for (i = 0; i < spec->dac_info_filled; i++) {
3961 nid = spec->dac_info[i].dac;
3963 nid = spec->multiout.dac_nids[0];
3964 else if (nid & DAC_SLAVE_FLAG)
3965 nid &= ~DAC_SLAVE_FLAG;
3966 select_connection(codec, spec->dac_info[i].pin, nid);
3968 if (spec->auto_mute) {
3969 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
3970 CONEXANT_HP_EVENT, cx_auto_hp_automute);
3971 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3973 if (spec->detect_line) {
3974 enable_unsol_pins(codec, cfg->line_outs,
3976 CONEXANT_LINE_EVENT,
3977 cx_auto_line_automute);
3978 spec->line_present =
3979 detect_jacks(codec, cfg->line_outs,
3980 cfg->line_out_pins);
3983 cx_auto_update_speakers(codec);
3984 /* turn on all EAPDs if no individual EAPD control is available */
3985 if (!spec->pin_eapd_ctrls)
3986 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
3987 clear_unsol_on_unused_pins(codec);
3990 static void cx_auto_init_input(struct hda_codec *codec)
3992 struct conexant_spec *spec = codec->spec;
3993 struct auto_pin_cfg *cfg = &spec->autocfg;
3996 for (i = 0; i < spec->num_adc_nids; i++) {
3997 hda_nid_t nid = spec->adc_nids[i];
3998 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4000 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4001 val = AMP_IN_MUTE(0);
4003 val = AMP_IN_UNMUTE(0);
4004 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4008 for (i = 0; i < cfg->num_inputs; i++) {
4009 hda_nid_t pin = cfg->inputs[i].pin;
4010 unsigned int type = PIN_IN;
4011 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4012 type |= snd_hda_get_default_vref(codec, pin);
4013 snd_hda_set_pin_ctl(codec, pin, type);
4016 if (spec->auto_mic) {
4017 if (spec->auto_mic_ext >= 0) {
4018 snd_hda_jack_detect_enable_callback(codec,
4019 cfg->inputs[spec->auto_mic_ext].pin,
4020 CONEXANT_MIC_EVENT, cx_auto_automic);
4022 if (spec->auto_mic_dock >= 0) {
4023 snd_hda_jack_detect_enable_callback(codec,
4024 cfg->inputs[spec->auto_mic_dock].pin,
4025 CONEXANT_MIC_EVENT, cx_auto_automic);
4027 cx_auto_automic(codec, NULL);
4029 select_input_connection(codec, spec->imux_info[0].adc,
4030 spec->imux_info[0].pin);
4034 static void cx_auto_init_digital(struct hda_codec *codec)
4036 struct conexant_spec *spec = codec->spec;
4037 struct auto_pin_cfg *cfg = &spec->autocfg;
4039 if (spec->multiout.dig_out_nid)
4040 snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT);
4041 if (spec->dig_in_nid)
4042 snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN);
4045 static int cx_auto_init(struct hda_codec *codec)
4047 struct conexant_spec *spec = codec->spec;
4048 snd_hda_gen_apply_verbs(codec);
4049 cx_auto_init_output(codec);
4050 cx_auto_init_input(codec);
4051 cx_auto_init_digital(codec);
4052 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4056 static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
4057 const char *dir, int cidx,
4058 hda_nid_t nid, int hda_dir, int amp_idx, int chs)
4060 static char name[44];
4061 static struct snd_kcontrol_new knew[] = {
4062 HDA_CODEC_VOLUME(name, 0, 0, 0),
4063 HDA_CODEC_MUTE(name, 0, 0, 0),
4065 static const char * const sfx[2] = { "Volume", "Switch" };
4068 for (i = 0; i < 2; i++) {
4069 struct snd_kcontrol *kctl;
4070 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
4072 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4073 knew[i].index = cidx;
4074 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4075 kctl = snd_ctl_new1(&knew[i], codec);
4078 err = snd_hda_ctl_add(codec, nid, kctl);
4081 if (!(query_amp_caps(codec, nid, hda_dir) &
4082 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
4088 #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4089 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
4091 #define cx_auto_add_pb_volume(codec, nid, str, idx) \
4092 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4094 static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4095 hda_nid_t pin, const char *name, int idx)
4098 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4099 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4100 if (caps & AC_AMPCAP_NUM_STEPS)
4101 return cx_auto_add_pb_volume(codec, dac, name, idx);
4103 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4104 if (caps & AC_AMPCAP_NUM_STEPS)
4105 return cx_auto_add_pb_volume(codec, pin, name, idx);
4109 static bool is_2_1_speaker(struct conexant_spec *spec)
4111 int i, type, num_spk = 0;
4113 for (i = 0; i < spec->dac_info_filled; i++) {
4114 type = spec->dac_info[i].type;
4115 if (type == AUTO_PIN_LINE_OUT)
4116 type = spec->autocfg.line_out_type;
4117 if (type == AUTO_PIN_SPEAKER_OUT)
4120 return (num_spk == 2 && spec->autocfg.line_out_type != AUTO_PIN_LINE_OUT);
4123 static int cx_auto_build_output_controls(struct hda_codec *codec)
4125 struct conexant_spec *spec = codec->spec;
4127 int num_line = 0, num_hp = 0, num_spk = 0;
4129 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
4131 if (spec->dac_info_filled == 1)
4132 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4133 spec->dac_info[0].pin,
4136 speaker_2_1 = is_2_1_speaker(spec);
4138 for (i = 0; i < spec->dac_info_filled; i++) {
4141 hda_nid_t dac = spec->dac_info[i].dac;
4142 type = spec->dac_info[i].type;
4143 if (type == AUTO_PIN_LINE_OUT)
4144 type = spec->autocfg.line_out_type;
4146 case AUTO_PIN_LINE_OUT:
4148 label = texts[num_line++];
4151 case AUTO_PIN_HP_OUT:
4152 label = "Headphone";
4155 case AUTO_PIN_SPEAKER_OUT:
4157 label = num_spk++ ? "Bass Speaker" : "Speaker";
4165 err = try_add_pb_volume(codec, dac,
4166 spec->dac_info[i].pin,
4172 if (spec->auto_mute) {
4173 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4181 /* Returns zero if this is a normal stereo channel, and non-zero if it should
4182 be split in two independent channels.
4183 dest_label must be at least 44 characters. */
4184 static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
4185 char *dest_label, int nid)
4187 struct conexant_spec *spec = codec->spec;
4190 if (!spec->fixup_stereo_dmic)
4193 for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
4195 if (spec->autocfg.inputs[i].pin != nid)
4198 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
4200 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4201 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
4204 /* Finally found the inverted internal mic! */
4205 snprintf(dest_label, 44, "Inverted %s", label);
4211 static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4212 const char *label, const char *pfx,
4215 struct conexant_spec *spec = codec->spec;
4218 for (i = 0; i < spec->num_adc_nids; i++) {
4219 char rightch_label[44];
4220 hda_nid_t adc_nid = spec->adc_nids[i];
4221 int idx = get_input_connection(codec, adc_nid, nid);
4224 if (codec->single_adc_amp)
4227 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4228 /* Make two independent kcontrols for left and right */
4229 int err = cx_auto_add_volume_idx(codec, label, pfx,
4230 cidx, adc_nid, HDA_INPUT, idx, 1);
4233 return cx_auto_add_volume_idx(codec, rightch_label, pfx,
4234 cidx, adc_nid, HDA_INPUT, idx, 2);
4236 return cx_auto_add_volume_idx(codec, label, pfx,
4237 cidx, adc_nid, HDA_INPUT, idx, 3);
4242 static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4243 const char *label, int cidx)
4245 struct conexant_spec *spec = codec->spec;
4249 nid = spec->imux_info[idx].pin;
4250 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4251 char rightch_label[44];
4252 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4253 int err = cx_auto_add_volume_idx(codec, label, " Boost",
4254 cidx, nid, HDA_INPUT, 0, 1);
4257 return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
4258 cidx, nid, HDA_INPUT, 0, 2);
4260 return cx_auto_add_volume(codec, label, " Boost", cidx,
4263 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4267 for (i = 0; i < idx; i++) {
4268 if (spec->imux_info[i].boost == mux)
4269 return 0; /* already present */
4272 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
4273 spec->imux_info[idx].boost = mux;
4274 return cx_auto_add_volume(codec, label, " Boost", cidx,
4280 static int cx_auto_build_input_controls(struct hda_codec *codec)
4282 struct conexant_spec *spec = codec->spec;
4283 struct hda_input_mux *imux = &spec->private_imux;
4284 const char *prev_label;
4285 int input_conn[HDA_MAX_NUM_INPUTS];
4286 int i, j, err, cidx;
4287 int multi_connection;
4289 if (!imux->num_items)
4292 multi_connection = 0;
4293 for (i = 0; i < imux->num_items; i++) {
4294 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4295 spec->imux_info[i].pin);
4298 input_conn[i] = spec->imux_info[i].adc;
4299 if (!codec->single_adc_amp)
4300 input_conn[i] |= cidx << 8;
4301 if (i > 0 && input_conn[i] != input_conn[0])
4302 multi_connection = 1;
4307 for (i = 0; i < imux->num_items; i++) {
4308 hda_nid_t nid = spec->imux_info[i].pin;
4311 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
4312 spec->imux_info[i].index);
4313 if (label == prev_label)
4319 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4323 if (!multi_connection) {
4326 err = cx_auto_add_capture_volume(codec, nid,
4327 "Capture", "", cidx);
4329 bool dup_found = false;
4330 for (j = 0; j < i; j++) {
4331 if (input_conn[j] == input_conn[i]) {
4338 err = cx_auto_add_capture_volume(codec, nid,
4339 label, " Capture", cidx);
4345 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4346 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4354 static int cx_auto_build_controls(struct hda_codec *codec)
4356 struct conexant_spec *spec = codec->spec;
4359 err = cx_auto_build_output_controls(codec);
4362 err = cx_auto_build_input_controls(codec);
4365 err = conexant_build_controls(codec);
4368 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4371 if (spec->vmaster_mute.sw_kctl) {
4372 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
4373 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4374 spec->vmaster_mute_led);
4381 static int cx_auto_search_adcs(struct hda_codec *codec)
4383 struct conexant_spec *spec = codec->spec;
4384 hda_nid_t nid, end_nid;
4386 end_nid = codec->start_nid + codec->num_nodes;
4387 for (nid = codec->start_nid; nid < end_nid; nid++) {
4388 unsigned int caps = get_wcaps(codec, nid);
4389 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4391 if (caps & AC_WCAP_DIGITAL)
4393 if (snd_BUG_ON(spec->num_adc_nids >=
4394 ARRAY_SIZE(spec->private_adc_nids)))
4396 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4398 spec->adc_nids = spec->private_adc_nids;
4402 static const struct hda_codec_ops cx_auto_patch_ops = {
4403 .build_controls = cx_auto_build_controls,
4404 .build_pcms = conexant_build_pcms,
4405 .init = cx_auto_init,
4406 .free = conexant_free,
4407 .unsol_event = snd_hda_jack_unsol_event,
4409 .suspend = conexant_suspend,
4411 .reboot_notify = snd_hda_shutup_pins,
4418 CXT_PINCFG_LENOVO_X200,
4419 CXT_PINCFG_LENOVO_TP410,
4420 CXT_PINCFG_LEMOTE_A1004,
4421 CXT_PINCFG_LEMOTE_A1205,
4422 CXT_FIXUP_STEREO_DMIC,
4423 CXT_FIXUP_INC_MIC_BOOST,
4426 static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
4427 const struct hda_fixup *fix, int action)
4429 struct conexant_spec *spec = codec->spec;
4430 spec->fixup_stereo_dmic = 1;
4433 static void cxt5066_increase_mic_boost(struct hda_codec *codec,
4434 const struct hda_fixup *fix, int action)
4436 if (action != HDA_FIXUP_ACT_PRE_PROBE)
4439 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
4440 (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
4441 (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4442 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4443 (0 << AC_AMPCAP_MUTE_SHIFT));
4446 /* ThinkPad X200 & co with cxt5051 */
4447 static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
4448 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4449 { 0x17, 0x21a11000 }, /* dock-mic */
4450 { 0x19, 0x2121103f }, /* dock-HP */
4451 { 0x1c, 0x21440100 }, /* dock SPDIF out */
4455 /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
4456 static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
4457 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
4458 { 0x1a, 0x21a190f0 }, /* dock-mic */
4459 { 0x1c, 0x212140ff }, /* dock-HP */
4463 /* Lemote A1004/A1205 with cxt5066 */
4464 static const struct hda_pintbl cxt_pincfg_lemote[] = {
4465 { 0x1a, 0x90a10020 }, /* Internal mic */
4466 { 0x1b, 0x03a11020 }, /* External mic */
4467 { 0x1d, 0x400101f0 }, /* Not used */
4468 { 0x1e, 0x40a701f0 }, /* Not used */
4469 { 0x20, 0x404501f0 }, /* Not used */
4470 { 0x22, 0x404401f0 }, /* Not used */
4471 { 0x23, 0x40a701f0 }, /* Not used */
4475 static const struct hda_fixup cxt_fixups[] = {
4476 [CXT_PINCFG_LENOVO_X200] = {
4477 .type = HDA_FIXUP_PINS,
4478 .v.pins = cxt_pincfg_lenovo_x200,
4480 [CXT_PINCFG_LENOVO_TP410] = {
4481 .type = HDA_FIXUP_PINS,
4482 .v.pins = cxt_pincfg_lenovo_tp410,
4484 [CXT_PINCFG_LEMOTE_A1004] = {
4485 .type = HDA_FIXUP_PINS,
4487 .chain_id = CXT_FIXUP_INC_MIC_BOOST,
4488 .v.pins = cxt_pincfg_lemote,
4490 [CXT_PINCFG_LEMOTE_A1205] = {
4491 .type = HDA_FIXUP_PINS,
4492 .v.pins = cxt_pincfg_lemote,
4494 [CXT_FIXUP_STEREO_DMIC] = {
4495 .type = HDA_FIXUP_FUNC,
4496 .v.func = cxt_fixup_stereo_dmic,
4498 [CXT_FIXUP_INC_MIC_BOOST] = {
4499 .type = HDA_FIXUP_FUNC,
4500 .v.func = cxt5066_increase_mic_boost,
4504 static const struct snd_pci_quirk cxt5051_fixups[] = {
4505 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4509 static const struct snd_pci_quirk cxt5066_fixups[] = {
4510 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
4511 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
4512 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
4513 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4514 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
4515 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
4516 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
4517 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
4518 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
4519 SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
4520 SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
4524 /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4525 * can be created (bko#42825)
4527 static void add_cx5051_fake_mutes(struct hda_codec *codec)
4529 static hda_nid_t out_nids[] = {
4534 for (p = out_nids; *p; p++)
4535 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4536 AC_AMPCAP_MIN_MUTE |
4537 query_amp_caps(codec, *p, HDA_OUTPUT));
4540 static int patch_conexant_auto(struct hda_codec *codec)
4542 struct conexant_spec *spec;
4545 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4548 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4552 snd_hda_gen_init(&spec->gen);
4554 switch (codec->vendor_id) {
4556 codec->single_adc_amp = 1;
4559 add_cx5051_fake_mutes(codec);
4560 codec->pin_amp_workaround = 1;
4561 snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups);
4564 codec->pin_amp_workaround = 1;
4565 snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups);
4569 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4571 /* Show mute-led control only on HP laptops
4572 * This is a sort of white-list: on HP laptops, EAPD corresponds
4573 * only to the mute-LED without actualy amp function. Meanwhile,
4574 * others may use EAPD really as an amp switch, so it might be
4575 * not good to expose it blindly.
4577 switch (codec->subsystem_id >> 16) {
4579 spec->vmaster_mute_led = 1;
4583 err = cx_auto_search_adcs(codec);
4586 err = cx_auto_parse_auto_config(codec);
4592 spec->capture_stream = &cx_auto_pcm_analog_capture;
4593 codec->patch_ops = cx_auto_patch_ops;
4595 snd_hda_attach_beep_device(codec, spec->beep_amp);
4597 /* Some laptops with Conexant chips show stalls in S3 resume,
4598 * which falls into the single-cmd mode.
4599 * Better to make reset, then.
4601 if (!codec->bus->sync_write) {
4602 snd_printd("hda_codec: "
4603 "Enable sync_write for stable communication\n");
4604 codec->bus->sync_write = 1;
4605 codec->bus->allow_bus_reset = 1;
4614 static const struct hda_codec_preset snd_hda_preset_conexant[] = {
4615 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4616 .patch = patch_cxt5045 },
4617 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4618 .patch = patch_cxt5047 },
4619 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4620 .patch = patch_cxt5051 },
4621 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4622 .patch = patch_cxt5066 },
4623 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4624 .patch = patch_cxt5066 },
4625 { .id = 0x14f15068, .name = "CX20584",
4626 .patch = patch_cxt5066 },
4627 { .id = 0x14f15069, .name = "CX20585",
4628 .patch = patch_cxt5066 },
4629 { .id = 0x14f1506c, .name = "CX20588",
4630 .patch = patch_cxt5066 },
4631 { .id = 0x14f1506e, .name = "CX20590",
4632 .patch = patch_cxt5066 },
4633 { .id = 0x14f15097, .name = "CX20631",
4634 .patch = patch_conexant_auto },
4635 { .id = 0x14f15098, .name = "CX20632",
4636 .patch = patch_conexant_auto },
4637 { .id = 0x14f150a1, .name = "CX20641",
4638 .patch = patch_conexant_auto },
4639 { .id = 0x14f150a2, .name = "CX20642",
4640 .patch = patch_conexant_auto },
4641 { .id = 0x14f150ab, .name = "CX20651",
4642 .patch = patch_conexant_auto },
4643 { .id = 0x14f150ac, .name = "CX20652",
4644 .patch = patch_conexant_auto },
4645 { .id = 0x14f150b8, .name = "CX20664",
4646 .patch = patch_conexant_auto },
4647 { .id = 0x14f150b9, .name = "CX20665",
4648 .patch = patch_conexant_auto },
4649 { .id = 0x14f1510f, .name = "CX20751/2",
4650 .patch = patch_conexant_auto },
4651 { .id = 0x14f15110, .name = "CX20751/2",
4652 .patch = patch_conexant_auto },
4653 { .id = 0x14f15111, .name = "CX20753/4",
4654 .patch = patch_conexant_auto },
4658 MODULE_ALIAS("snd-hda-codec-id:14f15045");
4659 MODULE_ALIAS("snd-hda-codec-id:14f15047");
4660 MODULE_ALIAS("snd-hda-codec-id:14f15051");
4661 MODULE_ALIAS("snd-hda-codec-id:14f15066");
4662 MODULE_ALIAS("snd-hda-codec-id:14f15067");
4663 MODULE_ALIAS("snd-hda-codec-id:14f15068");
4664 MODULE_ALIAS("snd-hda-codec-id:14f15069");
4665 MODULE_ALIAS("snd-hda-codec-id:14f1506c");
4666 MODULE_ALIAS("snd-hda-codec-id:14f1506e");
4667 MODULE_ALIAS("snd-hda-codec-id:14f15097");
4668 MODULE_ALIAS("snd-hda-codec-id:14f15098");
4669 MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4670 MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4671 MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4672 MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4673 MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4674 MODULE_ALIAS("snd-hda-codec-id:14f150b9");
4675 MODULE_ALIAS("snd-hda-codec-id:14f1510f");
4676 MODULE_ALIAS("snd-hda-codec-id:14f15110");
4677 MODULE_ALIAS("snd-hda-codec-id:14f15111");
4679 MODULE_LICENSE("GPL");
4680 MODULE_DESCRIPTION("Conexant HD-audio codec");
4682 static struct hda_codec_preset_list conexant_list = {
4683 .preset = snd_hda_preset_conexant,
4684 .owner = THIS_MODULE,
4687 static int __init patch_conexant_init(void)
4689 return snd_hda_add_codec_preset(&conexant_list);
4692 static void __exit patch_conexant_exit(void)
4694 snd_hda_delete_codec_preset(&conexant_list);
4697 module_init(patch_conexant_init)
4698 module_exit(patch_conexant_exit)