2 * HD audio interface patch for Conexant HDA audio codec
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
27 #include <linux/module.h>
28 #include <sound/core.h>
29 #include <sound/jack.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
35 #define CXT_PIN_DIR_IN 0x00
36 #define CXT_PIN_DIR_OUT 0x01
37 #define CXT_PIN_DIR_INOUT 0x02
38 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
39 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
41 #define CONEXANT_HP_EVENT 0x37
42 #define CONEXANT_MIC_EVENT 0x38
43 #define CONEXANT_LINE_EVENT 0x39
45 /* Conexant 5051 specific */
47 #define CXT5051_SPDIF_OUT 0x12
48 #define CXT5051_PORTB_EVENT 0x38
49 #define CXT5051_PORTC_EVENT 0x39
51 #define AUTO_MIC_PORTB (1 << 1)
52 #define AUTO_MIC_PORTC (1 << 2)
61 hda_nid_t pin; /* input pin NID */
62 hda_nid_t adc; /* connected ADC NID */
63 hda_nid_t boost; /* optional boost volume NID */
64 int index; /* corresponding to autocfg.input */
67 struct conexant_spec {
69 const struct snd_kcontrol_new *mixers[5];
71 hda_nid_t vmaster_nid;
73 const struct hda_verb *init_verbs[5]; /* initialization verbs
77 unsigned int num_init_verbs;
80 struct hda_multi_out multiout; /* playback set-up
81 * max_channels, dacs must be set
82 * dig_out_nid and hp_nid are optional
84 unsigned int cur_eapd;
85 unsigned int hp_present;
86 unsigned int line_present;
87 unsigned int auto_mic;
88 int auto_mic_ext; /* imux_pins[] index for ext mic */
89 int auto_mic_dock; /* imux_pins[] index for dock mic */
90 int auto_mic_int; /* imux_pins[] index for int mic */
91 unsigned int need_dac_fix;
92 hda_nid_t slave_dig_outs[2];
95 unsigned int num_adc_nids;
96 const hda_nid_t *adc_nids;
97 hda_nid_t dig_in_nid; /* digital-in NID; optional */
99 unsigned int cur_adc_idx;
101 unsigned int cur_adc_stream_tag;
102 unsigned int cur_adc_format;
104 const struct hda_pcm_stream *capture_stream;
107 const struct hda_input_mux *input_mux;
108 const hda_nid_t *capsrc_nids;
109 unsigned int cur_mux[3];
112 const struct hda_channel_mode *channel_mode;
113 int num_channel_mode;
115 /* PCM information */
116 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
118 unsigned int spdif_route;
120 /* dynamic controls, init_verbs and input_mux */
121 struct auto_pin_cfg autocfg;
122 struct hda_input_mux private_imux;
123 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
124 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
125 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
126 struct pin_dac_pair dac_info[8];
129 unsigned int port_d_mode;
130 unsigned int auto_mute:1; /* used in auto-parser */
131 unsigned int detect_line:1; /* Line-out detection enabled */
132 unsigned int automute_lines:1; /* automute line-out as well */
133 unsigned int automute_hp_lo:1; /* both HP and LO available */
134 unsigned int dell_automute:1;
135 unsigned int dell_vostro:1;
136 unsigned int ideapad:1;
137 unsigned int thinkpad:1;
138 unsigned int hp_laptop:1;
140 unsigned int pin_eapd_ctrls:1;
141 unsigned int single_adc_amp:1;
142 unsigned int fixup_stereo_dmic:1;
144 unsigned int adc_switching:1;
146 unsigned int ext_mic_present;
147 unsigned int recording;
148 void (*capture_prepare)(struct hda_codec *codec);
149 void (*capture_cleanup)(struct hda_codec *codec);
151 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
152 * through the microphone jack.
153 * When the user enables this through a mixer switch, both internal and
154 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
155 * we also allow the bias to be configured through a separate mixer
157 unsigned int dc_enable;
158 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
159 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
161 unsigned int beep_amp;
163 /* extra EAPD pins */
164 unsigned int num_eapds;
168 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
169 struct hda_codec *codec,
170 struct snd_pcm_substream *substream)
172 struct conexant_spec *spec = codec->spec;
173 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
177 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
178 struct hda_codec *codec,
179 unsigned int stream_tag,
181 struct snd_pcm_substream *substream)
183 struct conexant_spec *spec = codec->spec;
184 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
189 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
190 struct hda_codec *codec,
191 struct snd_pcm_substream *substream)
193 struct conexant_spec *spec = codec->spec;
194 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
200 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
201 struct hda_codec *codec,
202 struct snd_pcm_substream *substream)
204 struct conexant_spec *spec = codec->spec;
205 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
208 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
209 struct hda_codec *codec,
210 struct snd_pcm_substream *substream)
212 struct conexant_spec *spec = codec->spec;
213 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
216 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
217 struct hda_codec *codec,
218 unsigned int stream_tag,
220 struct snd_pcm_substream *substream)
222 struct conexant_spec *spec = codec->spec;
223 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
231 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
232 struct hda_codec *codec,
233 unsigned int stream_tag,
235 struct snd_pcm_substream *substream)
237 struct conexant_spec *spec = codec->spec;
238 if (spec->capture_prepare)
239 spec->capture_prepare(codec);
240 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
241 stream_tag, 0, format);
245 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
246 struct hda_codec *codec,
247 struct snd_pcm_substream *substream)
249 struct conexant_spec *spec = codec->spec;
250 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
251 if (spec->capture_cleanup)
252 spec->capture_cleanup(codec);
258 static const struct hda_pcm_stream conexant_pcm_analog_playback = {
262 .nid = 0, /* fill later */
264 .open = conexant_playback_pcm_open,
265 .prepare = conexant_playback_pcm_prepare,
266 .cleanup = conexant_playback_pcm_cleanup
270 static const struct hda_pcm_stream conexant_pcm_analog_capture = {
274 .nid = 0, /* fill later */
276 .prepare = conexant_capture_pcm_prepare,
277 .cleanup = conexant_capture_pcm_cleanup
282 static const struct hda_pcm_stream conexant_pcm_digital_playback = {
286 .nid = 0, /* fill later */
288 .open = conexant_dig_playback_pcm_open,
289 .close = conexant_dig_playback_pcm_close,
290 .prepare = conexant_dig_playback_pcm_prepare
294 static const struct hda_pcm_stream conexant_pcm_digital_capture = {
298 /* NID is set in alc_build_pcms */
301 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
302 struct hda_codec *codec,
303 unsigned int stream_tag,
305 struct snd_pcm_substream *substream)
307 struct conexant_spec *spec = codec->spec;
308 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
309 spec->cur_adc_stream_tag = stream_tag;
310 spec->cur_adc_format = format;
311 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
315 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
316 struct hda_codec *codec,
317 struct snd_pcm_substream *substream)
319 struct conexant_spec *spec = codec->spec;
320 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
325 static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
329 .nid = 0, /* fill later */
331 .prepare = cx5051_capture_pcm_prepare,
332 .cleanup = cx5051_capture_pcm_cleanup
336 static int conexant_build_pcms(struct hda_codec *codec)
338 struct conexant_spec *spec = codec->spec;
339 struct hda_pcm *info = spec->pcm_rec;
342 codec->pcm_info = info;
344 info->name = "CONEXANT Analog";
345 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
346 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
347 spec->multiout.max_channels;
348 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
349 spec->multiout.dac_nids[0];
350 if (spec->capture_stream)
351 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
353 if (codec->vendor_id == 0x14f15051)
354 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
355 cx5051_pcm_analog_capture;
357 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
358 conexant_pcm_analog_capture;
359 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
363 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
365 if (spec->multiout.dig_out_nid) {
368 info->name = "Conexant Digital";
369 info->pcm_type = HDA_PCM_TYPE_SPDIF;
370 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
371 conexant_pcm_digital_playback;
372 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
373 spec->multiout.dig_out_nid;
374 if (spec->dig_in_nid) {
375 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
376 conexant_pcm_digital_capture;
377 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
380 if (spec->slave_dig_outs[0])
381 codec->slave_dig_outs = spec->slave_dig_outs;
387 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
388 struct snd_ctl_elem_info *uinfo)
390 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
391 struct conexant_spec *spec = codec->spec;
393 return snd_hda_input_mux_info(spec->input_mux, uinfo);
396 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
397 struct snd_ctl_elem_value *ucontrol)
399 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
400 struct conexant_spec *spec = codec->spec;
401 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
403 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
407 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
408 struct snd_ctl_elem_value *ucontrol)
410 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
411 struct conexant_spec *spec = codec->spec;
412 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
414 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
415 spec->capsrc_nids[adc_idx],
416 &spec->cur_mux[adc_idx]);
419 static int conexant_init_jacks(struct hda_codec *codec)
421 #ifdef CONFIG_SND_HDA_INPUT_JACK
422 struct conexant_spec *spec = codec->spec;
425 for (i = 0; i < spec->num_init_verbs; i++) {
426 const struct hda_verb *hv;
428 hv = spec->init_verbs[i];
431 switch (hv->param ^ AC_USRSP_EN) {
432 case CONEXANT_HP_EVENT:
433 err = snd_hda_input_jack_add(codec, hv->nid,
434 SND_JACK_HEADPHONE, NULL);
435 snd_hda_input_jack_report(codec, hv->nid);
437 case CXT5051_PORTC_EVENT:
438 case CONEXANT_MIC_EVENT:
439 err = snd_hda_input_jack_add(codec, hv->nid,
440 SND_JACK_MICROPHONE, NULL);
441 snd_hda_input_jack_report(codec, hv->nid);
449 #endif /* CONFIG_SND_HDA_INPUT_JACK */
453 static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
454 unsigned int power_state)
456 if (power_state == AC_PWRST_D3)
458 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
460 /* partial workaround for "azx_get_response timeout" */
461 if (power_state == AC_PWRST_D0)
463 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
466 static int conexant_init(struct hda_codec *codec)
468 struct conexant_spec *spec = codec->spec;
471 for (i = 0; i < spec->num_init_verbs; i++)
472 snd_hda_sequence_write(codec, spec->init_verbs[i]);
476 static void conexant_free(struct hda_codec *codec)
478 snd_hda_input_jack_free(codec);
479 snd_hda_detach_beep_device(codec);
483 static const struct snd_kcontrol_new cxt_capture_mixers[] = {
485 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
486 .name = "Capture Source",
487 .info = conexant_mux_enum_info,
488 .get = conexant_mux_enum_get,
489 .put = conexant_mux_enum_put
494 #ifdef CONFIG_SND_HDA_INPUT_BEEP
495 /* additional beep mixers; the actual parameters are overwritten at build */
496 static const struct snd_kcontrol_new cxt_beep_mixer[] = {
497 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
498 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
503 static const char * const slave_vols[] = {
504 "Headphone Playback Volume",
505 "Speaker Playback Volume",
506 "Front Playback Volume",
507 "Surround Playback Volume",
508 "CLFE Playback Volume",
512 static const char * const slave_sws[] = {
513 "Headphone Playback Switch",
514 "Speaker Playback Switch",
515 "Front Playback Switch",
516 "Surround Playback Switch",
517 "CLFE Playback Switch",
521 static int conexant_build_controls(struct hda_codec *codec)
523 struct conexant_spec *spec = codec->spec;
527 for (i = 0; i < spec->num_mixers; i++) {
528 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
532 if (spec->multiout.dig_out_nid) {
533 err = snd_hda_create_spdif_out_ctls(codec,
534 spec->multiout.dig_out_nid,
535 spec->multiout.dig_out_nid);
538 err = snd_hda_create_spdif_share_sw(codec,
542 spec->multiout.share_spdif = 1;
544 if (spec->dig_in_nid) {
545 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
550 /* if we have no master control, let's create it */
551 if (spec->vmaster_nid &&
552 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
553 unsigned int vmaster_tlv[4];
554 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
555 HDA_OUTPUT, vmaster_tlv);
556 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
557 vmaster_tlv, slave_vols);
561 if (spec->vmaster_nid &&
562 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
563 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
569 if (spec->input_mux) {
570 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
575 #ifdef CONFIG_SND_HDA_INPUT_BEEP
576 /* create beep controls if needed */
577 if (spec->beep_amp) {
578 const struct snd_kcontrol_new *knew;
579 for (knew = cxt_beep_mixer; knew->name; knew++) {
580 struct snd_kcontrol *kctl;
581 kctl = snd_ctl_new1(knew, codec);
584 kctl->private_value = spec->beep_amp;
585 err = snd_hda_ctl_add(codec, 0, kctl);
595 static const struct hda_codec_ops conexant_patch_ops = {
596 .build_controls = conexant_build_controls,
597 .build_pcms = conexant_build_pcms,
598 .init = conexant_init,
599 .free = conexant_free,
600 .set_power_state = conexant_set_power,
603 #ifdef CONFIG_SND_HDA_INPUT_BEEP
604 #define set_beep_amp(spec, nid, idx, dir) \
605 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
607 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
610 static int patch_conexant_auto(struct hda_codec *codec);
613 * the private value = nid | (invert << 8)
616 #define cxt_eapd_info snd_ctl_boolean_mono_info
618 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
619 struct snd_ctl_elem_value *ucontrol)
621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
622 struct conexant_spec *spec = codec->spec;
623 int invert = (kcontrol->private_value >> 8) & 1;
625 ucontrol->value.integer.value[0] = !spec->cur_eapd;
627 ucontrol->value.integer.value[0] = spec->cur_eapd;
632 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_value *ucontrol)
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct conexant_spec *spec = codec->spec;
637 int invert = (kcontrol->private_value >> 8) & 1;
638 hda_nid_t nid = kcontrol->private_value & 0xff;
641 eapd = !!ucontrol->value.integer.value[0];
644 if (eapd == spec->cur_eapd)
647 spec->cur_eapd = eapd;
648 snd_hda_codec_write_cache(codec, nid,
649 0, AC_VERB_SET_EAPD_BTLENABLE,
654 /* controls for test mode */
655 #ifdef CONFIG_SND_DEBUG
657 #define CXT_EAPD_SWITCH(xname, nid, mask) \
658 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
659 .info = cxt_eapd_info, \
660 .get = cxt_eapd_get, \
661 .put = cxt_eapd_put, \
662 .private_value = nid | (mask<<16) }
666 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_info *uinfo)
669 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670 struct conexant_spec *spec = codec->spec;
671 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
672 spec->num_channel_mode);
675 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
676 struct snd_ctl_elem_value *ucontrol)
678 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
679 struct conexant_spec *spec = codec->spec;
680 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
681 spec->num_channel_mode,
682 spec->multiout.max_channels);
685 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
686 struct snd_ctl_elem_value *ucontrol)
688 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
689 struct conexant_spec *spec = codec->spec;
690 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
691 spec->num_channel_mode,
692 &spec->multiout.max_channels);
693 if (err >= 0 && spec->need_dac_fix)
694 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
698 #define CXT_PIN_MODE(xname, nid, dir) \
699 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
700 .info = conexant_ch_mode_info, \
701 .get = conexant_ch_mode_get, \
702 .put = conexant_ch_mode_put, \
703 .private_value = nid | (dir<<16) }
705 #endif /* CONFIG_SND_DEBUG */
707 /* Conexant 5045 specific */
709 static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
710 static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
711 static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
712 #define CXT5045_SPDIF_OUT 0x18
714 static const struct hda_channel_mode cxt5045_modes[1] = {
718 static const struct hda_input_mux cxt5045_capture_source = {
726 static const struct hda_input_mux cxt5045_capture_source_benq = {
737 static const struct hda_input_mux cxt5045_capture_source_hp530 = {
745 /* turn on/off EAPD (+ mute HP) as a master switch */
746 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
747 struct snd_ctl_elem_value *ucontrol)
749 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
750 struct conexant_spec *spec = codec->spec;
753 if (!cxt_eapd_put(kcontrol, ucontrol))
756 /* toggle internal speakers mute depending of presence of
759 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
760 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
763 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
764 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
769 /* bind volumes of both NID 0x10 and 0x11 */
770 static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
771 .ops = &snd_hda_bind_vol,
773 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
774 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
779 /* toggle input of built-in and mic jack appropriately */
780 static void cxt5045_hp_automic(struct hda_codec *codec)
782 static const struct hda_verb mic_jack_on[] = {
783 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
784 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
787 static const struct hda_verb mic_jack_off[] = {
788 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
789 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
792 unsigned int present;
794 present = snd_hda_jack_detect(codec, 0x12);
796 snd_hda_sequence_write(codec, mic_jack_on);
798 snd_hda_sequence_write(codec, mic_jack_off);
802 /* mute internal speaker if HP is plugged */
803 static void cxt5045_hp_automute(struct hda_codec *codec)
805 struct conexant_spec *spec = codec->spec;
808 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
810 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
811 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
815 /* unsolicited event for HP jack sensing */
816 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
821 case CONEXANT_HP_EVENT:
822 cxt5045_hp_automute(codec);
824 case CONEXANT_MIC_EVENT:
825 cxt5045_hp_automic(codec);
831 static const struct snd_kcontrol_new cxt5045_mixers[] = {
832 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
833 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
834 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
835 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
836 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
837 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
838 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
839 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
840 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
841 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
842 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
844 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
845 .name = "Master Playback Switch",
846 .info = cxt_eapd_info,
848 .put = cxt5045_hp_master_sw_put,
849 .private_value = 0x10,
855 static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
856 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
857 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
858 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
859 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
861 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
862 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
863 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
864 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
866 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
867 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
872 static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
873 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
874 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
875 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
876 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
877 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
878 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
879 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
880 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
881 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
882 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
883 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
885 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
886 .name = "Master Playback Switch",
887 .info = cxt_eapd_info,
889 .put = cxt5045_hp_master_sw_put,
890 .private_value = 0x10,
896 static const struct hda_verb cxt5045_init_verbs[] = {
898 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
899 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
901 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
902 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
903 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
904 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
905 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
906 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
907 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
908 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
909 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
910 /* Record selector: Internal mic */
911 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
912 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
913 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
914 /* SPDIF route: PCM */
915 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
916 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
918 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
922 static const struct hda_verb cxt5045_benq_init_verbs[] = {
923 /* Internal Mic, Mic */
924 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
925 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
926 /* Line In,HP, Amp */
927 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
928 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
929 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
930 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
931 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
932 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
933 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
934 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
935 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
936 /* Record selector: Internal mic */
937 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
938 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
939 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
940 /* SPDIF route: PCM */
941 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
942 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
944 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
948 static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
949 /* pin sensing on HP jack */
950 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
954 static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
955 /* pin sensing on HP jack */
956 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
960 #ifdef CONFIG_SND_DEBUG
961 /* Test configuration for debugging, modelled after the ALC260 test
964 static const struct hda_input_mux cxt5045_test_capture_source = {
969 { "LINE1 pin", 0x2 },
970 { "HP-OUT pin", 0x3 },
975 static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
977 /* Output controls */
978 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
979 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
980 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
981 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
982 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
983 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
985 /* Modes for retasking pin widgets */
986 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
987 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
989 /* EAPD Switch Control */
990 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
992 /* Loopback mixer controls */
994 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
995 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
996 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
997 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
998 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
999 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1000 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1001 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1002 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1003 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
1005 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1006 .name = "Input Source",
1007 .info = conexant_mux_enum_info,
1008 .get = conexant_mux_enum_get,
1009 .put = conexant_mux_enum_put,
1011 /* Audio input controls */
1012 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1013 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1014 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1015 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1016 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1017 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1018 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1019 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1020 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1021 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1025 static const struct hda_verb cxt5045_test_init_verbs[] = {
1026 /* Set connections */
1027 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1028 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1029 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1030 /* Enable retasking pins as output, initially without power amp */
1031 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1032 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1034 /* Disable digital (SPDIF) pins initially, but users can enable
1035 * them via a mixer switch. In the case of SPDIF-out, this initverb
1036 * payload also sets the generation to 0, output to be in "consumer"
1037 * PCM format, copyright asserted, no pre-emphasis and no validity
1040 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1041 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1043 /* Start with output sum widgets muted and their output gains at min */
1044 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1045 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1047 /* Unmute retasking pin widget output buffers since the default
1048 * state appears to be output. As the pin mode is changed by the
1049 * user the pin mode control will take care of enabling the pin's
1050 * input/output buffers as needed.
1052 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1053 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1055 /* Mute capture amp left and right */
1056 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1058 /* Set ADC connection select to match default mixer setting (mic1
1061 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1062 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1064 /* Mute all inputs to mixer widget (even unconnected ones) */
1065 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1066 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1067 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1068 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1069 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1076 /* initialize jack-sensing, too */
1077 static int cxt5045_init(struct hda_codec *codec)
1079 conexant_init(codec);
1080 cxt5045_hp_automute(codec);
1086 CXT5045_LAPTOP_HPSENSE,
1087 CXT5045_LAPTOP_MICSENSE,
1088 CXT5045_LAPTOP_HPMICSENSE,
1090 CXT5045_LAPTOP_HP530,
1091 #ifdef CONFIG_SND_DEBUG
1098 static const char * const cxt5045_models[CXT5045_MODELS] = {
1099 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1100 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1101 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1102 [CXT5045_BENQ] = "benq",
1103 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1104 #ifdef CONFIG_SND_DEBUG
1105 [CXT5045_TEST] = "test",
1107 [CXT5045_AUTO] = "auto",
1110 static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1111 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1112 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1113 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1114 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1115 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1116 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1117 CXT5045_LAPTOP_HPMICSENSE),
1118 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1119 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1120 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1121 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1122 CXT5045_LAPTOP_HPMICSENSE),
1123 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1127 static int patch_cxt5045(struct hda_codec *codec)
1129 struct conexant_spec *spec;
1132 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1135 if (board_config < 0)
1136 board_config = CXT5045_AUTO; /* model=auto as default */
1137 if (board_config == CXT5045_AUTO)
1138 return patch_conexant_auto(codec);
1140 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1144 codec->pin_amp_workaround = 1;
1146 spec->multiout.max_channels = 2;
1147 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1148 spec->multiout.dac_nids = cxt5045_dac_nids;
1149 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1150 spec->num_adc_nids = 1;
1151 spec->adc_nids = cxt5045_adc_nids;
1152 spec->capsrc_nids = cxt5045_capsrc_nids;
1153 spec->input_mux = &cxt5045_capture_source;
1154 spec->num_mixers = 1;
1155 spec->mixers[0] = cxt5045_mixers;
1156 spec->num_init_verbs = 1;
1157 spec->init_verbs[0] = cxt5045_init_verbs;
1158 spec->spdif_route = 0;
1159 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1160 spec->channel_mode = cxt5045_modes;
1162 set_beep_amp(spec, 0x16, 0, 1);
1164 codec->patch_ops = conexant_patch_ops;
1166 switch (board_config) {
1167 case CXT5045_LAPTOP_HPSENSE:
1168 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1169 spec->input_mux = &cxt5045_capture_source;
1170 spec->num_init_verbs = 2;
1171 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1172 spec->mixers[0] = cxt5045_mixers;
1173 codec->patch_ops.init = cxt5045_init;
1175 case CXT5045_LAPTOP_MICSENSE:
1176 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1177 spec->input_mux = &cxt5045_capture_source;
1178 spec->num_init_verbs = 2;
1179 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1180 spec->mixers[0] = cxt5045_mixers;
1181 codec->patch_ops.init = cxt5045_init;
1184 case CXT5045_LAPTOP_HPMICSENSE:
1185 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1186 spec->input_mux = &cxt5045_capture_source;
1187 spec->num_init_verbs = 3;
1188 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1189 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1190 spec->mixers[0] = cxt5045_mixers;
1191 codec->patch_ops.init = cxt5045_init;
1194 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1195 spec->input_mux = &cxt5045_capture_source_benq;
1196 spec->num_init_verbs = 1;
1197 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1198 spec->mixers[0] = cxt5045_mixers;
1199 spec->mixers[1] = cxt5045_benq_mixers;
1200 spec->num_mixers = 2;
1201 codec->patch_ops.init = cxt5045_init;
1203 case CXT5045_LAPTOP_HP530:
1204 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1205 spec->input_mux = &cxt5045_capture_source_hp530;
1206 spec->num_init_verbs = 2;
1207 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1208 spec->mixers[0] = cxt5045_mixers_hp530;
1209 codec->patch_ops.init = cxt5045_init;
1211 #ifdef CONFIG_SND_DEBUG
1213 spec->input_mux = &cxt5045_test_capture_source;
1214 spec->mixers[0] = cxt5045_test_mixer;
1215 spec->init_verbs[0] = cxt5045_test_init_verbs;
1221 switch (codec->subsystem_id >> 16) {
1226 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1227 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1228 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1230 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1231 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1232 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1233 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1234 (1 << AC_AMPCAP_MUTE_SHIFT));
1239 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
1245 /* Conexant 5047 specific */
1246 #define CXT5047_SPDIF_OUT 0x11
1248 static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1249 static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1250 static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1252 static const struct hda_channel_mode cxt5047_modes[1] = {
1256 static const struct hda_input_mux cxt5047_toshiba_capture_source = {
1264 /* turn on/off EAPD (+ mute HP) as a master switch */
1265 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1266 struct snd_ctl_elem_value *ucontrol)
1268 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1269 struct conexant_spec *spec = codec->spec;
1272 if (!cxt_eapd_put(kcontrol, ucontrol))
1275 /* toggle internal speakers mute depending of presence of
1276 * the headphone jack
1278 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1279 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1280 * pin widgets unlike other codecs. In this case, we need to
1281 * set index 0x01 for the volume from the mixer amp 0x19.
1283 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1284 HDA_AMP_MUTE, bits);
1285 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1286 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1287 HDA_AMP_MUTE, bits);
1291 /* mute internal speaker if HP is plugged */
1292 static void cxt5047_hp_automute(struct hda_codec *codec)
1294 struct conexant_spec *spec = codec->spec;
1297 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1299 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1300 /* See the note in cxt5047_hp_master_sw_put */
1301 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1302 HDA_AMP_MUTE, bits);
1305 /* toggle input of built-in and mic jack appropriately */
1306 static void cxt5047_hp_automic(struct hda_codec *codec)
1308 static const struct hda_verb mic_jack_on[] = {
1309 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1310 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1313 static const struct hda_verb mic_jack_off[] = {
1314 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1315 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1318 unsigned int present;
1320 present = snd_hda_jack_detect(codec, 0x15);
1322 snd_hda_sequence_write(codec, mic_jack_on);
1324 snd_hda_sequence_write(codec, mic_jack_off);
1327 /* unsolicited event for HP jack sensing */
1328 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1331 switch (res >> 26) {
1332 case CONEXANT_HP_EVENT:
1333 cxt5047_hp_automute(codec);
1335 case CONEXANT_MIC_EVENT:
1336 cxt5047_hp_automic(codec);
1341 static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1342 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1343 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1344 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1345 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1346 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1347 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1348 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1350 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1351 .name = "Master Playback Switch",
1352 .info = cxt_eapd_info,
1353 .get = cxt_eapd_get,
1354 .put = cxt5047_hp_master_sw_put,
1355 .private_value = 0x13,
1361 static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1362 /* See the note in cxt5047_hp_master_sw_put */
1363 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1364 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1368 static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1369 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1373 static const struct hda_verb cxt5047_init_verbs[] = {
1374 /* Line in, Mic, Built-in Mic */
1375 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1376 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1377 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1379 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1380 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1381 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1382 /* Record selector: Mic */
1383 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1384 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1385 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1386 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1387 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1388 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1389 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1390 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1391 /* SPDIF route: PCM */
1392 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1393 /* Enable unsolicited events */
1394 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1395 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1399 /* configuration for Toshiba Laptops */
1400 static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
1401 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1405 /* Test configuration for debugging, modelled after the ALC260 test
1408 #ifdef CONFIG_SND_DEBUG
1409 static const struct hda_input_mux cxt5047_test_capture_source = {
1412 { "LINE1 pin", 0x0 },
1413 { "MIC1 pin", 0x1 },
1414 { "MIC2 pin", 0x2 },
1419 static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1421 /* Output only controls */
1422 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1423 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1424 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1425 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1426 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1427 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1428 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1429 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1431 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1432 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1433 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1435 /* Modes for retasking pin widgets */
1436 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1437 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1439 /* EAPD Switch Control */
1440 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1442 /* Loopback mixer controls */
1443 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1444 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1445 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1446 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1447 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1448 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1449 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1450 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1452 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1453 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1454 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1455 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1456 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1457 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1458 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1459 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1462 .name = "Input Source",
1463 .info = conexant_mux_enum_info,
1464 .get = conexant_mux_enum_get,
1465 .put = conexant_mux_enum_put,
1467 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1472 static const struct hda_verb cxt5047_test_init_verbs[] = {
1473 /* Enable retasking pins as output, initially without power amp */
1474 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1475 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1476 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1478 /* Disable digital (SPDIF) pins initially, but users can enable
1479 * them via a mixer switch. In the case of SPDIF-out, this initverb
1480 * payload also sets the generation to 0, output to be in "consumer"
1481 * PCM format, copyright asserted, no pre-emphasis and no validity
1484 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1486 /* Ensure mic1, mic2, line1 pin widgets take input from the
1487 * OUT1 sum bus when acting as an output.
1489 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1490 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1492 /* Start with output sum widgets muted and their output gains at min */
1493 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1494 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1496 /* Unmute retasking pin widget output buffers since the default
1497 * state appears to be output. As the pin mode is changed by the
1498 * user the pin mode control will take care of enabling the pin's
1499 * input/output buffers as needed.
1501 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1502 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1503 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1505 /* Mute capture amp left and right */
1506 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1508 /* Set ADC connection select to match default mixer setting (mic1
1511 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1513 /* Mute all inputs to mixer widget (even unconnected ones) */
1514 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1515 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1516 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1517 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1518 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1519 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1520 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1521 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1528 /* initialize jack-sensing, too */
1529 static int cxt5047_hp_init(struct hda_codec *codec)
1531 conexant_init(codec);
1532 cxt5047_hp_automute(codec);
1538 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1539 CXT5047_LAPTOP_HP, /* Some HP laptops */
1540 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1541 #ifdef CONFIG_SND_DEBUG
1548 static const char * const cxt5047_models[CXT5047_MODELS] = {
1549 [CXT5047_LAPTOP] = "laptop",
1550 [CXT5047_LAPTOP_HP] = "laptop-hp",
1551 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1552 #ifdef CONFIG_SND_DEBUG
1553 [CXT5047_TEST] = "test",
1555 [CXT5047_AUTO] = "auto",
1558 static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1559 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1560 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1562 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1566 static int patch_cxt5047(struct hda_codec *codec)
1568 struct conexant_spec *spec;
1571 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1574 if (board_config < 0)
1575 board_config = CXT5047_AUTO; /* model=auto as default */
1576 if (board_config == CXT5047_AUTO)
1577 return patch_conexant_auto(codec);
1579 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1583 codec->pin_amp_workaround = 1;
1585 spec->multiout.max_channels = 2;
1586 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1587 spec->multiout.dac_nids = cxt5047_dac_nids;
1588 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1589 spec->num_adc_nids = 1;
1590 spec->adc_nids = cxt5047_adc_nids;
1591 spec->capsrc_nids = cxt5047_capsrc_nids;
1592 spec->num_mixers = 1;
1593 spec->mixers[0] = cxt5047_base_mixers;
1594 spec->num_init_verbs = 1;
1595 spec->init_verbs[0] = cxt5047_init_verbs;
1596 spec->spdif_route = 0;
1597 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1598 spec->channel_mode = cxt5047_modes,
1600 codec->patch_ops = conexant_patch_ops;
1602 switch (board_config) {
1603 case CXT5047_LAPTOP:
1604 spec->num_mixers = 2;
1605 spec->mixers[1] = cxt5047_hp_spk_mixers;
1606 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1608 case CXT5047_LAPTOP_HP:
1609 spec->num_mixers = 2;
1610 spec->mixers[1] = cxt5047_hp_only_mixers;
1611 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1612 codec->patch_ops.init = cxt5047_hp_init;
1614 case CXT5047_LAPTOP_EAPD:
1615 spec->input_mux = &cxt5047_toshiba_capture_source;
1616 spec->num_mixers = 2;
1617 spec->mixers[1] = cxt5047_hp_spk_mixers;
1618 spec->num_init_verbs = 2;
1619 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1620 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1622 #ifdef CONFIG_SND_DEBUG
1624 spec->input_mux = &cxt5047_test_capture_source;
1625 spec->mixers[0] = cxt5047_test_mixer;
1626 spec->init_verbs[0] = cxt5047_test_init_verbs;
1627 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1630 spec->vmaster_nid = 0x13;
1632 switch (codec->subsystem_id >> 16) {
1634 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1635 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1636 * with 0 dB offset 0x17)
1638 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1639 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1640 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1641 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1642 (1 << AC_AMPCAP_MUTE_SHIFT));
1649 /* Conexant 5051 specific */
1650 static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1651 static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1653 static const struct hda_channel_mode cxt5051_modes[1] = {
1657 static void cxt5051_update_speaker(struct hda_codec *codec)
1659 struct conexant_spec *spec = codec->spec;
1660 unsigned int pinctl;
1662 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1663 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1666 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1667 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1669 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1671 snd_hda_codec_write(codec, 0x1b, 0,
1672 AC_VERB_SET_PIN_WIDGET_CONTROL,
1676 /* turn on/off EAPD (+ mute HP) as a master switch */
1677 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1678 struct snd_ctl_elem_value *ucontrol)
1680 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1682 if (!cxt_eapd_put(kcontrol, ucontrol))
1684 cxt5051_update_speaker(codec);
1688 /* toggle input of built-in and mic jack appropriately */
1689 static void cxt5051_portb_automic(struct hda_codec *codec)
1691 struct conexant_spec *spec = codec->spec;
1692 unsigned int present;
1694 if (!(spec->auto_mic & AUTO_MIC_PORTB))
1696 present = snd_hda_jack_detect(codec, 0x17);
1697 snd_hda_codec_write(codec, 0x14, 0,
1698 AC_VERB_SET_CONNECT_SEL,
1699 present ? 0x01 : 0x00);
1702 /* switch the current ADC according to the jack state */
1703 static void cxt5051_portc_automic(struct hda_codec *codec)
1705 struct conexant_spec *spec = codec->spec;
1706 unsigned int present;
1709 if (!(spec->auto_mic & AUTO_MIC_PORTC))
1711 present = snd_hda_jack_detect(codec, 0x18);
1713 spec->cur_adc_idx = 1;
1715 spec->cur_adc_idx = 0;
1716 new_adc = spec->adc_nids[spec->cur_adc_idx];
1717 if (spec->cur_adc && spec->cur_adc != new_adc) {
1718 /* stream is running, let's swap the current ADC */
1719 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1720 spec->cur_adc = new_adc;
1721 snd_hda_codec_setup_stream(codec, new_adc,
1722 spec->cur_adc_stream_tag, 0,
1723 spec->cur_adc_format);
1727 /* mute internal speaker if HP is plugged */
1728 static void cxt5051_hp_automute(struct hda_codec *codec)
1730 struct conexant_spec *spec = codec->spec;
1732 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1733 cxt5051_update_speaker(codec);
1736 /* unsolicited event for HP jack sensing */
1737 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1740 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1741 switch (res >> 26) {
1742 case CONEXANT_HP_EVENT:
1743 cxt5051_hp_automute(codec);
1745 case CXT5051_PORTB_EVENT:
1746 cxt5051_portb_automic(codec);
1748 case CXT5051_PORTC_EVENT:
1749 cxt5051_portc_automic(codec);
1752 snd_hda_input_jack_report(codec, nid);
1755 static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1756 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1758 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1759 .name = "Master Playback Switch",
1760 .info = cxt_eapd_info,
1761 .get = cxt_eapd_get,
1762 .put = cxt5051_hp_master_sw_put,
1763 .private_value = 0x1a,
1768 static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1769 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1770 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1771 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1772 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1773 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1774 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1778 static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1779 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1780 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1781 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1782 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1786 static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1787 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1788 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
1792 static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1793 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1794 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1798 static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1799 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1800 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1801 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1802 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1806 static const struct hda_verb cxt5051_init_verbs[] = {
1808 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1809 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1810 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1811 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1812 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1813 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1815 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1816 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1818 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1819 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1821 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1822 /* Record selector: Internal mic */
1823 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1824 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1825 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1826 /* SPDIF route: PCM */
1827 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1828 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1830 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1831 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1835 static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1837 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1838 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1839 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1840 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1842 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1843 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1845 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1846 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1848 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1849 /* Record selector: Internal mic */
1850 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1851 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1852 /* SPDIF route: PCM */
1853 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1855 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1856 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1860 static const struct hda_verb cxt5051_f700_init_verbs[] = {
1862 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1863 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1864 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1865 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1867 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1868 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1870 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1871 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1873 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1874 /* Record selector: Internal mic */
1875 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1876 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1877 /* SPDIF route: PCM */
1878 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1880 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1881 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1885 static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1888 snd_hda_codec_write(codec, nid, 0,
1889 AC_VERB_SET_UNSOLICITED_ENABLE,
1890 AC_USRSP_EN | event);
1893 static void cxt5051_init_mic_jack(struct hda_codec *codec, hda_nid_t nid)
1895 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1896 snd_hda_input_jack_report(codec, nid);
1899 static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1901 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1902 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1906 /* initialize jack-sensing, too */
1907 static int cxt5051_init(struct hda_codec *codec)
1909 struct conexant_spec *spec = codec->spec;
1911 conexant_init(codec);
1913 if (spec->auto_mic & AUTO_MIC_PORTB)
1914 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1915 if (spec->auto_mic & AUTO_MIC_PORTC)
1916 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1918 if (codec->patch_ops.unsol_event) {
1919 cxt5051_hp_automute(codec);
1920 cxt5051_portb_automic(codec);
1921 cxt5051_portc_automic(codec);
1928 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1929 CXT5051_HP, /* no docking */
1930 CXT5051_HP_DV6736, /* HP without mic switch */
1931 CXT5051_F700, /* HP Compaq Presario F700 */
1932 CXT5051_TOSHIBA, /* Toshiba M300 & co */
1933 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
1934 CXT5051_AUTO, /* auto-parser */
1938 static const char *const cxt5051_models[CXT5051_MODELS] = {
1939 [CXT5051_LAPTOP] = "laptop",
1940 [CXT5051_HP] = "hp",
1941 [CXT5051_HP_DV6736] = "hp-dv6736",
1942 [CXT5051_F700] = "hp-700",
1943 [CXT5051_TOSHIBA] = "toshiba",
1944 [CXT5051_IDEAPAD] = "ideapad",
1945 [CXT5051_AUTO] = "auto",
1948 static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1949 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1950 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1951 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1952 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1953 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1955 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1956 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1960 static int patch_cxt5051(struct hda_codec *codec)
1962 struct conexant_spec *spec;
1965 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1968 if (board_config < 0)
1969 board_config = CXT5051_AUTO; /* model=auto as default */
1970 if (board_config == CXT5051_AUTO)
1971 return patch_conexant_auto(codec);
1973 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1977 codec->pin_amp_workaround = 1;
1979 codec->patch_ops = conexant_patch_ops;
1980 codec->patch_ops.init = cxt5051_init;
1982 spec->multiout.max_channels = 2;
1983 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1984 spec->multiout.dac_nids = cxt5051_dac_nids;
1985 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1986 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1987 spec->adc_nids = cxt5051_adc_nids;
1988 spec->num_mixers = 2;
1989 spec->mixers[0] = cxt5051_capture_mixers;
1990 spec->mixers[1] = cxt5051_playback_mixers;
1991 spec->num_init_verbs = 1;
1992 spec->init_verbs[0] = cxt5051_init_verbs;
1993 spec->spdif_route = 0;
1994 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1995 spec->channel_mode = cxt5051_modes;
1997 spec->cur_adc_idx = 0;
1999 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2001 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2003 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
2004 switch (board_config) {
2006 spec->mixers[0] = cxt5051_hp_mixers;
2008 case CXT5051_HP_DV6736:
2009 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2010 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2014 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2015 spec->mixers[0] = cxt5051_f700_mixers;
2018 case CXT5051_TOSHIBA:
2019 spec->mixers[0] = cxt5051_toshiba_mixers;
2020 spec->auto_mic = AUTO_MIC_PORTB;
2022 case CXT5051_IDEAPAD:
2023 spec->init_verbs[spec->num_init_verbs++] =
2024 cxt5051_ideapad_init_verbs;
2030 snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
2032 conexant_init_jacks(codec);
2033 if (spec->auto_mic & AUTO_MIC_PORTB)
2034 cxt5051_init_mic_jack(codec, 0x17);
2035 if (spec->auto_mic & AUTO_MIC_PORTC)
2036 cxt5051_init_mic_jack(codec, 0x18);
2041 /* Conexant 5066 specific */
2043 static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2044 static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2045 static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2046 static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
2048 /* OLPC's microphone port is DC coupled for use with external sensors,
2049 * therefore we use a 50% mic bias in order to center the input signal with
2050 * the DC input range of the codec. */
2051 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2053 static const struct hda_channel_mode cxt5066_modes[1] = {
2057 #define HP_PRESENT_PORT_A (1 << 0)
2058 #define HP_PRESENT_PORT_D (1 << 1)
2059 #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2060 #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2062 static void cxt5066_update_speaker(struct hda_codec *codec)
2064 struct conexant_spec *spec = codec->spec;
2065 unsigned int pinctl;
2067 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2068 spec->hp_present, spec->cur_eapd);
2071 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
2072 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2075 /* Port D (HP/LO) */
2076 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2077 if (spec->dell_automute || spec->thinkpad) {
2078 /* Mute if Port A is connected */
2079 if (hp_port_a_present(spec))
2082 /* Thinkpad/Dell doesn't give pin-D status */
2083 if (!hp_port_d_present(spec))
2086 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2090 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2091 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2095 /* turn on/off EAPD (+ mute HP) as a master switch */
2096 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2097 struct snd_ctl_elem_value *ucontrol)
2099 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2101 if (!cxt_eapd_put(kcontrol, ucontrol))
2104 cxt5066_update_speaker(codec);
2108 static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2112 { "50%", PIN_VREF50 },
2113 { "80%", PIN_VREF80 },
2117 static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2119 struct conexant_spec *spec = codec->spec;
2120 /* Even though port F is the DC input, the bias is controlled on port B.
2121 * we also leave that port as an active input (but unselected) in DC mode
2122 * just in case that is necessary to make the bias setting take effect. */
2123 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2124 AC_VERB_SET_PIN_WIDGET_CONTROL,
2125 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2128 /* OLPC defers mic widget control until when capture is started because the
2129 * microphone LED comes on as soon as these settings are put in place. if we
2130 * did this before recording, it would give the false indication that recording
2131 * is happening when it is not. */
2132 static void cxt5066_olpc_select_mic(struct hda_codec *codec)
2134 struct conexant_spec *spec = codec->spec;
2135 if (!spec->recording)
2138 if (spec->dc_enable) {
2139 /* in DC mode we ignore presence detection and just use the jack
2140 * through our special DC port */
2141 const struct hda_verb enable_dc_mode[] = {
2142 /* disble internal mic, port C */
2143 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2145 /* enable DC capture, port F */
2146 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2150 snd_hda_sequence_write(codec, enable_dc_mode);
2151 /* port B input disabled (and bias set) through the following call */
2152 cxt5066_set_olpc_dc_bias(codec);
2156 /* disable DC (port F) */
2157 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2159 /* external mic, port B */
2160 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2161 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
2163 /* internal mic, port C */
2164 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2165 spec->ext_mic_present ? 0 : PIN_VREF80);
2168 /* toggle input of built-in and mic jack appropriately */
2169 static void cxt5066_olpc_automic(struct hda_codec *codec)
2171 struct conexant_spec *spec = codec->spec;
2172 unsigned int present;
2174 if (spec->dc_enable) /* don't do presence detection in DC mode */
2177 present = snd_hda_codec_read(codec, 0x1a, 0,
2178 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2180 snd_printdd("CXT5066: external microphone detected\n");
2182 snd_printdd("CXT5066: external microphone absent\n");
2184 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2186 spec->ext_mic_present = !!present;
2188 cxt5066_olpc_select_mic(codec);
2191 /* toggle input of built-in digital mic and mic jack appropriately */
2192 static void cxt5066_vostro_automic(struct hda_codec *codec)
2194 unsigned int present;
2196 struct hda_verb ext_mic_present[] = {
2197 /* enable external mic, port B */
2198 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2200 /* switch to external mic input */
2201 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2202 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2204 /* disable internal digital mic */
2205 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2208 static const struct hda_verb ext_mic_absent[] = {
2209 /* enable internal mic, port C */
2210 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2212 /* switch to internal mic input */
2213 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2215 /* disable external mic, port B */
2216 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2220 present = snd_hda_jack_detect(codec, 0x1a);
2222 snd_printdd("CXT5066: external microphone detected\n");
2223 snd_hda_sequence_write(codec, ext_mic_present);
2225 snd_printdd("CXT5066: external microphone absent\n");
2226 snd_hda_sequence_write(codec, ext_mic_absent);
2230 /* toggle input of built-in digital mic and mic jack appropriately */
2231 static void cxt5066_ideapad_automic(struct hda_codec *codec)
2233 unsigned int present;
2235 struct hda_verb ext_mic_present[] = {
2236 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2237 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2238 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2241 static const struct hda_verb ext_mic_absent[] = {
2242 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2243 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2244 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2248 present = snd_hda_jack_detect(codec, 0x1b);
2250 snd_printdd("CXT5066: external microphone detected\n");
2251 snd_hda_sequence_write(codec, ext_mic_present);
2253 snd_printdd("CXT5066: external microphone absent\n");
2254 snd_hda_sequence_write(codec, ext_mic_absent);
2259 /* toggle input of built-in digital mic and mic jack appropriately */
2260 static void cxt5066_asus_automic(struct hda_codec *codec)
2262 unsigned int present;
2264 present = snd_hda_jack_detect(codec, 0x1b);
2265 snd_printdd("CXT5066: external microphone present=%d\n", present);
2266 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2271 /* toggle input of built-in digital mic and mic jack appropriately */
2272 static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2274 unsigned int present;
2276 present = snd_hda_jack_detect(codec, 0x1b);
2277 snd_printdd("CXT5066: external microphone present=%d\n", present);
2278 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2283 /* toggle input of built-in digital mic and mic jack appropriately
2284 order is: external mic -> dock mic -> interal mic */
2285 static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2287 unsigned int ext_present, dock_present;
2289 static const struct hda_verb ext_mic_present[] = {
2290 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2291 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2292 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2293 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2294 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2297 static const struct hda_verb dock_mic_present[] = {
2298 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2299 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2300 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2301 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2302 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2305 static const struct hda_verb ext_mic_absent[] = {
2306 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2307 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2308 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2309 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2313 ext_present = snd_hda_jack_detect(codec, 0x1b);
2314 dock_present = snd_hda_jack_detect(codec, 0x1a);
2316 snd_printdd("CXT5066: external microphone detected\n");
2317 snd_hda_sequence_write(codec, ext_mic_present);
2318 } else if (dock_present) {
2319 snd_printdd("CXT5066: dock microphone detected\n");
2320 snd_hda_sequence_write(codec, dock_mic_present);
2322 snd_printdd("CXT5066: external microphone absent\n");
2323 snd_hda_sequence_write(codec, ext_mic_absent);
2327 /* mute internal speaker if HP is plugged */
2328 static void cxt5066_hp_automute(struct hda_codec *codec)
2330 struct conexant_spec *spec = codec->spec;
2331 unsigned int portA, portD;
2334 portA = snd_hda_jack_detect(codec, 0x19);
2337 portD = snd_hda_jack_detect(codec, 0x1c);
2339 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2340 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
2341 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2342 portA, portD, spec->hp_present);
2343 cxt5066_update_speaker(codec);
2346 /* Dispatch the right mic autoswitch function */
2347 static void cxt5066_automic(struct hda_codec *codec)
2349 struct conexant_spec *spec = codec->spec;
2351 if (spec->dell_vostro)
2352 cxt5066_vostro_automic(codec);
2353 else if (spec->ideapad)
2354 cxt5066_ideapad_automic(codec);
2355 else if (spec->thinkpad)
2356 cxt5066_thinkpad_automic(codec);
2357 else if (spec->hp_laptop)
2358 cxt5066_hp_laptop_automic(codec);
2359 else if (spec->asus)
2360 cxt5066_asus_automic(codec);
2363 /* unsolicited event for jack sensing */
2364 static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
2366 struct conexant_spec *spec = codec->spec;
2367 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2368 switch (res >> 26) {
2369 case CONEXANT_HP_EVENT:
2370 cxt5066_hp_automute(codec);
2372 case CONEXANT_MIC_EVENT:
2373 /* ignore mic events in DC mode; we're always using the jack */
2374 if (!spec->dc_enable)
2375 cxt5066_olpc_automic(codec);
2380 /* unsolicited event for jack sensing */
2381 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2383 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2384 switch (res >> 26) {
2385 case CONEXANT_HP_EVENT:
2386 cxt5066_hp_automute(codec);
2388 case CONEXANT_MIC_EVENT:
2389 cxt5066_automic(codec);
2395 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2406 static void cxt5066_set_mic_boost(struct hda_codec *codec)
2408 struct conexant_spec *spec = codec->spec;
2409 snd_hda_codec_write_cache(codec, 0x17, 0,
2410 AC_VERB_SET_AMP_GAIN_MUTE,
2411 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2412 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
2413 if (spec->ideapad || spec->thinkpad) {
2414 /* adjust the internal mic as well...it is not through 0x17 */
2415 snd_hda_codec_write_cache(codec, 0x23, 0,
2416 AC_VERB_SET_AMP_GAIN_MUTE,
2417 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2418 cxt5066_analog_mic_boost.
2419 items[spec->mic_boost].index);
2423 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2424 struct snd_ctl_elem_info *uinfo)
2426 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2429 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2430 struct snd_ctl_elem_value *ucontrol)
2432 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2433 struct conexant_spec *spec = codec->spec;
2434 ucontrol->value.enumerated.item[0] = spec->mic_boost;
2438 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2439 struct snd_ctl_elem_value *ucontrol)
2441 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2442 struct conexant_spec *spec = codec->spec;
2443 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2445 idx = ucontrol->value.enumerated.item[0];
2446 if (idx >= imux->num_items)
2447 idx = imux->num_items - 1;
2449 spec->mic_boost = idx;
2450 if (!spec->dc_enable)
2451 cxt5066_set_mic_boost(codec);
2455 static void cxt5066_enable_dc(struct hda_codec *codec)
2457 const struct hda_verb enable_dc_mode[] = {
2459 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2461 /* switch to DC input */
2462 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2466 /* configure as input source */
2467 snd_hda_sequence_write(codec, enable_dc_mode);
2468 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2471 static void cxt5066_disable_dc(struct hda_codec *codec)
2473 /* reconfigure input source */
2474 cxt5066_set_mic_boost(codec);
2475 /* automic also selects the right mic if we're recording */
2476 cxt5066_olpc_automic(codec);
2479 static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2480 struct snd_ctl_elem_value *ucontrol)
2482 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2483 struct conexant_spec *spec = codec->spec;
2484 ucontrol->value.integer.value[0] = spec->dc_enable;
2488 static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2489 struct snd_ctl_elem_value *ucontrol)
2491 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2492 struct conexant_spec *spec = codec->spec;
2493 int dc_enable = !!ucontrol->value.integer.value[0];
2495 if (dc_enable == spec->dc_enable)
2498 spec->dc_enable = dc_enable;
2500 cxt5066_enable_dc(codec);
2502 cxt5066_disable_dc(codec);
2507 static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2508 struct snd_ctl_elem_info *uinfo)
2510 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2513 static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2514 struct snd_ctl_elem_value *ucontrol)
2516 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2517 struct conexant_spec *spec = codec->spec;
2518 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2522 static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2523 struct snd_ctl_elem_value *ucontrol)
2525 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2526 struct conexant_spec *spec = codec->spec;
2527 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2530 idx = ucontrol->value.enumerated.item[0];
2531 if (idx >= imux->num_items)
2532 idx = imux->num_items - 1;
2534 spec->dc_input_bias = idx;
2535 if (spec->dc_enable)
2536 cxt5066_set_olpc_dc_bias(codec);
2540 static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2542 struct conexant_spec *spec = codec->spec;
2543 /* mark as recording and configure the microphone widget so that the
2544 * recording LED comes on. */
2545 spec->recording = 1;
2546 cxt5066_olpc_select_mic(codec);
2549 static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2551 struct conexant_spec *spec = codec->spec;
2552 const struct hda_verb disable_mics[] = {
2553 /* disable external mic, port B */
2554 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2556 /* disble internal mic, port C */
2557 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2559 /* disable DC capture, port F */
2560 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2564 snd_hda_sequence_write(codec, disable_mics);
2565 spec->recording = 0;
2568 static void conexant_check_dig_outs(struct hda_codec *codec,
2569 const hda_nid_t *dig_pins,
2572 struct conexant_spec *spec = codec->spec;
2573 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2576 for (i = 0; i < num_pins; i++, dig_pins++) {
2577 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2578 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2580 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2582 if (spec->slave_dig_outs[0])
2585 nid_loc = spec->slave_dig_outs;
2589 static const struct hda_input_mux cxt5066_capture_source = {
2599 static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2600 .ops = &snd_hda_bind_vol,
2602 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2603 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2608 static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2609 .ops = &snd_hda_bind_sw,
2611 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2612 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2617 static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
2618 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2622 static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2625 .name = "Master Playback Volume",
2626 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2627 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2628 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2629 .subdevice = HDA_SUBDEV_AMP_FLAG,
2630 .info = snd_hda_mixer_amp_volume_info,
2631 .get = snd_hda_mixer_amp_volume_get,
2632 .put = snd_hda_mixer_amp_volume_put,
2633 .tlv = { .c = snd_hda_mixer_amp_tlv },
2634 /* offset by 28 volume steps to limit minimum gain to -46dB */
2636 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2641 static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2643 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2644 .name = "DC Mode Enable Switch",
2645 .info = snd_ctl_boolean_mono_info,
2646 .get = cxt5066_olpc_dc_get,
2647 .put = cxt5066_olpc_dc_put,
2650 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2651 .name = "DC Input Bias Enum",
2652 .info = cxt5066_olpc_dc_bias_enum_info,
2653 .get = cxt5066_olpc_dc_bias_enum_get,
2654 .put = cxt5066_olpc_dc_bias_enum_put,
2659 static const struct snd_kcontrol_new cxt5066_mixers[] = {
2661 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2662 .name = "Master Playback Switch",
2663 .info = cxt_eapd_info,
2664 .get = cxt_eapd_get,
2665 .put = cxt5066_hp_master_sw_put,
2666 .private_value = 0x1d,
2670 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2671 .name = "Analog Mic Boost Capture Enum",
2672 .info = cxt5066_mic_boost_mux_enum_info,
2673 .get = cxt5066_mic_boost_mux_enum_get,
2674 .put = cxt5066_mic_boost_mux_enum_put,
2677 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2678 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2682 static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2684 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2685 .name = "Internal Mic Boost Capture Enum",
2686 .info = cxt5066_mic_boost_mux_enum_info,
2687 .get = cxt5066_mic_boost_mux_enum_get,
2688 .put = cxt5066_mic_boost_mux_enum_put,
2689 .private_value = 0x23 | 0x100,
2694 static const struct hda_verb cxt5066_init_verbs[] = {
2695 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2696 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2697 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2698 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2701 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2702 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2705 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2706 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2708 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2709 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2712 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2714 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2715 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2716 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2717 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2718 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2719 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2721 /* no digital microphone support yet */
2722 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2724 /* Audio input selector */
2725 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2727 /* SPDIF route: PCM */
2728 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2729 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2731 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2732 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2735 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2737 /* not handling these yet */
2738 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2739 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2740 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2741 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2742 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2743 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2744 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2745 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2749 static const struct hda_verb cxt5066_init_verbs_olpc[] = {
2750 /* Port A: headphones */
2751 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2752 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2754 /* Port B: external microphone */
2755 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2757 /* Port C: internal microphone */
2758 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2760 /* Port D: unused */
2761 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2763 /* Port E: unused, but has primary EAPD */
2764 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2765 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2767 /* Port F: external DC input through microphone port */
2768 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2770 /* Port G: internal speakers */
2771 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2772 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2775 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2778 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2780 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2781 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2782 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2783 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2784 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2785 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2786 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2787 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2788 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2789 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2790 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2791 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2793 /* Disable digital microphone port */
2794 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2796 /* Audio input selectors */
2797 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2798 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2801 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2802 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2804 /* enable unsolicited events for Port A and B */
2805 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2806 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2810 static const struct hda_verb cxt5066_init_verbs_vostro[] = {
2811 /* Port A: headphones */
2812 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2813 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2815 /* Port B: external microphone */
2816 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2818 /* Port C: unused */
2819 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2821 /* Port D: unused */
2822 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2824 /* Port E: unused, but has primary EAPD */
2825 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2826 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2828 /* Port F: unused */
2829 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2831 /* Port G: internal speakers */
2832 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2833 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2836 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2839 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2841 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2842 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2843 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2844 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2845 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2846 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2847 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2848 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2849 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2850 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2851 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2852 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2854 /* Digital microphone port */
2855 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2857 /* Audio input selectors */
2858 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2859 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2862 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2863 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2865 /* enable unsolicited events for Port A and B */
2866 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2867 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2871 static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2872 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2873 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2874 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2875 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2878 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2879 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2882 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2883 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2885 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2886 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2889 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2891 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2892 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2893 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2894 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2895 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2896 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2897 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2899 /* Audio input selector */
2900 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2901 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2903 /* SPDIF route: PCM */
2904 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2905 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2907 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2908 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2910 /* internal microphone */
2911 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2914 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2916 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2917 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2921 static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2922 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2923 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2925 /* Port G: internal speakers */
2926 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2927 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2929 /* Port A: HP, Amp */
2930 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2931 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2933 /* Port B: Mic Dock */
2934 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2937 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2939 /* Port D: HP Dock, Amp */
2940 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2941 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2944 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2946 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2947 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2948 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2949 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2950 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2951 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2952 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2954 /* Audio input selector */
2955 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2956 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2958 /* SPDIF route: PCM */
2959 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2960 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2962 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2963 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2965 /* internal microphone */
2966 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2969 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2971 /* enable unsolicited events for Port A, B, C and D */
2972 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2973 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2974 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2975 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2979 static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2980 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2985 static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2986 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2987 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2988 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2992 /* initialize jack-sensing, too */
2993 static int cxt5066_init(struct hda_codec *codec)
2995 snd_printdd("CXT5066: init\n");
2996 conexant_init(codec);
2997 if (codec->patch_ops.unsol_event) {
2998 cxt5066_hp_automute(codec);
2999 cxt5066_automic(codec);
3001 cxt5066_set_mic_boost(codec);
3005 static int cxt5066_olpc_init(struct hda_codec *codec)
3007 struct conexant_spec *spec = codec->spec;
3008 snd_printdd("CXT5066: init\n");
3009 conexant_init(codec);
3010 cxt5066_hp_automute(codec);
3011 if (!spec->dc_enable) {
3012 cxt5066_set_mic_boost(codec);
3013 cxt5066_olpc_automic(codec);
3015 cxt5066_enable_dc(codec);
3021 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
3022 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3023 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
3024 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
3025 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
3026 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
3027 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
3028 CXT5066_HP_LAPTOP, /* HP Laptop */
3029 CXT5066_AUTO, /* BIOS auto-parser */
3033 static const char * const cxt5066_models[CXT5066_MODELS] = {
3034 [CXT5066_LAPTOP] = "laptop",
3035 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3036 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
3037 [CXT5066_DELL_VOSTRO] = "dell-vostro",
3038 [CXT5066_IDEAPAD] = "ideapad",
3039 [CXT5066_THINKPAD] = "thinkpad",
3040 [CXT5066_ASUS] = "asus",
3041 [CXT5066_HP_LAPTOP] = "hp-laptop",
3042 [CXT5066_AUTO] = "auto",
3045 static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3046 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
3047 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
3048 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
3049 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3050 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
3051 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3052 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3053 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
3054 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3055 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
3056 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
3057 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
3058 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3059 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
3060 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3062 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
3063 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3064 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
3065 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
3066 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3067 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
3068 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
3069 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
3070 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
3071 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
3072 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
3073 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
3074 SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
3078 static int patch_cxt5066(struct hda_codec *codec)
3080 struct conexant_spec *spec;
3083 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3084 cxt5066_models, cxt5066_cfg_tbl);
3085 if (board_config < 0)
3086 board_config = CXT5066_AUTO; /* model=auto as default */
3087 if (board_config == CXT5066_AUTO)
3088 return patch_conexant_auto(codec);
3090 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3095 codec->patch_ops = conexant_patch_ops;
3096 codec->patch_ops.init = conexant_init;
3098 spec->dell_automute = 0;
3099 spec->multiout.max_channels = 2;
3100 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3101 spec->multiout.dac_nids = cxt5066_dac_nids;
3102 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3103 ARRAY_SIZE(cxt5066_digout_pin_nids));
3104 spec->num_adc_nids = 1;
3105 spec->adc_nids = cxt5066_adc_nids;
3106 spec->capsrc_nids = cxt5066_capsrc_nids;
3107 spec->input_mux = &cxt5066_capture_source;
3109 spec->port_d_mode = PIN_HP;