2 * HD audio interface patch for Conexant HDA audio codec
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
27 #include <linux/module.h>
28 #include <sound/core.h>
29 #include <sound/jack.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_auto_parser.h"
37 #define CXT_PIN_DIR_IN 0x00
38 #define CXT_PIN_DIR_OUT 0x01
39 #define CXT_PIN_DIR_INOUT 0x02
40 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
41 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
43 #define CONEXANT_HP_EVENT 0x37
44 #define CONEXANT_MIC_EVENT 0x38
45 #define CONEXANT_LINE_EVENT 0x39
47 /* Conexant 5051 specific */
49 #define CXT5051_SPDIF_OUT 0x12
50 #define CXT5051_PORTB_EVENT 0x38
51 #define CXT5051_PORTC_EVENT 0x39
53 #define AUTO_MIC_PORTB (1 << 1)
54 #define AUTO_MIC_PORTC (1 << 2)
63 hda_nid_t pin; /* input pin NID */
64 hda_nid_t adc; /* connected ADC NID */
65 hda_nid_t boost; /* optional boost volume NID */
66 int index; /* corresponding to autocfg.input */
69 struct conexant_spec {
70 const struct snd_kcontrol_new *mixers[5];
72 hda_nid_t vmaster_nid;
73 struct hda_vmaster_mute_hook vmaster_mute;
74 bool vmaster_mute_led;
76 const struct hda_verb *init_verbs[5]; /* initialization verbs
80 unsigned int num_init_verbs;
83 struct hda_multi_out multiout; /* playback set-up
84 * max_channels, dacs must be set
85 * dig_out_nid and hp_nid are optional
87 unsigned int cur_eapd;
88 unsigned int hp_present;
89 unsigned int line_present;
90 unsigned int auto_mic;
91 int auto_mic_ext; /* imux_pins[] index for ext mic */
92 int auto_mic_dock; /* imux_pins[] index for dock mic */
93 int auto_mic_int; /* imux_pins[] index for int mic */
94 unsigned int need_dac_fix;
95 hda_nid_t slave_dig_outs[2];
98 unsigned int num_adc_nids;
99 const hda_nid_t *adc_nids;
100 hda_nid_t dig_in_nid; /* digital-in NID; optional */
102 unsigned int cur_adc_idx;
104 unsigned int cur_adc_stream_tag;
105 unsigned int cur_adc_format;
107 const struct hda_pcm_stream *capture_stream;
110 const struct hda_input_mux *input_mux;
111 const hda_nid_t *capsrc_nids;
112 unsigned int cur_mux[3];
115 const struct hda_channel_mode *channel_mode;
116 int num_channel_mode;
118 /* PCM information */
119 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
121 unsigned int spdif_route;
123 /* dynamic controls, init_verbs and input_mux */
124 struct auto_pin_cfg autocfg;
125 struct hda_input_mux private_imux;
126 struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
127 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
128 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
129 struct pin_dac_pair dac_info[8];
132 unsigned int port_d_mode;
133 unsigned int auto_mute:1; /* used in auto-parser */
134 unsigned int detect_line:1; /* Line-out detection enabled */
135 unsigned int automute_lines:1; /* automute line-out as well */
136 unsigned int automute_hp_lo:1; /* both HP and LO available */
137 unsigned int dell_automute:1;
138 unsigned int dell_vostro:1;
139 unsigned int ideapad:1;
140 unsigned int thinkpad:1;
141 unsigned int hp_laptop:1;
143 unsigned int pin_eapd_ctrls:1;
144 unsigned int fixup_stereo_dmic:1;
146 unsigned int adc_switching:1;
148 unsigned int ext_mic_present;
149 unsigned int recording;
150 void (*capture_prepare)(struct hda_codec *codec);
151 void (*capture_cleanup)(struct hda_codec *codec);
153 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
154 * through the microphone jack.
155 * When the user enables this through a mixer switch, both internal and
156 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
157 * we also allow the bias to be configured through a separate mixer
159 unsigned int dc_enable;
160 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
161 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
163 unsigned int beep_amp;
165 /* extra EAPD pins */
166 unsigned int num_eapds;
170 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
171 struct hda_codec *codec,
172 struct snd_pcm_substream *substream)
174 struct conexant_spec *spec = codec->spec;
175 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
179 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
181 unsigned int stream_tag,
183 struct snd_pcm_substream *substream)
185 struct conexant_spec *spec = codec->spec;
186 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
191 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
192 struct hda_codec *codec,
193 struct snd_pcm_substream *substream)
195 struct conexant_spec *spec = codec->spec;
196 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
202 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
203 struct hda_codec *codec,
204 struct snd_pcm_substream *substream)
206 struct conexant_spec *spec = codec->spec;
207 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
210 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
211 struct hda_codec *codec,
212 struct snd_pcm_substream *substream)
214 struct conexant_spec *spec = codec->spec;
215 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
218 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
219 struct hda_codec *codec,
220 unsigned int stream_tag,
222 struct snd_pcm_substream *substream)
224 struct conexant_spec *spec = codec->spec;
225 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
233 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
234 struct hda_codec *codec,
235 unsigned int stream_tag,
237 struct snd_pcm_substream *substream)
239 struct conexant_spec *spec = codec->spec;
240 if (spec->capture_prepare)
241 spec->capture_prepare(codec);
242 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
243 stream_tag, 0, format);
247 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
248 struct hda_codec *codec,
249 struct snd_pcm_substream *substream)
251 struct conexant_spec *spec = codec->spec;
252 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
253 if (spec->capture_cleanup)
254 spec->capture_cleanup(codec);
260 static const struct hda_pcm_stream conexant_pcm_analog_playback = {
264 .nid = 0, /* fill later */
266 .open = conexant_playback_pcm_open,
267 .prepare = conexant_playback_pcm_prepare,
268 .cleanup = conexant_playback_pcm_cleanup
272 static const struct hda_pcm_stream conexant_pcm_analog_capture = {
276 .nid = 0, /* fill later */
278 .prepare = conexant_capture_pcm_prepare,
279 .cleanup = conexant_capture_pcm_cleanup
284 static const struct hda_pcm_stream conexant_pcm_digital_playback = {
288 .nid = 0, /* fill later */
290 .open = conexant_dig_playback_pcm_open,
291 .close = conexant_dig_playback_pcm_close,
292 .prepare = conexant_dig_playback_pcm_prepare
296 static const struct hda_pcm_stream conexant_pcm_digital_capture = {
300 /* NID is set in alc_build_pcms */
303 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
304 struct hda_codec *codec,
305 unsigned int stream_tag,
307 struct snd_pcm_substream *substream)
309 struct conexant_spec *spec = codec->spec;
310 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
311 spec->cur_adc_stream_tag = stream_tag;
312 spec->cur_adc_format = format;
313 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
317 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
318 struct hda_codec *codec,
319 struct snd_pcm_substream *substream)
321 struct conexant_spec *spec = codec->spec;
322 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
327 static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
331 .nid = 0, /* fill later */
333 .prepare = cx5051_capture_pcm_prepare,
334 .cleanup = cx5051_capture_pcm_cleanup
338 static bool is_2_1_speaker(struct conexant_spec *spec);
340 static int conexant_build_pcms(struct hda_codec *codec)
342 struct conexant_spec *spec = codec->spec;
343 struct hda_pcm *info = spec->pcm_rec;
346 codec->pcm_info = info;
348 info->name = "CONEXANT Analog";
349 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
350 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
351 spec->multiout.max_channels;
352 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
353 spec->multiout.dac_nids[0];
354 if (is_2_1_speaker(spec))
355 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
357 if (spec->capture_stream)
358 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
360 if (codec->vendor_id == 0x14f15051)
361 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
362 cx5051_pcm_analog_capture;
364 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
365 conexant_pcm_analog_capture;
366 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
370 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
372 if (spec->multiout.dig_out_nid) {
375 info->name = "Conexant Digital";
376 info->pcm_type = HDA_PCM_TYPE_SPDIF;
377 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
378 conexant_pcm_digital_playback;
379 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
380 spec->multiout.dig_out_nid;
381 if (spec->dig_in_nid) {
382 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
383 conexant_pcm_digital_capture;
384 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
387 if (spec->slave_dig_outs[0])
388 codec->slave_dig_outs = spec->slave_dig_outs;
394 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
395 struct snd_ctl_elem_info *uinfo)
397 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
398 struct conexant_spec *spec = codec->spec;
400 return snd_hda_input_mux_info(spec->input_mux, uinfo);
403 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
404 struct snd_ctl_elem_value *ucontrol)
406 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407 struct conexant_spec *spec = codec->spec;
408 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
410 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
414 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
415 struct snd_ctl_elem_value *ucontrol)
417 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
418 struct conexant_spec *spec = codec->spec;
419 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
421 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
422 spec->capsrc_nids[adc_idx],
423 &spec->cur_mux[adc_idx]);
426 static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
427 unsigned int power_state)
429 if (power_state == AC_PWRST_D3)
431 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
433 /* partial workaround for "azx_get_response timeout" */
434 if (power_state == AC_PWRST_D0)
436 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
439 static int conexant_init(struct hda_codec *codec)
441 struct conexant_spec *spec = codec->spec;
444 for (i = 0; i < spec->num_init_verbs; i++)
445 snd_hda_sequence_write(codec, spec->init_verbs[i]);
449 static void conexant_free(struct hda_codec *codec)
451 struct conexant_spec *spec = codec->spec;
452 snd_hda_detach_beep_device(codec);
456 static const struct snd_kcontrol_new cxt_capture_mixers[] = {
458 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
459 .name = "Capture Source",
460 .info = conexant_mux_enum_info,
461 .get = conexant_mux_enum_get,
462 .put = conexant_mux_enum_put
467 #ifdef CONFIG_SND_HDA_INPUT_BEEP
468 /* additional beep mixers; the actual parameters are overwritten at build */
469 static const struct snd_kcontrol_new cxt_beep_mixer[] = {
470 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
471 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
476 static const char * const slave_pfxs[] = {
477 "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
481 static int conexant_build_controls(struct hda_codec *codec)
483 struct conexant_spec *spec = codec->spec;
487 for (i = 0; i < spec->num_mixers; i++) {
488 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
492 if (spec->multiout.dig_out_nid) {
493 err = snd_hda_create_spdif_out_ctls(codec,
494 spec->multiout.dig_out_nid,
495 spec->multiout.dig_out_nid);
498 err = snd_hda_create_spdif_share_sw(codec,
502 spec->multiout.share_spdif = 1;
504 if (spec->dig_in_nid) {
505 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
510 /* if we have no master control, let's create it */
511 if (spec->vmaster_nid &&
512 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
513 unsigned int vmaster_tlv[4];
514 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
515 HDA_OUTPUT, vmaster_tlv);
516 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
517 vmaster_tlv, slave_pfxs,
522 if (spec->vmaster_nid &&
523 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
524 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
526 "Playback Switch", true,
527 &spec->vmaster_mute.sw_kctl);
532 if (spec->input_mux) {
533 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
538 #ifdef CONFIG_SND_HDA_INPUT_BEEP
539 /* create beep controls if needed */
540 if (spec->beep_amp) {
541 const struct snd_kcontrol_new *knew;
542 for (knew = cxt_beep_mixer; knew->name; knew++) {
543 struct snd_kcontrol *kctl;
544 kctl = snd_ctl_new1(knew, codec);
547 kctl->private_value = spec->beep_amp;
548 err = snd_hda_ctl_add(codec, 0, kctl);
558 static const struct hda_codec_ops conexant_patch_ops = {
559 .build_controls = conexant_build_controls,
560 .build_pcms = conexant_build_pcms,
561 .init = conexant_init,
562 .free = conexant_free,
563 .set_power_state = conexant_set_power,
566 #ifdef CONFIG_SND_HDA_INPUT_BEEP
567 #define set_beep_amp(spec, nid, idx, dir) \
568 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
570 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
573 static int patch_conexant_auto(struct hda_codec *codec);
576 * the private value = nid | (invert << 8)
579 #define cxt_eapd_info snd_ctl_boolean_mono_info
581 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
582 struct snd_ctl_elem_value *ucontrol)
584 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
585 struct conexant_spec *spec = codec->spec;
586 int invert = (kcontrol->private_value >> 8) & 1;
588 ucontrol->value.integer.value[0] = !spec->cur_eapd;
590 ucontrol->value.integer.value[0] = spec->cur_eapd;
595 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
596 struct snd_ctl_elem_value *ucontrol)
598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
599 struct conexant_spec *spec = codec->spec;
600 int invert = (kcontrol->private_value >> 8) & 1;
601 hda_nid_t nid = kcontrol->private_value & 0xff;
604 eapd = !!ucontrol->value.integer.value[0];
607 if (eapd == spec->cur_eapd)
610 spec->cur_eapd = eapd;
611 snd_hda_codec_write_cache(codec, nid,
612 0, AC_VERB_SET_EAPD_BTLENABLE,
617 /* controls for test mode */
618 #ifdef CONFIG_SND_DEBUG
620 #define CXT_EAPD_SWITCH(xname, nid, mask) \
621 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
622 .info = cxt_eapd_info, \
623 .get = cxt_eapd_get, \
624 .put = cxt_eapd_put, \
625 .private_value = nid | (mask<<16) }
629 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
630 struct snd_ctl_elem_info *uinfo)
632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633 struct conexant_spec *spec = codec->spec;
634 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
635 spec->num_channel_mode);
638 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
639 struct snd_ctl_elem_value *ucontrol)
641 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
642 struct conexant_spec *spec = codec->spec;
643 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
644 spec->num_channel_mode,
645 spec->multiout.max_channels);
648 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct conexant_spec *spec = codec->spec;
653 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
654 spec->num_channel_mode,
655 &spec->multiout.max_channels);
656 if (err >= 0 && spec->need_dac_fix)
657 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
661 #define CXT_PIN_MODE(xname, nid, dir) \
662 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
663 .info = conexant_ch_mode_info, \
664 .get = conexant_ch_mode_get, \
665 .put = conexant_ch_mode_put, \
666 .private_value = nid | (dir<<16) }
668 #endif /* CONFIG_SND_DEBUG */
670 /* Conexant 5045 specific */
672 static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
673 static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
674 static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
675 #define CXT5045_SPDIF_OUT 0x18
677 static const struct hda_channel_mode cxt5045_modes[1] = {
681 static const struct hda_input_mux cxt5045_capture_source = {
684 { "Internal Mic", 0x1 },
689 static const struct hda_input_mux cxt5045_capture_source_benq = {
692 { "Internal Mic", 0x1 },
699 static const struct hda_input_mux cxt5045_capture_source_hp530 = {
703 { "Internal Mic", 0x2 },
707 /* turn on/off EAPD (+ mute HP) as a master switch */
708 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
709 struct snd_ctl_elem_value *ucontrol)
711 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
712 struct conexant_spec *spec = codec->spec;
715 if (!cxt_eapd_put(kcontrol, ucontrol))
718 /* toggle internal speakers mute depending of presence of
721 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
722 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
725 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
726 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
731 /* bind volumes of both NID 0x10 and 0x11 */
732 static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
733 .ops = &snd_hda_bind_vol,
735 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
736 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
741 /* toggle input of built-in and mic jack appropriately */
742 static void cxt5045_hp_automic(struct hda_codec *codec)
744 static const struct hda_verb mic_jack_on[] = {
745 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
746 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
749 static const struct hda_verb mic_jack_off[] = {
750 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
751 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
754 unsigned int present;
756 present = snd_hda_jack_detect(codec, 0x12);
758 snd_hda_sequence_write(codec, mic_jack_on);
760 snd_hda_sequence_write(codec, mic_jack_off);
764 /* mute internal speaker if HP is plugged */
765 static void cxt5045_hp_automute(struct hda_codec *codec)
767 struct conexant_spec *spec = codec->spec;
770 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
772 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
773 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
777 /* unsolicited event for HP jack sensing */
778 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
783 case CONEXANT_HP_EVENT:
784 cxt5045_hp_automute(codec);
786 case CONEXANT_MIC_EVENT:
787 cxt5045_hp_automic(codec);
793 static const struct snd_kcontrol_new cxt5045_mixers[] = {
794 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
795 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
796 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
797 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
798 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
799 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
800 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
801 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
802 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
805 .name = "Master Playback Switch",
806 .info = cxt_eapd_info,
808 .put = cxt5045_hp_master_sw_put,
809 .private_value = 0x10,
815 static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
816 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
817 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
822 static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
823 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
824 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
825 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
826 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
827 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
828 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
829 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
830 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
831 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
833 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
834 .name = "Master Playback Switch",
835 .info = cxt_eapd_info,
837 .put = cxt5045_hp_master_sw_put,
838 .private_value = 0x10,
844 static const struct hda_verb cxt5045_init_verbs[] = {
846 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
847 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
849 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
850 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
851 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
852 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
853 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
854 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
855 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
856 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
857 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
858 /* Record selector: Internal mic */
859 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
860 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
861 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
862 /* SPDIF route: PCM */
863 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
864 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
866 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
870 static const struct hda_verb cxt5045_benq_init_verbs[] = {
871 /* Internal Mic, Mic */
872 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
873 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
874 /* Line In,HP, Amp */
875 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
876 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
877 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
878 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
879 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
880 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
881 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
882 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
883 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
884 /* Record selector: Internal mic */
885 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
886 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
887 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
888 /* SPDIF route: PCM */
889 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
890 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
892 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
896 static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
897 /* pin sensing on HP jack */
898 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
902 static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
903 /* pin sensing on HP jack */
904 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
908 #ifdef CONFIG_SND_DEBUG
909 /* Test configuration for debugging, modelled after the ALC260 test
912 static const struct hda_input_mux cxt5045_test_capture_source = {
917 { "LINE1 pin", 0x2 },
918 { "HP-OUT pin", 0x3 },
923 static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
925 /* Output controls */
926 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
927 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
928 HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
929 HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
930 HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
931 HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
933 /* Modes for retasking pin widgets */
934 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
935 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
937 /* EAPD Switch Control */
938 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
940 /* Loopback mixer controls */
942 HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
943 HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
944 HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
945 HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
946 HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
947 HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
948 HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
949 HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
950 HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
951 HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
953 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
954 .name = "Input Source",
955 .info = conexant_mux_enum_info,
956 .get = conexant_mux_enum_get,
957 .put = conexant_mux_enum_put,
959 /* Audio input controls */
960 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
961 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
965 static const struct hda_verb cxt5045_test_init_verbs[] = {
966 /* Set connections */
967 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
968 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
969 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
970 /* Enable retasking pins as output, initially without power amp */
971 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
972 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
974 /* Disable digital (SPDIF) pins initially, but users can enable
975 * them via a mixer switch. In the case of SPDIF-out, this initverb
976 * payload also sets the generation to 0, output to be in "consumer"
977 * PCM format, copyright asserted, no pre-emphasis and no validity
980 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
981 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
983 /* Unmute retasking pin widget output buffers since the default
984 * state appears to be output. As the pin mode is changed by the
985 * user the pin mode control will take care of enabling the pin's
986 * input/output buffers as needed.
988 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
989 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
991 /* Mute capture amp left and right */
992 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
994 /* Set ADC connection select to match default mixer setting (mic1
997 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
998 {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
1000 /* Mute all inputs to mixer widget (even unconnected ones) */
1001 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
1002 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1003 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1004 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1005 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1012 /* initialize jack-sensing, too */
1013 static int cxt5045_init(struct hda_codec *codec)
1015 conexant_init(codec);
1016 cxt5045_hp_automute(codec);
1022 CXT5045_LAPTOP_HPSENSE,
1023 CXT5045_LAPTOP_MICSENSE,
1024 CXT5045_LAPTOP_HPMICSENSE,
1026 CXT5045_LAPTOP_HP530,
1027 #ifdef CONFIG_SND_DEBUG
1034 static const char * const cxt5045_models[CXT5045_MODELS] = {
1035 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1036 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1037 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1038 [CXT5045_BENQ] = "benq",
1039 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1040 #ifdef CONFIG_SND_DEBUG
1041 [CXT5045_TEST] = "test",
1043 [CXT5045_AUTO] = "auto",
1046 static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1047 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1048 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1049 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1050 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1051 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1052 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1053 CXT5045_LAPTOP_HPMICSENSE),
1054 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1055 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1056 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1057 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1058 CXT5045_LAPTOP_HPMICSENSE),
1059 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1063 static int patch_cxt5045(struct hda_codec *codec)
1065 struct conexant_spec *spec;
1068 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1071 if (board_config < 0)
1072 board_config = CXT5045_AUTO; /* model=auto as default */
1073 if (board_config == CXT5045_AUTO)
1074 return patch_conexant_auto(codec);
1076 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1080 codec->single_adc_amp = 1;
1082 spec->multiout.max_channels = 2;
1083 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1084 spec->multiout.dac_nids = cxt5045_dac_nids;
1085 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1086 spec->num_adc_nids = 1;
1087 spec->adc_nids = cxt5045_adc_nids;
1088 spec->capsrc_nids = cxt5045_capsrc_nids;
1089 spec->input_mux = &cxt5045_capture_source;
1090 spec->num_mixers = 1;
1091 spec->mixers[0] = cxt5045_mixers;
1092 spec->num_init_verbs = 1;
1093 spec->init_verbs[0] = cxt5045_init_verbs;
1094 spec->spdif_route = 0;
1095 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1096 spec->channel_mode = cxt5045_modes;
1098 set_beep_amp(spec, 0x16, 0, 1);
1100 codec->patch_ops = conexant_patch_ops;
1102 switch (board_config) {
1103 case CXT5045_LAPTOP_HPSENSE:
1104 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1105 spec->input_mux = &cxt5045_capture_source;
1106 spec->num_init_verbs = 2;
1107 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1108 spec->mixers[0] = cxt5045_mixers;
1109 codec->patch_ops.init = cxt5045_init;
1111 case CXT5045_LAPTOP_MICSENSE:
1112 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1113 spec->input_mux = &cxt5045_capture_source;
1114 spec->num_init_verbs = 2;
1115 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1116 spec->mixers[0] = cxt5045_mixers;
1117 codec->patch_ops.init = cxt5045_init;
1120 case CXT5045_LAPTOP_HPMICSENSE:
1121 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1122 spec->input_mux = &cxt5045_capture_source;
1123 spec->num_init_verbs = 3;
1124 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1125 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1126 spec->mixers[0] = cxt5045_mixers;
1127 codec->patch_ops.init = cxt5045_init;
1130 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1131 spec->input_mux = &cxt5045_capture_source_benq;
1132 spec->num_init_verbs = 1;
1133 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1134 spec->mixers[0] = cxt5045_mixers;
1135 spec->mixers[1] = cxt5045_benq_mixers;
1136 spec->num_mixers = 2;
1137 codec->patch_ops.init = cxt5045_init;
1139 case CXT5045_LAPTOP_HP530:
1140 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1141 spec->input_mux = &cxt5045_capture_source_hp530;
1142 spec->num_init_verbs = 2;
1143 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1144 spec->mixers[0] = cxt5045_mixers_hp530;
1145 codec->patch_ops.init = cxt5045_init;
1147 #ifdef CONFIG_SND_DEBUG
1149 spec->input_mux = &cxt5045_test_capture_source;
1150 spec->mixers[0] = cxt5045_test_mixer;
1151 spec->init_verbs[0] = cxt5045_test_init_verbs;
1157 switch (codec->subsystem_id >> 16) {
1162 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1163 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1164 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1166 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1167 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1168 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1169 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1170 (1 << AC_AMPCAP_MUTE_SHIFT));
1175 snd_hda_attach_beep_device(codec, spec->beep_amp);
1181 /* Conexant 5047 specific */
1182 #define CXT5047_SPDIF_OUT 0x11
1184 static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1185 static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1186 static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1188 static const struct hda_channel_mode cxt5047_modes[1] = {
1192 static const struct hda_input_mux cxt5047_toshiba_capture_source = {
1200 /* turn on/off EAPD (+ mute HP) as a master switch */
1201 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1202 struct snd_ctl_elem_value *ucontrol)
1204 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1205 struct conexant_spec *spec = codec->spec;
1208 if (!cxt_eapd_put(kcontrol, ucontrol))
1211 /* toggle internal speakers mute depending of presence of
1212 * the headphone jack
1214 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1215 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1216 * pin widgets unlike other codecs. In this case, we need to
1217 * set index 0x01 for the volume from the mixer amp 0x19.
1219 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1220 HDA_AMP_MUTE, bits);
1221 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1222 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1223 HDA_AMP_MUTE, bits);
1227 /* mute internal speaker if HP is plugged */
1228 static void cxt5047_hp_automute(struct hda_codec *codec)
1230 struct conexant_spec *spec = codec->spec;
1233 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1235 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1236 /* See the note in cxt5047_hp_master_sw_put */
1237 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1238 HDA_AMP_MUTE, bits);
1241 /* toggle input of built-in and mic jack appropriately */
1242 static void cxt5047_hp_automic(struct hda_codec *codec)
1244 static const struct hda_verb mic_jack_on[] = {
1245 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1246 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1249 static const struct hda_verb mic_jack_off[] = {
1250 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1251 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1254 unsigned int present;
1256 present = snd_hda_jack_detect(codec, 0x15);
1258 snd_hda_sequence_write(codec, mic_jack_on);
1260 snd_hda_sequence_write(codec, mic_jack_off);
1263 /* unsolicited event for HP jack sensing */
1264 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1267 switch (res >> 26) {
1268 case CONEXANT_HP_EVENT:
1269 cxt5047_hp_automute(codec);
1271 case CONEXANT_MIC_EVENT:
1272 cxt5047_hp_automic(codec);
1277 static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1278 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1279 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1280 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1281 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1282 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1283 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1284 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1286 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1287 .name = "Master Playback Switch",
1288 .info = cxt_eapd_info,
1289 .get = cxt_eapd_get,
1290 .put = cxt5047_hp_master_sw_put,
1291 .private_value = 0x13,
1297 static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1298 /* See the note in cxt5047_hp_master_sw_put */
1299 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1300 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1304 static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1305 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1309 static const struct hda_verb cxt5047_init_verbs[] = {
1310 /* Line in, Mic, Built-in Mic */
1311 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1312 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1313 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1315 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1316 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1317 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1318 /* Record selector: Mic */
1319 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1320 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1321 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1322 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1323 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1324 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1325 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1326 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1327 /* SPDIF route: PCM */
1328 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1329 /* Enable unsolicited events */
1330 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1331 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1335 /* configuration for Toshiba Laptops */
1336 static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
1337 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1341 /* Test configuration for debugging, modelled after the ALC260 test
1344 #ifdef CONFIG_SND_DEBUG
1345 static const struct hda_input_mux cxt5047_test_capture_source = {
1348 { "LINE1 pin", 0x0 },
1349 { "MIC1 pin", 0x1 },
1350 { "MIC2 pin", 0x2 },
1355 static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1357 /* Output only controls */
1358 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1359 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1360 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1361 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1362 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1364 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1365 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1366 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1367 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1368 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1369 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1371 /* Modes for retasking pin widgets */
1372 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1373 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1375 /* EAPD Switch Control */
1376 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1378 /* Loopback mixer controls */
1379 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1380 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1381 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1382 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1383 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1384 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1385 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1386 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1388 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1389 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1390 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1391 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1392 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1393 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1394 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1395 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1397 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1398 .name = "Input Source",
1399 .info = conexant_mux_enum_info,
1400 .get = conexant_mux_enum_get,
1401 .put = conexant_mux_enum_put,
1403 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1408 static const struct hda_verb cxt5047_test_init_verbs[] = {
1409 /* Enable retasking pins as output, initially without power amp */
1410 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1411 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1412 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1414 /* Disable digital (SPDIF) pins initially, but users can enable
1415 * them via a mixer switch. In the case of SPDIF-out, this initverb
1416 * payload also sets the generation to 0, output to be in "consumer"
1417 * PCM format, copyright asserted, no pre-emphasis and no validity
1420 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1422 /* Ensure mic1, mic2, line1 pin widgets take input from the
1423 * OUT1 sum bus when acting as an output.
1425 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1426 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1428 /* Start with output sum widgets muted and their output gains at min */
1429 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1430 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1432 /* Unmute retasking pin widget output buffers since the default
1433 * state appears to be output. As the pin mode is changed by the
1434 * user the pin mode control will take care of enabling the pin's
1435 * input/output buffers as needed.
1437 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1438 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1439 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1441 /* Mute capture amp left and right */
1442 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1444 /* Set ADC connection select to match default mixer setting (mic1
1447 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1449 /* Mute all inputs to mixer widget (even unconnected ones) */
1450 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1451 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1452 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1453 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1454 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1455 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1456 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1457 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1464 /* initialize jack-sensing, too */
1465 static int cxt5047_hp_init(struct hda_codec *codec)
1467 conexant_init(codec);
1468 cxt5047_hp_automute(codec);
1474 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1475 CXT5047_LAPTOP_HP, /* Some HP laptops */
1476 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1477 #ifdef CONFIG_SND_DEBUG
1484 static const char * const cxt5047_models[CXT5047_MODELS] = {
1485 [CXT5047_LAPTOP] = "laptop",
1486 [CXT5047_LAPTOP_HP] = "laptop-hp",
1487 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1488 #ifdef CONFIG_SND_DEBUG
1489 [CXT5047_TEST] = "test",
1491 [CXT5047_AUTO] = "auto",
1494 static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1495 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1496 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1498 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1502 static int patch_cxt5047(struct hda_codec *codec)
1504 struct conexant_spec *spec;
1507 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1510 if (board_config < 0)
1511 board_config = CXT5047_AUTO; /* model=auto as default */
1512 if (board_config == CXT5047_AUTO)
1513 return patch_conexant_auto(codec);
1515 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1519 codec->pin_amp_workaround = 1;
1521 spec->multiout.max_channels = 2;
1522 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1523 spec->multiout.dac_nids = cxt5047_dac_nids;
1524 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1525 spec->num_adc_nids = 1;
1526 spec->adc_nids = cxt5047_adc_nids;
1527 spec->capsrc_nids = cxt5047_capsrc_nids;
1528 spec->num_mixers = 1;
1529 spec->mixers[0] = cxt5047_base_mixers;
1530 spec->num_init_verbs = 1;
1531 spec->init_verbs[0] = cxt5047_init_verbs;
1532 spec->spdif_route = 0;
1533 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1534 spec->channel_mode = cxt5047_modes,
1536 codec->patch_ops = conexant_patch_ops;
1538 switch (board_config) {
1539 case CXT5047_LAPTOP:
1540 spec->num_mixers = 2;
1541 spec->mixers[1] = cxt5047_hp_spk_mixers;
1542 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1544 case CXT5047_LAPTOP_HP:
1545 spec->num_mixers = 2;
1546 spec->mixers[1] = cxt5047_hp_only_mixers;
1547 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1548 codec->patch_ops.init = cxt5047_hp_init;
1550 case CXT5047_LAPTOP_EAPD:
1551 spec->input_mux = &cxt5047_toshiba_capture_source;
1552 spec->num_mixers = 2;
1553 spec->mixers[1] = cxt5047_hp_spk_mixers;
1554 spec->num_init_verbs = 2;
1555 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1556 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1558 #ifdef CONFIG_SND_DEBUG
1560 spec->input_mux = &cxt5047_test_capture_source;
1561 spec->mixers[0] = cxt5047_test_mixer;
1562 spec->init_verbs[0] = cxt5047_test_init_verbs;
1563 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1566 spec->vmaster_nid = 0x13;
1568 switch (codec->subsystem_id >> 16) {
1570 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1571 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1572 * with 0 dB offset 0x17)
1574 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1575 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1576 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1577 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1578 (1 << AC_AMPCAP_MUTE_SHIFT));
1585 /* Conexant 5051 specific */
1586 static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1587 static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1589 static const struct hda_channel_mode cxt5051_modes[1] = {
1593 static void cxt5051_update_speaker(struct hda_codec *codec)
1595 struct conexant_spec *spec = codec->spec;
1596 unsigned int pinctl;
1598 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1599 snd_hda_set_pin_ctl(codec, 0x16, pinctl);
1601 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1602 snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
1603 /* on ideapad there is an additional speaker (subwoofer) to mute */
1605 snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
1608 /* turn on/off EAPD (+ mute HP) as a master switch */
1609 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1610 struct snd_ctl_elem_value *ucontrol)
1612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1614 if (!cxt_eapd_put(kcontrol, ucontrol))
1616 cxt5051_update_speaker(codec);
1620 /* toggle input of built-in and mic jack appropriately */
1621 static void cxt5051_portb_automic(struct hda_codec *codec)
1623 struct conexant_spec *spec = codec->spec;
1624 unsigned int present;
1626 if (!(spec->auto_mic & AUTO_MIC_PORTB))
1628 present = snd_hda_jack_detect(codec, 0x17);
1629 snd_hda_codec_write(codec, 0x14, 0,
1630 AC_VERB_SET_CONNECT_SEL,
1631 present ? 0x01 : 0x00);
1634 /* switch the current ADC according to the jack state */
1635 static void cxt5051_portc_automic(struct hda_codec *codec)
1637 struct conexant_spec *spec = codec->spec;
1638 unsigned int present;
1641 if (!(spec->auto_mic & AUTO_MIC_PORTC))
1643 present = snd_hda_jack_detect(codec, 0x18);
1645 spec->cur_adc_idx = 1;
1647 spec->cur_adc_idx = 0;
1648 new_adc = spec->adc_nids[spec->cur_adc_idx];
1649 if (spec->cur_adc && spec->cur_adc != new_adc) {
1650 /* stream is running, let's swap the current ADC */
1651 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1652 spec->cur_adc = new_adc;
1653 snd_hda_codec_setup_stream(codec, new_adc,
1654 spec->cur_adc_stream_tag, 0,
1655 spec->cur_adc_format);
1659 /* mute internal speaker if HP is plugged */
1660 static void cxt5051_hp_automute(struct hda_codec *codec)
1662 struct conexant_spec *spec = codec->spec;
1664 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1665 cxt5051_update_speaker(codec);
1668 /* unsolicited event for HP jack sensing */
1669 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1672 switch (res >> 26) {
1673 case CONEXANT_HP_EVENT:
1674 cxt5051_hp_automute(codec);
1676 case CXT5051_PORTB_EVENT:
1677 cxt5051_portb_automic(codec);
1679 case CXT5051_PORTC_EVENT:
1680 cxt5051_portc_automic(codec);
1685 static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1686 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1688 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1689 .name = "Master Playback Switch",
1690 .info = cxt_eapd_info,
1691 .get = cxt_eapd_get,
1692 .put = cxt5051_hp_master_sw_put,
1693 .private_value = 0x1a,
1698 static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1699 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1700 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1701 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1702 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1703 HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1704 HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
1708 static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1709 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1710 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1711 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
1712 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1716 static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1717 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1718 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
1722 static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1723 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1724 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1728 static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1729 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1730 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1731 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
1732 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1736 static const struct hda_verb cxt5051_init_verbs[] = {
1738 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1739 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1740 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1741 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1742 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1743 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1745 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1746 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1748 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1749 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1751 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1752 /* Record selector: Internal mic */
1753 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1754 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1755 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1756 /* SPDIF route: PCM */
1757 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1758 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1760 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1761 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1765 static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1767 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1768 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1769 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1770 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1772 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1773 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1775 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1776 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1778 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1779 /* Record selector: Internal mic */
1780 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1781 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1782 /* SPDIF route: PCM */
1783 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1785 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1786 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1790 static const struct hda_verb cxt5051_f700_init_verbs[] = {
1792 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1793 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1794 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1795 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1797 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1798 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1800 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1801 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1803 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1804 /* Record selector: Internal mic */
1805 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1806 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1807 /* SPDIF route: PCM */
1808 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1810 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1811 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1815 static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1818 snd_hda_codec_write(codec, nid, 0,
1819 AC_VERB_SET_UNSOLICITED_ENABLE,
1820 AC_USRSP_EN | event);
1823 static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1825 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1826 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1830 /* initialize jack-sensing, too */
1831 static int cxt5051_init(struct hda_codec *codec)
1833 struct conexant_spec *spec = codec->spec;
1835 conexant_init(codec);
1837 if (spec->auto_mic & AUTO_MIC_PORTB)
1838 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1839 if (spec->auto_mic & AUTO_MIC_PORTC)
1840 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1842 if (codec->patch_ops.unsol_event) {
1843 cxt5051_hp_automute(codec);
1844 cxt5051_portb_automic(codec);
1845 cxt5051_portc_automic(codec);
1852 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1853 CXT5051_HP, /* no docking */
1854 CXT5051_HP_DV6736, /* HP without mic switch */
1855 CXT5051_F700, /* HP Compaq Presario F700 */
1856 CXT5051_TOSHIBA, /* Toshiba M300 & co */
1857 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
1858 CXT5051_AUTO, /* auto-parser */
1862 static const char *const cxt5051_models[CXT5051_MODELS] = {
1863 [CXT5051_LAPTOP] = "laptop",
1864 [CXT5051_HP] = "hp",
1865 [CXT5051_HP_DV6736] = "hp-dv6736",
1866 [CXT5051_F700] = "hp-700",
1867 [CXT5051_TOSHIBA] = "toshiba",
1868 [CXT5051_IDEAPAD] = "ideapad",
1869 [CXT5051_AUTO] = "auto",
1872 static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1873 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1874 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1875 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1876 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1877 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1879 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1880 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1884 static int patch_cxt5051(struct hda_codec *codec)
1886 struct conexant_spec *spec;
1889 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1892 if (board_config < 0)
1893 board_config = CXT5051_AUTO; /* model=auto as default */
1894 if (board_config == CXT5051_AUTO)
1895 return patch_conexant_auto(codec);
1897 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1901 codec->pin_amp_workaround = 1;
1903 codec->patch_ops = conexant_patch_ops;
1904 codec->patch_ops.init = cxt5051_init;
1906 spec->multiout.max_channels = 2;
1907 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1908 spec->multiout.dac_nids = cxt5051_dac_nids;
1909 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1910 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1911 spec->adc_nids = cxt5051_adc_nids;
1912 spec->num_mixers = 2;
1913 spec->mixers[0] = cxt5051_capture_mixers;
1914 spec->mixers[1] = cxt5051_playback_mixers;
1915 spec->num_init_verbs = 1;
1916 spec->init_verbs[0] = cxt5051_init_verbs;
1917 spec->spdif_route = 0;
1918 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1919 spec->channel_mode = cxt5051_modes;
1921 spec->cur_adc_idx = 0;
1923 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
1925 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1927 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
1928 switch (board_config) {
1930 spec->mixers[0] = cxt5051_hp_mixers;
1932 case CXT5051_HP_DV6736:
1933 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1934 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1938 spec->init_verbs[0] = cxt5051_f700_init_verbs;
1939 spec->mixers[0] = cxt5051_f700_mixers;
1942 case CXT5051_TOSHIBA:
1943 spec->mixers[0] = cxt5051_toshiba_mixers;
1944 spec->auto_mic = AUTO_MIC_PORTB;
1946 case CXT5051_IDEAPAD:
1947 spec->init_verbs[spec->num_init_verbs++] =
1948 cxt5051_ideapad_init_verbs;
1954 snd_hda_attach_beep_device(codec, spec->beep_amp);
1959 /* Conexant 5066 specific */
1961 static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1962 static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1963 static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1964 static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
1966 /* OLPC's microphone port is DC coupled for use with external sensors,
1967 * therefore we use a 50% mic bias in order to center the input signal with
1968 * the DC input range of the codec. */
1969 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1971 static const struct hda_channel_mode cxt5066_modes[1] = {
1975 #define HP_PRESENT_PORT_A (1 << 0)
1976 #define HP_PRESENT_PORT_D (1 << 1)
1977 #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
1978 #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
1980 static void cxt5066_update_speaker(struct hda_codec *codec)
1982 struct conexant_spec *spec = codec->spec;
1983 unsigned int pinctl;
1985 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
1986 spec->hp_present, spec->cur_eapd);
1989 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
1990 snd_hda_set_pin_ctl(codec, 0x19, pinctl);
1992 /* Port D (HP/LO) */
1993 pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
1994 if (spec->dell_automute || spec->thinkpad) {
1995 /* Mute if Port A is connected */
1996 if (hp_port_a_present(spec))
1999 /* Thinkpad/Dell doesn't give pin-D status */
2000 if (!hp_port_d_present(spec))
2003 snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
2006 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2007 snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
2010 /* turn on/off EAPD (+ mute HP) as a master switch */
2011 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2012 struct snd_ctl_elem_value *ucontrol)
2014 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2016 if (!cxt_eapd_put(kcontrol, ucontrol))
2019 cxt5066_update_speaker(codec);
2023 static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2027 { "50%", PIN_VREF50 },
2028 { "80%", PIN_VREF80 },
2032 static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2034 struct conexant_spec *spec = codec->spec;
2035 /* Even though port F is the DC input, the bias is controlled on port B.
2036 * we also leave that port as an active input (but unselected) in DC mode
2037 * just in case that is necessary to make the bias setting take effect. */
2038 return snd_hda_set_pin_ctl_cache(codec, 0x1a,
2039 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2042 /* OLPC defers mic widget control until when capture is started because the
2043 * microphone LED comes on as soon as these settings are put in place. if we
2044 * did this before recording, it would give the false indication that recording
2045 * is happening when it is not. */
2046 static void cxt5066_olpc_select_mic(struct hda_codec *codec)
2048 struct conexant_spec *spec = codec->spec;
2049 if (!spec->recording)
2052 if (spec->dc_enable) {
2053 /* in DC mode we ignore presence detection and just use the jack
2054 * through our special DC port */
2055 const struct hda_verb enable_dc_mode[] = {
2056 /* disble internal mic, port C */
2057 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2059 /* enable DC capture, port F */
2060 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2064 snd_hda_sequence_write(codec, enable_dc_mode);
2065 /* port B input disabled (and bias set) through the following call */
2066 cxt5066_set_olpc_dc_bias(codec);
2070 /* disable DC (port F) */
2071 snd_hda_set_pin_ctl(codec, 0x1e, 0);
2073 /* external mic, port B */
2074 snd_hda_set_pin_ctl(codec, 0x1a,
2075 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
2077 /* internal mic, port C */
2078 snd_hda_set_pin_ctl(codec, 0x1b,
2079 spec->ext_mic_present ? 0 : PIN_VREF80);
2082 /* toggle input of built-in and mic jack appropriately */
2083 static void cxt5066_olpc_automic(struct hda_codec *codec)
2085 struct conexant_spec *spec = codec->spec;
2086 unsigned int present;
2088 if (spec->dc_enable) /* don't do presence detection in DC mode */
2091 present = snd_hda_codec_read(codec, 0x1a, 0,
2092 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2094 snd_printdd("CXT5066: external microphone detected\n");
2096 snd_printdd("CXT5066: external microphone absent\n");
2098 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2100 spec->ext_mic_present = !!present;
2102 cxt5066_olpc_select_mic(codec);
2105 /* toggle input of built-in digital mic and mic jack appropriately */
2106 static void cxt5066_vostro_automic(struct hda_codec *codec)
2108 unsigned int present;
2110 struct hda_verb ext_mic_present[] = {
2111 /* enable external mic, port B */
2112 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2114 /* switch to external mic input */
2115 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2116 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2118 /* disable internal digital mic */
2119 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2122 static const struct hda_verb ext_mic_absent[] = {
2123 /* enable internal mic, port C */
2124 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2126 /* switch to internal mic input */
2127 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2129 /* disable external mic, port B */
2130 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2134 present = snd_hda_jack_detect(codec, 0x1a);
2136 snd_printdd("CXT5066: external microphone detected\n");
2137 snd_hda_sequence_write(codec, ext_mic_present);
2139 snd_printdd("CXT5066: external microphone absent\n");
2140 snd_hda_sequence_write(codec, ext_mic_absent);
2144 /* toggle input of built-in digital mic and mic jack appropriately */
2145 static void cxt5066_ideapad_automic(struct hda_codec *codec)
2147 unsigned int present;
2149 struct hda_verb ext_mic_present[] = {
2150 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2151 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2152 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2155 static const struct hda_verb ext_mic_absent[] = {
2156 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2157 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2158 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2162 present = snd_hda_jack_detect(codec, 0x1b);
2164 snd_printdd("CXT5066: external microphone detected\n");
2165 snd_hda_sequence_write(codec, ext_mic_present);
2167 snd_printdd("CXT5066: external microphone absent\n");
2168 snd_hda_sequence_write(codec, ext_mic_absent);
2173 /* toggle input of built-in digital mic and mic jack appropriately */
2174 static void cxt5066_asus_automic(struct hda_codec *codec)
2176 unsigned int present;
2178 present = snd_hda_jack_detect(codec, 0x1b);
2179 snd_printdd("CXT5066: external microphone present=%d\n", present);
2180 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2185 /* toggle input of built-in digital mic and mic jack appropriately */
2186 static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2188 unsigned int present;
2190 present = snd_hda_jack_detect(codec, 0x1b);
2191 snd_printdd("CXT5066: external microphone present=%d\n", present);
2192 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2197 /* toggle input of built-in digital mic and mic jack appropriately
2198 order is: external mic -> dock mic -> interal mic */
2199 static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2201 unsigned int ext_present, dock_present;
2203 static const struct hda_verb ext_mic_present[] = {
2204 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2205 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2206 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2207 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2208 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2211 static const struct hda_verb dock_mic_present[] = {
2212 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2213 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2214 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2215 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2216 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2219 static const struct hda_verb ext_mic_absent[] = {
2220 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2221 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2222 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2223 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2227 ext_present = snd_hda_jack_detect(codec, 0x1b);
2228 dock_present = snd_hda_jack_detect(codec, 0x1a);
2230 snd_printdd("CXT5066: external microphone detected\n");
2231 snd_hda_sequence_write(codec, ext_mic_present);
2232 } else if (dock_present) {
2233 snd_printdd("CXT5066: dock microphone detected\n");
2234 snd_hda_sequence_write(codec, dock_mic_present);
2236 snd_printdd("CXT5066: external microphone absent\n");
2237 snd_hda_sequence_write(codec, ext_mic_absent);
2241 /* mute internal speaker if HP is plugged */
2242 static void cxt5066_hp_automute(struct hda_codec *codec)
2244 struct conexant_spec *spec = codec->spec;
2245 unsigned int portA, portD;
2248 portA = snd_hda_jack_detect(codec, 0x19);
2251 portD = snd_hda_jack_detect(codec, 0x1c);
2253 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2254 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
2255 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2256 portA, portD, spec->hp_present);
2257 cxt5066_update_speaker(codec);
2260 /* Dispatch the right mic autoswitch function */
2261 static void cxt5066_automic(struct hda_codec *codec)
2263 struct conexant_spec *spec = codec->spec;
2265 if (spec->dell_vostro)
2266 cxt5066_vostro_automic(codec);
2267 else if (spec->ideapad)
2268 cxt5066_ideapad_automic(codec);
2269 else if (spec->thinkpad)
2270 cxt5066_thinkpad_automic(codec);
2271 else if (spec->hp_laptop)
2272 cxt5066_hp_laptop_automic(codec);
2273 else if (spec->asus)
2274 cxt5066_asus_automic(codec);
2277 /* unsolicited event for jack sensing */
2278 static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
2280 struct conexant_spec *spec = codec->spec;
2281 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2282 switch (res >> 26) {
2283 case CONEXANT_HP_EVENT:
2284 cxt5066_hp_automute(codec);
2286 case CONEXANT_MIC_EVENT:
2287 /* ignore mic events in DC mode; we're always using the jack */
2288 if (!spec->dc_enable)
2289 cxt5066_olpc_automic(codec);
2294 /* unsolicited event for jack sensing */
2295 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2297 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2298 switch (res >> 26) {
2299 case CONEXANT_HP_EVENT:
2300 cxt5066_hp_automute(codec);
2302 case CONEXANT_MIC_EVENT:
2303 cxt5066_automic(codec);
2309 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2320 static void cxt5066_set_mic_boost(struct hda_codec *codec)
2322 struct conexant_spec *spec = codec->spec;
2323 snd_hda_codec_write_cache(codec, 0x17, 0,
2324 AC_VERB_SET_AMP_GAIN_MUTE,
2325 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2326 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
2327 if (spec->ideapad || spec->thinkpad) {
2328 /* adjust the internal mic as well...it is not through 0x17 */
2329 snd_hda_codec_write_cache(codec, 0x23, 0,
2330 AC_VERB_SET_AMP_GAIN_MUTE,
2331 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2332 cxt5066_analog_mic_boost.
2333 items[spec->mic_boost].index);
2337 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2338 struct snd_ctl_elem_info *uinfo)
2340 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2343 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2344 struct snd_ctl_elem_value *ucontrol)
2346 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2347 struct conexant_spec *spec = codec->spec;
2348 ucontrol->value.enumerated.item[0] = spec->mic_boost;
2352 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2353 struct snd_ctl_elem_value *ucontrol)
2355 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2356 struct conexant_spec *spec = codec->spec;
2357 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2359 idx = ucontrol->value.enumerated.item[0];
2360 if (idx >= imux->num_items)
2361 idx = imux->num_items - 1;
2363 spec->mic_boost = idx;
2364 if (!spec->dc_enable)
2365 cxt5066_set_mic_boost(codec);
2369 static void cxt5066_enable_dc(struct hda_codec *codec)
2371 const struct hda_verb enable_dc_mode[] = {
2373 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2375 /* switch to DC input */
2376 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2380 /* configure as input source */
2381 snd_hda_sequence_write(codec, enable_dc_mode);
2382 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2385 static void cxt5066_disable_dc(struct hda_codec *codec)
2387 /* reconfigure input source */
2388 cxt5066_set_mic_boost(codec);
2389 /* automic also selects the right mic if we're recording */
2390 cxt5066_olpc_automic(codec);
2393 static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2394 struct snd_ctl_elem_value *ucontrol)
2396 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2397 struct conexant_spec *spec = codec->spec;
2398 ucontrol->value.integer.value[0] = spec->dc_enable;
2402 static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2403 struct snd_ctl_elem_value *ucontrol)
2405 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2406 struct conexant_spec *spec = codec->spec;
2407 int dc_enable = !!ucontrol->value.integer.value[0];
2409 if (dc_enable == spec->dc_enable)
2412 spec->dc_enable = dc_enable;
2414 cxt5066_enable_dc(codec);
2416 cxt5066_disable_dc(codec);
2421 static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2422 struct snd_ctl_elem_info *uinfo)
2424 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2427 static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2428 struct snd_ctl_elem_value *ucontrol)
2430 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2431 struct conexant_spec *spec = codec->spec;
2432 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2436 static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2437 struct snd_ctl_elem_value *ucontrol)
2439 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2440 struct conexant_spec *spec = codec->spec;
2441 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2444 idx = ucontrol->value.enumerated.item[0];
2445 if (idx >= imux->num_items)
2446 idx = imux->num_items - 1;
2448 spec->dc_input_bias = idx;
2449 if (spec->dc_enable)
2450 cxt5066_set_olpc_dc_bias(codec);
2454 static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2456 struct conexant_spec *spec = codec->spec;
2457 /* mark as recording and configure the microphone widget so that the
2458 * recording LED comes on. */
2459 spec->recording = 1;
2460 cxt5066_olpc_select_mic(codec);
2463 static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2465 struct conexant_spec *spec = codec->spec;
2466 const struct hda_verb disable_mics[] = {
2467 /* disable external mic, port B */
2468 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2470 /* disble internal mic, port C */
2471 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2473 /* disable DC capture, port F */
2474 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2478 snd_hda_sequence_write(codec, disable_mics);
2479 spec->recording = 0;
2482 static void conexant_check_dig_outs(struct hda_codec *codec,
2483 const hda_nid_t *dig_pins,
2486 struct conexant_spec *spec = codec->spec;
2487 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2490 for (i = 0; i < num_pins; i++, dig_pins++) {
2491 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2492 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2494 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2496 if (spec->slave_dig_outs[0])
2499 nid_loc = spec->slave_dig_outs;
2503 static const struct hda_input_mux cxt5066_capture_source = {
2513 static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2514 .ops = &snd_hda_bind_vol,
2516 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2517 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2522 static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2523 .ops = &snd_hda_bind_sw,
2525 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2526 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2531 static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
2532 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2536 static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2538 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2539 .name = "Master Playback Volume",
2540 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2541 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2542 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2543 .subdevice = HDA_SUBDEV_AMP_FLAG,
2544 .info = snd_hda_mixer_amp_volume_info,
2545 .get = snd_hda_mixer_amp_volume_get,
2546 .put = snd_hda_mixer_amp_volume_put,
2547 .tlv = { .c = snd_hda_mixer_amp_tlv },
2548 /* offset by 28 volume steps to limit minimum gain to -46dB */
2550 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2555 static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2557 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2558 .name = "DC Mode Enable Switch",
2559 .info = snd_ctl_boolean_mono_info,
2560 .get = cxt5066_olpc_dc_get,
2561 .put = cxt5066_olpc_dc_put,
2564 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2565 .name = "DC Input Bias Enum",
2566 .info = cxt5066_olpc_dc_bias_enum_info,
2567 .get = cxt5066_olpc_dc_bias_enum_get,
2568 .put = cxt5066_olpc_dc_bias_enum_put,
2573 static const struct snd_kcontrol_new cxt5066_mixers[] = {
2575 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2576 .name = "Master Playback Switch",
2577 .info = cxt_eapd_info,
2578 .get = cxt_eapd_get,
2579 .put = cxt5066_hp_master_sw_put,
2580 .private_value = 0x1d,
2584 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2585 .name = "Analog Mic Boost Capture Enum",
2586 .info = cxt5066_mic_boost_mux_enum_info,
2587 .get = cxt5066_mic_boost_mux_enum_get,
2588 .put = cxt5066_mic_boost_mux_enum_put,
2591 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2592 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2596 static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2598 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2599 .name = "Internal Mic Boost Capture Enum",
2600 .info = cxt5066_mic_boost_mux_enum_info,
2601 .get = cxt5066_mic_boost_mux_enum_get,
2602 .put = cxt5066_mic_boost_mux_enum_put,
2603 .private_value = 0x23 | 0x100,
2608 static const struct hda_verb cxt5066_init_verbs[] = {
2609 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2610 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2611 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2612 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2615 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2616 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2619 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2620 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2622 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2623 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2626 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2628 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2629 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2630 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2631 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2632 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2633 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2635 /* no digital microphone support yet */
2636 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2638 /* Audio input selector */
2639 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2641 /* SPDIF route: PCM */
2642 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2643 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2645 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2646 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2649 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2651 /* not handling these yet */
2652 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2653 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2654 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2655 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2656 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2657 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2658 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2659 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2663 static const struct hda_verb cxt5066_init_verbs_olpc[] = {
2664 /* Port A: headphones */
2665 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2666 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2668 /* Port B: external microphone */
2669 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2671 /* Port C: internal microphone */
2672 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2674 /* Port D: unused */
2675 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2677 /* Port E: unused, but has primary EAPD */
2678 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2679 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2681 /* Port F: external DC input through microphone port */
2682 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2684 /* Port G: internal speakers */
2685 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2686 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2689 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2692 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2694 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2695 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2696 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2697 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2698 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2699 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2700 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2701 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2702 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2703 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2704 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2705 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2707 /* Disable digital microphone port */
2708 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2710 /* Audio input selectors */
2711 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2712 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2715 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2716 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2718 /* enable unsolicited events for Port A and B */
2719 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2720 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2724 static const struct hda_verb cxt5066_init_verbs_vostro[] = {
2725 /* Port A: headphones */
2726 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2727 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2729 /* Port B: external microphone */
2730 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2732 /* Port C: unused */
2733 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2735 /* Port D: unused */
2736 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2738 /* Port E: unused, but has primary EAPD */
2739 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2740 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2742 /* Port F: unused */
2743 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2745 /* Port G: internal speakers */
2746 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2747 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2750 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2753 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2755 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2756 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2757 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2758 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2759 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2760 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2761 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2762 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2763 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2764 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2765 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2766 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2768 /* Digital microphone port */
2769 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2771 /* Audio input selectors */
2772 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2773 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2776 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2777 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2779 /* enable unsolicited events for Port A and B */
2780 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2781 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2785 static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2786 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2787 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2788 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2789 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2792 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2793 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2796 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2797 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2799 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2800 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2803 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2805 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2806 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2807 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2808 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2809 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2810 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2811 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2813 /* Audio input selector */
2814 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2815 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2817 /* SPDIF route: PCM */
2818 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2819 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2821 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2822 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2824 /* internal microphone */
2825 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2828 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2830 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2831 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2835 static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2836 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2837 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2839 /* Port G: internal speakers */
2840 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2841 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2843 /* Port A: HP, Amp */
2844 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2845 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2847 /* Port B: Mic Dock */
2848 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2851 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2853 /* Port D: HP Dock, Amp */
2854 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2855 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2858 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2860 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2861 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2862 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2863 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2864 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2865 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2866 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2868 /* Audio input selector */
2869 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2870 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2872 /* SPDIF route: PCM */
2873 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2874 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2876 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2877 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2879 /* internal microphone */
2880 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2883 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2885 /* enable unsolicited events for Port A, B, C and D */
2886 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2887 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2888 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2889 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2893 static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2894 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2899 static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2900 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2901 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2902 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2906 /* initialize jack-sensing, too */
2907 static int cxt5066_init(struct hda_codec *codec)
2909 snd_printdd("CXT5066: init\n");
2910 conexant_init(codec);
2911 if (codec->patch_ops.unsol_event) {
2912 cxt5066_hp_automute(codec);
2913 cxt5066_automic(codec);
2915 cxt5066_set_mic_boost(codec);
2919 static int cxt5066_olpc_init(struct hda_codec *codec)
2921 struct conexant_spec *spec = codec->spec;
2922 snd_printdd("CXT5066: init\n");
2923 conexant_init(codec);
2924 cxt5066_hp_automute(codec);
2925 if (!spec->dc_enable) {
2926 cxt5066_set_mic_boost(codec);
2927 cxt5066_olpc_automic(codec);
2929 cxt5066_enable_dc(codec);
2935 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2936 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2937 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
2938 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
2939 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
2940 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
2941 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
2942 CXT5066_HP_LAPTOP, /* HP Laptop */
2943 CXT5066_AUTO, /* BIOS auto-parser */
2947 static const char * const cxt5066_models[CXT5066_MODELS] = {
2948 [CXT5066_LAPTOP] = "laptop",
2949 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2950 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
2951 [CXT5066_DELL_VOSTRO] = "dell-vostro",
2952 [CXT5066_IDEAPAD] = "ideapad",
2953 [CXT5066_THINKPAD] = "thinkpad",
2954 [CXT5066_ASUS] = "asus",
2955 [CXT5066_HP_LAPTOP] = "hp-laptop",
2956 [CXT5066_AUTO] = "auto",
2959 static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2960 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
2961 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
2962 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
2963 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
2964 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
2965 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2966 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
2967 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
2968 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
2969 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
2970 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
2971 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
2972 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
2973 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2975 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
2976 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
2977 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
2978 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
2979 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
2980 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
2981 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
2982 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
2986 static int patch_cxt5066(struct hda_codec *codec)
2988 struct conexant_spec *spec;
2991 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2992 cxt5066_models, cxt5066_cfg_tbl);
2993 if (board_config < 0)
2994 board_config = CXT5066_AUTO; /* model=auto as default */
2995 if (board_config == CXT5066_AUTO)
2996 return patch_conexant_auto(codec);
2998 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3003 codec->patch_ops = conexant_patch_ops;
3004 codec->patch_ops.init = conexant_init;
3006 spec->dell_automute = 0;
3007 spec->multiout.max_channels = 2;
3008 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3009 spec->multiout.dac_nids = cxt5066_dac_nids;
3010 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3011 ARRAY_SIZE(cxt5066_digout_pin_nids));
3012 spec->num_adc_nids = 1;
3013 spec->adc_nids = cxt5066_adc_nids;
3014 spec->capsrc_nids = cxt5066_capsrc_nids;
3015 spec->input_mux = &cxt5066_capture_source;
3017 spec->port_d_mode = PIN_HP;
3019 spec->num_init_verbs = 1;
3020 spec->init_verbs[0] = cxt5066_init_verbs;
3021 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3022 spec->channel_mode = cxt5066_modes;
3024 spec->cur_adc_idx = 0;
3026 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3028 switch (board_config) {
3030 case CXT5066_LAPTOP:
3031 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3032 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3034 case CXT5066_DELL_LAPTOP:
3035 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3036 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3038 spec->port_d_mode = PIN_OUT;
3039 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3040 spec->num_init_verbs++;
3041 spec->dell_automute = 1;
3044 case CXT5066_HP_LAPTOP:
3045 codec->patch_ops.init = cxt5066_init;
3046 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3047 spec->init_verbs[spec->num_init_verbs] =
3048 cxt5066_init_verbs_hp_laptop;
3049 spec->num_init_verbs++;
3050 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3051 spec->asus = board_config == CXT5066_ASUS;
3052 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3053 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3055 if (board_config == CXT5066_HP_LAPTOP)
3056 spec->multiout.dig_out_nid = 0;
3057 /* input source automatically selected */
3058 spec->input_mux = NULL;
3059 spec->port_d_mode = 0;
3060 spec->mic_boost = 3; /* default 30dB gain */
3063 case CXT5066_OLPC_XO_1_5:
3064 codec->patch_ops.init = cxt5066_olpc_init;
3065 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
3066 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3067 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3068 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
3069 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3070 spec->port_d_mode = 0;
3071 spec->mic_boost = 3; /* default 30dB gain */
3074 spec->multiout.dig_out_nid = 0;
3076 /* input source automatically selected */
3077 spec->input_mux = NULL;
3079 /* our capture hooks which allow us to turn on the microphone LED
3080 * at the right time */
3081 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3082 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
3084 case CXT5066_DELL_VOSTRO:
3085 codec->patch_ops.init = cxt5066_init;
3086 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3087 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3088 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3089 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3090 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
3091 spec->port_d_mode = 0;
3092 spec->dell_vostro = 1;
3093 spec->mic_boost = 3; /* default 30dB gain */
3096 spec->multiout.dig_out_nid = 0;
3098 /* input source automatically selected */
3099 spec->input_mux = NULL;
3101 case CXT5066_IDEAPAD:
3102 codec->patch_ops.init = cxt5066_init;
3103 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3104 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3105 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3106 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3107 spec->port_d_mode = 0;
3109 spec->mic_boost = 2; /* default 20dB gain */
3112 spec->multiout.dig_out_nid = 0;
3114 /* input source automatically selected */
3115 spec->input_mux = NULL;
3117 case CXT5066_THINKPAD:
3118 codec->patch_ops.init = cxt5066_init;
3119 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3120 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3121 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3122 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3124 spec->port_d_mode = PIN_OUT;
3125 spec->mic_boost = 2; /* default 20dB gain */
3128 spec->multiout.dig_out_nid = 0;
3130 /* input source automatically selected */
3131 spec->input_mux = NULL;
3136 snd_hda_attach_beep_device(codec, spec->beep_amp);
3142 * Automatic parser for CX20641 & co
3145 static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3146 struct hda_codec *codec,
3147 unsigned int stream_tag,
3148 unsigned int format,
3149 struct snd_pcm_substream *substream)
3151 struct conexant_spec *spec = codec->spec;
3152 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
3153 if (spec->adc_switching) {
3154 spec->cur_adc = adc;
3155 spec->cur_adc_stream_tag = stream_tag;
3156 spec->cur_adc_format = format;
3158 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3162 static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3163 struct hda_codec *codec,
3164 struct snd_pcm_substream *substream)
3166 struct conexant_spec *spec = codec->spec;
3167 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3172 static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3176 .nid = 0, /* fill later */
3178 .prepare = cx_auto_capture_pcm_prepare,
3179 .cleanup = cx_auto_capture_pcm_cleanup
3183 static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3185 #define get_connection_index(codec, mux, nid)\
3186 snd_hda_get_conn_index(codec, mux, nid, 0)
3188 /* get an unassigned DAC from the given list.
3189 * Return the nid if found and reduce the DAC list, or return zero if
3192 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3193 hda_nid_t *dacs, int *num_dacs)
3195 int i, nums = *num_dacs;
3198 for (i = 0; i < nums; i++) {
3199 if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3207 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3212 #define MAX_AUTO_DACS 5
3214 #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3216 /* fill analog DAC list from the widget tree */
3217 static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3219 hda_nid_t nid, end_nid;
3222 end_nid = codec->start_nid + codec->num_nodes;
3223 for (nid = codec->start_nid; nid < end_nid; nid++) {
3224 unsigned int wcaps = get_wcaps(codec, nid);
3225 unsigned int type = get_wcaps_type(wcaps);
3226 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3228 if (nums >= MAX_AUTO_DACS)
3235 /* fill pin_dac_pair list from the pin and dac list */
3236 static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3237 int num_pins, hda_nid_t *dacs, int *rest,
3238 struct pin_dac_pair *filled, int nums,
3241 int i, start = nums;
3243 for (i = 0; i < num_pins; i++, nums++) {
3244 filled[nums].pin = pins[i];
3245 filled[nums].type = type;
3246 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3247 if (filled[nums].dac)
3249 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3250 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3253 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
3254 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
3257 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
3262 /* parse analog output paths */
3263 static void cx_auto_parse_output(struct hda_codec *codec)
3265 struct conexant_spec *spec = codec->spec;
3266 struct auto_pin_cfg *cfg = &spec->autocfg;
3267 hda_nid_t dacs[MAX_AUTO_DACS];
3268 int i, j, nums, rest;
3270 rest = fill_cx_auto_dacs(codec, dacs);
3271 /* parse all analog output pins */
3272 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3273 dacs, &rest, spec->dac_info, 0,
3275 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3276 dacs, &rest, spec->dac_info, nums,
3278 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3279 dacs, &rest, spec->dac_info, nums,
3280 AUTO_PIN_SPEAKER_OUT);
3281 spec->dac_info_filled = nums;
3282 /* fill multiout struct */
3283 for (i = 0; i < nums; i++) {
3284 hda_nid_t dac = spec->dac_info[i].dac;
3285 if (!dac || (dac & DAC_SLAVE_FLAG))
3287 switch (spec->dac_info[i].type) {
3288 case AUTO_PIN_LINE_OUT:
3289 spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3290 spec->multiout.num_dacs++;
3292 case AUTO_PIN_HP_OUT:
3293 case AUTO_PIN_SPEAKER_OUT:
3294 if (!spec->multiout.hp_nid) {
3295 spec->multiout.hp_nid = dac;
3298 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3299 if (!spec->multiout.extra_out_nid[j]) {
3300 spec->multiout.extra_out_nid[j] = dac;
3306 spec->multiout.dac_nids = spec->private_dac_nids;
3307 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3309 for (i = 0; i < cfg->hp_outs; i++) {
3310 if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3311 spec->auto_mute = 1;
3315 if (spec->auto_mute &&
3316 cfg->line_out_pins[0] &&
3317 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
3318 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
3319 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
3320 for (i = 0; i < cfg->line_outs; i++) {
3321 if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
3322 spec->detect_line = 1;
3326 spec->automute_lines = spec->detect_line;
3329 spec->vmaster_nid = spec->private_dac_nids[0];
3332 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3333 hda_nid_t *pins, bool on);
3335 static void do_automute(struct hda_codec *codec, int num_pins,
3336 hda_nid_t *pins, bool on)
3338 struct conexant_spec *spec = codec->spec;
3340 for (i = 0; i < num_pins; i++)
3341 snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0);
3342 if (spec->pin_eapd_ctrls)
3343 cx_auto_turn_eapd(codec, num_pins, pins, on);
3346 static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3350 for (i = 0; i < num_pins; i++) {
3351 hda_nid_t nid = pins[i];
3352 if (!nid || !is_jack_detectable(codec, nid))
3354 present |= snd_hda_jack_detect(codec, nid);
3359 /* auto-mute/unmute speaker and line outs according to headphone jack */
3360 static void cx_auto_update_speakers(struct hda_codec *codec)
3362 struct conexant_spec *spec = codec->spec;
3363 struct auto_pin_cfg *cfg = &spec->autocfg;
3366 /* turn on HP EAPD when HP jacks are present */
3367 if (spec->pin_eapd_ctrls) {
3368 if (spec->auto_mute)
3369 on = spec->hp_present;
3370 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3373 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3374 if (spec->auto_mute)
3375 on = !(spec->hp_present ||
3376 (spec->detect_line && spec->line_present));
3377 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
3379 /* toggle line-out mutes if needed, too */
3380 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3381 if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
3382 cfg->line_out_pins[0] == cfg->speaker_pins[0])
3384 if (spec->auto_mute) {
3385 /* mute LO in auto-mode when HP jack is present */
3386 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3387 spec->automute_lines)
3388 on = !spec->hp_present;
3392 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
3395 static void cx_auto_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3397 struct conexant_spec *spec = codec->spec;
3398 struct auto_pin_cfg *cfg = &spec->autocfg;
3400 if (!spec->auto_mute)
3402 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
3403 cx_auto_update_speakers(codec);
3406 static void cx_auto_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
3408 struct conexant_spec *spec = codec->spec;
3409 struct auto_pin_cfg *cfg = &spec->autocfg;
3411 if (!spec->auto_mute || !spec->detect_line)
3413 spec->line_present = detect_jacks(codec, cfg->line_outs,
3414 cfg->line_out_pins);
3415 cx_auto_update_speakers(codec);
3418 static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
3419 struct snd_ctl_elem_info *uinfo)
3421 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3422 struct conexant_spec *spec = codec->spec;
3423 static const char * const texts3[] = {
3424 "Disabled", "Speaker Only", "Line Out+Speaker"
3427 if (spec->automute_hp_lo)
3428 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
3429 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
3432 static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
3433 struct snd_ctl_elem_value *ucontrol)
3435 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3436 struct conexant_spec *spec = codec->spec;
3438 if (!spec->auto_mute)
3440 else if (!spec->automute_lines)
3444 ucontrol->value.enumerated.item[0] = val;
3448 static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
3449 struct snd_ctl_elem_value *ucontrol)
3451 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3452 struct conexant_spec *spec = codec->spec;
3454 switch (ucontrol->value.enumerated.item[0]) {
3456 if (!spec->auto_mute)
3458 spec->auto_mute = 0;
3461 if (spec->auto_mute && !spec->automute_lines)
3463 spec->auto_mute = 1;
3464 spec->automute_lines = 0;
3467 if (!spec->automute_hp_lo)
3469 if (spec->auto_mute && spec->automute_lines)
3471 spec->auto_mute = 1;
3472 spec->automute_lines = 1;
3477 cx_auto_update_speakers(codec);
3481 static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
3483 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3484 .name = "Auto-Mute Mode",
3485 .info = cx_automute_mode_info,
3486 .get = cx_automute_mode_get,
3487 .put = cx_automute_mode_put,
3492 static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3493 struct snd_ctl_elem_info *uinfo)
3495 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3496 struct conexant_spec *spec = codec->spec;
3498 return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3501 static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3502 struct snd_ctl_elem_value *ucontrol)
3504 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3505 struct conexant_spec *spec = codec->spec;
3507 ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3511 /* look for the route the given pin from mux and return the index;
3512 * if do_select is set, actually select the route.
3514 static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3515 hda_nid_t pin, hda_nid_t *srcp,
3516 bool do_select, int depth)
3518 struct conexant_spec *spec = codec->spec;
3519 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3520 int startidx, i, nums;
3522 switch (get_wcaps_type(get_wcaps(codec, mux))) {
3524 case AC_WID_AUD_SEL:
3525 case AC_WID_AUD_MIX:
3531 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3532 for (i = 0; i < nums; i++)
3533 if (conn[i] == pin) {
3535 snd_hda_codec_write(codec, mux, 0,
3536 AC_VERB_SET_CONNECT_SEL, i);
3545 /* Try to rotate around connections to avoid one boost controlling
3546 another input path as well */
3548 for (i = 0; i < spec->private_imux.num_items; i++)
3549 if (spec->imux_info[i].pin == pin) {
3554 for (i = 0; i < nums; i++) {
3555 int j = (i + startidx) % nums;
3556 int ret = __select_input_connection(codec, conn[j], pin, srcp,
3560 snd_hda_codec_write(codec, mux, 0,
3561 AC_VERB_SET_CONNECT_SEL, j);
3568 static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3571 __select_input_connection(codec, mux, pin, NULL, true, 0);
3574 static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
3577 return __select_input_connection(codec, mux, pin, NULL, false, 0);
3580 static int cx_auto_mux_enum_update(struct hda_codec *codec,
3581 const struct hda_input_mux *imux,
3584 struct conexant_spec *spec = codec->spec;
3588 if (!imux->num_items)
3590 if (idx >= imux->num_items)
3591 idx = imux->num_items - 1;
3592 if (spec->cur_mux[0] == idx)
3594 adc = spec->imux_info[idx].adc;
3595 select_input_connection(codec, spec->imux_info[idx].adc,
3596 spec->imux_info[idx].pin);
3597 if (spec->cur_adc && spec->cur_adc != adc) {
3598 /* stream is running, let's swap the current ADC */
3599 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3600 spec->cur_adc = adc;
3601 snd_hda_codec_setup_stream(codec, adc,
3602 spec->cur_adc_stream_tag, 0,
3603 spec->cur_adc_format);
3605 spec->cur_mux[0] = idx;
3609 static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3610 struct snd_ctl_elem_value *ucontrol)
3612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3613 struct conexant_spec *spec = codec->spec;
3615 return cx_auto_mux_enum_update(codec, &spec->private_imux,
3616 ucontrol->value.enumerated.item[0]);
3619 static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3621 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3622 .name = "Capture Source",
3623 .info = cx_auto_mux_enum_info,
3624 .get = cx_auto_mux_enum_get,
3625 .put = cx_auto_mux_enum_put
3630 static bool select_automic(struct hda_codec *codec, int idx, bool detect)
3632 struct conexant_spec *spec = codec->spec;
3635 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
3637 cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
3641 /* automatic switch internal and external mic */
3642 static void cx_auto_automic(struct hda_codec *codec, struct hda_jack_tbl *jack)
3644 struct conexant_spec *spec = codec->spec;
3646 if (!spec->auto_mic)
3648 if (!select_automic(codec, spec->auto_mic_ext, true))
3649 if (!select_automic(codec, spec->auto_mic_dock, true))
3650 select_automic(codec, spec->auto_mic_int, false);
3653 /* check whether the pin config is suitable for auto-mic switching;
3654 * auto-mic is enabled only when one int-mic and one ext- and/or
3655 * one dock-mic exist
3657 static void cx_auto_check_auto_mic(struct hda_codec *codec)
3659 struct conexant_spec *spec = codec->spec;
3660 int pset[INPUT_PIN_ATTR_NORMAL + 1];
3663 for (i = 0; i < ARRAY_SIZE(pset); i++)
3665 for (i = 0; i < spec->private_imux.num_items; i++) {
3666 hda_nid_t pin = spec->imux_info[i].pin;
3667 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3669 attr = snd_hda_get_input_pin_attr(def_conf);
3670 if (attr == INPUT_PIN_ATTR_UNUSED)
3671 return; /* invalid entry */
3672 if (attr > INPUT_PIN_ATTR_NORMAL)
3673 attr = INPUT_PIN_ATTR_NORMAL;
3674 if (attr != INPUT_PIN_ATTR_INT &&
3675 !is_jack_detectable(codec, pin))
3676 return; /* non-detectable pin */
3677 type = get_defcfg_device(def_conf);
3678 if (type != AC_JACK_MIC_IN &&
3679 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3680 return; /* no valid input type */
3681 if (pset[attr] >= 0)
3682 return; /* already occupied */
3685 if (pset[INPUT_PIN_ATTR_INT] < 0 ||
3686 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
3687 return; /* no input to switch*/
3689 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
3690 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
3691 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
3694 static void cx_auto_parse_input(struct hda_codec *codec)
3696 struct conexant_spec *spec = codec->spec;
3697 struct auto_pin_cfg *cfg = &spec->autocfg;
3698 struct hda_input_mux *imux;
3701 imux = &spec->private_imux;
3702 for (i = 0; i < cfg->num_inputs; i++) {
3703 for (j = 0; j < spec->num_adc_nids; j++) {
3704 hda_nid_t adc = spec->adc_nids[j];
3705 int idx = get_input_connection(codec, adc,
3706 cfg->inputs[i].pin);
3709 label = hda_get_autocfg_input_label(codec, cfg, i);
3710 spec->imux_info[imux->num_items].index = i;
3711 spec->imux_info[imux->num_items].boost = 0;
3712 spec->imux_info[imux->num_items].adc = adc;
3713 spec->imux_info[imux->num_items].pin =
3715 snd_hda_add_imux_item(imux, label, idx, NULL);
3720 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
3721 cx_auto_check_auto_mic(codec);
3722 if (imux->num_items > 1) {
3723 for (i = 1; i < imux->num_items; i++) {
3724 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
3725 spec->adc_switching = 1;
3732 /* get digital-input audio widget corresponding to the given pin */
3733 static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3735 hda_nid_t nid, end_nid;
3737 end_nid = codec->start_nid + codec->num_nodes;
3738 for (nid = codec->start_nid; nid < end_nid; nid++) {
3739 unsigned int wcaps = get_wcaps(codec, nid);
3740 unsigned int type = get_wcaps_type(wcaps);
3741 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3742 if (get_connection_index(codec, nid, pin) >= 0)
3749 static void cx_auto_parse_digital(struct hda_codec *codec)
3751 struct conexant_spec *spec = codec->spec;
3752 struct auto_pin_cfg *cfg = &spec->autocfg;
3755 if (cfg->dig_outs &&
3756 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3757 spec->multiout.dig_out_nid = nid;
3758 if (cfg->dig_in_pin)
3759 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3762 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3763 static void cx_auto_parse_beep(struct hda_codec *codec)
3765 struct conexant_spec *spec = codec->spec;
3766 hda_nid_t nid, end_nid;
3768 end_nid = codec->start_nid + codec->num_nodes;
3769 for (nid = codec->start_nid; nid < end_nid; nid++)
3770 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3771 set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3776 #define cx_auto_parse_beep(codec)
3780 static void cx_auto_parse_eapd(struct hda_codec *codec)
3782 struct conexant_spec *spec = codec->spec;
3783 hda_nid_t nid, end_nid;
3785 end_nid = codec->start_nid + codec->num_nodes;
3786 for (nid = codec->start_nid; nid < end_nid; nid++) {
3787 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3789 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3791 spec->eapds[spec->num_eapds++] = nid;
3792 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3796 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3797 * it's a new chip, where EAPDs are supposed to be associated to
3798 * pins, and we can control EAPD per pin.
3799 * OTOH, if only one or two EAPDs are found, it's an old chip,
3800 * thus it might control over all pins.
3802 spec->pin_eapd_ctrls = spec->num_eapds > 2;
3805 static int cx_auto_parse_auto_config(struct hda_codec *codec)
3807 struct conexant_spec *spec = codec->spec;
3810 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3814 cx_auto_parse_output(codec);
3815 cx_auto_parse_input(codec);
3816 cx_auto_parse_digital(codec);
3817 cx_auto_parse_beep(codec);
3818 cx_auto_parse_eapd(codec);
3822 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3823 hda_nid_t *pins, bool on)
3826 for (i = 0; i < num_pins; i++) {
3827 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3828 snd_hda_codec_write(codec, pins[i], 0,
3829 AC_VERB_SET_EAPD_BTLENABLE,
3834 static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3837 int idx = get_connection_index(codec, pin, src);
3839 snd_hda_codec_write(codec, pin, 0,
3840 AC_VERB_SET_CONNECT_SEL, idx);
3843 static void mute_outputs(struct hda_codec *codec, int num_nids,
3844 const hda_nid_t *nids)
3848 for (i = 0; i < num_nids; i++) {
3849 hda_nid_t nid = nids[i];
3850 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
3852 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
3856 snd_hda_codec_write(codec, nid, 0,
3857 AC_VERB_SET_AMP_GAIN_MUTE, val);
3861 static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3862 hda_nid_t *pins, unsigned int action,
3863 hda_jack_callback cb)
3866 for (i = 0; i < num_pins; i++)
3867 snd_hda_jack_detect_enable_callback(codec, pins[i], action, cb);
3870 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3873 for (i = 0; i < nums; i++)
3879 /* is the given NID found in any of autocfg items? */
3880 static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid)
3884 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3885 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3886 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) ||
3887 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs))
3889 for (i = 0; i < cfg->num_inputs; i++)
3890 if (cfg->inputs[i].pin == nid)
3892 if (cfg->dig_in_pin == nid)
3897 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
3898 * invalid unsol tags by some reason
3900 static void clear_unsol_on_unused_pins(struct hda_codec *codec)
3902 struct conexant_spec *spec = codec->spec;
3903 struct auto_pin_cfg *cfg = &spec->autocfg;
3906 for (i = 0; i < codec->init_pins.used; i++) {
3907 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
3908 if (!found_in_autocfg(cfg, pin->nid))
3909 snd_hda_codec_write(codec, pin->nid, 0,
3910 AC_VERB_SET_UNSOLICITED_ENABLE, 0);
3914 /* turn on/off EAPD according to Master switch */
3915 static void cx_auto_vmaster_hook(void *private_data, int enabled)
3917 struct hda_codec *codec = private_data;
3918 struct conexant_spec *spec = codec->spec;
3920 if (enabled && spec->pin_eapd_ctrls) {
3921 cx_auto_update_speakers(codec);
3924 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3927 static void cx_auto_init_output(struct hda_codec *codec)
3929 struct conexant_spec *spec = codec->spec;
3930 struct auto_pin_cfg *cfg = &spec->autocfg;
3934 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
3935 for (i = 0; i < cfg->hp_outs; i++) {
3936 unsigned int val = PIN_OUT;
3937 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) &
3939 val |= AC_PINCTL_HP_EN;
3940 snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val);
3942 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
3943 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
3944 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
3945 for (i = 0; i < spec->dac_info_filled; i++) {
3946 nid = spec->dac_info[i].dac;
3948 nid = spec->multiout.dac_nids[0];
3949 else if (nid & DAC_SLAVE_FLAG)
3950 nid &= ~DAC_SLAVE_FLAG;
3951 select_connection(codec, spec->dac_info[i].pin, nid);
3953 if (spec->auto_mute) {
3954 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
3955 CONEXANT_HP_EVENT, cx_auto_hp_automute);
3956 spec->hp_present = detect_jacks(codec, cfg->hp_outs,
3958 if (spec->detect_line) {
3959 enable_unsol_pins(codec, cfg->line_outs,
3961 CONEXANT_LINE_EVENT,
3962 cx_auto_line_automute);
3963 spec->line_present =
3964 detect_jacks(codec, cfg->line_outs,
3965 cfg->line_out_pins);
3968 cx_auto_update_speakers(codec);
3969 /* turn on all EAPDs if no individual EAPD control is available */
3970 if (!spec->pin_eapd_ctrls)
3971 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
3972 clear_unsol_on_unused_pins(codec);
3975 static void cx_auto_init_input(struct hda_codec *codec)
3977 struct conexant_spec *spec = codec->spec;
3978 struct auto_pin_cfg *cfg = &spec->autocfg;
3981 for (i = 0; i < spec->num_adc_nids; i++) {
3982 hda_nid_t nid = spec->adc_nids[i];
3983 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
3985 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
3986 val = AMP_IN_MUTE(0);
3988 val = AMP_IN_UNMUTE(0);
3989 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3993 for (i = 0; i < cfg->num_inputs; i++) {
3994 hda_nid_t pin = cfg->inputs[i].pin;
3995 unsigned int type = PIN_IN;
3996 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3997 type |= snd_hda_get_default_vref(codec, pin);
3998 snd_hda_set_pin_ctl(codec, pin, type);
4001 if (spec->auto_mic) {
4002 if (spec->auto_mic_ext >= 0) {
4003 snd_hda_jack_detect_enable_callback(codec,
4004 cfg->inputs[spec->auto_mic_ext].pin,
4005 CONEXANT_MIC_EVENT, cx_auto_automic);
4007 if (spec->auto_mic_dock >= 0) {
4008 snd_hda_jack_detect_enable_callback(codec,
4009 cfg->inputs[spec->auto_mic_dock].pin,
4010 CONEXANT_MIC_EVENT, cx_auto_automic);
4012 cx_auto_automic(codec, NULL);
4014 select_input_connection(codec, spec->imux_info[0].adc,
4015 spec->imux_info[0].pin);
4019 static void cx_auto_init_digital(struct hda_codec *codec)
4021 struct conexant_spec *spec = codec->spec;
4022 struct auto_pin_cfg *cfg = &spec->autocfg;
4024 if (spec->multiout.dig_out_nid)
4025 snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT);
4026 if (spec->dig_in_nid)
4027 snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN);
4030 static int cx_auto_init(struct hda_codec *codec)
4032 struct conexant_spec *spec = codec->spec;
4033 snd_hda_apply_verbs(codec);
4034 cx_auto_init_output(codec);
4035 cx_auto_init_input(codec);
4036 cx_auto_init_digital(codec);
4037 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4041 static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
4042 const char *dir, int cidx,
4043 hda_nid_t nid, int hda_dir, int amp_idx, int chs)
4045 static char name[44];
4046 static struct snd_kcontrol_new knew[] = {
4047 HDA_CODEC_VOLUME(name, 0, 0, 0),
4048 HDA_CODEC_MUTE(name, 0, 0, 0),
4050 static const char * const sfx[2] = { "Volume", "Switch" };
4053 for (i = 0; i < 2; i++) {
4054 struct snd_kcontrol *kctl;
4055 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx,
4057 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4058 knew[i].index = cidx;
4059 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4060 kctl = snd_ctl_new1(&knew[i], codec);
4063 err = snd_hda_ctl_add(codec, nid, kctl);
4066 if (!(query_amp_caps(codec, nid, hda_dir) &
4067 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE)))
4073 #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
4074 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3)
4076 #define cx_auto_add_pb_volume(codec, nid, str, idx) \
4077 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4079 static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4080 hda_nid_t pin, const char *name, int idx)
4083 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4084 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4085 if (caps & AC_AMPCAP_NUM_STEPS)
4086 return cx_auto_add_pb_volume(codec, dac, name, idx);
4088 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4089 if (caps & AC_AMPCAP_NUM_STEPS)
4090 return cx_auto_add_pb_volume(codec, pin, name, idx);
4094 static bool is_2_1_speaker(struct conexant_spec *spec)
4096 int i, type, num_spk = 0;
4098 for (i = 0; i < spec->dac_info_filled; i++) {
4099 type = spec->dac_info[i].type;
4100 if (type == AUTO_PIN_LINE_OUT)
4101 type = spec->autocfg.line_out_type;
4102 if (type == AUTO_PIN_SPEAKER_OUT)
4105 return (num_spk == 2 && spec->autocfg.line_out_type != AUTO_PIN_LINE_OUT);
4108 static int cx_auto_build_output_controls(struct hda_codec *codec)
4110 struct conexant_spec *spec = codec->spec;
4112 int num_line = 0, num_hp = 0, num_spk = 0;
4114 static const char * const texts[3] = { "Front", "Surround", "CLFE" };
4116 if (spec->dac_info_filled == 1)
4117 return try_add_pb_volume(codec, spec->dac_info[0].dac,
4118 spec->dac_info[0].pin,
4121 speaker_2_1 = is_2_1_speaker(spec);
4123 for (i = 0; i < spec->dac_info_filled; i++) {
4126 hda_nid_t dac = spec->dac_info[i].dac;
4127 type = spec->dac_info[i].type;
4128 if (type == AUTO_PIN_LINE_OUT)
4129 type = spec->autocfg.line_out_type;
4131 case AUTO_PIN_LINE_OUT:
4133 label = texts[num_line++];
4136 case AUTO_PIN_HP_OUT:
4137 label = "Headphone";
4140 case AUTO_PIN_SPEAKER_OUT:
4142 label = num_spk++ ? "Bass Speaker" : "Speaker";
4150 err = try_add_pb_volume(codec, dac,
4151 spec->dac_info[i].pin,
4157 if (spec->auto_mute) {
4158 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
4166 /* Returns zero if this is a normal stereo channel, and non-zero if it should
4167 be split in two independent channels.
4168 dest_label must be at least 44 characters. */
4169 static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label,
4170 char *dest_label, int nid)
4172 struct conexant_spec *spec = codec->spec;
4175 if (!spec->fixup_stereo_dmic)
4178 for (i = 0; i < AUTO_CFG_MAX_INS; i++) {
4180 if (spec->autocfg.inputs[i].pin != nid)
4183 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC)
4185 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4186 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT)
4189 /* Finally found the inverted internal mic! */
4190 snprintf(dest_label, 44, "Inverted %s", label);
4196 static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4197 const char *label, const char *pfx,
4200 struct conexant_spec *spec = codec->spec;
4203 for (i = 0; i < spec->num_adc_nids; i++) {
4204 char rightch_label[44];
4205 hda_nid_t adc_nid = spec->adc_nids[i];
4206 int idx = get_input_connection(codec, adc_nid, nid);
4209 if (codec->single_adc_amp)
4212 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4213 /* Make two independent kcontrols for left and right */
4214 int err = cx_auto_add_volume_idx(codec, label, pfx,
4215 cidx, adc_nid, HDA_INPUT, idx, 1);
4218 return cx_auto_add_volume_idx(codec, rightch_label, pfx,
4219 cidx, adc_nid, HDA_INPUT, idx, 2);
4221 return cx_auto_add_volume_idx(codec, label, pfx,
4222 cidx, adc_nid, HDA_INPUT, idx, 3);
4227 static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4228 const char *label, int cidx)
4230 struct conexant_spec *spec = codec->spec;
4234 nid = spec->imux_info[idx].pin;
4235 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4236 char rightch_label[44];
4237 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) {
4238 int err = cx_auto_add_volume_idx(codec, label, " Boost",
4239 cidx, nid, HDA_INPUT, 0, 1);
4242 return cx_auto_add_volume_idx(codec, rightch_label, " Boost",
4243 cidx, nid, HDA_INPUT, 0, 2);
4245 return cx_auto_add_volume(codec, label, " Boost", cidx,
4248 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
4252 for (i = 0; i < idx; i++) {
4253 if (spec->imux_info[i].boost == mux)
4254 return 0; /* already present */
4257 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
4258 spec->imux_info[idx].boost = mux;
4259 return cx_auto_add_volume(codec, label, " Boost", cidx,
4265 static int cx_auto_build_input_controls(struct hda_codec *codec)
4267 struct conexant_spec *spec = codec->spec;
4268 struct hda_input_mux *imux = &spec->private_imux;
4269 const char *prev_label;
4270 int input_conn[HDA_MAX_NUM_INPUTS];
4271 int i, j, err, cidx;
4272 int multi_connection;
4274 if (!imux->num_items)
4277 multi_connection = 0;
4278 for (i = 0; i < imux->num_items; i++) {
4279 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4280 spec->imux_info[i].pin);
4283 input_conn[i] = spec->imux_info[i].adc;
4284 if (!codec->single_adc_amp)
4285 input_conn[i] |= cidx << 8;
4286 if (i > 0 && input_conn[i] != input_conn[0])
4287 multi_connection = 1;
4292 for (i = 0; i < imux->num_items; i++) {
4293 hda_nid_t nid = spec->imux_info[i].pin;
4296 label = hda_get_autocfg_input_label(codec, &spec->autocfg,
4297 spec->imux_info[i].index);
4298 if (label == prev_label)
4304 err = cx_auto_add_boost_volume(codec, i, label, cidx);
4308 if (!multi_connection) {
4311 err = cx_auto_add_capture_volume(codec, nid,
4312 "Capture", "", cidx);
4314 bool dup_found = false;
4315 for (j = 0; j < i; j++) {
4316 if (input_conn[j] == input_conn[i]) {
4323 err = cx_auto_add_capture_volume(codec, nid,
4324 label, " Capture", cidx);
4330 if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
4331 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
4339 static int cx_auto_build_controls(struct hda_codec *codec)
4341 struct conexant_spec *spec = codec->spec;
4344 err = cx_auto_build_output_controls(codec);
4347 err = cx_auto_build_input_controls(codec);
4350 err = conexant_build_controls(codec);
4353 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4356 if (spec->vmaster_mute.sw_kctl) {
4357 spec->vmaster_mute.hook = cx_auto_vmaster_hook;
4358 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4359 spec->vmaster_mute_led);
4366 static int cx_auto_search_adcs(struct hda_codec *codec)
4368 struct conexant_spec *spec = codec->spec;
4369 hda_nid_t nid, end_nid;
4371 end_nid = codec->start_nid + codec->num_nodes;
4372 for (nid = codec->start_nid; nid < end_nid; nid++) {
4373 unsigned int caps = get_wcaps(codec, nid);
4374 if (get_wcaps_type(caps) != AC_WID_AUD_IN)
4376 if (caps & AC_WCAP_DIGITAL)
4378 if (snd_BUG_ON(spec->num_adc_nids >=
4379 ARRAY_SIZE(spec->private_adc_nids)))
4381 spec->private_adc_nids[spec->num_adc_nids++] = nid;
4383 spec->adc_nids = spec->private_adc_nids;
4387 static const struct hda_codec_ops cx_auto_patch_ops = {
4388 .build_controls = cx_auto_build_controls,
4389 .build_pcms = conexant_build_pcms,
4390 .init = cx_auto_init,
4391 .free = conexant_free,
4392 .unsol_event = snd_hda_jack_unsol_event,
4399 CXT_PINCFG_LENOVO_X200,
4400 CXT_PINCFG_LENOVO_TP410,
4401 CXT_PINCFG_LEMOTE_A1004,
4402 CXT_PINCFG_LEMOTE_A1205,
4403 CXT_FIXUP_STEREO_DMIC,
4404 CXT_FIXUP_INC_MIC_BOOST,
4407 static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
4408 const struct hda_fixup *fix, int action)
4410 struct conexant_spec *spec = codec->spec;
4411 spec->fixup_stereo_dmic = 1;
4414 static void cxt5066_increase_mic_boost(struct hda_codec *codec,
4415 const struct hda_fixup *fix, int action)
4417 if (action != HDA_FIXUP_ACT_PRE_PROBE)
4420 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
4421 (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
4422 (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4423 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4424 (0 << AC_AMPCAP_MUTE_SHIFT));
4427 /* ThinkPad X200 & co with cxt5051 */
4428 static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
4429 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4430 { 0x17, 0x21a11000 }, /* dock-mic */
4431 { 0x19, 0x2121103f }, /* dock-HP */
4432 { 0x1c, 0x21440100 }, /* dock SPDIF out */
4436 /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
4437 static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
4438 { 0x19, 0x042110ff }, /* HP (seq# overridden) */
4439 { 0x1a, 0x21a190f0 }, /* dock-mic */
4440 { 0x1c, 0x212140ff }, /* dock-HP */
4444 /* Lemote A1004/A1205 with cxt5066 */
4445 static const struct hda_pintbl cxt_pincfg_lemote[] = {
4446 { 0x1a, 0x90a10020 }, /* Internal mic */
4447 { 0x1b, 0x03a11020 }, /* External mic */
4448 { 0x1d, 0x400101f0 }, /* Not used */
4449 { 0x1e, 0x40a701f0 }, /* Not used */
4450 { 0x20, 0x404501f0 }, /* Not used */
4451 { 0x22, 0x404401f0 }, /* Not used */
4452 { 0x23, 0x40a701f0 }, /* Not used */
4456 static const struct hda_fixup cxt_fixups[] = {
4457 [CXT_PINCFG_LENOVO_X200] = {
4458 .type = HDA_FIXUP_PINS,
4459 .v.pins = cxt_pincfg_lenovo_x200,
4461 [CXT_PINCFG_LENOVO_TP410] = {
4462 .type = HDA_FIXUP_PINS,
4463 .v.pins = cxt_pincfg_lenovo_tp410,
4465 [CXT_PINCFG_LEMOTE_A1004] = {
4466 .type = HDA_FIXUP_PINS,
4468 .chain_id = CXT_FIXUP_INC_MIC_BOOST,
4469 .v.pins = cxt_pincfg_lemote,
4471 [CXT_PINCFG_LEMOTE_A1205] = {
4472 .type = HDA_FIXUP_PINS,
4473 .v.pins = cxt_pincfg_lemote,
4475 [CXT_FIXUP_STEREO_DMIC] = {
4476 .type = HDA_FIXUP_FUNC,
4477 .v.func = cxt_fixup_stereo_dmic,
4479 [CXT_FIXUP_INC_MIC_BOOST] = {
4480 .type = HDA_FIXUP_FUNC,
4481 .v.func = cxt5066_increase_mic_boost,
4485 static const struct snd_pci_quirk cxt5051_fixups[] = {
4486 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4490 static const struct snd_pci_quirk cxt5066_fixups[] = {
4491 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
4492 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
4493 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
4494 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
4495 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
4496 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
4497 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
4498 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
4499 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
4500 SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
4501 SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
4505 /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
4506 * can be created (bko#42825)
4508 static void add_cx5051_fake_mutes(struct hda_codec *codec)
4510 static hda_nid_t out_nids[] = {
4515 for (p = out_nids; *p; p++)
4516 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
4517 AC_AMPCAP_MIN_MUTE |
4518 query_amp_caps(codec, *p, HDA_OUTPUT));
4521 static int patch_conexant_auto(struct hda_codec *codec)
4523 struct conexant_spec *spec;
4526 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4529 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4534 switch (codec->vendor_id) {
4536 codec->single_adc_amp = 1;
4539 add_cx5051_fake_mutes(codec);
4540 codec->pin_amp_workaround = 1;
4541 snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups);
4544 codec->pin_amp_workaround = 1;
4545 snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups);
4549 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
4551 /* Show mute-led control only on HP laptops
4552 * This is a sort of white-list: on HP laptops, EAPD corresponds
4553 * only to the mute-LED without actualy amp function. Meanwhile,
4554 * others may use EAPD really as an amp switch, so it might be
4555 * not good to expose it blindly.
4557 switch (codec->subsystem_id >> 16) {
4559 spec->vmaster_mute_led = 1;
4563 err = cx_auto_search_adcs(codec);
4566 err = cx_auto_parse_auto_config(codec);
4572 spec->capture_stream = &cx_auto_pcm_analog_capture;
4573 codec->patch_ops = cx_auto_patch_ops;
4575 snd_hda_attach_beep_device(codec, spec->beep_amp);
4577 /* Some laptops with Conexant chips show stalls in S3 resume,
4578 * which falls into the single-cmd mode.
4579 * Better to make reset, then.
4581 if (!codec->bus->sync_write) {
4582 snd_printd("hda_codec: "
4583 "Enable sync_write for stable communication\n");
4584 codec->bus->sync_write = 1;
4585 codec->bus->allow_bus_reset = 1;
4594 static const struct hda_codec_preset snd_hda_preset_conexant[] = {
4595 { .id = 0x14f15045, .name = "CX20549 (Venice)",
4596 .patch = patch_cxt5045 },
4597 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
4598 .patch = patch_cxt5047 },
4599 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4600 .patch = patch_cxt5051 },
4601 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
4602 .patch = patch_cxt5066 },
4603 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
4604 .patch = patch_cxt5066 },
4605 { .id = 0x14f15068, .name = "CX20584",
4606 .patch = patch_cxt5066 },
4607 { .id = 0x14f15069, .name = "CX20585",
4608 .patch = patch_cxt5066 },
4609 { .id = 0x14f1506c, .name = "CX20588",
4610 .patch = patch_cxt5066 },
4611 { .id = 0x14f1506e, .name = "CX20590",
4612 .patch = patch_cxt5066 },
4613 { .id = 0x14f15097, .name = "CX20631",
4614 .patch = patch_conexant_auto },
4615 { .id = 0x14f15098, .name = "CX20632",
4616 .patch = patch_conexant_auto },
4617 { .id = 0x14f150a1, .name = "CX20641",
4618 .patch = patch_conexant_auto },
4619 { .id = 0x14f150a2, .name = "CX20642",
4620 .patch = patch_conexant_auto },
4621 { .id = 0x14f150ab, .name = "CX20651",
4622 .patch = patch_conexant_auto },
4623 { .id = 0x14f150ac, .name = "CX20652",
4624 .patch = patch_conexant_auto },
4625 { .id = 0x14f150b8, .name = "CX20664",
4626 .patch = patch_conexant_auto },
4627 { .id = 0x14f150b9, .name = "CX20665",
4628 .patch = patch_conexant_auto },
4629 { .id = 0x14f1510f, .name = "CX20751/2",
4630 .patch = patch_conexant_auto },
4631 { .id = 0x14f15110, .name = "CX20751/2",
4632 .patch = patch_conexant_auto },
4633 { .id = 0x14f15111, .name = "CX20753/4",
4634 .patch = patch_conexant_auto },
4638 MODULE_ALIAS("snd-hda-codec-id:14f15045");
4639 MODULE_ALIAS("snd-hda-codec-id:14f15047");
4640 MODULE_ALIAS("snd-hda-codec-id:14f15051");
4641 MODULE_ALIAS("snd-hda-codec-id:14f15066");
4642 MODULE_ALIAS("snd-hda-codec-id:14f15067");
4643 MODULE_ALIAS("snd-hda-codec-id:14f15068");
4644 MODULE_ALIAS("snd-hda-codec-id:14f15069");
4645 MODULE_ALIAS("snd-hda-codec-id:14f1506c");
4646 MODULE_ALIAS("snd-hda-codec-id:14f1506e");
4647 MODULE_ALIAS("snd-hda-codec-id:14f15097");
4648 MODULE_ALIAS("snd-hda-codec-id:14f15098");
4649 MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4650 MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4651 MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4652 MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4653 MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4654 MODULE_ALIAS("snd-hda-codec-id:14f150b9");
4655 MODULE_ALIAS("snd-hda-codec-id:14f1510f");
4656 MODULE_ALIAS("snd-hda-codec-id:14f15110");
4657 MODULE_ALIAS("snd-hda-codec-id:14f15111");
4659 MODULE_LICENSE("GPL");
4660 MODULE_DESCRIPTION("Conexant HD-audio codec");
4662 static struct hda_codec_preset_list conexant_list = {
4663 .preset = snd_hda_preset_conexant,
4664 .owner = THIS_MODULE,
4667 static int __init patch_conexant_init(void)
4669 return snd_hda_add_codec_preset(&conexant_list);
4672 static void __exit patch_conexant_exit(void)
4674 snd_hda_delete_codec_preset(&conexant_list);
4677 module_init(patch_conexant_init)
4678 module_exit(patch_conexant_exit)