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 <sound/core.h>
28 #include <sound/jack.h>
30 #include "hda_codec.h"
31 #include "hda_local.h"
33 #define CXT_PIN_DIR_IN 0x00
34 #define CXT_PIN_DIR_OUT 0x01
35 #define CXT_PIN_DIR_INOUT 0x02
36 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
37 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39 #define CONEXANT_HP_EVENT 0x37
40 #define CONEXANT_MIC_EVENT 0x38
42 /* Conexant 5051 specific */
44 #define CXT5051_SPDIF_OUT 0x1C
45 #define CXT5051_PORTB_EVENT 0x38
46 #define CXT5051_PORTC_EVENT 0x39
49 struct conexant_jack {
53 struct snd_jack *jack;
57 struct conexant_spec {
59 struct snd_kcontrol_new *mixers[5];
62 const struct hda_verb *init_verbs[5]; /* initialization verbs
66 unsigned int num_init_verbs;
69 struct hda_multi_out multiout; /* playback set-up
70 * max_channels, dacs must be set
71 * dig_out_nid and hp_nid are optional
73 unsigned int cur_eapd;
74 unsigned int hp_present;
75 unsigned int need_dac_fix;
78 unsigned int num_adc_nids;
80 hda_nid_t dig_in_nid; /* digital-in NID; optional */
82 unsigned int cur_adc_idx;
84 unsigned int cur_adc_stream_tag;
85 unsigned int cur_adc_format;
88 const struct hda_input_mux *input_mux;
89 hda_nid_t *capsrc_nids;
90 unsigned int cur_mux[3];
93 const struct hda_channel_mode *channel_mode;
97 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
99 unsigned int spdif_route;
102 struct snd_array jacks;
104 /* dynamic controls, init_verbs and input_mux */
105 struct auto_pin_cfg autocfg;
106 struct hda_input_mux private_imux;
107 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
111 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
112 struct hda_codec *codec,
113 struct snd_pcm_substream *substream)
115 struct conexant_spec *spec = codec->spec;
116 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
120 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
121 struct hda_codec *codec,
122 unsigned int stream_tag,
124 struct snd_pcm_substream *substream)
126 struct conexant_spec *spec = codec->spec;
127 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
132 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
133 struct hda_codec *codec,
134 struct snd_pcm_substream *substream)
136 struct conexant_spec *spec = codec->spec;
137 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
143 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
144 struct hda_codec *codec,
145 struct snd_pcm_substream *substream)
147 struct conexant_spec *spec = codec->spec;
148 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
151 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
152 struct hda_codec *codec,
153 struct snd_pcm_substream *substream)
155 struct conexant_spec *spec = codec->spec;
156 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
159 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
160 struct hda_codec *codec,
161 unsigned int stream_tag,
163 struct snd_pcm_substream *substream)
165 struct conexant_spec *spec = codec->spec;
166 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
174 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
175 struct hda_codec *codec,
176 unsigned int stream_tag,
178 struct snd_pcm_substream *substream)
180 struct conexant_spec *spec = codec->spec;
181 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
182 stream_tag, 0, format);
186 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
187 struct hda_codec *codec,
188 struct snd_pcm_substream *substream)
190 struct conexant_spec *spec = codec->spec;
191 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
197 static struct hda_pcm_stream conexant_pcm_analog_playback = {
201 .nid = 0, /* fill later */
203 .open = conexant_playback_pcm_open,
204 .prepare = conexant_playback_pcm_prepare,
205 .cleanup = conexant_playback_pcm_cleanup
209 static struct hda_pcm_stream conexant_pcm_analog_capture = {
213 .nid = 0, /* fill later */
215 .prepare = conexant_capture_pcm_prepare,
216 .cleanup = conexant_capture_pcm_cleanup
221 static struct hda_pcm_stream conexant_pcm_digital_playback = {
225 .nid = 0, /* fill later */
227 .open = conexant_dig_playback_pcm_open,
228 .close = conexant_dig_playback_pcm_close,
229 .prepare = conexant_dig_playback_pcm_prepare
233 static struct hda_pcm_stream conexant_pcm_digital_capture = {
237 /* NID is set in alc_build_pcms */
240 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
241 struct hda_codec *codec,
242 unsigned int stream_tag,
244 struct snd_pcm_substream *substream)
246 struct conexant_spec *spec = codec->spec;
247 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
248 spec->cur_adc_stream_tag = stream_tag;
249 spec->cur_adc_format = format;
250 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
254 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
255 struct hda_codec *codec,
256 struct snd_pcm_substream *substream)
258 struct conexant_spec *spec = codec->spec;
259 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
264 static struct hda_pcm_stream cx5051_pcm_analog_capture = {
268 .nid = 0, /* fill later */
270 .prepare = cx5051_capture_pcm_prepare,
271 .cleanup = cx5051_capture_pcm_cleanup
275 static int conexant_build_pcms(struct hda_codec *codec)
277 struct conexant_spec *spec = codec->spec;
278 struct hda_pcm *info = spec->pcm_rec;
281 codec->pcm_info = info;
283 info->name = "CONEXANT Analog";
284 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
285 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
286 spec->multiout.max_channels;
287 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
288 spec->multiout.dac_nids[0];
289 if (codec->vendor_id == 0x14f15051)
290 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
291 cx5051_pcm_analog_capture;
293 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
294 conexant_pcm_analog_capture;
295 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
296 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
298 if (spec->multiout.dig_out_nid) {
301 info->name = "Conexant Digital";
302 info->pcm_type = HDA_PCM_TYPE_SPDIF;
303 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
304 conexant_pcm_digital_playback;
305 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
306 spec->multiout.dig_out_nid;
307 if (spec->dig_in_nid) {
308 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
309 conexant_pcm_digital_capture;
310 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
318 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
319 struct snd_ctl_elem_info *uinfo)
321 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
322 struct conexant_spec *spec = codec->spec;
324 return snd_hda_input_mux_info(spec->input_mux, uinfo);
327 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
328 struct snd_ctl_elem_value *ucontrol)
330 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
331 struct conexant_spec *spec = codec->spec;
332 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
334 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
338 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
339 struct snd_ctl_elem_value *ucontrol)
341 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
342 struct conexant_spec *spec = codec->spec;
343 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
345 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
346 spec->capsrc_nids[adc_idx],
347 &spec->cur_mux[adc_idx]);
350 #ifdef CONFIG_SND_JACK
351 static int conexant_add_jack(struct hda_codec *codec,
352 hda_nid_t nid, int type)
354 struct conexant_spec *spec;
355 struct conexant_jack *jack;
359 snd_array_init(&spec->jacks, sizeof(*jack), 32);
360 jack = snd_array_new(&spec->jacks);
361 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
369 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
372 static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
374 struct conexant_spec *spec = codec->spec;
375 struct conexant_jack *jacks = spec->jacks.list;
379 for (i = 0; i < spec->jacks.used; i++) {
380 if (jacks->nid == nid) {
381 unsigned int present;
382 present = snd_hda_codec_read(codec, nid, 0,
383 AC_VERB_GET_PIN_SENSE, 0) &
384 AC_PINSENSE_PRESENCE;
386 present = (present) ? jacks->type : 0 ;
388 snd_jack_report(jacks->jack,
396 static int conexant_init_jacks(struct hda_codec *codec)
398 struct conexant_spec *spec = codec->spec;
401 for (i = 0; i < spec->num_init_verbs; i++) {
402 const struct hda_verb *hv;
404 hv = spec->init_verbs[i];
407 switch (hv->param ^ AC_USRSP_EN) {
408 case CONEXANT_HP_EVENT:
409 err = conexant_add_jack(codec, hv->nid,
411 conexant_report_jack(codec, hv->nid);
413 case CXT5051_PORTC_EVENT:
414 case CONEXANT_MIC_EVENT:
415 err = conexant_add_jack(codec, hv->nid,
416 SND_JACK_MICROPHONE);
417 conexant_report_jack(codec, hv->nid);
429 static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
433 static inline int conexant_init_jacks(struct hda_codec *codec)
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 #ifdef CONFIG_SND_JACK
452 struct conexant_spec *spec = codec->spec;
453 if (spec->jacks.list) {
454 struct conexant_jack *jacks = spec->jacks.list;
456 for (i = 0; i < spec->jacks.used; i++)
457 snd_device_free(codec->bus->card, &jacks[i].jack);
458 snd_array_free(&spec->jacks);
464 static int conexant_build_controls(struct hda_codec *codec)
466 struct conexant_spec *spec = codec->spec;
470 for (i = 0; i < spec->num_mixers; i++) {
471 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
475 if (spec->multiout.dig_out_nid) {
476 err = snd_hda_create_spdif_out_ctls(codec,
477 spec->multiout.dig_out_nid);
480 err = snd_hda_create_spdif_share_sw(codec,
484 spec->multiout.share_spdif = 1;
486 if (spec->dig_in_nid) {
487 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
494 static struct hda_codec_ops conexant_patch_ops = {
495 .build_controls = conexant_build_controls,
496 .build_pcms = conexant_build_pcms,
497 .init = conexant_init,
498 .free = conexant_free,
503 * the private value = nid | (invert << 8)
506 #define cxt_eapd_info snd_ctl_boolean_mono_info
508 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
509 struct snd_ctl_elem_value *ucontrol)
511 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
512 struct conexant_spec *spec = codec->spec;
513 int invert = (kcontrol->private_value >> 8) & 1;
515 ucontrol->value.integer.value[0] = !spec->cur_eapd;
517 ucontrol->value.integer.value[0] = spec->cur_eapd;
522 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
523 struct snd_ctl_elem_value *ucontrol)
525 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
526 struct conexant_spec *spec = codec->spec;
527 int invert = (kcontrol->private_value >> 8) & 1;
528 hda_nid_t nid = kcontrol->private_value & 0xff;
531 eapd = !!ucontrol->value.integer.value[0];
534 if (eapd == spec->cur_eapd)
537 spec->cur_eapd = eapd;
538 snd_hda_codec_write_cache(codec, nid,
539 0, AC_VERB_SET_EAPD_BTLENABLE,
544 /* controls for test mode */
545 #ifdef CONFIG_SND_DEBUG
547 #define CXT_EAPD_SWITCH(xname, nid, mask) \
548 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
549 .info = cxt_eapd_info, \
550 .get = cxt_eapd_get, \
551 .put = cxt_eapd_put, \
552 .private_value = nid | (mask<<16) }
556 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
557 struct snd_ctl_elem_info *uinfo)
559 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
560 struct conexant_spec *spec = codec->spec;
561 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
562 spec->num_channel_mode);
565 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
566 struct snd_ctl_elem_value *ucontrol)
568 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
569 struct conexant_spec *spec = codec->spec;
570 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
571 spec->num_channel_mode,
572 spec->multiout.max_channels);
575 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
576 struct snd_ctl_elem_value *ucontrol)
578 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
579 struct conexant_spec *spec = codec->spec;
580 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
581 spec->num_channel_mode,
582 &spec->multiout.max_channels);
583 if (err >= 0 && spec->need_dac_fix)
584 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
588 #define CXT_PIN_MODE(xname, nid, dir) \
589 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
590 .info = conexant_ch_mode_info, \
591 .get = conexant_ch_mode_get, \
592 .put = conexant_ch_mode_put, \
593 .private_value = nid | (dir<<16) }
595 #endif /* CONFIG_SND_DEBUG */
597 /* Conexant 5045 specific */
599 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
600 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
601 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
602 #define CXT5045_SPDIF_OUT 0x18
604 static struct hda_channel_mode cxt5045_modes[1] = {
608 static struct hda_input_mux cxt5045_capture_source = {
616 static struct hda_input_mux cxt5045_capture_source_benq = {
625 static struct hda_input_mux cxt5045_capture_source_hp530 = {
633 /* turn on/off EAPD (+ mute HP) as a master switch */
634 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
635 struct snd_ctl_elem_value *ucontrol)
637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638 struct conexant_spec *spec = codec->spec;
641 if (!cxt_eapd_put(kcontrol, ucontrol))
644 /* toggle internal speakers mute depending of presence of
647 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
648 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
651 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
652 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
657 /* bind volumes of both NID 0x10 and 0x11 */
658 static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
659 .ops = &snd_hda_bind_vol,
661 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
662 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
667 /* toggle input of built-in and mic jack appropriately */
668 static void cxt5045_hp_automic(struct hda_codec *codec)
670 static struct hda_verb mic_jack_on[] = {
671 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
672 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
675 static struct hda_verb mic_jack_off[] = {
676 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
677 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
680 unsigned int present;
682 present = snd_hda_codec_read(codec, 0x12, 0,
683 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
685 snd_hda_sequence_write(codec, mic_jack_on);
687 snd_hda_sequence_write(codec, mic_jack_off);
691 /* mute internal speaker if HP is plugged */
692 static void cxt5045_hp_automute(struct hda_codec *codec)
694 struct conexant_spec *spec = codec->spec;
697 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
698 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
700 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
701 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
705 /* unsolicited event for HP jack sensing */
706 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
711 case CONEXANT_HP_EVENT:
712 cxt5045_hp_automute(codec);
714 case CONEXANT_MIC_EVENT:
715 cxt5045_hp_automic(codec);
721 static struct snd_kcontrol_new cxt5045_mixers[] = {
723 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
724 .name = "Capture Source",
725 .info = conexant_mux_enum_info,
726 .get = conexant_mux_enum_get,
727 .put = conexant_mux_enum_put
729 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
730 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
731 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
732 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
733 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
734 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
735 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
736 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
737 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
738 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
739 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
741 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
742 .name = "Master Playback Switch",
743 .info = cxt_eapd_info,
745 .put = cxt5045_hp_master_sw_put,
746 .private_value = 0x10,
752 static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
753 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
754 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
755 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
756 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
761 static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
763 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
764 .name = "Capture Source",
765 .info = conexant_mux_enum_info,
766 .get = conexant_mux_enum_get,
767 .put = conexant_mux_enum_put
769 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
770 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
771 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
772 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
773 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
774 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
775 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
776 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
777 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
778 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
779 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
781 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
782 .name = "Master Playback Switch",
783 .info = cxt_eapd_info,
785 .put = cxt5045_hp_master_sw_put,
786 .private_value = 0x10,
792 static struct hda_verb cxt5045_init_verbs[] = {
794 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
795 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
797 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
798 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
799 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
800 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
801 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
802 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
803 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
804 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
805 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
806 /* Record selector: Int mic */
807 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
808 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
809 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
810 /* SPDIF route: PCM */
811 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
812 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
814 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
818 static struct hda_verb cxt5045_benq_init_verbs[] = {
820 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
821 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
822 /* Line In,HP, Amp */
823 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
824 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
825 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
826 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
827 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
828 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
829 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
830 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
831 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
832 /* Record selector: Int mic */
833 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
834 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
835 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
836 /* SPDIF route: PCM */
837 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
838 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
840 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
844 static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
845 /* pin sensing on HP jack */
846 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
850 static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
851 /* pin sensing on HP jack */
852 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
856 #ifdef CONFIG_SND_DEBUG
857 /* Test configuration for debugging, modelled after the ALC260 test
860 static struct hda_input_mux cxt5045_test_capture_source = {
865 { "LINE1 pin", 0x2 },
866 { "HP-OUT pin", 0x3 },
871 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
873 /* Output controls */
874 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
875 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
876 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
877 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
878 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
879 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
881 /* Modes for retasking pin widgets */
882 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
883 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
885 /* EAPD Switch Control */
886 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
888 /* Loopback mixer controls */
890 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
891 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
892 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
893 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
894 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
895 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
896 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
897 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
898 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
899 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
901 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
902 .name = "Input Source",
903 .info = conexant_mux_enum_info,
904 .get = conexant_mux_enum_get,
905 .put = conexant_mux_enum_put,
907 /* Audio input controls */
908 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
909 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
910 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
911 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
912 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
913 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
914 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
915 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
916 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
917 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
921 static struct hda_verb cxt5045_test_init_verbs[] = {
922 /* Set connections */
923 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
924 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
925 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
926 /* Enable retasking pins as output, initially without power amp */
927 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
928 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
930 /* Disable digital (SPDIF) pins initially, but users can enable
931 * them via a mixer switch. In the case of SPDIF-out, this initverb
932 * payload also sets the generation to 0, output to be in "consumer"
933 * PCM format, copyright asserted, no pre-emphasis and no validity
936 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
937 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
939 /* Start with output sum widgets muted and their output gains at min */
940 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
941 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
943 /* Unmute retasking pin widget output buffers since the default
944 * state appears to be output. As the pin mode is changed by the
945 * user the pin mode control will take care of enabling the pin's
946 * input/output buffers as needed.
948 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
949 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
951 /* Mute capture amp left and right */
952 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
954 /* Set ADC connection select to match default mixer setting (mic1
957 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
958 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
960 /* Mute all inputs to mixer widget (even unconnected ones) */
961 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
962 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
963 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
964 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
965 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
972 /* initialize jack-sensing, too */
973 static int cxt5045_init(struct hda_codec *codec)
975 conexant_init(codec);
976 cxt5045_hp_automute(codec);
982 CXT5045_LAPTOP_HPSENSE,
983 CXT5045_LAPTOP_MICSENSE,
984 CXT5045_LAPTOP_HPMICSENSE,
986 CXT5045_LAPTOP_HP530,
987 #ifdef CONFIG_SND_DEBUG
993 static const char *cxt5045_models[CXT5045_MODELS] = {
994 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
995 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
996 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
997 [CXT5045_BENQ] = "benq",
998 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
999 #ifdef CONFIG_SND_DEBUG
1000 [CXT5045_TEST] = "test",
1004 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1005 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1006 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1007 CXT5045_LAPTOP_HPSENSE),
1008 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1009 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1010 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1011 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1012 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1013 CXT5045_LAPTOP_HPMICSENSE),
1014 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1015 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1016 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1017 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1018 CXT5045_LAPTOP_HPMICSENSE),
1019 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1023 static int patch_cxt5045(struct hda_codec *codec)
1025 struct conexant_spec *spec;
1028 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1033 spec->multiout.max_channels = 2;
1034 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1035 spec->multiout.dac_nids = cxt5045_dac_nids;
1036 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1037 spec->num_adc_nids = 1;
1038 spec->adc_nids = cxt5045_adc_nids;
1039 spec->capsrc_nids = cxt5045_capsrc_nids;
1040 spec->input_mux = &cxt5045_capture_source;
1041 spec->num_mixers = 1;
1042 spec->mixers[0] = cxt5045_mixers;
1043 spec->num_init_verbs = 1;
1044 spec->init_verbs[0] = cxt5045_init_verbs;
1045 spec->spdif_route = 0;
1046 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1047 spec->channel_mode = cxt5045_modes,
1050 codec->patch_ops = conexant_patch_ops;
1052 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1055 switch (board_config) {
1056 case CXT5045_LAPTOP_HPSENSE:
1057 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1058 spec->input_mux = &cxt5045_capture_source;
1059 spec->num_init_verbs = 2;
1060 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1061 spec->mixers[0] = cxt5045_mixers;
1062 codec->patch_ops.init = cxt5045_init;
1064 case CXT5045_LAPTOP_MICSENSE:
1065 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1066 spec->input_mux = &cxt5045_capture_source;
1067 spec->num_init_verbs = 2;
1068 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1069 spec->mixers[0] = cxt5045_mixers;
1070 codec->patch_ops.init = cxt5045_init;
1073 case CXT5045_LAPTOP_HPMICSENSE:
1074 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1075 spec->input_mux = &cxt5045_capture_source;
1076 spec->num_init_verbs = 3;
1077 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1078 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1079 spec->mixers[0] = cxt5045_mixers;
1080 codec->patch_ops.init = cxt5045_init;
1083 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1084 spec->input_mux = &cxt5045_capture_source_benq;
1085 spec->num_init_verbs = 1;
1086 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1087 spec->mixers[0] = cxt5045_mixers;
1088 spec->mixers[1] = cxt5045_benq_mixers;
1089 spec->num_mixers = 2;
1090 codec->patch_ops.init = cxt5045_init;
1092 case CXT5045_LAPTOP_HP530:
1093 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1094 spec->input_mux = &cxt5045_capture_source_hp530;
1095 spec->num_init_verbs = 2;
1096 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1097 spec->mixers[0] = cxt5045_mixers_hp530;
1098 codec->patch_ops.init = cxt5045_init;
1100 #ifdef CONFIG_SND_DEBUG
1102 spec->input_mux = &cxt5045_test_capture_source;
1103 spec->mixers[0] = cxt5045_test_mixer;
1104 spec->init_verbs[0] = cxt5045_test_init_verbs;
1110 switch (codec->subsystem_id >> 16) {
1112 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1113 * Fix max PCM level to 0 dB
1114 * (originall it has 0x2b steps with 0dB offset 0x14)
1116 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1117 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1118 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1119 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1120 (1 << AC_AMPCAP_MUTE_SHIFT));
1128 /* Conexant 5047 specific */
1129 #define CXT5047_SPDIF_OUT 0x11
1131 static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
1132 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1133 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1135 static struct hda_channel_mode cxt5047_modes[1] = {
1139 static struct hda_input_mux cxt5047_capture_source = {
1146 static struct hda_input_mux cxt5047_hp_capture_source = {
1153 static struct hda_input_mux cxt5047_toshiba_capture_source = {
1161 /* turn on/off EAPD (+ mute HP) as a master switch */
1162 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1163 struct snd_ctl_elem_value *ucontrol)
1165 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1166 struct conexant_spec *spec = codec->spec;
1169 if (!cxt_eapd_put(kcontrol, ucontrol))
1172 /* toggle internal speakers mute depending of presence of
1173 * the headphone jack
1175 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1176 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1177 HDA_AMP_MUTE, bits);
1178 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1179 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1180 HDA_AMP_MUTE, bits);
1184 /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
1185 static struct hda_bind_ctls cxt5047_bind_master_vol = {
1186 .ops = &snd_hda_bind_vol,
1188 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1189 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1194 /* mute internal speaker if HP is plugged */
1195 static void cxt5047_hp_automute(struct hda_codec *codec)
1197 struct conexant_spec *spec = codec->spec;
1200 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1201 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1203 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1204 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1205 HDA_AMP_MUTE, bits);
1206 /* Mute/Unmute PCM 2 for good measure - some systems need this */
1207 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1208 HDA_AMP_MUTE, bits);
1211 /* mute internal speaker if HP is plugged */
1212 static void cxt5047_hp2_automute(struct hda_codec *codec)
1214 struct conexant_spec *spec = codec->spec;
1217 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1218 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1220 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1221 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1222 HDA_AMP_MUTE, bits);
1223 /* Mute/Unmute PCM 2 for good measure - some systems need this */
1224 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1225 HDA_AMP_MUTE, bits);
1228 /* toggle input of built-in and mic jack appropriately */
1229 static void cxt5047_hp_automic(struct hda_codec *codec)
1231 static struct hda_verb mic_jack_on[] = {
1232 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1233 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1236 static struct hda_verb mic_jack_off[] = {
1237 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1238 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1241 unsigned int present;
1243 present = snd_hda_codec_read(codec, 0x15, 0,
1244 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1246 snd_hda_sequence_write(codec, mic_jack_on);
1248 snd_hda_sequence_write(codec, mic_jack_off);
1251 /* unsolicited event for HP jack sensing */
1252 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1255 switch (res >> 26) {
1256 case CONEXANT_HP_EVENT:
1257 cxt5047_hp_automute(codec);
1259 case CONEXANT_MIC_EVENT:
1260 cxt5047_hp_automic(codec);
1265 /* unsolicited event for HP jack sensing - non-EAPD systems */
1266 static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1271 case CONEXANT_HP_EVENT:
1272 cxt5047_hp2_automute(codec);
1274 case CONEXANT_MIC_EVENT:
1275 cxt5047_hp_automic(codec);
1280 static struct snd_kcontrol_new cxt5047_mixers[] = {
1281 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1282 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1283 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1284 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
1285 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1286 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1287 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1288 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1289 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1290 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1291 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1292 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1293 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1294 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
1299 static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1301 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1302 .name = "Capture Source",
1303 .info = conexant_mux_enum_info,
1304 .get = conexant_mux_enum_get,
1305 .put = conexant_mux_enum_put
1307 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1308 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1309 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1310 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1311 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1312 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1313 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
1315 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1316 .name = "Master Playback Switch",
1317 .info = cxt_eapd_info,
1318 .get = cxt_eapd_get,
1319 .put = cxt5047_hp_master_sw_put,
1320 .private_value = 0x13,
1326 static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1328 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1329 .name = "Capture Source",
1330 .info = conexant_mux_enum_info,
1331 .get = conexant_mux_enum_get,
1332 .put = conexant_mux_enum_put
1334 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1335 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1336 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1337 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1338 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1339 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1340 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1342 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1343 .name = "Master Playback Switch",
1344 .info = cxt_eapd_info,
1345 .get = cxt_eapd_get,
1346 .put = cxt5047_hp_master_sw_put,
1347 .private_value = 0x13,
1352 static struct hda_verb cxt5047_init_verbs[] = {
1353 /* Line in, Mic, Built-in Mic */
1354 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1355 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1356 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1358 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1359 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
1360 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1361 /* Record selector: Mic */
1362 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1363 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1364 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1365 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1366 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1367 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1368 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1369 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1370 /* SPDIF route: PCM */
1371 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1372 /* Enable unsolicited events */
1373 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1374 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1378 /* configuration for Toshiba Laptops */
1379 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1380 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1381 /* pin sensing on HP and Mic jacks */
1382 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1383 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1384 /* Speaker routing */
1385 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1389 /* configuration for HP Laptops */
1390 static struct hda_verb cxt5047_hp_init_verbs[] = {
1391 /* pin sensing on HP jack */
1392 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1393 /* 0x13 is actually shared by both HP and speaker;
1394 * setting the connection to 0 (=0x19) makes the master volume control
1395 * working mysteriouslly...
1397 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1398 /* Record selector: Ext Mic */
1399 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1400 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1401 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1402 /* Speaker routing */
1403 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1407 /* Test configuration for debugging, modelled after the ALC260 test
1410 #ifdef CONFIG_SND_DEBUG
1411 static struct hda_input_mux cxt5047_test_capture_source = {
1414 { "LINE1 pin", 0x0 },
1415 { "MIC1 pin", 0x1 },
1416 { "MIC2 pin", 0x2 },
1421 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1423 /* Output only controls */
1424 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1425 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1426 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1427 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1428 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1429 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1431 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1432 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1433 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1434 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1435 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1437 /* Modes for retasking pin widgets */
1438 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1439 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1441 /* EAPD Switch Control */
1442 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1444 /* Loopback mixer controls */
1445 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1446 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1447 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1448 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1449 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1450 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1451 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1452 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1454 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1455 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1456 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1457 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1458 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1459 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1460 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1461 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1463 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1464 .name = "Input Source",
1465 .info = conexant_mux_enum_info,
1466 .get = conexant_mux_enum_get,
1467 .put = conexant_mux_enum_put,
1469 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1470 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1471 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1472 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1473 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1474 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1475 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1476 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1477 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1478 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1483 static struct hda_verb cxt5047_test_init_verbs[] = {
1484 /* Enable retasking pins as output, initially without power amp */
1485 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1486 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1487 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1489 /* Disable digital (SPDIF) pins initially, but users can enable
1490 * them via a mixer switch. In the case of SPDIF-out, this initverb
1491 * payload also sets the generation to 0, output to be in "consumer"
1492 * PCM format, copyright asserted, no pre-emphasis and no validity
1495 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1497 /* Ensure mic1, mic2, line1 pin widgets take input from the
1498 * OUT1 sum bus when acting as an output.
1500 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1501 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1503 /* Start with output sum widgets muted and their output gains at min */
1504 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1505 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1507 /* Unmute retasking pin widget output buffers since the default
1508 * state appears to be output. As the pin mode is changed by the
1509 * user the pin mode control will take care of enabling the pin's
1510 * input/output buffers as needed.
1512 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1513 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1514 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1516 /* Mute capture amp left and right */
1517 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1519 /* Set ADC connection select to match default mixer setting (mic1
1522 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1524 /* Mute all inputs to mixer widget (even unconnected ones) */
1525 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1526 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1530 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1531 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1539 /* initialize jack-sensing, too */
1540 static int cxt5047_hp_init(struct hda_codec *codec)
1542 conexant_init(codec);
1543 cxt5047_hp_automute(codec);
1549 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1550 CXT5047_LAPTOP_HP, /* Some HP laptops */
1551 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1552 #ifdef CONFIG_SND_DEBUG
1558 static const char *cxt5047_models[CXT5047_MODELS] = {
1559 [CXT5047_LAPTOP] = "laptop",
1560 [CXT5047_LAPTOP_HP] = "laptop-hp",
1561 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1562 #ifdef CONFIG_SND_DEBUG
1563 [CXT5047_TEST] = "test",
1567 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1568 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1569 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1571 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1575 static int patch_cxt5047(struct hda_codec *codec)
1577 struct conexant_spec *spec;
1580 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1585 spec->multiout.max_channels = 2;
1586 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1587 spec->multiout.dac_nids = cxt5047_dac_nids;
1588 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1589 spec->num_adc_nids = 1;
1590 spec->adc_nids = cxt5047_adc_nids;
1591 spec->capsrc_nids = cxt5047_capsrc_nids;
1592 spec->input_mux = &cxt5047_capture_source;
1593 spec->num_mixers = 1;
1594 spec->mixers[0] = cxt5047_mixers;
1595 spec->num_init_verbs = 1;
1596 spec->init_verbs[0] = cxt5047_init_verbs;
1597 spec->spdif_route = 0;
1598 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1599 spec->channel_mode = cxt5047_modes,
1601 codec->patch_ops = conexant_patch_ops;
1603 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1606 switch (board_config) {
1607 case CXT5047_LAPTOP:
1608 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
1610 case CXT5047_LAPTOP_HP:
1611 spec->input_mux = &cxt5047_hp_capture_source;
1612 spec->num_init_verbs = 2;
1613 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1614 spec->mixers[0] = cxt5047_hp_mixers;
1615 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1616 codec->patch_ops.init = cxt5047_hp_init;
1618 case CXT5047_LAPTOP_EAPD:
1619 spec->input_mux = &cxt5047_toshiba_capture_source;
1620 spec->num_init_verbs = 2;
1621 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1622 spec->mixers[0] = cxt5047_toshiba_mixers;
1623 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1625 #ifdef CONFIG_SND_DEBUG
1627 spec->input_mux = &cxt5047_test_capture_source;
1628 spec->mixers[0] = cxt5047_test_mixer;
1629 spec->init_verbs[0] = cxt5047_test_init_verbs;
1630 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1636 /* Conexant 5051 specific */
1637 static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1638 static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1640 static struct hda_channel_mode cxt5051_modes[1] = {
1644 static void cxt5051_update_speaker(struct hda_codec *codec)
1646 struct conexant_spec *spec = codec->spec;
1647 unsigned int pinctl;
1648 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1649 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1653 /* turn on/off EAPD (+ mute HP) as a master switch */
1654 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1655 struct snd_ctl_elem_value *ucontrol)
1657 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1659 if (!cxt_eapd_put(kcontrol, ucontrol))
1661 cxt5051_update_speaker(codec);
1665 /* toggle input of built-in and mic jack appropriately */
1666 static void cxt5051_portb_automic(struct hda_codec *codec)
1668 unsigned int present;
1670 present = snd_hda_codec_read(codec, 0x17, 0,
1671 AC_VERB_GET_PIN_SENSE, 0) &
1672 AC_PINSENSE_PRESENCE;
1673 snd_hda_codec_write(codec, 0x14, 0,
1674 AC_VERB_SET_CONNECT_SEL,
1675 present ? 0x01 : 0x00);
1678 /* switch the current ADC according to the jack state */
1679 static void cxt5051_portc_automic(struct hda_codec *codec)
1681 struct conexant_spec *spec = codec->spec;
1682 unsigned int present;
1685 present = snd_hda_codec_read(codec, 0x18, 0,
1686 AC_VERB_GET_PIN_SENSE, 0) &
1687 AC_PINSENSE_PRESENCE;
1689 spec->cur_adc_idx = 1;
1691 spec->cur_adc_idx = 0;
1692 new_adc = spec->adc_nids[spec->cur_adc_idx];
1693 if (spec->cur_adc && spec->cur_adc != new_adc) {
1694 /* stream is running, let's swap the current ADC */
1695 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1696 spec->cur_adc = new_adc;
1697 snd_hda_codec_setup_stream(codec, new_adc,
1698 spec->cur_adc_stream_tag, 0,
1699 spec->cur_adc_format);
1703 /* mute internal speaker if HP is plugged */
1704 static void cxt5051_hp_automute(struct hda_codec *codec)
1706 struct conexant_spec *spec = codec->spec;
1708 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1709 AC_VERB_GET_PIN_SENSE, 0) &
1710 AC_PINSENSE_PRESENCE;
1711 cxt5051_update_speaker(codec);
1714 /* unsolicited event for HP jack sensing */
1715 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1718 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1719 switch (res >> 26) {
1720 case CONEXANT_HP_EVENT:
1721 cxt5051_hp_automute(codec);
1723 case CXT5051_PORTB_EVENT:
1724 cxt5051_portb_automic(codec);
1726 case CXT5051_PORTC_EVENT:
1727 cxt5051_portc_automic(codec);
1730 conexant_report_jack(codec, nid);
1733 static struct snd_kcontrol_new cxt5051_mixers[] = {
1734 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1735 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1736 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1737 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1738 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1739 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1740 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1742 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1743 .name = "Master Playback Switch",
1744 .info = cxt_eapd_info,
1745 .get = cxt_eapd_get,
1746 .put = cxt5051_hp_master_sw_put,
1747 .private_value = 0x1a,
1753 static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1754 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1755 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1756 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1757 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1758 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1761 .name = "Master Playback Switch",
1762 .info = cxt_eapd_info,
1763 .get = cxt_eapd_get,
1764 .put = cxt5051_hp_master_sw_put,
1765 .private_value = 0x1a,
1771 static struct hda_verb cxt5051_init_verbs[] = {
1773 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1774 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1775 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1776 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1777 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1778 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1780 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1781 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1783 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1784 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1786 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1787 /* Record selector: Int mic */
1788 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1789 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1790 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1791 /* SPDIF route: PCM */
1792 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1794 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1795 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1796 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1797 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1801 static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1803 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1804 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1805 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1806 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1807 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1808 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1810 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1811 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1813 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1814 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1816 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1817 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1819 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1820 /* Record selector: Int mic */
1821 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1822 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1823 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1824 /* SPDIF route: PCM */
1825 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1827 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1828 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1829 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1830 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1831 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1835 /* initialize jack-sensing, too */
1836 static int cxt5051_init(struct hda_codec *codec)
1838 conexant_init(codec);
1839 conexant_init_jacks(codec);
1840 if (codec->patch_ops.unsol_event) {
1841 cxt5051_hp_automute(codec);
1842 cxt5051_portb_automic(codec);
1843 cxt5051_portc_automic(codec);
1850 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1851 CXT5051_HP, /* no docking */
1852 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
1856 static const char *cxt5051_models[CXT5051_MODELS] = {
1857 [CXT5051_LAPTOP] = "laptop",
1858 [CXT5051_HP] = "hp",
1859 [CXT5051_LENOVO_X200] = "lenovo-x200",
1862 static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1863 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1865 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1866 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1870 static int patch_cxt5051(struct hda_codec *codec)
1872 struct conexant_spec *spec;
1875 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1880 codec->patch_ops = conexant_patch_ops;
1881 codec->patch_ops.init = cxt5051_init;
1883 spec->multiout.max_channels = 2;
1884 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1885 spec->multiout.dac_nids = cxt5051_dac_nids;
1886 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1887 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1888 spec->adc_nids = cxt5051_adc_nids;
1889 spec->num_mixers = 1;
1890 spec->mixers[0] = cxt5051_mixers;
1891 spec->num_init_verbs = 1;
1892 spec->init_verbs[0] = cxt5051_init_verbs;
1893 spec->spdif_route = 0;
1894 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1895 spec->channel_mode = cxt5051_modes;
1897 spec->cur_adc_idx = 0;
1899 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1902 switch (board_config) {
1904 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1905 spec->mixers[0] = cxt5051_hp_mixers;
1907 case CXT5051_LENOVO_X200:
1908 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1911 case CXT5051_LAPTOP:
1912 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1923 static struct hda_codec_preset snd_hda_preset_conexant[] = {
1924 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1925 .patch = patch_cxt5045 },
1926 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1927 .patch = patch_cxt5047 },
1928 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1929 .patch = patch_cxt5051 },
1933 MODULE_ALIAS("snd-hda-codec-id:14f15045");
1934 MODULE_ALIAS("snd-hda-codec-id:14f15047");
1935 MODULE_ALIAS("snd-hda-codec-id:14f15051");
1937 MODULE_LICENSE("GPL");
1938 MODULE_DESCRIPTION("Conexant HD-audio codec");
1940 static struct hda_codec_preset_list conexant_list = {
1941 .preset = snd_hda_preset_conexant,
1942 .owner = THIS_MODULE,
1945 static int __init patch_conexant_init(void)
1947 return snd_hda_add_codec_preset(&conexant_list);
1950 static void __exit patch_conexant_exit(void)
1952 snd_hda_delete_codec_preset(&conexant_list);
1955 module_init(patch_conexant_init)
1956 module_exit(patch_conexant_exit)