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 static int conexant_add_jack(struct hda_codec *codec,
351 hda_nid_t nid, int type)
353 struct conexant_spec *spec;
354 struct conexant_jack *jack;
358 snd_array_init(&spec->jacks, sizeof(*jack), 32);
359 jack = snd_array_new(&spec->jacks);
360 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
368 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
371 static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
373 struct conexant_spec *spec = codec->spec;
374 struct conexant_jack *jacks = spec->jacks.list;
378 for (i = 0; i < spec->jacks.used; i++) {
379 if (jacks->nid == nid) {
380 unsigned int present;
381 present = snd_hda_codec_read(codec, nid, 0,
382 AC_VERB_GET_PIN_SENSE, 0) &
383 AC_PINSENSE_PRESENCE;
385 present = (present) ? jacks->type : 0 ;
387 snd_jack_report(jacks->jack,
395 static int conexant_init_jacks(struct hda_codec *codec)
397 #ifdef CONFIG_SND_JACK
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);
430 static int conexant_init(struct hda_codec *codec)
432 struct conexant_spec *spec = codec->spec;
435 for (i = 0; i < spec->num_init_verbs; i++)
436 snd_hda_sequence_write(codec, spec->init_verbs[i]);
440 static void conexant_free(struct hda_codec *codec)
442 #ifdef CONFIG_SND_JACK
443 struct conexant_spec *spec = codec->spec;
444 if (spec->jacks.list) {
445 struct conexant_jack *jacks = spec->jacks.list;
447 for (i = 0; i < spec->jacks.used; i++)
448 snd_device_free(codec->bus->card, &jacks[i].jack);
449 snd_array_free(&spec->jacks);
455 static int conexant_build_controls(struct hda_codec *codec)
457 struct conexant_spec *spec = codec->spec;
461 for (i = 0; i < spec->num_mixers; i++) {
462 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
466 if (spec->multiout.dig_out_nid) {
467 err = snd_hda_create_spdif_out_ctls(codec,
468 spec->multiout.dig_out_nid);
471 err = snd_hda_create_spdif_share_sw(codec,
475 spec->multiout.share_spdif = 1;
477 if (spec->dig_in_nid) {
478 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
485 static struct hda_codec_ops conexant_patch_ops = {
486 .build_controls = conexant_build_controls,
487 .build_pcms = conexant_build_pcms,
488 .init = conexant_init,
489 .free = conexant_free,
494 * the private value = nid | (invert << 8)
497 #define cxt_eapd_info snd_ctl_boolean_mono_info
499 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
500 struct snd_ctl_elem_value *ucontrol)
502 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
503 struct conexant_spec *spec = codec->spec;
504 int invert = (kcontrol->private_value >> 8) & 1;
506 ucontrol->value.integer.value[0] = !spec->cur_eapd;
508 ucontrol->value.integer.value[0] = spec->cur_eapd;
513 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
514 struct snd_ctl_elem_value *ucontrol)
516 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
517 struct conexant_spec *spec = codec->spec;
518 int invert = (kcontrol->private_value >> 8) & 1;
519 hda_nid_t nid = kcontrol->private_value & 0xff;
522 eapd = !!ucontrol->value.integer.value[0];
525 if (eapd == spec->cur_eapd)
528 spec->cur_eapd = eapd;
529 snd_hda_codec_write_cache(codec, nid,
530 0, AC_VERB_SET_EAPD_BTLENABLE,
535 /* controls for test mode */
536 #ifdef CONFIG_SND_DEBUG
538 #define CXT_EAPD_SWITCH(xname, nid, mask) \
539 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
540 .info = cxt_eapd_info, \
541 .get = cxt_eapd_get, \
542 .put = cxt_eapd_put, \
543 .private_value = nid | (mask<<16) }
547 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
548 struct snd_ctl_elem_info *uinfo)
550 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
551 struct conexant_spec *spec = codec->spec;
552 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
553 spec->num_channel_mode);
556 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
557 struct snd_ctl_elem_value *ucontrol)
559 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
560 struct conexant_spec *spec = codec->spec;
561 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
562 spec->num_channel_mode,
563 spec->multiout.max_channels);
566 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
567 struct snd_ctl_elem_value *ucontrol)
569 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
570 struct conexant_spec *spec = codec->spec;
571 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
572 spec->num_channel_mode,
573 &spec->multiout.max_channels);
574 if (err >= 0 && spec->need_dac_fix)
575 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
579 #define CXT_PIN_MODE(xname, nid, dir) \
580 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
581 .info = conexant_ch_mode_info, \
582 .get = conexant_ch_mode_get, \
583 .put = conexant_ch_mode_put, \
584 .private_value = nid | (dir<<16) }
586 #endif /* CONFIG_SND_DEBUG */
588 /* Conexant 5045 specific */
590 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
591 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
592 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
593 #define CXT5045_SPDIF_OUT 0x18
595 static struct hda_channel_mode cxt5045_modes[1] = {
599 static struct hda_input_mux cxt5045_capture_source = {
607 static struct hda_input_mux cxt5045_capture_source_benq = {
616 static struct hda_input_mux cxt5045_capture_source_hp530 = {
624 /* turn on/off EAPD (+ mute HP) as a master switch */
625 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
626 struct snd_ctl_elem_value *ucontrol)
628 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
629 struct conexant_spec *spec = codec->spec;
632 if (!cxt_eapd_put(kcontrol, ucontrol))
635 /* toggle internal speakers mute depending of presence of
638 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
639 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
642 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
643 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
648 /* bind volumes of both NID 0x10 and 0x11 */
649 static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
650 .ops = &snd_hda_bind_vol,
652 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
653 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
658 /* toggle input of built-in and mic jack appropriately */
659 static void cxt5045_hp_automic(struct hda_codec *codec)
661 static struct hda_verb mic_jack_on[] = {
662 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
663 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
666 static struct hda_verb mic_jack_off[] = {
667 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
668 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
671 unsigned int present;
673 present = snd_hda_codec_read(codec, 0x12, 0,
674 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
676 snd_hda_sequence_write(codec, mic_jack_on);
678 snd_hda_sequence_write(codec, mic_jack_off);
682 /* mute internal speaker if HP is plugged */
683 static void cxt5045_hp_automute(struct hda_codec *codec)
685 struct conexant_spec *spec = codec->spec;
688 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
689 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
691 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
692 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
696 /* unsolicited event for HP jack sensing */
697 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
702 case CONEXANT_HP_EVENT:
703 cxt5045_hp_automute(codec);
705 case CONEXANT_MIC_EVENT:
706 cxt5045_hp_automic(codec);
712 static struct snd_kcontrol_new cxt5045_mixers[] = {
714 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
715 .name = "Capture Source",
716 .info = conexant_mux_enum_info,
717 .get = conexant_mux_enum_get,
718 .put = conexant_mux_enum_put
720 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
721 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
722 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
723 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
724 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
725 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
726 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
727 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
728 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
729 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
730 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
733 .name = "Master Playback Switch",
734 .info = cxt_eapd_info,
736 .put = cxt5045_hp_master_sw_put,
737 .private_value = 0x10,
743 static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
744 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
745 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
746 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
747 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
752 static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
754 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
755 .name = "Capture Source",
756 .info = conexant_mux_enum_info,
757 .get = conexant_mux_enum_get,
758 .put = conexant_mux_enum_put
760 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
761 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
762 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
763 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
764 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
765 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
766 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
767 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
768 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
769 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
770 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
772 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
773 .name = "Master Playback Switch",
774 .info = cxt_eapd_info,
776 .put = cxt5045_hp_master_sw_put,
777 .private_value = 0x10,
783 static struct hda_verb cxt5045_init_verbs[] = {
785 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
786 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
788 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
789 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
790 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
791 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
792 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
793 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
794 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
795 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
796 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
797 /* Record selector: Int mic */
798 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
799 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
800 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
801 /* SPDIF route: PCM */
802 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
803 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
805 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
809 static struct hda_verb cxt5045_benq_init_verbs[] = {
811 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
812 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
813 /* Line In,HP, Amp */
814 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
815 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
816 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
817 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
818 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
819 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
820 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
821 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
822 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
823 /* Record selector: Int mic */
824 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
825 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
826 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
827 /* SPDIF route: PCM */
828 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
829 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
831 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
835 static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
836 /* pin sensing on HP jack */
837 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
841 static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
842 /* pin sensing on HP jack */
843 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
847 #ifdef CONFIG_SND_DEBUG
848 /* Test configuration for debugging, modelled after the ALC260 test
851 static struct hda_input_mux cxt5045_test_capture_source = {
856 { "LINE1 pin", 0x2 },
857 { "HP-OUT pin", 0x3 },
862 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
864 /* Output controls */
865 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
866 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
867 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
868 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
869 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
870 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
872 /* Modes for retasking pin widgets */
873 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
874 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
876 /* EAPD Switch Control */
877 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
879 /* Loopback mixer controls */
881 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
882 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
883 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
884 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
885 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
886 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
887 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
888 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
889 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
890 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
892 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
893 .name = "Input Source",
894 .info = conexant_mux_enum_info,
895 .get = conexant_mux_enum_get,
896 .put = conexant_mux_enum_put,
898 /* Audio input controls */
899 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
900 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
901 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
902 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
903 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
904 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
905 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
906 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
907 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
908 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
912 static struct hda_verb cxt5045_test_init_verbs[] = {
913 /* Set connections */
914 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
915 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
916 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
917 /* Enable retasking pins as output, initially without power amp */
918 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
919 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
921 /* Disable digital (SPDIF) pins initially, but users can enable
922 * them via a mixer switch. In the case of SPDIF-out, this initverb
923 * payload also sets the generation to 0, output to be in "consumer"
924 * PCM format, copyright asserted, no pre-emphasis and no validity
927 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
928 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
930 /* Start with output sum widgets muted and their output gains at min */
931 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
932 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
934 /* Unmute retasking pin widget output buffers since the default
935 * state appears to be output. As the pin mode is changed by the
936 * user the pin mode control will take care of enabling the pin's
937 * input/output buffers as needed.
939 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
940 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
942 /* Mute capture amp left and right */
943 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
945 /* Set ADC connection select to match default mixer setting (mic1
948 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
949 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
951 /* Mute all inputs to mixer widget (even unconnected ones) */
952 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
953 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
954 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
955 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
956 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
963 /* initialize jack-sensing, too */
964 static int cxt5045_init(struct hda_codec *codec)
966 conexant_init(codec);
967 cxt5045_hp_automute(codec);
973 CXT5045_LAPTOP_HPSENSE,
974 CXT5045_LAPTOP_MICSENSE,
975 CXT5045_LAPTOP_HPMICSENSE,
977 CXT5045_LAPTOP_HP530,
978 #ifdef CONFIG_SND_DEBUG
984 static const char *cxt5045_models[CXT5045_MODELS] = {
985 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
986 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
987 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
988 [CXT5045_BENQ] = "benq",
989 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
990 #ifdef CONFIG_SND_DEBUG
991 [CXT5045_TEST] = "test",
995 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
996 SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
997 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
998 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
999 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
1000 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
1001 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
1002 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
1003 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1004 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
1005 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1006 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1007 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1008 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1009 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1010 CXT5045_LAPTOP_HPMICSENSE),
1011 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1012 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1013 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1014 SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
1015 SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
1016 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1020 static int patch_cxt5045(struct hda_codec *codec)
1022 struct conexant_spec *spec;
1025 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1030 spec->multiout.max_channels = 2;
1031 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1032 spec->multiout.dac_nids = cxt5045_dac_nids;
1033 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1034 spec->num_adc_nids = 1;
1035 spec->adc_nids = cxt5045_adc_nids;
1036 spec->capsrc_nids = cxt5045_capsrc_nids;
1037 spec->input_mux = &cxt5045_capture_source;
1038 spec->num_mixers = 1;
1039 spec->mixers[0] = cxt5045_mixers;
1040 spec->num_init_verbs = 1;
1041 spec->init_verbs[0] = cxt5045_init_verbs;
1042 spec->spdif_route = 0;
1043 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1044 spec->channel_mode = cxt5045_modes,
1047 codec->patch_ops = conexant_patch_ops;
1049 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1052 switch (board_config) {
1053 case CXT5045_LAPTOP_HPSENSE:
1054 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1055 spec->input_mux = &cxt5045_capture_source;
1056 spec->num_init_verbs = 2;
1057 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1058 spec->mixers[0] = cxt5045_mixers;
1059 codec->patch_ops.init = cxt5045_init;
1061 case CXT5045_LAPTOP_MICSENSE:
1062 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1063 spec->input_mux = &cxt5045_capture_source;
1064 spec->num_init_verbs = 2;
1065 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1066 spec->mixers[0] = cxt5045_mixers;
1067 codec->patch_ops.init = cxt5045_init;
1070 case CXT5045_LAPTOP_HPMICSENSE:
1071 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1072 spec->input_mux = &cxt5045_capture_source;
1073 spec->num_init_verbs = 3;
1074 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1075 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1076 spec->mixers[0] = cxt5045_mixers;
1077 codec->patch_ops.init = cxt5045_init;
1080 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1081 spec->input_mux = &cxt5045_capture_source_benq;
1082 spec->num_init_verbs = 1;
1083 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1084 spec->mixers[0] = cxt5045_mixers;
1085 spec->mixers[1] = cxt5045_benq_mixers;
1086 spec->num_mixers = 2;
1087 codec->patch_ops.init = cxt5045_init;
1089 case CXT5045_LAPTOP_HP530:
1090 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1091 spec->input_mux = &cxt5045_capture_source_hp530;
1092 spec->num_init_verbs = 2;
1093 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1094 spec->mixers[0] = cxt5045_mixers_hp530;
1095 codec->patch_ops.init = cxt5045_init;
1097 #ifdef CONFIG_SND_DEBUG
1099 spec->input_mux = &cxt5045_test_capture_source;
1100 spec->mixers[0] = cxt5045_test_mixer;
1101 spec->init_verbs[0] = cxt5045_test_init_verbs;
1107 switch (codec->subsystem_id >> 16) {
1109 /* HP laptop has a really bad sound over 0dB on NID 0x17.
1110 * Fix max PCM level to 0 dB
1111 * (originall it has 0x2b steps with 0dB offset 0x14)
1113 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1114 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1115 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1116 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1117 (1 << AC_AMPCAP_MUTE_SHIFT));
1125 /* Conexant 5047 specific */
1126 #define CXT5047_SPDIF_OUT 0x11
1128 static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
1129 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1130 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1132 static struct hda_channel_mode cxt5047_modes[1] = {
1136 static struct hda_input_mux cxt5047_capture_source = {
1143 static struct hda_input_mux cxt5047_hp_capture_source = {
1150 static struct hda_input_mux cxt5047_toshiba_capture_source = {
1158 /* turn on/off EAPD (+ mute HP) as a master switch */
1159 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1160 struct snd_ctl_elem_value *ucontrol)
1162 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1163 struct conexant_spec *spec = codec->spec;
1166 if (!cxt_eapd_put(kcontrol, ucontrol))
1169 /* toggle internal speakers mute depending of presence of
1170 * the headphone jack
1172 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1173 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1174 HDA_AMP_MUTE, bits);
1175 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1176 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1177 HDA_AMP_MUTE, bits);
1181 /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
1182 static struct hda_bind_ctls cxt5047_bind_master_vol = {
1183 .ops = &snd_hda_bind_vol,
1185 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1186 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1191 /* mute internal speaker if HP is plugged */
1192 static void cxt5047_hp_automute(struct hda_codec *codec)
1194 struct conexant_spec *spec = codec->spec;
1197 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1198 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1200 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1201 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1202 HDA_AMP_MUTE, bits);
1203 /* Mute/Unmute PCM 2 for good measure - some systems need this */
1204 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1205 HDA_AMP_MUTE, bits);
1208 /* mute internal speaker if HP is plugged */
1209 static void cxt5047_hp2_automute(struct hda_codec *codec)
1211 struct conexant_spec *spec = codec->spec;
1214 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1215 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1217 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1218 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1219 HDA_AMP_MUTE, bits);
1220 /* Mute/Unmute PCM 2 for good measure - some systems need this */
1221 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1222 HDA_AMP_MUTE, bits);
1225 /* toggle input of built-in and mic jack appropriately */
1226 static void cxt5047_hp_automic(struct hda_codec *codec)
1228 static struct hda_verb mic_jack_on[] = {
1229 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1230 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1233 static struct hda_verb mic_jack_off[] = {
1234 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1235 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1238 unsigned int present;
1240 present = snd_hda_codec_read(codec, 0x15, 0,
1241 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1243 snd_hda_sequence_write(codec, mic_jack_on);
1245 snd_hda_sequence_write(codec, mic_jack_off);
1248 /* unsolicited event for HP jack sensing */
1249 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1252 switch (res >> 26) {
1253 case CONEXANT_HP_EVENT:
1254 cxt5047_hp_automute(codec);
1256 case CONEXANT_MIC_EVENT:
1257 cxt5047_hp_automic(codec);
1262 /* unsolicited event for HP jack sensing - non-EAPD systems */
1263 static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1268 case CONEXANT_HP_EVENT:
1269 cxt5047_hp2_automute(codec);
1271 case CONEXANT_MIC_EVENT:
1272 cxt5047_hp_automic(codec);
1277 static struct snd_kcontrol_new cxt5047_mixers[] = {
1278 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1279 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1280 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1281 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
1282 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1283 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1284 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1285 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1286 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1287 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1288 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1289 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1290 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1291 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
1296 static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1298 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1299 .name = "Capture Source",
1300 .info = conexant_mux_enum_info,
1301 .get = conexant_mux_enum_get,
1302 .put = conexant_mux_enum_put
1304 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1305 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1306 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1307 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1308 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1309 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1310 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
1312 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1313 .name = "Master Playback Switch",
1314 .info = cxt_eapd_info,
1315 .get = cxt_eapd_get,
1316 .put = cxt5047_hp_master_sw_put,
1317 .private_value = 0x13,
1323 static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1325 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1326 .name = "Capture Source",
1327 .info = conexant_mux_enum_info,
1328 .get = conexant_mux_enum_get,
1329 .put = conexant_mux_enum_put
1331 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1332 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1333 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1334 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1335 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1336 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1337 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1339 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1340 .name = "Master Playback Switch",
1341 .info = cxt_eapd_info,
1342 .get = cxt_eapd_get,
1343 .put = cxt5047_hp_master_sw_put,
1344 .private_value = 0x13,
1349 static struct hda_verb cxt5047_init_verbs[] = {
1350 /* Line in, Mic, Built-in Mic */
1351 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1352 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1353 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1355 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1356 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
1357 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1358 /* Record selector: Mic */
1359 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1360 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1361 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1362 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1363 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1364 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1365 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1366 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1367 /* SPDIF route: PCM */
1368 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1369 /* Enable unsolicited events */
1370 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1371 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1375 /* configuration for Toshiba Laptops */
1376 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1377 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1378 /* pin sensing on HP and Mic jacks */
1379 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1380 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1381 /* Speaker routing */
1382 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1386 /* configuration for HP Laptops */
1387 static struct hda_verb cxt5047_hp_init_verbs[] = {
1388 /* pin sensing on HP jack */
1389 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1390 /* 0x13 is actually shared by both HP and speaker;
1391 * setting the connection to 0 (=0x19) makes the master volume control
1392 * working mysteriouslly...
1394 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1395 /* Record selector: Ext Mic */
1396 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1397 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1398 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1399 /* Speaker routing */
1400 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1404 /* Test configuration for debugging, modelled after the ALC260 test
1407 #ifdef CONFIG_SND_DEBUG
1408 static struct hda_input_mux cxt5047_test_capture_source = {
1411 { "LINE1 pin", 0x0 },
1412 { "MIC1 pin", 0x1 },
1413 { "MIC2 pin", 0x2 },
1418 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1420 /* Output only controls */
1421 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1422 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1423 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1424 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1425 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1426 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1427 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1428 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1429 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1431 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1432 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1434 /* Modes for retasking pin widgets */
1435 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1436 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1438 /* EAPD Switch Control */
1439 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1441 /* Loopback mixer controls */
1442 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1443 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1444 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1445 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1446 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1447 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1448 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1449 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1451 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1452 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1453 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1454 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1455 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1456 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1457 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1458 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1460 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1461 .name = "Input Source",
1462 .info = conexant_mux_enum_info,
1463 .get = conexant_mux_enum_get,
1464 .put = conexant_mux_enum_put,
1466 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1467 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1468 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1469 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1470 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1471 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1472 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1473 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1474 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1475 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1480 static struct hda_verb cxt5047_test_init_verbs[] = {
1481 /* Enable retasking pins as output, initially without power amp */
1482 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1483 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1484 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1486 /* Disable digital (SPDIF) pins initially, but users can enable
1487 * them via a mixer switch. In the case of SPDIF-out, this initverb
1488 * payload also sets the generation to 0, output to be in "consumer"
1489 * PCM format, copyright asserted, no pre-emphasis and no validity
1492 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1494 /* Ensure mic1, mic2, line1 pin widgets take input from the
1495 * OUT1 sum bus when acting as an output.
1497 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1498 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1500 /* Start with output sum widgets muted and their output gains at min */
1501 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1502 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1504 /* Unmute retasking pin widget output buffers since the default
1505 * state appears to be output. As the pin mode is changed by the
1506 * user the pin mode control will take care of enabling the pin's
1507 * input/output buffers as needed.
1509 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1510 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1511 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1513 /* Mute capture amp left and right */
1514 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1516 /* Set ADC connection select to match default mixer setting (mic1
1519 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1521 /* Mute all inputs to mixer widget (even unconnected ones) */
1522 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1523 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1524 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1525 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1526 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1527 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1529 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1536 /* initialize jack-sensing, too */
1537 static int cxt5047_hp_init(struct hda_codec *codec)
1539 conexant_init(codec);
1540 cxt5047_hp_automute(codec);
1546 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1547 CXT5047_LAPTOP_HP, /* Some HP laptops */
1548 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1549 #ifdef CONFIG_SND_DEBUG
1555 static const char *cxt5047_models[CXT5047_MODELS] = {
1556 [CXT5047_LAPTOP] = "laptop",
1557 [CXT5047_LAPTOP_HP] = "laptop-hp",
1558 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1559 #ifdef CONFIG_SND_DEBUG
1560 [CXT5047_TEST] = "test",
1564 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1565 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1566 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1567 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
1568 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
1569 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1573 static int patch_cxt5047(struct hda_codec *codec)
1575 struct conexant_spec *spec;
1578 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1583 spec->multiout.max_channels = 2;
1584 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1585 spec->multiout.dac_nids = cxt5047_dac_nids;
1586 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1587 spec->num_adc_nids = 1;
1588 spec->adc_nids = cxt5047_adc_nids;
1589 spec->capsrc_nids = cxt5047_capsrc_nids;
1590 spec->input_mux = &cxt5047_capture_source;
1591 spec->num_mixers = 1;
1592 spec->mixers[0] = cxt5047_mixers;
1593 spec->num_init_verbs = 1;
1594 spec->init_verbs[0] = cxt5047_init_verbs;
1595 spec->spdif_route = 0;
1596 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1597 spec->channel_mode = cxt5047_modes,
1599 codec->patch_ops = conexant_patch_ops;
1601 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1604 switch (board_config) {
1605 case CXT5047_LAPTOP:
1606 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
1608 case CXT5047_LAPTOP_HP:
1609 spec->input_mux = &cxt5047_hp_capture_source;
1610 spec->num_init_verbs = 2;
1611 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1612 spec->mixers[0] = cxt5047_hp_mixers;
1613 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1614 codec->patch_ops.init = cxt5047_hp_init;
1616 case CXT5047_LAPTOP_EAPD:
1617 spec->input_mux = &cxt5047_toshiba_capture_source;
1618 spec->num_init_verbs = 2;
1619 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1620 spec->mixers[0] = cxt5047_toshiba_mixers;
1621 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1623 #ifdef CONFIG_SND_DEBUG
1625 spec->input_mux = &cxt5047_test_capture_source;
1626 spec->mixers[0] = cxt5047_test_mixer;
1627 spec->init_verbs[0] = cxt5047_test_init_verbs;
1628 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1634 /* Conexant 5051 specific */
1635 static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1636 static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1638 static struct hda_channel_mode cxt5051_modes[1] = {
1642 static void cxt5051_update_speaker(struct hda_codec *codec)
1644 struct conexant_spec *spec = codec->spec;
1645 unsigned int pinctl;
1646 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1647 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1651 /* turn on/off EAPD (+ mute HP) as a master switch */
1652 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1653 struct snd_ctl_elem_value *ucontrol)
1655 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1657 if (!cxt_eapd_put(kcontrol, ucontrol))
1659 cxt5051_update_speaker(codec);
1663 /* toggle input of built-in and mic jack appropriately */
1664 static void cxt5051_portb_automic(struct hda_codec *codec)
1666 unsigned int present;
1668 present = snd_hda_codec_read(codec, 0x17, 0,
1669 AC_VERB_GET_PIN_SENSE, 0) &
1670 AC_PINSENSE_PRESENCE;
1671 snd_hda_codec_write(codec, 0x14, 0,
1672 AC_VERB_SET_CONNECT_SEL,
1673 present ? 0x01 : 0x00);
1676 /* switch the current ADC according to the jack state */
1677 static void cxt5051_portc_automic(struct hda_codec *codec)
1679 struct conexant_spec *spec = codec->spec;
1680 unsigned int present;
1683 present = snd_hda_codec_read(codec, 0x18, 0,
1684 AC_VERB_GET_PIN_SENSE, 0) &
1685 AC_PINSENSE_PRESENCE;
1687 spec->cur_adc_idx = 1;
1689 spec->cur_adc_idx = 0;
1690 new_adc = spec->adc_nids[spec->cur_adc_idx];
1691 if (spec->cur_adc && spec->cur_adc != new_adc) {
1692 /* stream is running, let's swap the current ADC */
1693 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1694 spec->cur_adc = new_adc;
1695 snd_hda_codec_setup_stream(codec, new_adc,
1696 spec->cur_adc_stream_tag, 0,
1697 spec->cur_adc_format);
1701 /* mute internal speaker if HP is plugged */
1702 static void cxt5051_hp_automute(struct hda_codec *codec)
1704 struct conexant_spec *spec = codec->spec;
1706 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1707 AC_VERB_GET_PIN_SENSE, 0) &
1708 AC_PINSENSE_PRESENCE;
1709 cxt5051_update_speaker(codec);
1712 /* unsolicited event for HP jack sensing */
1713 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1716 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1717 switch (res >> 26) {
1718 case CONEXANT_HP_EVENT:
1719 cxt5051_hp_automute(codec);
1721 case CXT5051_PORTB_EVENT:
1722 cxt5051_portb_automic(codec);
1724 case CXT5051_PORTC_EVENT:
1725 cxt5051_portc_automic(codec);
1728 conexant_report_jack(codec, nid);
1731 static struct snd_kcontrol_new cxt5051_mixers[] = {
1732 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1733 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1734 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1735 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1736 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1737 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1738 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1741 .name = "Master Playback Switch",
1742 .info = cxt_eapd_info,
1743 .get = cxt_eapd_get,
1744 .put = cxt5051_hp_master_sw_put,
1745 .private_value = 0x1a,
1751 static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1752 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1753 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1754 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1755 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1756 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1758 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1759 .name = "Master Playback Switch",
1760 .info = cxt_eapd_info,
1761 .get = cxt_eapd_get,
1762 .put = cxt5051_hp_master_sw_put,
1763 .private_value = 0x1a,
1769 static struct hda_verb cxt5051_init_verbs[] = {
1771 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1772 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1773 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1774 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1775 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1776 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1778 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1779 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1781 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1782 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1784 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1785 /* Record selector: Int mic */
1786 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1787 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1788 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1789 /* SPDIF route: PCM */
1790 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1792 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1793 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1794 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1795 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1799 /* initialize jack-sensing, too */
1800 static int cxt5051_init(struct hda_codec *codec)
1802 conexant_init(codec);
1803 conexant_init_jacks(codec);
1804 if (codec->patch_ops.unsol_event) {
1805 cxt5051_hp_automute(codec);
1806 cxt5051_portb_automic(codec);
1807 cxt5051_portc_automic(codec);
1814 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1815 CXT5051_HP, /* no docking */
1819 static const char *cxt5051_models[CXT5051_MODELS] = {
1820 [CXT5051_LAPTOP] = "laptop",
1821 [CXT5051_HP] = "hp",
1824 static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1825 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1827 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1831 static int patch_cxt5051(struct hda_codec *codec)
1833 struct conexant_spec *spec;
1836 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1841 codec->patch_ops = conexant_patch_ops;
1842 codec->patch_ops.init = cxt5051_init;
1844 spec->multiout.max_channels = 2;
1845 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1846 spec->multiout.dac_nids = cxt5051_dac_nids;
1847 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1848 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1849 spec->adc_nids = cxt5051_adc_nids;
1850 spec->num_mixers = 1;
1851 spec->mixers[0] = cxt5051_mixers;
1852 spec->num_init_verbs = 1;
1853 spec->init_verbs[0] = cxt5051_init_verbs;
1854 spec->spdif_route = 0;
1855 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1856 spec->channel_mode = cxt5051_modes;
1858 spec->cur_adc_idx = 0;
1860 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1863 switch (board_config) {
1865 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1866 spec->mixers[0] = cxt5051_hp_mixers;
1869 case CXT5051_LAPTOP:
1870 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1881 static struct hda_codec_preset snd_hda_preset_conexant[] = {
1882 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1883 .patch = patch_cxt5045 },
1884 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1885 .patch = patch_cxt5047 },
1886 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1887 .patch = patch_cxt5051 },
1891 MODULE_ALIAS("snd-hda-codec-id:14f15045");
1892 MODULE_ALIAS("snd-hda-codec-id:14f15047");
1893 MODULE_ALIAS("snd-hda-codec-id:14f15051");
1895 MODULE_LICENSE("GPL");
1896 MODULE_DESCRIPTION("Conexant HD-audio codec");
1898 static struct hda_codec_preset_list conexant_list = {
1899 .preset = snd_hda_preset_conexant,
1900 .owner = THIS_MODULE,
1903 static int __init patch_conexant_init(void)
1905 return snd_hda_add_codec_preset(&conexant_list);
1908 static void __exit patch_conexant_exit(void)
1910 snd_hda_delete_codec_preset(&conexant_list);
1913 module_init(patch_conexant_init)
1914 module_exit(patch_conexant_exit)