2 * HD audio interface patch for Conexant HDA audio codec
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
27 #include <linux/module.h>
28 #include <sound/core.h>
29 #include <sound/jack.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
35 #define CXT_PIN_DIR_IN 0x00
36 #define CXT_PIN_DIR_OUT 0x01
37 #define CXT_PIN_DIR_INOUT 0x02
38 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
39 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
41 #define CONEXANT_HP_EVENT 0x37
42 #define CONEXANT_MIC_EVENT 0x38
43 #define CONEXANT_LINE_EVENT 0x39
45 /* Conexant 5051 specific */
47 #define CXT5051_SPDIF_OUT 0x12
48 #define CXT5051_PORTB_EVENT 0x38
49 #define CXT5051_PORTC_EVENT 0x39
51 #define AUTO_MIC_PORTB (1 << 1)
52 #define AUTO_MIC_PORTC (1 << 2)
61 hda_nid_t pin; /* input pin NID */
62 hda_nid_t adc; /* connected ADC NID */
63 hda_nid_t boost; /* optional boost volume NID */
64 int index; /* corresponding to autocfg.input */
67 struct conexant_spec {
69 const struct snd_kcontrol_new *mixers[5];
71 hda_nid_t vmaster_nid;
73 const struct hda_verb *init_verbs[5]; /* initialization verbs
77 unsigned int num_init_verbs;
80 struct hda_multi_out multiout; /* playback set-up
81 * max_channels, dacs must be set
82 * dig_out_nid and hp_nid are optional
84 unsigned int cur_eapd;
85 unsigned int hp_present;
86 unsigned int line_present;
87 unsigned int auto_mic;
88 int auto_mic_ext; /* imux_pins[] index for ext mic */
89 int auto_mic_dock; /* imux_pins[] index for dock mic */
90 int auto_mic_int; /* imux_pins[] index for int mic */
91 unsigned int need_dac_fix;
92 hda_nid_t slave_dig_outs[2];
95 unsigned int num_adc_nids;
96 const hda_nid_t *adc_nids;
97 hda_nid_t dig_in_nid; /* digital-in NID; optional */
99 unsigned int cur_adc_idx;
101 unsigned int cur_adc_stream_tag;
102 unsigned int cur_adc_format;
104 const struct hda_pcm_stream *capture_stream;
107 const struct hda_input_mux *input_mux;
108 const hda_nid_t *capsrc_nids;
109 unsigned int cur_mux[3];
112 const struct hda_channel_mode *channel_mode;
113 int num_channel_mode;
115 /* PCM information */
116 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
118 unsigned int spdif_route;
120 /* dynamic controls, init_verbs and input_mux */
121 struct auto_pin_cfg autocfg;
122 struct hda_input_mux private_imux;
123 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
124 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
125 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
126 struct pin_dac_pair dac_info[8];
129 unsigned int port_d_mode;
130 unsigned int auto_mute:1; /* used in auto-parser */
131 unsigned int detect_line:1; /* Line-out detection enabled */
132 unsigned int automute_lines:1; /* automute line-out as well */
133 unsigned int automute_hp_lo:1; /* both HP and LO available */
134 unsigned int dell_automute:1;
135 unsigned int dell_vostro:1;
136 unsigned int ideapad:1;
137 unsigned int thinkpad:1;
138 unsigned int hp_laptop:1;
140 unsigned int pin_eapd_ctrls:1;
141 unsigned int single_adc_amp:1;
143 unsigned int adc_switching:1;
145 unsigned int ext_mic_present;
146 unsigned int recording;
147 void (*capture_prepare)(struct hda_codec *codec);
148 void (*capture_cleanup)(struct hda_codec *codec);
150 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
151 * through the microphone jack.
152 * When the user enables this through a mixer switch, both internal and
153 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
154 * we also allow the bias to be configured through a separate mixer
156 unsigned int dc_enable;
157 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
158 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
160 unsigned int beep_amp;
162 /* extra EAPD pins */
163 unsigned int num_eapds;
167 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
168 struct hda_codec *codec,
169 struct snd_pcm_substream *substream)
171 struct conexant_spec *spec = codec->spec;
172 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
176 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
177 struct hda_codec *codec,
178 unsigned int stream_tag,
180 struct snd_pcm_substream *substream)
182 struct conexant_spec *spec = codec->spec;
183 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
188 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
189 struct hda_codec *codec,
190 struct snd_pcm_substream *substream)
192 struct conexant_spec *spec = codec->spec;
193 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
199 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
200 struct hda_codec *codec,
201 struct snd_pcm_substream *substream)
203 struct conexant_spec *spec = codec->spec;
204 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
207 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
208 struct hda_codec *codec,
209 struct snd_pcm_substream *substream)
211 struct conexant_spec *spec = codec->spec;
212 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
215 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
216 struct hda_codec *codec,
217 unsigned int stream_tag,
219 struct snd_pcm_substream *substream)
221 struct conexant_spec *spec = codec->spec;
222 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
230 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
231 struct hda_codec *codec,
232 unsigned int stream_tag,
234 struct snd_pcm_substream *substream)
236 struct conexant_spec *spec = codec->spec;
237 if (spec->capture_prepare)
238 spec->capture_prepare(codec);
239 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
240 stream_tag, 0, format);
244 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
245 struct hda_codec *codec,
246 struct snd_pcm_substream *substream)
248 struct conexant_spec *spec = codec->spec;
249 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
250 if (spec->capture_cleanup)
251 spec->capture_cleanup(codec);
257 static const struct hda_pcm_stream conexant_pcm_analog_playback = {
261 .nid = 0, /* fill later */
263 .open = conexant_playback_pcm_open,
264 .prepare = conexant_playback_pcm_prepare,
265 .cleanup = conexant_playback_pcm_cleanup
269 static const struct hda_pcm_stream conexant_pcm_analog_capture = {
273 .nid = 0, /* fill later */
275 .prepare = conexant_capture_pcm_prepare,
276 .cleanup = conexant_capture_pcm_cleanup
281 static const struct hda_pcm_stream conexant_pcm_digital_playback = {
285 .nid = 0, /* fill later */
287 .open = conexant_dig_playback_pcm_open,
288 .close = conexant_dig_playback_pcm_close,
289 .prepare = conexant_dig_playback_pcm_prepare
293 static const struct hda_pcm_stream conexant_pcm_digital_capture = {
297 /* NID is set in alc_build_pcms */
300 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
301 struct hda_codec *codec,
302 unsigned int stream_tag,
304 struct snd_pcm_substream *substream)
306 struct conexant_spec *spec = codec->spec;
307 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
308 spec->cur_adc_stream_tag = stream_tag;
309 spec->cur_adc_format = format;
310 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
314 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
315 struct hda_codec *codec,
316 struct snd_pcm_substream *substream)
318 struct conexant_spec *spec = codec->spec;
319 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
324 static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
328 .nid = 0, /* fill later */
330 .prepare = cx5051_capture_pcm_prepare,
331 .cleanup = cx5051_capture_pcm_cleanup
335 static int conexant_build_pcms(struct hda_codec *codec)
337 struct conexant_spec *spec = codec->spec;
338 struct hda_pcm *info = spec->pcm_rec;
341 codec->pcm_info = info;
343 info->name = "CONEXANT Analog";
344 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
345 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
346 spec->multiout.max_channels;
347 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
348 spec->multiout.dac_nids[0];
349 if (spec->capture_stream)
350 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
352 if (codec->vendor_id == 0x14f15051)
353 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
354 cx5051_pcm_analog_capture;
356 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
357 conexant_pcm_analog_capture;
358 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
362 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
364 if (spec->multiout.dig_out_nid) {
367 info->name = "Conexant Digital";
368 info->pcm_type = HDA_PCM_TYPE_SPDIF;
369 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
370 conexant_pcm_digital_playback;
371 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
372 spec->multiout.dig_out_nid;
373 if (spec->dig_in_nid) {
374 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
375 conexant_pcm_digital_capture;
376 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
379 if (spec->slave_dig_outs[0])
380 codec->slave_dig_outs = spec->slave_dig_outs;
386 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
387 struct snd_ctl_elem_info *uinfo)
389 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
390 struct conexant_spec *spec = codec->spec;
392 return snd_hda_input_mux_info(spec->input_mux, uinfo);
395 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
396 struct snd_ctl_elem_value *ucontrol)
398 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
399 struct conexant_spec *spec = codec->spec;
400 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
402 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
406 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
407 struct snd_ctl_elem_value *ucontrol)
409 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
410 struct conexant_spec *spec = codec->spec;
411 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
413 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
414 spec->capsrc_nids[adc_idx],
415 &spec->cur_mux[adc_idx]);
418 static int conexant_init_jacks(struct hda_codec *codec)
420 #ifdef CONFIG_SND_HDA_INPUT_JACK
421 struct conexant_spec *spec = codec->spec;
424 for (i = 0; i < spec->num_init_verbs; i++) {
425 const struct hda_verb *hv;
427 hv = spec->init_verbs[i];
430 switch (hv->param ^ AC_USRSP_EN) {
431 case CONEXANT_HP_EVENT:
432 err = snd_hda_input_jack_add(codec, hv->nid,
433 SND_JACK_HEADPHONE, NULL);
434 snd_hda_input_jack_report(codec, hv->nid);
436 case CXT5051_PORTC_EVENT:
437 case CONEXANT_MIC_EVENT:
438 err = snd_hda_input_jack_add(codec, hv->nid,
439 SND_JACK_MICROPHONE, NULL);
440 snd_hda_input_jack_report(codec, hv->nid);
448 #endif /* CONFIG_SND_HDA_INPUT_JACK */
452 static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
453 unsigned int power_state)
455 if (power_state == AC_PWRST_D3)
457 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
459 /* partial workaround for "azx_get_response timeout" */
460 if (power_state == AC_PWRST_D0)
462 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
465 static int conexant_init(struct hda_codec *codec)
467 struct conexant_spec *spec = codec->spec;
470 for (i = 0; i < spec->num_init_verbs; i++)
471 snd_hda_sequence_write(codec, spec->init_verbs[i]);
475 static void conexant_free(struct hda_codec *codec)
477 snd_hda_input_jack_free(codec);
478 snd_hda_detach_beep_device(codec);
482 static const struct snd_kcontrol_new cxt_capture_mixers[] = {
484 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
485 .name = "Capture Source",
486 .info = conexant_mux_enum_info,
487 .get = conexant_mux_enum_get,
488 .put = conexant_mux_enum_put
493 #ifdef CONFIG_SND_HDA_INPUT_BEEP
494 /* additional beep mixers; the actual parameters are overwritten at build */
495 static const struct snd_kcontrol_new cxt_beep_mixer[] = {
496 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
497 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
502 static const char * const slave_vols[] = {
503 "Headphone Playback Volume",
504 "Speaker Playback Volume",
505 "Front Playback Volume",
506 "Surround Playback Volume",
507 "CLFE Playback Volume",
511 static const char * const slave_sws[] = {
512 "Headphone Playback Switch",
513 "Speaker Playback Switch",
514 "Front Playback Switch",
515 "Surround Playback Switch",
516 "CLFE Playback Switch",
520 static int conexant_build_controls(struct hda_codec *codec)
522 struct conexant_spec *spec = codec->spec;
526 for (i = 0; i < spec->num_mixers; i++) {
527 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
531 if (spec->multiout.dig_out_nid) {
532 err = snd_hda_create_spdif_out_ctls(codec,
533 spec->multiout.dig_out_nid,
534 spec->multiout.dig_out_nid);
537 err = snd_hda_create_spdif_share_sw(codec,
541 spec->multiout.share_spdif = 1;
543 if (spec->dig_in_nid) {
544 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
549 /* if we have no master control, let's create it */
550 if (spec->vmaster_nid &&
551 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
552 unsigned int vmaster_tlv[4];
553 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
554 HDA_OUTPUT, vmaster_tlv);
555 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
556 vmaster_tlv, slave_vols);
560 if (spec->vmaster_nid &&
561 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
562 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
568 if (spec->input_mux) {
569 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
574 #ifdef CONFIG_SND_HDA_INPUT_BEEP
575 /* create beep controls if needed */
576 if (spec->beep_amp) {
577 const struct snd_kcontrol_new *knew;
578 for (knew = cxt_beep_mixer; knew->name; knew++) {
579 struct snd_kcontrol *kctl;
580 kctl = snd_ctl_new1(knew, codec);
583 kctl->private_value = spec->beep_amp;
584 err = snd_hda_ctl_add(codec, 0, kctl);
594 #ifdef CONFIG_SND_HDA_POWER_SAVE
595 static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
597 snd_hda_shutup_pins(codec);
602 static const struct hda_codec_ops conexant_patch_ops = {
603 .build_controls = conexant_build_controls,
604 .build_pcms = conexant_build_pcms,
605 .init = conexant_init,
606 .free = conexant_free,
607 .set_power_state = conexant_set_power,
608 #ifdef CONFIG_SND_HDA_POWER_SAVE
609 .suspend = conexant_suspend,
611 .reboot_notify = snd_hda_shutup_pins,
614 #ifdef CONFIG_SND_HDA_INPUT_BEEP
615 #define set_beep_amp(spec, nid, idx, dir) \
616 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
618 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
621 static int patch_conexant_auto(struct hda_codec *codec);
624 * the private value = nid | (invert << 8)
627 #define cxt_eapd_info snd_ctl_boolean_mono_info
629 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
630 struct snd_ctl_elem_value *ucontrol)
632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633 struct conexant_spec *spec = codec->spec;
634 int invert = (kcontrol->private_value >> 8) & 1;
636 ucontrol->value.integer.value[0] = !spec->cur_eapd;
638 ucontrol->value.integer.value[0] = spec->cur_eapd;
643 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_value *ucontrol)
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct conexant_spec *spec = codec->spec;
648 int invert = (kcontrol->private_value >> 8) & 1;
649 hda_nid_t nid = kcontrol->private_value & 0xff;
652 eapd = !!ucontrol->value.integer.value[0];
655 if (eapd == spec->cur_eapd)
658 spec->cur_eapd = eapd;
659 snd_hda_codec_write_cache(codec, nid,
660 0, AC_VERB_SET_EAPD_BTLENABLE,
665 /* controls for test mode */
666 #ifdef CONFIG_SND_DEBUG
668 #define CXT_EAPD_SWITCH(xname, nid, mask) \
669 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
670 .info = cxt_eapd_info, \
671 .get = cxt_eapd_get, \
672 .put = cxt_eapd_put, \
673 .private_value = nid | (mask<<16) }
677 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
678 struct snd_ctl_elem_info *uinfo)
680 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
681 struct conexant_spec *spec = codec->spec;
682 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
683 spec->num_channel_mode);
686 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
687 struct snd_ctl_elem_value *ucontrol)
689 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
690 struct conexant_spec *spec = codec->spec;
691 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
692 spec->num_channel_mode,
693 spec->multiout.max_channels);
696 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
697 struct snd_ctl_elem_value *ucontrol)
699 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
700 struct conexant_spec *spec = codec->spec;
701 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
702 spec->num_channel_mode,
703 &spec->multiout.max_channels);
704 if (err >= 0 && spec->need_dac_fix)
705 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
709 #define CXT_PIN_MODE(xname, nid, dir) \
710 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
711 .info = conexant_ch_mode_info, \
712 .get = conexant_ch_mode_get, \
713 .put = conexant_ch_mode_put, \
714 .private_value = nid | (dir<<16) }
716 #endif /* CONFIG_SND_DEBUG */
718 /* Conexant 5045 specific */
720 static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
721 static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
722 static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
723 #define CXT5045_SPDIF_OUT 0x18
725 static const struct hda_channel_mode cxt5045_modes[1] = {
729 static const struct hda_input_mux cxt5045_capture_source = {
737 static const struct hda_input_mux cxt5045_capture_source_benq = {
748 static const struct hda_input_mux cxt5045_capture_source_hp530 = {
756 /* turn on/off EAPD (+ mute HP) as a master switch */
757 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
758 struct snd_ctl_elem_value *ucontrol)
760 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
761 struct conexant_spec *spec = codec->spec;
764 if (!cxt_eapd_put(kcontrol, ucontrol))
767 /* toggle internal speakers mute depending of presence of
770 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
771 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
774 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
775 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
780 /* bind volumes of both NID 0x10 and 0x11 */
781 static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
782 .ops = &snd_hda_bind_vol,
784 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
785 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
790 /* toggle input of built-in and mic jack appropriately */
791 static void cxt5045_hp_automic(struct hda_codec *codec)
793 static const struct hda_verb mic_jack_on[] = {
794 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
795 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
798 static const struct hda_verb mic_jack_off[] = {
799 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
800 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
803 unsigned int present;
805 present = snd_hda_jack_detect(codec, 0x12);
807 snd_hda_sequence_write(codec, mic_jack_on);
809 snd_hda_sequence_write(codec, mic_jack_off);
813 /* mute internal speaker if HP is plugged */
814 static void cxt5045_hp_automute(struct hda_codec *codec)
816 struct conexant_spec *spec = codec->spec;
819 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
821 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
822 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
826 /* unsolicited event for HP jack sensing */
827 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
832 case CONEXANT_HP_EVENT:
833 cxt5045_hp_automute(codec);
835 case CONEXANT_MIC_EVENT:
836 cxt5045_hp_automic(codec);
842 static const struct snd_kcontrol_new cxt5045_mixers[] = {
843 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
844 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
845 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
846 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
847 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
848 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
849 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
850 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
851 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
852 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
853 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
855 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
856 .name = "Master Playback Switch",
857 .info = cxt_eapd_info,
859 .put = cxt5045_hp_master_sw_put,
860 .private_value = 0x10,
866 static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
867 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
868 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
869 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
870 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
872 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
873 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
874 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
875 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
877 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
878 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
883 static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
884 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
885 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
886 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
887 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
888 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
889 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
890 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
891 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
892 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
893 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
894 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
896 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
897 .name = "Master Playback Switch",
898 .info = cxt_eapd_info,
900 .put = cxt5045_hp_master_sw_put,
901 .private_value = 0x10,
907 static const struct hda_verb cxt5045_init_verbs[] = {
909 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
910 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
912 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
913 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
914 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
915 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
916 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
917 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
918 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
919 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
920 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
921 /* Record selector: Internal mic */
922 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
923 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
924 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
925 /* SPDIF route: PCM */
926 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
927 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
929 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
933 static const struct hda_verb cxt5045_benq_init_verbs[] = {
934 /* Internal Mic, Mic */
935 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
936 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
937 /* Line In,HP, Amp */
938 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
939 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
940 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
941 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
942 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
943 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
944 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
945 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
946 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
947 /* Record selector: Internal mic */
948 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
949 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
950 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
951 /* SPDIF route: PCM */
952 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
953 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
955 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
959 static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
960 /* pin sensing on HP jack */
961 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
965 static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
966 /* pin sensing on HP jack */
967 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
971 #ifdef CONFIG_SND_DEBUG
972 /* Test configuration for debugging, modelled after the ALC260 test
975 static const struct hda_input_mux cxt5045_test_capture_source = {
980 { "LINE1 pin", 0x2 },
981 { "HP-OUT pin", 0x3 },
986 static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
988 /* Output controls */
989 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
990 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
991 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
992 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
993 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
994 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
996 /* Modes for retasking pin widgets */
997 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
998 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
1000 /* EAPD Switch Control */
1001 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
1003 /* Loopback mixer controls */
1005 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
1006 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
1007 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
1008 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
1009 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
1010 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1011 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1012 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1013 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1014 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
1016 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1017 .name = "Input Source",
1018 .info = conexant_mux_enum_info,
1019 .get = conexant_mux_enum_get,
1020 .put = conexant_mux_enum_put,
1022 /* Audio input controls */
1023 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1024 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1025 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1026 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1027 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1028 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1029 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1030 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1031 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1032 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1036 static const struct hda_verb cxt5045_test_init_verbs[] = {
1037 /* Set connections */
1038 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1039 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1040 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1041 /* Enable retasking pins as output, initially without power amp */
1042 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1043 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1045 /* Disable digital (SPDIF) pins initially, but users can enable
1046 * them via a mixer switch. In the case of SPDIF-out, this initverb
1047 * payload also sets the generation to 0, output to be in "consumer"
1048 * PCM format, copyright asserted, no pre-emphasis and no validity
1051 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1052 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1054 /* Start with output sum widgets muted and their output gains at min */
1055 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1056 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1058 /* Unmute retasking pin widget output buffers since the default
1059 * state appears to be output. As the pin mode is changed by the
1060 * user the pin mode control will take care of enabling the pin's
1061 * input/output buffers as needed.
1063 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1064 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1066 /* Mute capture amp left and right */
1067 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1069 /* Set ADC connection select to match default mixer setting (mic1
1072 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1073 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1075 /* Mute all inputs to mixer widget (even unconnected ones) */
1076 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1077 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1078 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1079 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1080 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1087 /* initialize jack-sensing, too */
1088 static int cxt5045_init(struct hda_codec *codec)
1090 conexant_init(codec);
1091 cxt5045_hp_automute(codec);
1097 CXT5045_LAPTOP_HPSENSE,
1098 CXT5045_LAPTOP_MICSENSE,
1099 CXT5045_LAPTOP_HPMICSENSE,
1101 CXT5045_LAPTOP_HP530,
1102 #ifdef CONFIG_SND_DEBUG
1109 static const char * const cxt5045_models[CXT5045_MODELS] = {
1110 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1111 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1112 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1113 [CXT5045_BENQ] = "benq",
1114 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1115 #ifdef CONFIG_SND_DEBUG
1116 [CXT5045_TEST] = "test",
1118 [CXT5045_AUTO] = "auto",
1121 static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1122 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1123 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1124 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1125 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1126 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1127 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1128 CXT5045_LAPTOP_HPMICSENSE),
1129 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1130 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1131 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1132 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1133 CXT5045_LAPTOP_HPMICSENSE),
1134 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1138 static int patch_cxt5045(struct hda_codec *codec)
1140 struct conexant_spec *spec;
1143 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1146 if (board_config < 0)
1147 board_config = CXT5045_AUTO; /* model=auto as default */
1148 if (board_config == CXT5045_AUTO)
1149 return patch_conexant_auto(codec);
1151 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1155 codec->pin_amp_workaround = 1;
1157 spec->multiout.max_channels = 2;
1158 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1159 spec->multiout.dac_nids = cxt5045_dac_nids;
1160 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1161 spec->num_adc_nids = 1;
1162 spec->adc_nids = cxt5045_adc_nids;
1163 spec->capsrc_nids = cxt5045_capsrc_nids;
1164 spec->input_mux = &cxt5045_capture_source;
1165 spec->num_mixers = 1;
1166 spec->mixers[0] = cxt5045_mixers;
1167 spec->num_init_verbs = 1;
1168 spec->init_verbs[0] = cxt5045_init_verbs;
1169 spec->spdif_route = 0;
1170 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1171 spec->channel_mode = cxt5045_modes;
1173 set_beep_amp(spec, 0x16, 0, 1);
1175 codec->patch_ops = conexant_patch_ops;
1177 switch (board_config) {
1178 case CXT5045_LAPTOP_HPSENSE:
1179 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1180 spec->input_mux = &cxt5045_capture_source;
1181 spec->num_init_verbs = 2;
1182 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1183 spec->mixers[0] = cxt5045_mixers;
1184 codec->patch_ops.init = cxt5045_init;
1186 case CXT5045_LAPTOP_MICSENSE:
1187 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1188 spec->input_mux = &cxt5045_capture_source;
1189 spec->num_init_verbs = 2;
1190 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1191 spec->mixers[0] = cxt5045_mixers;
1192 codec->patch_ops.init = cxt5045_init;
1195 case CXT5045_LAPTOP_HPMICSENSE:
1196 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1197 spec->input_mux = &cxt5045_capture_source;
1198 spec->num_init_verbs = 3;
1199 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1200 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1201 spec->mixers[0] = cxt5045_mixers;
1202 codec->patch_ops.init = cxt5045_init;
1205 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1206 spec->input_mux = &cxt5045_capture_source_benq;
1207 spec->num_init_verbs = 1;
1208 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1209 spec->mixers[0] = cxt5045_mixers;
1210 spec->mixers[1] = cxt5045_benq_mixers;
1211 spec->num_mixers = 2;
1212 codec->patch_ops.init = cxt5045_init;
1214 case CXT5045_LAPTOP_HP530:
1215 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1216 spec->input_mux = &cxt5045_capture_source_hp530;
1217 spec->num_init_verbs = 2;
1218 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1219 spec->mixers[0] = cxt5045_mixers_hp530;
1220 codec->patch_ops.init = cxt5045_init;
1222 #ifdef CONFIG_SND_DEBUG
1224 spec->input_mux = &cxt5045_test_capture_source;
1225 spec->mixers[0] = cxt5045_test_mixer;
1226 spec->init_verbs[0] = cxt5045_test_init_verbs;
1232 switch (codec->subsystem_id >> 16) {
1237 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1238 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1239 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1241 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1242 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1243 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1244 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1245 (1 << AC_AMPCAP_MUTE_SHIFT));
1250 snd_hda_attach_beep_device(codec, spec->beep_amp);
1256 /* Conexant 5047 specific */
1257 #define CXT5047_SPDIF_OUT 0x11
1259 static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1260 static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1261 static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1263 static const struct hda_channel_mode cxt5047_modes[1] = {
1267 static const struct hda_input_mux cxt5047_toshiba_capture_source = {
1275 /* turn on/off EAPD (+ mute HP) as a master switch */
1276 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1277 struct snd_ctl_elem_value *ucontrol)
1279 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1280 struct conexant_spec *spec = codec->spec;
1283 if (!cxt_eapd_put(kcontrol, ucontrol))
1286 /* toggle internal speakers mute depending of presence of
1287 * the headphone jack
1289 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1290 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1291 * pin widgets unlike other codecs. In this case, we need to
1292 * set index 0x01 for the volume from the mixer amp 0x19.
1294 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1295 HDA_AMP_MUTE, bits);
1296 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1297 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1298 HDA_AMP_MUTE, bits);
1302 /* mute internal speaker if HP is plugged */
1303 static void cxt5047_hp_automute(struct hda_codec *codec)
1305 struct conexant_spec *spec = codec->spec;
1308 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1310 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1311 /* See the note in cxt5047_hp_master_sw_put */
1312 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1313 HDA_AMP_MUTE, bits);
1316 /* toggle input of built-in and mic jack appropriately */
1317 static void cxt5047_hp_automic(struct hda_codec *codec)
1319 static const struct hda_verb mic_jack_on[] = {
1320 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1321 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1324 static const struct hda_verb mic_jack_off[] = {
1325 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1326 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1329 unsigned int present;
1331 present = snd_hda_jack_detect(codec, 0x15);
1333 snd_hda_sequence_write(codec, mic_jack_on);
1335 snd_hda_sequence_write(codec, mic_jack_off);
1338 /* unsolicited event for HP jack sensing */
1339 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1342 switch (res >> 26) {
1343 case CONEXANT_HP_EVENT:
1344 cxt5047_hp_automute(codec);
1346 case CONEXANT_MIC_EVENT:
1347 cxt5047_hp_automic(codec);
1352 static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1353 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1354 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1355 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1356 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1357 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1358 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1359 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1361 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1362 .name = "Master Playback Switch",
1363 .info = cxt_eapd_info,
1364 .get = cxt_eapd_get,
1365 .put = cxt5047_hp_master_sw_put,
1366 .private_value = 0x13,
1372 static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1373 /* See the note in cxt5047_hp_master_sw_put */
1374 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1375 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1379 static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1380 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1384 static const struct hda_verb cxt5047_init_verbs[] = {
1385 /* Line in, Mic, Built-in Mic */
1386 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1387 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1388 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1390 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1391 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1392 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1393 /* Record selector: Mic */
1394 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1395 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1396 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1397 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1398 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1399 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1400 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1401 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1402 /* SPDIF route: PCM */
1403 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1404 /* Enable unsolicited events */
1405 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1406 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1410 /* configuration for Toshiba Laptops */
1411 static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
1412 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1416 /* Test configuration for debugging, modelled after the ALC260 test
1419 #ifdef CONFIG_SND_DEBUG
1420 static const struct hda_input_mux cxt5047_test_capture_source = {
1423 { "LINE1 pin", 0x0 },
1424 { "MIC1 pin", 0x1 },
1425 { "MIC2 pin", 0x2 },
1430 static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1432 /* Output only controls */
1433 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1434 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1435 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1436 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1437 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1438 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1439 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1440 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1441 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1442 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1443 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1444 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1446 /* Modes for retasking pin widgets */
1447 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1448 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1450 /* EAPD Switch Control */
1451 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1453 /* Loopback mixer controls */
1454 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1455 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1456 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1457 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1458 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1459 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1460 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1461 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1463 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1464 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1465 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1466 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1467 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1468 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1469 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1470 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1472 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1473 .name = "Input Source",
1474 .info = conexant_mux_enum_info,
1475 .get = conexant_mux_enum_get,
1476 .put = conexant_mux_enum_put,
1478 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1483 static const struct hda_verb cxt5047_test_init_verbs[] = {
1484 /* Enable retasking pins as output, initially without power amp */
1485 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1486 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1487 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1489 /* Disable digital (SPDIF) pins initially, but users can enable
1490 * them via a mixer switch. In the case of SPDIF-out, this initverb
1491 * payload also sets the generation to 0, output to be in "consumer"
1492 * PCM format, copyright asserted, no pre-emphasis and no validity
1495 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1497 /* Ensure mic1, mic2, line1 pin widgets take input from the
1498 * OUT1 sum bus when acting as an output.
1500 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1501 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1503 /* Start with output sum widgets muted and their output gains at min */
1504 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1505 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1507 /* Unmute retasking pin widget output buffers since the default
1508 * state appears to be output. As the pin mode is changed by the
1509 * user the pin mode control will take care of enabling the pin's
1510 * input/output buffers as needed.
1512 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1513 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1514 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1516 /* Mute capture amp left and right */
1517 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1519 /* Set ADC connection select to match default mixer setting (mic1
1522 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1524 /* Mute all inputs to mixer widget (even unconnected ones) */
1525 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1526 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1530 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1531 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1539 /* initialize jack-sensing, too */
1540 static int cxt5047_hp_init(struct hda_codec *codec)
1542 conexant_init(codec);
1543 cxt5047_hp_automute(codec);
1549 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1550 CXT5047_LAPTOP_HP, /* Some HP laptops */
1551 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1552 #ifdef CONFIG_SND_DEBUG
1559 static const char * const cxt5047_models[CXT5047_MODELS] = {
1560 [CXT5047_LAPTOP] = "laptop",
1561 [CXT5047_LAPTOP_HP] = "laptop-hp",
1562 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1563 #ifdef CONFIG_SND_DEBUG
1564 [CXT5047_TEST] = "test",
1566 [CXT5047_AUTO] = "auto",
1569 static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1570 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1571 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1573 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1577 static int patch_cxt5047(struct hda_codec *codec)
1579 struct conexant_spec *spec;
1582 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1585 if (board_config < 0)
1586 board_config = CXT5047_AUTO; /* model=auto as default */
1587 if (board_config == CXT5047_AUTO)
1588 return patch_conexant_auto(codec);
1590 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1594 codec->pin_amp_workaround = 1;
1596 spec->multiout.max_channels = 2;
1597 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1598 spec->multiout.dac_nids = cxt5047_dac_nids;
1599 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1600 spec->num_adc_nids = 1;
1601 spec->adc_nids = cxt5047_adc_nids;
1602 spec->capsrc_nids = cxt5047_capsrc_nids;
1603 spec->num_mixers = 1;
1604 spec->mixers[0] = cxt5047_base_mixers;
1605 spec->num_init_verbs = 1;
1606 spec->init_verbs[0] = cxt5047_init_verbs;
1607 spec->spdif_route = 0;
1608 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1609 spec->channel_mode = cxt5047_modes,
1611 codec->patch_ops = conexant_patch_ops;
1613 switch (board_config) {
1614 case CXT5047_LAPTOP:
1615 spec->num_mixers = 2;
1616 spec->mixers[1] = cxt5047_hp_spk_mixers;
1617 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1619 case CXT5047_LAPTOP_HP:
1620 spec->num_mixers = 2;
1621 spec->mixers[1] = cxt5047_hp_only_mixers;
1622 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1623 codec->patch_ops.init = cxt5047_hp_init;
1625 case CXT5047_LAPTOP_EAPD:
1626 spec->input_mux = &cxt5047_toshiba_capture_source;
1627 spec->num_mixers = 2;
1628 spec->mixers[1] = cxt5047_hp_spk_mixers;
1629 spec->num_init_verbs = 2;
1630 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1631 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1633 #ifdef CONFIG_SND_DEBUG
1635 spec->input_mux = &cxt5047_test_capture_source;
1636 spec->mixers[0] = cxt5047_test_mixer;
1637 spec->init_verbs[0] = cxt5047_test_init_verbs;
1638 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1641 spec->vmaster_nid = 0x13;
1643 switch (codec->subsystem_id >> 16) {
1645 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1646 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1647 * with 0 dB offset 0x17)
1649 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1650 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1651 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1652 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1653 (1 << AC_AMPCAP_MUTE_SHIFT));
1660 /* Conexant 5051 specific */
1661 static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1662 static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1664 static const struct hda_channel_mode cxt5051_modes[1] = {
1668 static void cxt5051_update_speaker(struct hda_codec *codec)
1670 struct conexant_spec *spec = codec->spec;
1671 unsigned int pinctl;
1673 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1674 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1677 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1678 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1680 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1682 snd_hda_codec_write(codec, 0x1b, 0,
1683 AC_VERB_SET_PIN_WIDGET_CONTROL,
1687 /* turn on/off EAPD (+ mute HP) as a master switch */
1688 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1689 struct snd_ctl_elem_value *ucontrol)
1691 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1693 if (!cxt_eapd_put(kcontrol, ucontrol))
1695 cxt5051_update_speaker(codec);
1699 /* toggle input of built-in and mic jack appropriately */
1700 static void cxt5051_portb_automic(struct hda_codec *codec)
1702 struct conexant_spec *spec = codec->spec;
1703 unsigned int present;
1705 if (!(spec->auto_mic & AUTO_MIC_PORTB))
1707 present = snd_hda_jack_detect(codec, 0x17);
1708 snd_hda_codec_write(codec, 0x14, 0,
1709 AC_VERB_SET_CONNECT_SEL,
1710 present ? 0x01 : 0x00);
1713 /* switch the current ADC according to the jack state */
1714 static void cxt5051_portc_automic(struct hda_codec *codec)
1716 struct conexant_spec *spec = codec->spec;
1717 unsigned int present;
1720 if (!(spec->auto_mic & AUTO_MIC_PORTC))
1722 present = snd_hda_jack_detect(codec, 0x18);
1724 spec->cur_adc_idx = 1;
1726 spec->cur_adc_idx = 0;
1727 new_adc = spec->adc_nids[spec->cur_adc_idx];
1728 if (spec->cur_adc && spec->cur_adc != new_adc) {
1729 /* stream is running, let's swap the current ADC */
1730 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1731 spec->cur_adc = new_adc;
1732 snd_hda_codec_setup_stream(codec, new_adc,
1733 spec->cur_adc_stream_tag, 0,
1734 spec->cur_adc_format);
1738 /* mute internal speaker if HP is plugged */
1739 static void cxt5051_hp_automute(struct hda_codec *codec)
1741 struct conexant_spec *spec = codec->spec;
1743 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1744 cxt5051_update_speaker(codec);
1747 /* unsolicited event for HP jack sensing */
1748 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1751 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1752 switch (res >> 26) {
1753 case CONEXANT_HP_EVENT:
1754 cxt5051_hp_automute(codec);
1756 case CXT5051_PORTB_EVENT:
1757 cxt5051_portb_automic(codec);
1759 case CXT5051_PORTC_EVENT:
1760 cxt5051_portc_automic(codec);
1763 snd_hda_input_jack_report(codec, nid);
1766 static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1767 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1769 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1770 .name = "Master Playback Switch",
1771 .info = cxt_eapd_info,
1772 .get = cxt_eapd_get,
1773 .put = cxt5051_hp_master_sw_put,
1774 .private_value = 0x1a,
1779 static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1780 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1781 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1782 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1783 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1784 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1785 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1789 static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1790 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1791 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1792 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1793 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1797 static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1798 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1799 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
1803 static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1804 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1805 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1809 static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1810 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1811 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1812 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1813 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1817 static const struct hda_verb cxt5051_init_verbs[] = {
1819 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1820 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1821 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1822 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1823 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1824 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1826 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1827 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1829 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1830 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1832 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1833 /* Record selector: Internal mic */
1834 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1835 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1836 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1837 /* SPDIF route: PCM */
1838 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1839 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1841 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1842 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1846 static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1848 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1849 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1850 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1851 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1853 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1854 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1856 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1857 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1859 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1860 /* Record selector: Internal mic */
1861 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1862 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1863 /* SPDIF route: PCM */
1864 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1866 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1867 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1871 static const struct hda_verb cxt5051_f700_init_verbs[] = {
1873 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1874 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1875 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1876 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1878 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1879 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1881 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1882 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1884 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1885 /* Record selector: Internal mic */
1886 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1887 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1888 /* SPDIF route: PCM */
1889 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1891 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1892 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1896 static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1899 snd_hda_codec_write(codec, nid, 0,
1900 AC_VERB_SET_UNSOLICITED_ENABLE,
1901 AC_USRSP_EN | event);
1904 static void cxt5051_init_mic_jack(struct hda_codec *codec, hda_nid_t nid)
1906 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1907 snd_hda_input_jack_report(codec, nid);
1910 static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1912 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1913 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1917 /* initialize jack-sensing, too */
1918 static int cxt5051_init(struct hda_codec *codec)
1920 struct conexant_spec *spec = codec->spec;
1922 conexant_init(codec);
1924 if (spec->auto_mic & AUTO_MIC_PORTB)
1925 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1926 if (spec->auto_mic & AUTO_MIC_PORTC)
1927 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1929 if (codec->patch_ops.unsol_event) {
1930 cxt5051_hp_automute(codec);
1931 cxt5051_portb_automic(codec);
1932 cxt5051_portc_automic(codec);
1939 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1940 CXT5051_HP, /* no docking */
1941 CXT5051_HP_DV6736, /* HP without mic switch */
1942 CXT5051_F700, /* HP Compaq Presario F700 */
1943 CXT5051_TOSHIBA, /* Toshiba M300 & co */
1944 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
1945 CXT5051_AUTO, /* auto-parser */
1949 static const char *const cxt5051_models[CXT5051_MODELS] = {
1950 [CXT5051_LAPTOP] = "laptop",
1951 [CXT5051_HP] = "hp",
1952 [CXT5051_HP_DV6736] = "hp-dv6736",
1953 [CXT5051_F700] = "hp-700",
1954 [CXT5051_TOSHIBA] = "toshiba",
1955 [CXT5051_IDEAPAD] = "ideapad",
1956 [CXT5051_AUTO] = "auto",
1959 static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1960 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1961 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1962 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1963 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1964 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1966 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1967 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1971 static int patch_cxt5051(struct hda_codec *codec)
1973 struct conexant_spec *spec;
1976 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1979 if (board_config < 0)
1980 board_config = CXT5051_AUTO; /* model=auto as default */
1981 if (board_config == CXT5051_AUTO)
1982 return patch_conexant_auto(codec);
1984 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1988 codec->pin_amp_workaround = 1;
1990 codec->patch_ops = conexant_patch_ops;
1991 codec->patch_ops.init = cxt5051_init;
1993 spec->multiout.max_channels = 2;
1994 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1995 spec->multiout.dac_nids = cxt5051_dac_nids;
1996 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1997 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1998 spec->adc_nids = cxt5051_adc_nids;
1999 spec->num_mixers = 2;
2000 spec->mixers[0] = cxt5051_capture_mixers;
2001 spec->mixers[1] = cxt5051_playback_mixers;
2002 spec->num_init_verbs = 1;
2003 spec->init_verbs[0] = cxt5051_init_verbs;
2004 spec->spdif_route = 0;
2005 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2006 spec->channel_mode = cxt5051_modes;
2008 spec->cur_adc_idx = 0;
2010 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2012 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2014 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
2015 switch (board_config) {
2017 spec->mixers[0] = cxt5051_hp_mixers;
2019 case CXT5051_HP_DV6736:
2020 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2021 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2025 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2026 spec->mixers[0] = cxt5051_f700_mixers;
2029 case CXT5051_TOSHIBA:
2030 spec->mixers[0] = cxt5051_toshiba_mixers;
2031 spec->auto_mic = AUTO_MIC_PORTB;
2033 case CXT5051_IDEAPAD:
2034 spec->init_verbs[spec->num_init_verbs++] =
2035 cxt5051_ideapad_init_verbs;
2041 snd_hda_attach_beep_device(codec, spec->beep_amp);
2043 conexant_init_jacks(codec);
2044 if (spec->auto_mic & AUTO_MIC_PORTB)
2045 cxt5051_init_mic_jack(codec, 0x17);
2046 if (spec->auto_mic & AUTO_MIC_PORTC)
2047 cxt5051_init_mic_jack(codec, 0x18);
2052 /* Conexant 5066 specific */
2054 static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2055 static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2056 static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2057 static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
2059 /* OLPC's microphone port is DC coupled for use with external sensors,
2060 * therefore we use a 50% mic bias in order to center the input signal with
2061 * the DC input range of the codec. */
2062 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2064 static const struct hda_channel_mode cxt5066_modes[1] = {
2068 #define HP_PRESENT_PORT_A (1 << 0)
2069 #define HP_PRESENT_PORT_D (1 << 1)
2070 #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2071 #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2073 static void cxt5066_update_speaker(struct hda_codec *codec)
2075 struct conexant_spec *spec = codec->spec;
2076 unsigned int pinctl;
2078 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2079 spec->hp_present, spec->cur_eapd);
2082 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
2083 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2086 /* Port D (HP/LO) */
2087 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2088 if (spec->dell_automute || spec->thinkpad) {
2089 /* Mute if Port A is connected */
2090 if (hp_port_a_present(spec))
2093 /* Thinkpad/Dell doesn't give pin-D status */
2094 if (!hp_port_d_present(spec))
2097 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2101 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2102 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2106 /* turn on/off EAPD (+ mute HP) as a master switch */
2107 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2108 struct snd_ctl_elem_value *ucontrol)
2110 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2112 if (!cxt_eapd_put(kcontrol, ucontrol))
2115 cxt5066_update_speaker(codec);
2119 static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2123 { "50%", PIN_VREF50 },
2124 { "80%", PIN_VREF80 },
2128 static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2130 struct conexant_spec *spec = codec->spec;
2131 /* Even though port F is the DC input, the bias is controlled on port B.
2132 * we also leave that port as an active input (but unselected) in DC mode
2133 * just in case that is necessary to make the bias setting take effect. */
2134 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2135 AC_VERB_SET_PIN_WIDGET_CONTROL,
2136 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2139 /* OLPC defers mic widget control until when capture is started because the
2140 * microphone LED comes on as soon as these settings are put in place. if we
2141 * did this before recording, it would give the false indication that recording
2142 * is happening when it is not. */
2143 static void cxt5066_olpc_select_mic(struct hda_codec *codec)
2145 struct conexant_spec *spec = codec->spec;
2146 if (!spec->recording)
2149 if (spec->dc_enable) {
2150 /* in DC mode we ignore presence detection and just use the jack
2151 * through our special DC port */
2152 const struct hda_verb enable_dc_mode[] = {
2153 /* disble internal mic, port C */
2154 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2156 /* enable DC capture, port F */
2157 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2161 snd_hda_sequence_write(codec, enable_dc_mode);
2162 /* port B input disabled (and bias set) through the following call */
2163 cxt5066_set_olpc_dc_bias(codec);
2167 /* disable DC (port F) */
2168 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2170 /* external mic, port B */
2171 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2172 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
2174 /* internal mic, port C */
2175 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2176 spec->ext_mic_present ? 0 : PIN_VREF80);
2179 /* toggle input of built-in and mic jack appropriately */
2180 static void cxt5066_olpc_automic(struct hda_codec *codec)
2182 struct conexant_spec *spec = codec->spec;
2183 unsigned int present;
2185 if (spec->dc_enable) /* don't do presence detection in DC mode */
2188 present = snd_hda_codec_read(codec, 0x1a, 0,
2189 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2191 snd_printdd("CXT5066: external microphone detected\n");
2193 snd_printdd("CXT5066: external microphone absent\n");
2195 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2197 spec->ext_mic_present = !!present;
2199 cxt5066_olpc_select_mic(codec);
2202 /* toggle input of built-in digital mic and mic jack appropriately */
2203 static void cxt5066_vostro_automic(struct hda_codec *codec)
2205 unsigned int present;
2207 struct hda_verb ext_mic_present[] = {
2208 /* enable external mic, port B */
2209 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2211 /* switch to external mic input */
2212 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2213 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2215 /* disable internal digital mic */
2216 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2219 static const struct hda_verb ext_mic_absent[] = {
2220 /* enable internal mic, port C */
2221 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2223 /* switch to internal mic input */
2224 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2226 /* disable external mic, port B */
2227 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2231 present = snd_hda_jack_detect(codec, 0x1a);
2233 snd_printdd("CXT5066: external microphone detected\n");
2234 snd_hda_sequence_write(codec, ext_mic_present);
2236 snd_printdd("CXT5066: external microphone absent\n");
2237 snd_hda_sequence_write(codec, ext_mic_absent);
2241 /* toggle input of built-in digital mic and mic jack appropriately */
2242 static void cxt5066_ideapad_automic(struct hda_codec *codec)
2244 unsigned int present;
2246 struct hda_verb ext_mic_present[] = {
2247 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2248 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2249 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2252 static const struct hda_verb ext_mic_absent[] = {
2253 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2254 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2255 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2259 present = snd_hda_jack_detect(codec, 0x1b);
2261 snd_printdd("CXT5066: external microphone detected\n");
2262 snd_hda_sequence_write(codec, ext_mic_present);
2264 snd_printdd("CXT5066: external microphone absent\n");
2265 snd_hda_sequence_write(codec, ext_mic_absent);
2270 /* toggle input of built-in digital mic and mic jack appropriately */
2271 static void cxt5066_asus_automic(struct hda_codec *codec)
2273 unsigned int present;
2275 present = snd_hda_jack_detect(codec, 0x1b);
2276 snd_printdd("CXT5066: external microphone present=%d\n", present);
2277 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2282 /* toggle input of built-in digital mic and mic jack appropriately */
2283 static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2285 unsigned int present;
2287 present = snd_hda_jack_detect(codec, 0x1b);
2288 snd_printdd("CXT5066: external microphone present=%d\n", present);
2289 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2294 /* toggle input of built-in digital mic and mic jack appropriately
2295 order is: external mic -> dock mic -> interal mic */
2296 static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2298 unsigned int ext_present, dock_present;
2300 static const struct hda_verb ext_mic_present[] = {
2301 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2302 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2303 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2304 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2305 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2308 static const struct hda_verb dock_mic_present[] = {
2309 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2310 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2311 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2312 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2313 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2316 static const struct hda_verb ext_mic_absent[] = {
2317 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2318 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2319 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2320 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2324 ext_present = snd_hda_jack_detect(codec, 0x1b);
2325 dock_present = snd_hda_jack_detect(codec, 0x1a);
2327 snd_printdd("CXT5066: external microphone detected\n");
2328 snd_hda_sequence_write(codec, ext_mic_present);
2329 } else if (dock_present) {
2330 snd_printdd("CXT5066: dock microphone detected\n");
2331 snd_hda_sequence_write(codec, dock_mic_present);
2333 snd_printdd("CXT5066: external microphone absent\n");
2334 snd_hda_sequence_write(codec, ext_mic_absent);
2338 /* mute internal speaker if HP is plugged */
2339 static void cxt5066_hp_automute(struct hda_codec *codec)
2341 struct conexant_spec *spec = codec->spec;
2342 unsigned int portA, portD;
2345 portA = snd_hda_jack_detect(codec, 0x19);
2348 portD = snd_hda_jack_detect(codec, 0x1c);
2350 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2351 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
2352 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2353 portA, portD, spec->hp_present);
2354 cxt5066_update_speaker(codec);
2357 /* Dispatch the right mic autoswitch function */
2358 static void cxt5066_automic(struct hda_codec *codec)
2360 struct conexant_spec *spec = codec->spec;
2362 if (spec->dell_vostro)
2363 cxt5066_vostro_automic(codec);
2364 else if (spec->ideapad)
2365 cxt5066_ideapad_automic(codec);
2366 else if (spec->thinkpad)
2367 cxt5066_thinkpad_automic(codec);
2368 else if (spec->hp_laptop)
2369 cxt5066_hp_laptop_automic(codec);
2370 else if (spec->asus)
2371 cxt5066_asus_automic(codec);
2374 /* unsolicited event for jack sensing */
2375 static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
2377 struct conexant_spec *spec = codec->spec;
2378 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2379 switch (res >> 26) {
2380 case CONEXANT_HP_EVENT:
2381 cxt5066_hp_automute(codec);
2383 case CONEXANT_MIC_EVENT:
2384 /* ignore mic events in DC mode; we're always using the jack */
2385 if (!spec->dc_enable)
2386 cxt5066_olpc_automic(codec);
2391 /* unsolicited event for jack sensing */
2392 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2394 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2395 switch (res >> 26) {
2396 case CONEXANT_HP_EVENT:
2397 cxt5066_hp_automute(codec);
2399 case CONEXANT_MIC_EVENT:
2400 cxt5066_automic(codec);
2406 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2417 static void cxt5066_set_mic_boost(struct hda_codec *codec)
2419 struct conexant_spec *spec = codec->spec;
2420 snd_hda_codec_write_cache(codec, 0x17, 0,
2421 AC_VERB_SET_AMP_GAIN_MUTE,
2422 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2423 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
2424 if (spec->ideapad || spec->thinkpad) {
2425 /* adjust the internal mic as well...it is not through 0x17 */
2426 snd_hda_codec_write_cache(codec, 0x23, 0,
2427 AC_VERB_SET_AMP_GAIN_MUTE,
2428 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2429 cxt5066_analog_mic_boost.
2430 items[spec->mic_boost].index);
2434 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2435 struct snd_ctl_elem_info *uinfo)
2437 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2440 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2441 struct snd_ctl_elem_value *ucontrol)
2443 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2444 struct conexant_spec *spec = codec->spec;
2445 ucontrol->value.enumerated.item[0] = spec->mic_boost;
2449 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2450 struct snd_ctl_elem_value *ucontrol)
2452 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2453 struct conexant_spec *spec = codec->spec;
2454 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2456 idx = ucontrol->value.enumerated.item[0];
2457 if (idx >= imux->num_items)
2458 idx = imux->num_items - 1;
2460 spec->mic_boost = idx;
2461 if (!spec->dc_enable)
2462 cxt5066_set_mic_boost(codec);
2466 static void cxt5066_enable_dc(struct hda_codec *codec)
2468 const struct hda_verb enable_dc_mode[] = {
2470 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2472 /* switch to DC input */
2473 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2477 /* configure as input source */
2478 snd_hda_sequence_write(codec, enable_dc_mode);
2479 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2482 static void cxt5066_disable_dc(struct hda_codec *codec)
2484 /* reconfigure input source */
2485 cxt5066_set_mic_boost(codec);
2486 /* automic also selects the right mic if we're recording */
2487 cxt5066_olpc_automic(codec);
2490 static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2491 struct snd_ctl_elem_value *ucontrol)
2493 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2494 struct conexant_spec *spec = codec->spec;
2495 ucontrol->value.integer.value[0] = spec->dc_enable;
2499 static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2500 struct snd_ctl_elem_value *ucontrol)
2502 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2503 struct conexant_spec *spec = codec->spec;
2504 int dc_enable = !!ucontrol->value.integer.value[0];
2506 if (dc_enable == spec->dc_enable)
2509 spec->dc_enable = dc_enable;
2511 cxt5066_enable_dc(codec);
2513 cxt5066_disable_dc(codec);
2518 static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2519 struct snd_ctl_elem_info *uinfo)
2521 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2524 static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2525 struct snd_ctl_elem_value *ucontrol)
2527 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2528 struct conexant_spec *spec = codec->spec;
2529 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2533 static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2534 struct snd_ctl_elem_value *ucontrol)
2536 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2537 struct conexant_spec *spec = codec->spec;
2538 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2541 idx = ucontrol->value.enumerated.item[0];
2542 if (idx >= imux->num_items)
2543 idx = imux->num_items - 1;
2545 spec->dc_input_bias = idx;
2546 if (spec->dc_enable)
2547 cxt5066_set_olpc_dc_bias(codec);
2551 static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2553 struct conexant_spec *spec = codec->spec;
2554 /* mark as recording and configure the microphone widget so that the
2555 * recording LED comes on. */
2556 spec->recording = 1;
2557 cxt5066_olpc_select_mic(codec);
2560 static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2562 struct conexant_spec *spec = codec->spec;
2563 const struct hda_verb disable_mics[] = {
2564 /* disable external mic, port B */
2565 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2567 /* disble internal mic, port C */
2568 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2570 /* disable DC capture, port F */
2571 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2575 snd_hda_sequence_write(codec, disable_mics);
2576 spec->recording = 0;
2579 static void conexant_check_dig_outs(struct hda_codec *codec,
2580 const hda_nid_t *dig_pins,
2583 struct conexant_spec *spec = codec->spec;
2584 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2587 for (i = 0; i < num_pins; i++, dig_pins++) {
2588 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2589 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2591 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2593 if (spec->slave_dig_outs[0])
2596 nid_loc = spec->slave_dig_outs;
2600 static const struct hda_input_mux cxt5066_capture_source = {
2610 static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2611 .ops = &snd_hda_bind_vol,
2613 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2614 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2619 static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2620 .ops = &snd_hda_bind_sw,
2622 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2623 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2628 static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
2629 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2633 static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2635 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2636 .name = "Master Playback Volume",
2637 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2638 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2639 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2640 .subdevice = HDA_SUBDEV_AMP_FLAG,
2641 .info = snd_hda_mixer_amp_volume_info,
2642 .get = snd_hda_mixer_amp_volume_get,
2643 .put = snd_hda_mixer_amp_volume_put,
2644 .tlv = { .c = snd_hda_mixer_amp_tlv },
2645 /* offset by 28 volume steps to limit minimum gain to -46dB */
2647 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2652 static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2654 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2655 .name = "DC Mode Enable Switch",
2656 .info = snd_ctl_boolean_mono_info,
2657 .get = cxt5066_olpc_dc_get,
2658 .put = cxt5066_olpc_dc_put,
2661 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2662 .name = "DC Input Bias Enum",
2663 .info = cxt5066_olpc_dc_bias_enum_info,
2664 .get = cxt5066_olpc_dc_bias_enum_get,
2665 .put = cxt5066_olpc_dc_bias_enum_put,
2670 static const struct snd_kcontrol_new cxt5066_mixers[] = {
2672 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2673 .name = "Master Playback Switch",
2674 .info = cxt_eapd_info,
2675 .get = cxt_eapd_get,
2676 .put = cxt5066_hp_master_sw_put,
2677 .private_value = 0x1d,
2681 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2682 .name = "Analog Mic Boost Capture Enum",
2683 .info = cxt5066_mic_boost_mux_enum_info,
2684 .get = cxt5066_mic_boost_mux_enum_get,
2685 .put = cxt5066_mic_boost_mux_enum_put,
2688 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2689 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2693 static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2695 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2696 .name = "Internal Mic Boost Capture Enum",
2697 .info = cxt5066_mic_boost_mux_enum_info,
2698 .get = cxt5066_mic_boost_mux_enum_get,
2699 .put = cxt5066_mic_boost_mux_enum_put,
2700 .private_value = 0x23 | 0x100,
2705 static const struct hda_verb cxt5066_init_verbs[] = {
2706 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2707 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2708 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2709 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2712 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2713 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2716 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2717 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2719 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2720 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2723 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2725 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2726 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2727 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2728 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2729 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2730 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2732 /* no digital microphone support yet */
2733 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2735 /* Audio input selector */
2736 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2738 /* SPDIF route: PCM */
2739 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2740 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2742 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2743 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2746 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2748 /* not handling these yet */
2749 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2750 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2751 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2752 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2753 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2754 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2755 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2756 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2760 static const struct hda_verb cxt5066_init_verbs_olpc[] = {
2761 /* Port A: headphones */
2762 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2763 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2765 /* Port B: external microphone */
2766 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2768 /* Port C: internal microphone */
2769 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2771 /* Port D: unused */
2772 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2774 /* Port E: unused, but has primary EAPD */
2775 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2776 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2778 /* Port F: external DC input through microphone port */
2779 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2781 /* Port G: internal speakers */
2782 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2783 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2786 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2789 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2791 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2792 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2793 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2794 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2795 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2796 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2797 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2798 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2799 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2800 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2801 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2802 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2804 /* Disable digital microphone port */
2805 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2807 /* Audio input selectors */
2808 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2809 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2812 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2813 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2815 /* enable unsolicited events for Port A and B */
2816 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2817 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2821 static const struct hda_verb cxt5066_init_verbs_vostro[] = {
2822 /* Port A: headphones */
2823 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2824 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2826 /* Port B: external microphone */
2827 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2829 /* Port C: unused */
2830 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2832 /* Port D: unused */
2833 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2835 /* Port E: unused, but has primary EAPD */
2836 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2837 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2839 /* Port F: unused */
2840 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2842 /* Port G: internal speakers */
2843 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2844 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2847 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2850 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2852 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2853 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2854 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2855 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2856 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2857 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2858 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2859 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2860 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2861 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2862 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2863 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2865 /* Digital microphone port */
2866 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2868 /* Audio input selectors */
2869 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2870 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2873 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2874 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2876 /* enable unsolicited events for Port A and B */
2877 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2878 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2882 static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2883 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2884 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2885 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2886 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2889 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2890 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2893 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2894 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2896 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2897 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2900 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2902 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2903 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2904 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2905 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2906 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2907 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2908 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2910 /* Audio input selector */
2911 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2912 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2914 /* SPDIF route: PCM */
2915 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2916 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2918 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2919 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2921 /* internal microphone */
2922 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2925 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2927 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2928 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2932 static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2933 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2934 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2936 /* Port G: internal speakers */
2937 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2938 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2940 /* Port A: HP, Amp */
2941 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2942 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2944 /* Port B: Mic Dock */
2945 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2948 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2950 /* Port D: HP Dock, Amp */
2951 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2952 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2955 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2957 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2958 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2959 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2960 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2961 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2962 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2963 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2965 /* Audio input selector */
2966 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2967 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2969 /* SPDIF route: PCM */
2970 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2971 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2973 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2974 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2976 /* internal microphone */
2977 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2980 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2982 /* enable unsolicited events for Port A, B, C and D */
2983 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2984 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2985 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2986 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2990 static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2991 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2996 static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2997 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2998 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2999 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3003 /* initialize jack-sensing, too */
3004 static int cxt5066_init(struct hda_codec *codec)
3006 snd_printdd("CXT5066: init\n");
3007 conexant_init(codec);
3008 if (codec->patch_ops.unsol_event) {
3009 cxt5066_hp_automute(codec);
3010 cxt5066_automic(codec);
3012 cxt5066_set_mic_boost(codec);
3016 static int cxt5066_olpc_init(struct hda_codec *codec)
3018 struct conexant_spec *spec = codec->spec;
3019 snd_printdd("CXT5066: init\n");
3020 conexant_init(codec);
3021 cxt5066_hp_automute(codec);
3022 if (!spec->dc_enable) {
3023 cxt5066_set_mic_boost(codec);
3024 cxt5066_olpc_automic(codec);
3026 cxt5066_enable_dc(codec);
3032 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
3033 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3034 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
3035 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
3036 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
3037 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
3038 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
3039 CXT5066_HP_LAPTOP, /* HP Laptop */
3040 CXT5066_AUTO, /* BIOS auto-parser */
3044 static const char * const cxt5066_models[CXT5066_MODELS] = {
3045 [CXT5066_LAPTOP] = "laptop",
3046 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3047 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
3048 [CXT5066_DELL_VOSTRO] = "dell-vostro",
3049 [CXT5066_IDEAPAD] = "ideapad",
3050 [CXT5066_THINKPAD] = "thinkpad",
3051 [CXT5066_ASUS] = "asus",
3052 [CXT5066_HP_LAPTOP] = "hp-laptop",
3053 [CXT5066_AUTO] = "auto",
3056 static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3057 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
3058 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
3059 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
3060 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3061 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
3062 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3063 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3064 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
3065 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3066 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
3067 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
3068 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
3069 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3070 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
3071 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3073 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
3074 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3075 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
3076 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
3077 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3078 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
3079 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
3080 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
3081 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
3082 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
3083 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
3084 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
3085 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
3089 static int patch_cxt5066(struct hda_codec *codec)
3091 struct conexant_spec *spec;
3094 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3095 cxt5066_models, cxt5066_cfg_tbl);
3096 if (board_config < 0)
3097 board_config = CXT5066_AUTO; /* model=auto as default */
3098 if (board_config == CXT5066_AUTO)
3099 return patch_conexant_auto(codec);
3101 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3106 codec->patch_ops = conexant_patch_ops;
3107 codec->patch_ops.init = conexant_init;
3109 spec->dell_automute = 0;
3110 spec->multiout.max_channels = 2;
3111 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3112 spec->multiout.dac_nids = cxt5066_dac_nids;
3113 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3114 ARRAY_SIZE(cxt5066_digout_pin_nids));
3115 spec->num_adc_nids = 1;
3116 spec->adc_nids = cxt5066_adc_nids;
3117 spec->capsrc_nids = cxt5066_capsrc_nids;
3118 spec->input_mux = &cxt5066_capture_source;
3120 spec->port_d_mode = PIN_HP;
3122 spec->num_init_verbs = 1;
3123 spec->init_verbs[0] = cxt5066_init_verbs;
3124 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3125 spec->channel_mode = cxt5066_modes;
3127 spec->cur_adc_idx = 0;
3129 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3131 switch (board_config) {
3133 case CXT5066_LAPTOP:
3134 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3135 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3137 case CXT5066_DELL_LAPTOP:
3138 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3139 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3141 spec->port_d_mode = PIN_OUT;
3142 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3143 spec->num_init_verbs++;
3144 spec->dell_automute = 1;
3147 case CXT5066_HP_LAPTOP:
3148 codec->patch_ops.init = cxt5066_init;
3149 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3150 spec->init_verbs[spec->num_init_verbs] =
3151 cxt5066_init_verbs_hp_laptop;
3152 spec->num_init_verbs++;
3153 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3154 spec->asus = board_config == CXT5066_ASUS;
3155 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3156 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3158 if (board_config == CXT5066_HP_LAPTOP)
3159 spec->multiout.dig_out_nid = 0;
3160 /* input source automatically selected */
3161 spec->input_mux = NULL;
3162 spec->port_d_mode = 0;
3163 spec->mic_boost = 3; /* default 30dB gain */
3166 case CXT5066_OLPC_XO_1_5:
3167 codec->patch_ops.init = cxt5066_olpc_init;
3168 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
3169 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3170 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3171 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
3172 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3173 spec->port_d_mode = 0;
3174 spec->mic_boost = 3; /* default 30dB gain */
3177 spec->multiout.dig_out_nid = 0;
3179 /* input source automatically selected */
3180 spec->input_mux = NULL;
3182 /* our capture hooks which allow us to turn on the microphone LED
3183 * at the right time */
3184 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3185 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
3187 case CXT5066_DELL_VOSTRO:
3188 codec->patch_ops.init = cxt5066_init;
3189 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3190 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3191 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3192 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3193 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
3194 spec->port_d_mode = 0;
3195 spec->dell_vostro = 1;
3196 spec->mic_boost = 3; /* default 30dB gain */
3199 spec->multiout.dig_out_nid = 0;
3201 /* input source automatically selected */
3202 spec->input_mux = NULL;
3204 case CXT5066_IDEAPAD:
3205 codec->patch_ops.init = cxt5066_init;
3206 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3207 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3208 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3209 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3210 spec->port_d_mode = 0;
3212 spec->mic_boost = 2; /* default 20dB gain */
3215 spec->multiout.dig_out_nid = 0;
3217 /* input source automatically selected */
3218 spec->input_mux = NULL;
3220 case CXT5066_THINKPAD:
3221 codec->patch_ops.init = cxt5066_init;
3222 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3223 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3224 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3225 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3227 spec->port_d_mode = PIN_OUT;
3228 spec->mic_boost = 2; /* default 20dB gain */
3231 spec->multiout.dig_out_nid = 0;
3233 /* input source automatically selected */
3234 spec->input_mux = NULL;
3239 snd_hda_attach_beep_device(codec, spec->beep_amp);
3245 * Automatic parser for CX20641 & co
3248 static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3249 struct hda_codec *codec,
3250 unsigned int stream_tag,
3251 unsigned int format,
3252 struct snd_pcm_substream *substream)
3254 struct conexant_spec *spec = codec->spec;
3255 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
3256 if (spec->adc_switching) {
3257 spec->cur_adc = adc;
3258 spec->cur_adc_stream_tag = stream_tag;
3259 spec->cur_adc_format = format;
3261 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3265 static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3266 struct hda_codec *codec,
3267 struct snd_pcm_substream *substream)
3269 struct conexant_spec *spec = codec->spec;
3270 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3275 static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3279 .nid = 0, /* fill later */
3281 .prepare = cx_auto_capture_pcm_prepare,
3282 .cleanup = cx_auto_capture_pcm_cleanup
3286 static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3288 #define get_connection_index(codec, mux, nid)\
3289 snd_hda_get_conn_index(codec, mux, nid, 0)
3291 /* get an unassigned DAC from the given list.
3292 * Return the nid if found and reduce the DAC list, or return zero if
3295 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3296 hda_nid_t *dacs, int *num_dacs)
3298 int i, nums = *num_dacs;
3301 for (i = 0; i < nums; i++) {
3302 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3310 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3315 #define MAX_AUTO_DACS 5
3317 #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3319 /* fill analog DAC list from the widget tree */
3320 static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3322 hda_nid_t nid, end_nid;
3325 end_nid = codec->start_nid + codec->num_nodes;
3326 for (nid = codec->start_nid; nid < end_nid; nid++) {
3327 unsigned int wcaps = get_wcaps(codec, nid);
3328 unsigned int type = get_wcaps_type(wcaps);
3329 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3331 if (nums >= MAX_AUTO_DACS)
3338 /* fill pin_dac_pair list from the pin and dac list */
3339 static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3340 int num_pins, hda_nid_t *dacs, int *rest,
3341 struct pin_dac_pair *filled, int nums,
3344 int i, start = nums;
3346 for (i = 0; i < num_pins; i++, nums++) {
3347 filled[nums].pin = pins[i];
3348 filled[nums].type = type;
3349 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3350 if (filled[nums].dac)
3352 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3353 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3356 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
3357 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
3360 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
3365 /* parse analog output paths */
3366 static void cx_auto_parse_output(struct hda_codec *codec)
3368 struct conexant_spec *spec = codec->spec;
3369 struct auto_pin_cfg *cfg = &spec->autocfg;
3370 hda_nid_t dacs[MAX_AUTO_DACS];
3371 int i, j, nums, rest;
3373 rest = fill_cx_auto_dacs(codec, dacs);
3374 /* parse all analog output pins */
3375 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3376 dacs, &rest, spec->dac_info, 0,
3378 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3379 dacs, &rest, spec->dac_info, nums,
3381 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3382 dacs, &rest, spec->dac_info, nums,
3383 AUTO_PIN_SPEAKER_OUT);
3384 spec->dac_info_filled = nums;
3385 /* fill multiout struct */
3386 for (i = 0; i < nums; i++) {
3387 hda_nid_t dac = spec->dac_info[i].dac;
3388 if (!dac || (dac & DAC_SLAVE_FLAG))
3390 switch (spec->dac_info[i].type) {
3391 case AUTO_PIN_LINE_OUT:
3392 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3393 spec->multiout.num_dacs++;
3395 case AUTO_PIN_HP_OUT:
3396 case AUTO_PIN_SPEAKER_OUT:
3397 if (!spec->multiout.hp_nid) {
3398 spec->multiout.hp_nid = dac;
3401 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3402 if (!spec->multiout.extra_out_nid[j]) {
3403 spec->multiout.extra_out_nid[j] = dac;
3409 spec->multiout.dac_nids = spec->private_dac_nids;
3410 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3412 for (i = 0; i < cfg->hp_outs; i++) {
3413 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3414 spec->auto_mute = 1;
3418 if (spec->auto_mute &&
3419 cfg->line_out_pins[0] &&
3420 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
3421 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3422 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3423 for (i = 0; i < cfg->line_outs; i++) {
3424 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3425 spec->detect_line = 1;
3429 spec->automute_lines = spec->detect_line;
3432 spec->vmaster_nid = spec->private_dac_nids[0];
3435 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3436 hda_nid_t *pins, bool on);
3438 static void do_automute(struct hda_codec *codec, int num_pins,
3439 hda_nid_t *pins, bool on)
3441 struct conexant_spec *spec = codec->spec;
3443 for (i = 0; i < num_pins; i++)
3444 snd_hda_codec_write(codec, pins[i], 0,
3445 AC_VERB_SET_PIN_WIDGET_CONTROL,
3447 if (spec->pin_eapd_ctrls)
3448 cx_auto_turn_eapd(codec, num_pins, pins, on);
3451 static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3455 for (i = 0; i < num_pins; i++) {
3456 hda_nid_t nid = pins[i];
3457 if (!nid || !is_jack_detectable(codec, nid))
3459 snd_hda_input_jack_report(codec, nid);
3460 present |= snd_hda_jack_detect(codec, nid);
3465 /* auto-mute/unmute speaker and line outs according to headphone jack */
3466 static void cx_auto_update_speakers(struct hda_codec *codec)
3468 struct conexant_spec *spec = codec->spec;
3469 struct auto_pin_cfg *cfg = &spec->autocfg;
3472 /* turn on HP EAPD when HP jacks are present */
3473 if (spec->pin_eapd_ctrls) {
3474 if (spec->auto_mute)
3475 on = spec->hp_present;
3476 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3479 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3480 if (spec->auto_mute)
3481 on = !(spec->hp_present ||
3482 (spec->detect_line && spec->line_present));
3483 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
3485 /* toggle line-out mutes if needed, too */
3486 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3487 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3488 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3490 if (spec->auto_mute) {
3491 /* mute LO in auto-mode when HP jack is present */
3492 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3493 spec->automute_lines)
3494 on = !spec->hp_present;
3498 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
3501 static void cx_auto_hp_automute(struct hda_codec *codec)
3503 struct conexant_spec *spec = codec->spec;
3504 struct auto_pin_cfg *cfg = &spec->autocfg;
3506 if (!spec->auto_mute)
3508 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3509 cx_auto_update_speakers(codec);
3512 static void cx_auto_line_automute(struct hda_codec *codec)
3514 struct conexant_spec *spec = codec->spec;
3515 struct auto_pin_cfg *cfg = &spec->autocfg;
3517 if (!spec->auto_mute || !spec->detect_line)
3519 spec->line_present = detect_jacks(codec, cfg->line_outs,
3520 cfg->line_out_pins);
3521 cx_auto_update_speakers(codec);
3524 static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3525 struct snd_ctl_elem_info *uinfo)
3527 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3528 struct conexant_spec *spec = codec->spec;
3529 static const char * const texts2[] = {
3530 "Disabled", "Enabled"
3532 static const char * const texts3[] = {
3533 "Disabled", "Speaker Only", "Line-Out+Speaker"
3535 const char * const *texts;
3537 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3539 if (spec->automute_hp_lo) {
3540 uinfo->value.enumerated.items = 3;
3543 uinfo->value.enumerated.items = 2;
3546 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3547 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
3548 strcpy(uinfo->value.enumerated.name,
3549 texts[uinfo->value.enumerated.item]);
3553 static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3554 struct snd_ctl_elem_value *ucontrol)
3556 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3557 struct conexant_spec *spec = codec->spec;
3559 if (!spec->auto_mute)
3561 else if (!spec->automute_lines)
3565 ucontrol->value.enumerated.item[0] = val;
3569 static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3570 struct snd_ctl_elem_value *ucontrol)
3572 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3573 struct conexant_spec *spec = codec->spec;
3575 switch (ucontrol->value.enumerated.item[0]) {
3577 if (!spec->auto_mute)
3579 spec->auto_mute = 0;
3582 if (spec->auto_mute && !spec->automute_lines)
3584 spec->auto_mute = 1;
3585 spec->automute_lines = 0;
3588 if (!spec->automute_hp_lo)
3590 if (spec->auto_mute && spec->automute_lines)
3592 spec->auto_mute = 1;
3593 spec->automute_lines = 1;
3598 cx_auto_update_speakers(codec);
3602 static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3604 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3605 .name = "Auto-Mute Mode",
3606 .info = cx_automute_mode_info,
3607 .get = cx_automute_mode_get,
3608 .put = cx_automute_mode_put,
3613 static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3614 struct snd_ctl_elem_info *uinfo)
3616 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3617 struct conexant_spec *spec = codec->spec;
3619 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3622 static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3623 struct snd_ctl_elem_value *ucontrol)
3625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3626 struct conexant_spec *spec = codec->spec;
3628 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3632 /* look for the route the given pin from mux and return the index;
3633 * if do_select is set, actually select the route.
3635 static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3636 hda_nid_t pin, hda_nid_t *srcp,
3637 bool do_select, int depth)
3639 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3642 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3644 case AC_WID_AUD_SEL:
3645 case AC_WID_AUD_MIX:
3651 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3652 for (i = 0; i < nums; i++)
3653 if (conn[i] == pin) {
3655 snd_hda_codec_write(codec, mux, 0,
3656 AC_VERB_SET_CONNECT_SEL, i);
3664 for (i = 0; i < nums; i++) {
3665 int ret = __select_input_connection(codec, conn[i], pin, srcp,
3669 snd_hda_codec_write(codec, mux, 0,
3670 AC_VERB_SET_CONNECT_SEL, i);
3677 static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3680 __select_input_connection(codec, mux, pin, NULL, true, 0);
3683 static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3686 return __select_input_connection(codec, mux, pin, NULL, false, 0);
3689 static int cx_auto_mux_enum_update(struct hda_codec *codec,
3690 const struct hda_input_mux *imux,
3693 struct conexant_spec *spec = codec->spec;
3697 if (!imux->num_items)
3699 if (idx >= imux->num_items)
3700 idx = imux->num_items - 1;
3701 if (spec->cur_mux[0] == idx)
3703 adc = spec->imux_info[idx].adc;
3704 select_input_connection(codec, spec->imux_info[idx].adc,
3705 spec->imux_info[idx].pin);
3706 if (spec->cur_adc && spec->cur_adc != adc) {
3707 /* stream is running, let's swap the current ADC */
3708 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3709 spec->cur_adc = adc;
3710 snd_hda_codec_setup_stream(codec, adc,
3711 spec->cur_adc_stream_tag, 0,
3712 spec->cur_adc_format);
3714 spec->cur_mux[0] = idx;
3718 static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3719 struct snd_ctl_elem_value *ucontrol)
3721 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3722 struct conexant_spec *spec = codec->spec;
3724 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3725 ucontrol->value.enumerated.item[0]);
3728 static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3730 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3731 .name = "Capture Source",
3732 .info = cx_auto_mux_enum_info,
3733 .get = cx_auto_mux_enum_get,
3734 .put = cx_auto_mux_enum_put
3739 static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3741 struct conexant_spec *spec = codec->spec;
3744 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3746 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3750 /* automatic switch internal and external mic */
3751 static void cx_auto_automic(struct hda_codec *codec)
3753 struct conexant_spec *spec = codec->spec;
3755 if (!spec->auto_mic)
3757 if (!select_automic(codec, spec->auto_mic_ext, true))
3758 if (!select_automic(codec, spec->auto_mic_dock, true))
3759 select_automic(codec, spec->auto_mic_int, false);
3762 static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3764 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3765 switch (res >> 26) {
3766 case CONEXANT_HP_EVENT:
3767 cx_auto_hp_automute(codec);
3769 case CONEXANT_LINE_EVENT:
3770 cx_auto_line_automute(codec);
3772 case CONEXANT_MIC_EVENT:
3773 cx_auto_automic(codec);
3774 snd_hda_input_jack_report(codec, nid);
3779 /* check whether the pin config is suitable for auto-mic switching;
3780 * auto-mic is enabled only when one int-mic and one ext- and/or
3781 * one dock-mic exist
3783 static void cx_auto_check_auto_mic(struct hda_codec *codec)
3785 struct conexant_spec *spec = codec->spec;
3786 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3789 for (i = 0; i < ARRAY_SIZE(pset); i++)
3791 for (i = 0; i < spec->private_imux.num_items; i++) {
3792 hda_nid_t pin = spec->imux_info[i].pin;
3793 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3795 attr = snd_hda_get_input_pin_attr(def_conf);
3796 if (attr == INPUT_PIN_ATTR_UNUSED)
3797 return; /* invalid entry */
3798 if (attr > INPUT_PIN_ATTR_NORMAL)
3799 attr = INPUT_PIN_ATTR_NORMAL;
3800 if (attr != INPUT_PIN_ATTR_INT &&
3801 !is_jack_detectable(codec, pin))
3802 return; /* non-detectable pin */
3803 type = get_defcfg_device(def_conf);
3804 if (type != AC_JACK_MIC_IN &&
3805 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3806 return; /* no valid input type */
3807 if (pset[attr] >= 0)
3808 return; /* already occupied */
3811 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3812 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3813 return; /* no input to switch*/
3815 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3816 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3817 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
3820 static void cx_auto_parse_input(struct hda_codec *codec)
3822 struct conexant_spec *spec = codec->spec;
3823 struct auto_pin_cfg *cfg = &spec->autocfg;
3824 struct hda_input_mux *imux;
3827 imux = &spec->private_imux;
3828 for (i = 0; i < cfg->num_inputs; i++) {
3829 for (j = 0; j < spec->num_adc_nids; j++) {
3830 hda_nid_t adc = spec->adc_nids[j];
3831 int idx = get_input_connection(codec, adc,
3832 cfg->inputs[i].pin);
3835 label = hda_get_autocfg_input_label(codec, cfg, i);
3836 spec->imux_info[imux->num_items].index = i;
3837 spec->imux_info[imux->num_items].boost = 0;
3838 spec->imux_info[imux->num_items].adc = adc;
3839 spec->imux_info[imux->num_items].pin =
3841 snd_hda_add_imux_item(imux, label, idx, NULL);
3846 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
3847 cx_auto_check_auto_mic(codec);
3848 if (imux->num_items > 1) {
3849 for (i = 1; i < imux->num_items; i++) {
3850 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
3851 spec->adc_switching = 1;
3858 /* get digital-input audio widget corresponding to the given pin */
3859 static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3861 hda_nid_t nid, end_nid;
3863 end_nid = codec->start_nid + codec->num_nodes;
3864 for (nid = codec->start_nid; nid < end_nid; nid++) {
3865 unsigned int wcaps = get_wcaps(codec, nid);
3866 unsigned int type = get_wcaps_type(wcaps);
3867 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3868 if (get_connection_index(codec, nid, pin) >= 0)
3875 static void cx_auto_parse_digital(struct hda_codec *codec)
3877 struct conexant_spec *spec = codec->spec;
3878 struct auto_pin_cfg *cfg = &spec->autocfg;
3881 if (cfg->dig_outs &&
3882 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3883 spec->multiout.dig_out_nid = nid;
3884 if (cfg->dig_in_pin)
3885 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3888 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3889 static void cx_auto_parse_beep(struct hda_codec *codec)
3891 struct conexant_spec *spec = codec->spec;
3892 hda_nid_t nid, end_nid;
3894 end_nid = codec->start_nid + codec->num_nodes;
3895 for (nid = codec->start_nid; nid < end_nid; nid++)
3896 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3897 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3902 #define cx_auto_parse_beep(codec)
3906 static void cx_auto_parse_eapd(struct hda_codec *codec)
3908 struct conexant_spec *spec = codec->spec;
3909 hda_nid_t nid, end_nid;
3911 end_nid = codec->start_nid + codec->num_nodes;
3912 for (nid = codec->start_nid; nid < end_nid; nid++) {
3913 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3915 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3917 spec->eapds[spec->num_eapds++] = nid;
3918 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3922 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3923 * it's a new chip, where EAPDs are supposed to be associated to
3924 * pins, and we can control EAPD per pin.
3925 * OTOH, if only one or two EAPDs are found, it's an old chip,
3926 * thus it might control over all pins.
3928 spec->pin_eapd_ctrls = spec->num_eapds > 2;
3931 static int cx_auto_parse_auto_config(struct hda_codec *codec)
3933 struct conexant_spec *spec = codec->spec;
3936 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3940 cx_auto_parse_output(codec);
3941 cx_auto_parse_input(codec);
3942 cx_auto_parse_digital(codec);
3943 cx_auto_parse_beep(codec);
3944 cx_auto_parse_eapd(codec);
3948 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3949 hda_nid_t *pins, bool on)
3952 for (i = 0; i < num_pins; i++) {
3953 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3954 snd_hda_codec_write(codec, pins[i], 0,
3955 AC_VERB_SET_EAPD_BTLENABLE,
3960 static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3963 int idx = get_connection_index(codec, pin, src);
3965 snd_hda_codec_write(codec, pin, 0,
3966 AC_VERB_SET_CONNECT_SEL, idx);
3969 static void mute_outputs(struct hda_codec *codec, int num_nids,
3970 const hda_nid_t *nids)
3974 for (i = 0; i < num_nids; i++) {
3975 hda_nid_t nid = nids[i];
3976 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3978 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3982 snd_hda_codec_write(codec, nid, 0,
3983 AC_VERB_SET_AMP_GAIN_MUTE, val);
3987 static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3988 hda_nid_t *pins, unsigned int tag)
3991 for (i = 0; i < num_pins; i++)
3992 snd_hda_codec_write(codec, pins[i], 0,
3993 AC_VERB_SET_UNSOLICITED_ENABLE,
3997 static void cx_auto_init_output(struct hda_codec *codec)
3999 struct conexant_spec *spec = codec->spec;
4000 struct auto_pin_cfg *cfg = &spec->autocfg;
4004 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
4005 for (i = 0; i < cfg->hp_outs; i++) {
4006 unsigned int val = PIN_OUT;
4007 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
4009 val |= AC_PINCTL_HP_EN;
4010 snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
4011 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
4013 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
4014 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
4015 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
4016 for (i = 0; i < spec->dac_info_filled; i++) {
4017 nid = spec->dac_info[i].dac;
4019 nid = spec->multiout.dac_nids[0];
4020 else if (nid & DAC_SLAVE_FLAG)
4021 nid &= ~DAC_SLAVE_FLAG;
4022 select_connection(codec, spec->dac_info[i].pin, nid);
4024 if (spec->auto_mute) {
4025 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
4027 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
4029 if (spec->detect_line) {
4030 enable_unsol_pins(codec, cfg->line_outs,
4032 CONEXANT_LINE_EVENT);
4033 spec->line_present =
4034 detect_jacks(codec, cfg->line_outs,
4035 cfg->line_out_pins);
4038 cx_auto_update_speakers(codec);
4039 /* turn on all EAPDs if no individual EAPD control is available */
4040 if (!spec->pin_eapd_ctrls)
4041 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
4044 static void cx_auto_init_input(struct hda_codec *codec)
4046 struct conexant_spec *spec = codec->spec;
4047 struct auto_pin_cfg *cfg = &spec->autocfg;
4050 for (i = 0; i < spec->num_adc_nids; i++) {
4051 hda_nid_t nid = spec->adc_nids[i];
4052 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
4054 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
4055 val = AMP_IN_MUTE(0);
4057 val = AMP_IN_UNMUTE(0);
4058 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4062 for (i = 0; i < cfg->num_inputs; i++) {
4064 if (cfg->inputs[i].type == AUTO_PIN_MIC)
4068 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4069 AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4072 if (spec->auto_mic) {
4073 if (spec->auto_mic_ext >= 0) {
4074 snd_hda_codec_write(codec,
4075 cfg->inputs[spec->auto_mic_ext].pin, 0,
4076 AC_VERB_SET_UNSOLICITED_ENABLE,
4077 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4079 if (spec->auto_mic_dock >= 0) {
4080 snd_hda_codec_write(codec,
4081 cfg->inputs[spec->auto_mic_dock].pin, 0,
4082 AC_VERB_SET_UNSOLICITED_ENABLE,
4083 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4085 cx_auto_automic(codec);
4087 select_input_connection(codec, spec->imux_info[0].adc,
4088 spec->imux_info[0].pin);
4092 static void cx_auto_init_digital(struct hda_codec *codec)
4094 struct conexant_spec *spec = codec->spec;
4095 struct auto_pin_cfg *cfg = &spec->autocfg;
4097 if (spec->multiout.dig_out_nid)
4098 snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4099 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4100 if (spec->dig_in_nid)
4101 snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4102 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4105 static int cx_auto_init(struct hda_codec *codec)
4107 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4108 cx_auto_init_output(codec);
4109 cx_auto_init_input(codec);
4110 cx_auto_init_digital(codec);
4114 static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
4115 const char *dir, int cidx,
4116 hda_nid_t nid, int hda_dir, int amp_idx)
4118 static char name[32];
4119 static struct snd_kcontrol_new knew[] = {
4120 HDA_CODEC_VOLUME(name, 0, 0, 0),
4121 HDA_CODEC_MUTE(name, 0, 0, 0),
4123 static const char * const sfx[2] = { "Volume", "Switch" };
4126 for (i = 0; i < 2; i++) {
4127 struct snd_kcontrol *kctl;
4128 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
4130 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4131 knew[i].index = cidx;
4132 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4133 kctl = snd_ctl_new1(&knew[i], codec);
4136 err = snd_hda_ctl_add(codec, nid, kctl);
4139 if (!(query_amp_caps(codec, nid, hda_dir) &
4140 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
4146 #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4147 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
4149 #define cx_auto_add_pb_volume(codec, nid, str, idx) \
4150 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4152 static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4153 hda_nid_t pin, const char *name, int idx)
4156 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4157 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4158 if (caps & AC_AMPCAP_NUM_STEPS)
4159 return cx_auto_add_pb_volume(codec, dac, name, idx);
4161 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4162 if (caps & AC_AMPCAP_NUM_STEPS)
4163 return cx_auto_add_pb_volume(codec, pin, name, idx);
4167 static int cx_auto_build_output_controls(struct hda_codec *codec)
4169 struct conexant_spec *spec = codec->spec;
4171 int num_line = 0, num_hp = 0, num_spk = 0;
4172 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
4174 if (spec->dac_info_filled == 1)
4175 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4176 spec->dac_info[0].pin,
4179 for (i = 0; i < spec->dac_info_filled; i++) {
4182 hda_nid_t dac = spec->dac_info[i].dac;
4183 type = spec->dac_info[i].type;
4184 if (type == AUTO_PIN_LINE_OUT)
4185 type = spec->autocfg.line_out_type;
4187 case AUTO_PIN_LINE_OUT:
4189 label = texts[num_line++];
4192 case AUTO_PIN_HP_OUT:
4193 label = "Headphone";
4196 case AUTO_PIN_SPEAKER_OUT:
4201 err = try_add_pb_volume(codec, dac,
4202 spec->dac_info[i].pin,
4208 if (spec->auto_mute) {
4209 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4217 static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4218 const char *label, const char *pfx,
4221 struct conexant_spec *spec = codec->spec;
4224 for (i = 0; i < spec->num_adc_nids; i++) {
4225 hda_nid_t adc_nid = spec->adc_nids[i];
4226 int idx = get_input_connection(codec, adc_nid, nid);
4229 if (spec->single_adc_amp)
4231 return cx_auto_add_volume_idx(codec, label, pfx,
4232 cidx, adc_nid, HDA_INPUT, idx);
4237 static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4238 const char *label, int cidx)
4240 struct conexant_spec *spec = codec->spec;
4244 nid = spec->imux_info[idx].pin;
4245 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4246 return cx_auto_add_volume(codec, label, " Boost", cidx,
4248 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4252 for (i = 0; i < idx; i++) {
4253 if (spec->imux_info[i].boost == mux)
4254 return 0; /* already present */
4257 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
4258 spec->imux_info[idx].boost = mux;
4259 return cx_auto_add_volume(codec, label, " Boost", 0,
4265 static int cx_auto_build_input_controls(struct hda_codec *codec)
4267 struct conexant_spec *spec = codec->spec;
4268 struct hda_input_mux *imux = &spec->private_imux;
4269 const char *prev_label;
4270 int input_conn[HDA_MAX_NUM_INPUTS];
4271 int i, j, err, cidx;
4272 int multi_connection;
4274 if (!imux->num_items)
4277 multi_connection = 0;
4278 for (i = 0; i < imux->num_items; i++) {
4279 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4280 spec->imux_info[i].pin);
4283 input_conn[i] = spec->imux_info[i].adc;
4284 if (!spec->single_adc_amp)
4285 input_conn[i] |= cidx << 8;
4286 if (i > 0 && input_conn[i] != input_conn[0])
4287 multi_connection = 1;
4292 for (i = 0; i < imux->num_items; i++) {
4293 hda_nid_t nid = spec->imux_info[i].pin;
4296 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
4297 spec->imux_info[i].index);
4298 if (label == prev_label)
4304 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4308 if (!multi_connection) {
4311 err = cx_auto_add_capture_volume(codec, nid,
4312 "Capture", "", cidx);
4314 bool dup_found = false;
4315 for (j = 0; j < i; j++) {
4316 if (input_conn[j] == input_conn[i]) {
4323 err = cx_auto_add_capture_volume(codec, nid,
4324 label, " Capture", cidx);
4330 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4331 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4339 static int cx_auto_build_controls(struct hda_codec *codec)
4343 err = cx_auto_build_output_controls(codec);
4346 err = cx_auto_build_input_controls(codec);
4349 return conexant_build_controls(codec);
4352 static int cx_auto_search_adcs(struct hda_codec *codec)
4354 struct conexant_spec *spec = codec->spec;
4355 hda_nid_t nid, end_nid;
4357 end_nid = codec->start_nid + codec->num_nodes;
4358 for (nid = codec->start_nid; nid < end_nid; nid++) {
4359 unsigned int caps = get_wcaps(codec, nid);
4360 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4362 if (caps & AC_WCAP_DIGITAL)
4364 if (snd_BUG_ON(spec->num_adc_nids >=
4365 ARRAY_SIZE(spec->private_adc_nids)))
4367 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4369 spec->adc_nids = spec->private_adc_nids;
4374 static const struct hda_codec_ops cx_auto_patch_ops = {
4375 .build_controls = cx_auto_build_controls,
4376 .build_pcms = conexant_build_pcms,
4377 .init = cx_auto_init,
4378 .free = conexant_free,
4379 .unsol_event = cx_auto_unsol_event,
4380 #ifdef CONFIG_SND_HDA_POWER_SAVE
4381 .suspend = conexant_suspend,
4383 .reboot_notify = snd_hda_shutup_pins,
4394 static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4396 for (; cfg->nid; cfg++)
4397 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4401 static void apply_pin_fixup(struct hda_codec *codec,
4402 const struct snd_pci_quirk *quirk,
4403 const struct cxt_pincfg **table)
4405 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
4407 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4409 apply_pincfg(codec, table[quirk->value]);
4414 CXT_PINCFG_LENOVO_X200,
4415 CXT_PINCFG_LENOVO_TP410,
4418 /* ThinkPad X200 & co with cxt5051 */
4419 static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4420 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4421 { 0x17, 0x21a11000 }, /* dock-mic */
4422 { 0x19, 0x2121103f }, /* dock-HP */
4426 /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
4427 static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = {
4428 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
4429 { 0x1a, 0x21a190f0 }, /* dock-mic */
4430 { 0x1c, 0x212140ff }, /* dock-HP */
4434 static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
4435 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
4436 [CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410,
4439 static const struct snd_pci_quirk cxt5051_fixups[] = {
4440 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4444 static const struct snd_pci_quirk cxt5066_fixups[] = {
4445 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
4446 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
4447 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4448 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
4449 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
4453 /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4454 * can be created (bko#42825)
4456 static void add_cx5051_fake_mutes(struct hda_codec *codec)
4458 static hda_nid_t out_nids[] = {
4463 for (p = out_nids; *p; p++)
4464 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4465 AC_AMPCAP_MIN_MUTE |
4466 query_amp_caps(codec, *p, HDA_OUTPUT));
4469 static int patch_conexant_auto(struct hda_codec *codec)
4471 struct conexant_spec *spec;
4474 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4477 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4481 codec->pin_amp_workaround = 1;
4483 switch (codec->vendor_id) {
4485 spec->single_adc_amp = 1;
4488 add_cx5051_fake_mutes(codec);
4489 apply_pin_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl);
4492 apply_pin_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl);
4496 err = cx_auto_search_adcs(codec);
4499 err = cx_auto_parse_auto_config(codec);
4505 spec->capture_stream = &cx_auto_pcm_analog_capture;
4506 codec->patch_ops = cx_auto_patch_ops;
4508 snd_hda_attach_beep_device(codec, spec->beep_amp);
4515 static const struct hda_codec_preset snd_hda_preset_conexant[] = {
4516 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4517 .patch = patch_cxt5045 },
4518 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4519 .patch = patch_cxt5047 },
4520 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4521 .patch = patch_cxt5051 },
4522 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4523 .patch = patch_cxt5066 },
4524 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4525 .patch = patch_cxt5066 },
4526 { .id = 0x14f15068, .name = "CX20584",
4527 .patch = patch_cxt5066 },
4528 { .id = 0x14f15069, .name = "CX20585",
4529 .patch = patch_cxt5066 },
4530 { .id = 0x14f1506c, .name = "CX20588",
4531 .patch = patch_cxt5066 },
4532 { .id = 0x14f1506e, .name = "CX20590",
4533 .patch = patch_cxt5066 },
4534 { .id = 0x14f15097, .name = "CX20631",
4535 .patch = patch_conexant_auto },
4536 { .id = 0x14f15098, .name = "CX20632",
4537 .patch = patch_conexant_auto },
4538 { .id = 0x14f150a1, .name = "CX20641",
4539 .patch = patch_conexant_auto },
4540 { .id = 0x14f150a2, .name = "CX20642",
4541 .patch = patch_conexant_auto },
4542 { .id = 0x14f150ab, .name = "CX20651",
4543 .patch = patch_conexant_auto },
4544 { .id = 0x14f150ac, .name = "CX20652",
4545 .patch = patch_conexant_auto },
4546 { .id = 0x14f150b8, .name = "CX20664",
4547 .patch = patch_conexant_auto },
4548 { .id = 0x14f150b9, .name = "CX20665",
4549 .patch = patch_conexant_auto },
4553 MODULE_ALIAS("snd-hda-codec-id:14f15045");
4554 MODULE_ALIAS("snd-hda-codec-id:14f15047");
4555 MODULE_ALIAS("snd-hda-codec-id:14f15051");
4556 MODULE_ALIAS("snd-hda-codec-id:14f15066");
4557 MODULE_ALIAS("snd-hda-codec-id:14f15067");
4558 MODULE_ALIAS("snd-hda-codec-id:14f15068");
4559 MODULE_ALIAS("snd-hda-codec-id:14f15069");
4560 MODULE_ALIAS("snd-hda-codec-id:14f1506c");
4561 MODULE_ALIAS("snd-hda-codec-id:14f1506e");
4562 MODULE_ALIAS("snd-hda-codec-id:14f15097");
4563 MODULE_ALIAS("snd-hda-codec-id:14f15098");
4564 MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4565 MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4566 MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4567 MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4568 MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4569 MODULE_ALIAS("snd-hda-codec-id:14f150b9");
4571 MODULE_LICENSE("GPL");
4572 MODULE_DESCRIPTION("Conexant HD-audio codec");
4574 static struct hda_codec_preset_list conexant_list = {
4575 .preset = snd_hda_preset_conexant,
4576 .owner = THIS_MODULE,
4579 static int __init patch_conexant_init(void)
4581 return snd_hda_add_codec_preset(&conexant_list);
4584 static void __exit patch_conexant_exit(void)
4586 snd_hda_delete_codec_preset(&conexant_list);
4589 module_init(patch_conexant_init)
4590 module_exit(patch_conexant_exit)