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 <sound/driver.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/pci.h>
28 #include <sound/core.h>
29 #include "hda_codec.h"
30 #include "hda_local.h"
32 #define CXT_PIN_DIR_IN 0x00
33 #define CXT_PIN_DIR_OUT 0x01
34 #define CXT_PIN_DIR_INOUT 0x02
35 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
36 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
38 #define CONEXANT_HP_EVENT 0x37
39 #define CONEXANT_MIC_EVENT 0x38
43 struct conexant_spec {
45 struct snd_kcontrol_new *mixers[5];
48 const struct hda_verb *init_verbs[5]; /* initialization verbs
52 unsigned int num_init_verbs;
55 struct hda_multi_out multiout; /* playback set-up
56 * max_channels, dacs must be set
57 * dig_out_nid and hp_nid are optional
59 unsigned int cur_eapd;
60 unsigned int hp_present;
61 unsigned int need_dac_fix;
64 unsigned int num_adc_nids;
66 hda_nid_t dig_in_nid; /* digital-in NID; optional */
69 const struct hda_input_mux *input_mux;
70 hda_nid_t *capsrc_nids;
71 unsigned int cur_mux[3];
74 const struct hda_channel_mode *channel_mode;
78 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
80 struct mutex amp_mutex; /* PCM volume/mute control mutex */
81 unsigned int spdif_route;
83 /* dynamic controls, init_verbs and input_mux */
84 struct auto_pin_cfg autocfg;
85 unsigned int num_kctl_alloc, num_kctl_used;
86 struct snd_kcontrol_new *kctl_alloc;
87 struct hda_input_mux private_imux;
88 hda_nid_t private_dac_nids[4];
92 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
93 struct hda_codec *codec,
94 struct snd_pcm_substream *substream)
96 struct conexant_spec *spec = codec->spec;
97 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
100 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
101 struct hda_codec *codec,
102 unsigned int stream_tag,
104 struct snd_pcm_substream *substream)
106 struct conexant_spec *spec = codec->spec;
107 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
112 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
113 struct hda_codec *codec,
114 struct snd_pcm_substream *substream)
116 struct conexant_spec *spec = codec->spec;
117 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
123 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
124 struct hda_codec *codec,
125 struct snd_pcm_substream *substream)
127 struct conexant_spec *spec = codec->spec;
128 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
131 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
132 struct hda_codec *codec,
133 struct snd_pcm_substream *substream)
135 struct conexant_spec *spec = codec->spec;
136 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
142 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
143 struct hda_codec *codec,
144 unsigned int stream_tag,
146 struct snd_pcm_substream *substream)
148 struct conexant_spec *spec = codec->spec;
149 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
150 stream_tag, 0, format);
154 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
155 struct hda_codec *codec,
156 struct snd_pcm_substream *substream)
158 struct conexant_spec *spec = codec->spec;
159 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
166 static struct hda_pcm_stream conexant_pcm_analog_playback = {
170 .nid = 0, /* fill later */
172 .open = conexant_playback_pcm_open,
173 .prepare = conexant_playback_pcm_prepare,
174 .cleanup = conexant_playback_pcm_cleanup
178 static struct hda_pcm_stream conexant_pcm_analog_capture = {
182 .nid = 0, /* fill later */
184 .prepare = conexant_capture_pcm_prepare,
185 .cleanup = conexant_capture_pcm_cleanup
190 static struct hda_pcm_stream conexant_pcm_digital_playback = {
194 .nid = 0, /* fill later */
196 .open = conexant_dig_playback_pcm_open,
197 .close = conexant_dig_playback_pcm_close
201 static struct hda_pcm_stream conexant_pcm_digital_capture = {
205 /* NID is set in alc_build_pcms */
208 static int conexant_build_pcms(struct hda_codec *codec)
210 struct conexant_spec *spec = codec->spec;
211 struct hda_pcm *info = spec->pcm_rec;
214 codec->pcm_info = info;
216 info->name = "CONEXANT Analog";
217 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
218 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
219 spec->multiout.max_channels;
220 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
221 spec->multiout.dac_nids[0];
222 info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture;
223 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
224 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
226 if (spec->multiout.dig_out_nid) {
229 info->name = "Conexant Digital";
230 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
231 conexant_pcm_digital_playback;
232 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
233 spec->multiout.dig_out_nid;
234 if (spec->dig_in_nid) {
235 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
236 conexant_pcm_digital_capture;
237 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
245 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
246 struct snd_ctl_elem_info *uinfo)
248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
249 struct conexant_spec *spec = codec->spec;
251 return snd_hda_input_mux_info(spec->input_mux, uinfo);
254 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
255 struct snd_ctl_elem_value *ucontrol)
257 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
258 struct conexant_spec *spec = codec->spec;
259 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
261 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
265 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
266 struct snd_ctl_elem_value *ucontrol)
268 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
269 struct conexant_spec *spec = codec->spec;
270 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
272 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
273 spec->capsrc_nids[adc_idx],
274 &spec->cur_mux[adc_idx]);
277 static int conexant_init(struct hda_codec *codec)
279 struct conexant_spec *spec = codec->spec;
282 for (i = 0; i < spec->num_init_verbs; i++)
283 snd_hda_sequence_write(codec, spec->init_verbs[i]);
287 static void conexant_free(struct hda_codec *codec)
289 struct conexant_spec *spec = codec->spec;
292 if (spec->kctl_alloc) {
293 for (i = 0; i < spec->num_kctl_used; i++)
294 kfree(spec->kctl_alloc[i].name);
295 kfree(spec->kctl_alloc);
302 static int conexant_resume(struct hda_codec *codec)
304 struct conexant_spec *spec = codec->spec;
307 codec->patch_ops.init(codec);
308 for (i = 0; i < spec->num_mixers; i++)
309 snd_hda_resume_ctls(codec, spec->mixers[i]);
310 if (spec->multiout.dig_out_nid)
311 snd_hda_resume_spdif_out(codec);
312 if (spec->dig_in_nid)
313 snd_hda_resume_spdif_in(codec);
318 static int conexant_build_controls(struct hda_codec *codec)
320 struct conexant_spec *spec = codec->spec;
324 for (i = 0; i < spec->num_mixers; i++) {
325 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
329 if (spec->multiout.dig_out_nid) {
330 err = snd_hda_create_spdif_out_ctls(codec,
331 spec->multiout.dig_out_nid);
335 if (spec->dig_in_nid) {
336 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
343 static struct hda_codec_ops conexant_patch_ops = {
344 .build_controls = conexant_build_controls,
345 .build_pcms = conexant_build_pcms,
346 .init = conexant_init,
347 .free = conexant_free,
349 .resume = conexant_resume,
355 * the private value = nid | (invert << 8)
358 static int cxt_eapd_info(struct snd_kcontrol *kcontrol,
359 struct snd_ctl_elem_info *uinfo)
361 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
363 uinfo->value.integer.min = 0;
364 uinfo->value.integer.max = 1;
368 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
369 struct snd_ctl_elem_value *ucontrol)
371 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
372 struct conexant_spec *spec = codec->spec;
373 int invert = (kcontrol->private_value >> 8) & 1;
375 ucontrol->value.integer.value[0] = !spec->cur_eapd;
377 ucontrol->value.integer.value[0] = spec->cur_eapd;
382 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
383 struct snd_ctl_elem_value *ucontrol)
385 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
386 struct conexant_spec *spec = codec->spec;
387 int invert = (kcontrol->private_value >> 8) & 1;
388 hda_nid_t nid = kcontrol->private_value & 0xff;
391 eapd = ucontrol->value.integer.value[0];
394 if (eapd == spec->cur_eapd && !codec->in_resume)
397 spec->cur_eapd = eapd;
398 snd_hda_codec_write(codec, nid,
399 0, AC_VERB_SET_EAPD_BTLENABLE,
404 /* controls for test mode */
405 #ifdef CONFIG_SND_DEBUG
407 #define CXT_EAPD_SWITCH(xname, nid, mask) \
408 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
409 .info = cxt_eapd_info, \
410 .get = cxt_eapd_get, \
411 .put = cxt_eapd_put, \
412 .private_value = nid | (mask<<16) }
416 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
417 struct snd_ctl_elem_info *uinfo)
419 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
420 struct conexant_spec *spec = codec->spec;
421 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
422 spec->num_channel_mode);
425 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
426 struct snd_ctl_elem_value *ucontrol)
428 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
429 struct conexant_spec *spec = codec->spec;
430 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
431 spec->num_channel_mode,
432 spec->multiout.max_channels);
435 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
436 struct snd_ctl_elem_value *ucontrol)
438 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
439 struct conexant_spec *spec = codec->spec;
440 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
441 spec->num_channel_mode,
442 &spec->multiout.max_channels);
443 if (err >= 0 && spec->need_dac_fix)
444 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
448 #define CXT_PIN_MODE(xname, nid, dir) \
449 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
450 .info = conexant_ch_mode_info, \
451 .get = conexant_ch_mode_get, \
452 .put = conexant_ch_mode_put, \
453 .private_value = nid | (dir<<16) }
455 static int cxt_gpio_data_info(struct snd_kcontrol *kcontrol,
456 struct snd_ctl_elem_info *uinfo)
458 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
460 uinfo->value.integer.min = 0;
461 uinfo->value.integer.max = 1;
465 static int cxt_gpio_data_get(struct snd_kcontrol *kcontrol,
466 struct snd_ctl_elem_value *ucontrol)
468 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
469 hda_nid_t nid = kcontrol->private_value & 0xffff;
470 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
471 long *valp = ucontrol->value.integer.value;
472 unsigned int val = snd_hda_codec_read(codec, nid, 0,
473 AC_VERB_GET_GPIO_DATA, 0x00);
475 *valp = (val & mask) != 0;
479 static int cxt_gpio_data_put(struct snd_kcontrol *kcontrol,
480 struct snd_ctl_elem_value *ucontrol)
482 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
483 hda_nid_t nid = kcontrol->private_value & 0xffff;
484 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
485 long val = *ucontrol->value.integer.value;
486 unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
487 AC_VERB_GET_GPIO_DATA,
489 unsigned int old_data = gpio_data;
491 /* Set/unset the masked GPIO bit(s) as needed */
496 if (gpio_data == old_data && !codec->in_resume)
498 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_GPIO_DATA, gpio_data);
502 #define CXT_GPIO_DATA_SWITCH(xname, nid, mask) \
503 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
504 .info = cxt_gpio_data_info, \
505 .get = cxt_gpio_data_get, \
506 .put = cxt_gpio_data_put, \
507 .private_value = nid | (mask<<16) }
509 static int cxt_spdif_ctrl_info(struct snd_kcontrol *kcontrol,
510 struct snd_ctl_elem_info *uinfo)
512 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
514 uinfo->value.integer.min = 0;
515 uinfo->value.integer.max = 1;
519 static int cxt_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
520 struct snd_ctl_elem_value *ucontrol)
522 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
523 hda_nid_t nid = kcontrol->private_value & 0xffff;
524 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
525 long *valp = ucontrol->value.integer.value;
526 unsigned int val = snd_hda_codec_read(codec, nid, 0,
527 AC_VERB_GET_DIGI_CONVERT, 0x00);
529 *valp = (val & mask) != 0;
533 static int cxt_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
534 struct snd_ctl_elem_value *ucontrol)
536 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
537 hda_nid_t nid = kcontrol->private_value & 0xffff;
538 unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
539 long val = *ucontrol->value.integer.value;
540 unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
541 AC_VERB_GET_DIGI_CONVERT,
543 unsigned int old_data = ctrl_data;
545 /* Set/unset the masked control bit(s) as needed */
550 if (ctrl_data == old_data && !codec->in_resume)
552 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
557 #define CXT_SPDIF_CTRL_SWITCH(xname, nid, mask) \
558 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
559 .info = cxt_spdif_ctrl_info, \
560 .get = cxt_spdif_ctrl_get, \
561 .put = cxt_spdif_ctrl_put, \
562 .private_value = nid | (mask<<16) }
564 #endif /* CONFIG_SND_DEBUG */
566 /* Conexant 5045 specific */
568 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
569 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
570 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
571 #define CXT5045_SPDIF_OUT 0x13
573 static struct hda_channel_mode cxt5045_modes[1] = {
577 static struct hda_input_mux cxt5045_capture_source = {
585 /* turn on/off EAPD (+ mute HP) as a master switch */
586 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
587 struct snd_ctl_elem_value *ucontrol)
589 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
590 struct conexant_spec *spec = codec->spec;
593 if (!cxt_eapd_put(kcontrol, ucontrol))
596 /* toggle internal speakers mute depending of presence of
599 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : 0x80;
600 snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, 0x80, bits);
601 snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, 0x80, bits);
602 bits = spec->cur_eapd ? 0 : 0x80;
603 snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0, 0x80, bits);
604 snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0, 0x80, bits);
608 /* bind volumes of both NID 0x10 and 0x11 */
609 static int cxt5045_hp_master_vol_put(struct snd_kcontrol *kcontrol,
610 struct snd_ctl_elem_value *ucontrol)
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613 long *valp = ucontrol->value.integer.value;
616 change = snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0,
617 0x7f, valp[0] & 0x7f);
618 change |= snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0,
619 0x7f, valp[1] & 0x7f);
620 snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0,
621 0x7f, valp[0] & 0x7f);
622 snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0,
623 0x7f, valp[1] & 0x7f);
628 /* mute internal speaker if HP is plugged */
629 static void cxt5045_hp_automute(struct hda_codec *codec)
631 struct conexant_spec *spec = codec->spec;
634 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
635 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
637 bits = (spec->hp_present || !spec->cur_eapd) ? 0x80 : 0;
638 snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, 0x80, bits);
639 snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, 0x80, bits);
642 /* unsolicited event for HP jack sensing */
643 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
648 case CONEXANT_HP_EVENT:
649 cxt5045_hp_automute(codec);
654 static struct snd_kcontrol_new cxt5045_mixers[] = {
656 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
657 .name = "Capture Source",
658 .info = conexant_mux_enum_info,
659 .get = conexant_mux_enum_get,
660 .put = conexant_mux_enum_put
662 HDA_CODEC_VOLUME("Int Mic Volume", 0x17, 0x01, HDA_INPUT),
663 HDA_CODEC_MUTE("Int Mic Switch", 0x17, 0x01, HDA_INPUT),
664 HDA_CODEC_VOLUME("Ext Mic Volume", 0x17, 0x02, HDA_INPUT),
665 HDA_CODEC_MUTE("Ext Mic Switch", 0x17, 0x02, HDA_INPUT),
666 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
667 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
669 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
670 .name = "Master Playback Volume",
671 .info = snd_hda_mixer_amp_volume_info,
672 .get = snd_hda_mixer_amp_volume_get,
673 .put = cxt5045_hp_master_vol_put,
674 .private_value = HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
677 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
678 .name = "Master Playback Switch",
679 .info = cxt_eapd_info,
681 .put = cxt5045_hp_master_sw_put,
682 .private_value = 0x10,
688 static struct hda_verb cxt5045_init_verbs[] = {
690 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
691 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
693 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
694 {0x17, AC_VERB_SET_CONNECT_SEL,0x01},
695 {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
696 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x01},
697 {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
698 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x02},
699 {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
700 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
701 {0x17, AC_VERB_SET_AMP_GAIN_MUTE,
702 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x04},
703 /* Record selector: Int mic */
704 {0x1a, AC_VERB_SET_CONNECT_SEL,0x0},
705 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
706 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
707 /* SPDIF route: PCM */
708 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
709 /* pin sensing on HP and Mic jacks */
710 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
712 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
716 #ifdef CONFIG_SND_DEBUG
717 /* Test configuration for debugging, modelled after the ALC260 test
720 static struct hda_input_mux cxt5045_test_capture_source = {
725 { "LINE1 pin", 0x2 },
726 { "HP-OUT pin", 0x3 },
731 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
733 /* Output controls */
734 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
735 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
737 /* Modes for retasking pin widgets */
738 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
739 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
741 /* EAPD Switch Control */
742 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
744 /* Loopback mixer controls */
745 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x17, 0x01, HDA_INPUT),
746 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x17, 0x01, HDA_INPUT),
747 HDA_CODEC_VOLUME("LINE loopback Playback Volume", 0x17, 0x02, HDA_INPUT),
748 HDA_CODEC_MUTE("LINE loopback Playback Switch", 0x17, 0x02, HDA_INPUT),
749 HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x17, 0x03, HDA_INPUT),
750 HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x17, 0x03, HDA_INPUT),
751 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x04, HDA_INPUT),
752 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x04, HDA_INPUT),
754 HDA_CODEC_VOLUME("Capture-1 Volume", 0x17, 0x0, HDA_INPUT),
755 HDA_CODEC_MUTE("Capture-1 Switch", 0x17, 0x0, HDA_INPUT),
756 HDA_CODEC_VOLUME("Capture-2 Volume", 0x17, 0x1, HDA_INPUT),
757 HDA_CODEC_MUTE("Capture-2 Switch", 0x17, 0x1, HDA_INPUT),
758 HDA_CODEC_VOLUME("Capture-3 Volume", 0x17, 0x2, HDA_INPUT),
759 HDA_CODEC_MUTE("Capture-3 Switch", 0x17, 0x2, HDA_INPUT),
760 HDA_CODEC_VOLUME("Capture-4 Volume", 0x17, 0x3, HDA_INPUT),
761 HDA_CODEC_MUTE("Capture-4 Switch", 0x17, 0x3, HDA_INPUT),
762 HDA_CODEC_VOLUME("Capture-5 Volume", 0x17, 0x4, HDA_INPUT),
763 HDA_CODEC_MUTE("Capture-5 Switch", 0x17, 0x4, HDA_INPUT),
765 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
766 .name = "Input Source",
767 .info = conexant_mux_enum_info,
768 .get = conexant_mux_enum_get,
769 .put = conexant_mux_enum_put,
775 static struct hda_verb cxt5045_test_init_verbs[] = {
776 /* Enable retasking pins as output, initially without power amp */
777 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
778 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
780 /* Disable digital (SPDIF) pins initially, but users can enable
781 * them via a mixer switch. In the case of SPDIF-out, this initverb
782 * payload also sets the generation to 0, output to be in "consumer"
783 * PCM format, copyright asserted, no pre-emphasis and no validity
786 {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0},
788 /* Start with output sum widgets muted and their output gains at min */
789 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
790 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
792 /* Unmute retasking pin widget output buffers since the default
793 * state appears to be output. As the pin mode is changed by the
794 * user the pin mode control will take care of enabling the pin's
795 * input/output buffers as needed.
797 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
798 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
800 /* Mute capture amp left and right */
801 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
803 /* Set ADC connection select to match default mixer setting (mic1
806 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
808 /* Mute all inputs to mixer widget (even unconnected ones) */
809 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
810 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
811 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
812 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
813 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
820 /* initialize jack-sensing, too */
821 static int cxt5045_init(struct hda_codec *codec)
823 conexant_init(codec);
824 cxt5045_hp_automute(codec);
830 CXT5045_LAPTOP, /* Laptops w/ EAPD support */
831 #ifdef CONFIG_SND_DEBUG
837 static const char *cxt5045_models[CXT5045_MODELS] = {
838 [CXT5045_LAPTOP] = "laptop",
839 #ifdef CONFIG_SND_DEBUG
840 [CXT5045_TEST] = "test",
844 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
845 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP),
846 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP),
847 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP),
851 static int patch_cxt5045(struct hda_codec *codec)
853 struct conexant_spec *spec;
856 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
859 mutex_init(&spec->amp_mutex);
862 spec->multiout.max_channels = 2;
863 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
864 spec->multiout.dac_nids = cxt5045_dac_nids;
865 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
866 spec->num_adc_nids = 1;
867 spec->adc_nids = cxt5045_adc_nids;
868 spec->capsrc_nids = cxt5045_capsrc_nids;
869 spec->input_mux = &cxt5045_capture_source;
870 spec->num_mixers = 1;
871 spec->mixers[0] = cxt5045_mixers;
872 spec->num_init_verbs = 1;
873 spec->init_verbs[0] = cxt5045_init_verbs;
874 spec->spdif_route = 0;
875 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
876 spec->channel_mode = cxt5045_modes,
879 codec->patch_ops = conexant_patch_ops;
880 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
882 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
885 switch (board_config) {
887 spec->input_mux = &cxt5045_capture_source;
888 spec->num_init_verbs = 2;
889 spec->init_verbs[1] = cxt5045_init_verbs;
890 spec->mixers[0] = cxt5045_mixers;
891 codec->patch_ops.init = cxt5045_init;
893 #ifdef CONFIG_SND_DEBUG
895 spec->input_mux = &cxt5045_test_capture_source;
896 spec->mixers[0] = cxt5045_test_mixer;
897 spec->init_verbs[0] = cxt5045_test_init_verbs;
904 /* Conexant 5047 specific */
905 #define CXT5047_SPDIF_OUT 0x11
907 static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
908 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
909 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
911 static struct hda_channel_mode cxt5047_modes[1] = {
915 static struct hda_input_mux cxt5047_capture_source = {
923 static struct hda_input_mux cxt5047_hp_capture_source = {
930 static struct hda_input_mux cxt5047_toshiba_capture_source = {
938 /* turn on/off EAPD (+ mute HP) as a master switch */
939 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
940 struct snd_ctl_elem_value *ucontrol)
942 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
943 struct conexant_spec *spec = codec->spec;
946 if (!cxt_eapd_put(kcontrol, ucontrol))
949 /* toggle internal speakers mute depending of presence of
952 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : 0x80;
953 snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0, 0x80, bits);
954 snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0, 0x80, bits);
955 bits = spec->cur_eapd ? 0 : 0x80;
956 snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0, 0x80, bits);
957 snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0, 0x80, bits);
961 /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
962 static int cxt5047_hp_master_vol_put(struct snd_kcontrol *kcontrol,
963 struct snd_ctl_elem_value *ucontrol)
965 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
966 long *valp = ucontrol->value.integer.value;
969 change = snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0,
970 0x7f, valp[0] & 0x7f);
971 change |= snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0,
972 0x7f, valp[1] & 0x7f);
973 snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0,
974 0x7f, valp[0] & 0x7f);
975 snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0,
976 0x7f, valp[1] & 0x7f);
980 /* mute internal speaker if HP is plugged */
981 static void cxt5047_hp_automute(struct hda_codec *codec)
983 struct conexant_spec *spec = codec->spec;
986 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
987 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
989 bits = (spec->hp_present || !spec->cur_eapd) ? 0x80 : 0;
990 snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0, 0x80, bits);
991 snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0, 0x80, bits);
992 /* Mute/Unmute PCM 2 for good measure - some systems need this */
993 snd_hda_codec_amp_update(codec, 0x1c, 0, HDA_OUTPUT, 0, 0x80, bits);
994 snd_hda_codec_amp_update(codec, 0x1c, 1, HDA_OUTPUT, 0, 0x80, bits);
997 /* toggle input of built-in and mic jack appropriately */
998 static void cxt5047_hp_automic(struct hda_codec *codec)
1000 static struct hda_verb mic_jack_on[] = {
1001 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1002 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1005 static struct hda_verb mic_jack_off[] = {
1006 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1007 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1010 unsigned int present;
1012 present = snd_hda_codec_read(codec, 0x08, 0,
1013 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1015 snd_hda_sequence_write(codec, mic_jack_on);
1017 snd_hda_sequence_write(codec, mic_jack_off);
1020 /* unsolicited event for HP jack sensing */
1021 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1026 case CONEXANT_HP_EVENT:
1027 cxt5047_hp_automute(codec);
1029 case CONEXANT_MIC_EVENT:
1030 cxt5047_hp_automic(codec);
1035 static struct snd_kcontrol_new cxt5047_mixers[] = {
1037 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1038 .name = "Capture Source",
1039 .info = conexant_mux_enum_info,
1040 .get = conexant_mux_enum_get,
1041 .put = conexant_mux_enum_put
1043 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1044 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1045 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1046 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1047 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1048 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1049 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1050 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1052 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1053 .name = "Master Playback Volume",
1054 .info = snd_hda_mixer_amp_volume_info,
1055 .get = snd_hda_mixer_amp_volume_get,
1056 .put = cxt5047_hp_master_vol_put,
1057 .private_value = HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1060 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1061 .name = "Master Playback Switch",
1062 .info = cxt_eapd_info,
1063 .get = cxt_eapd_get,
1064 .put = cxt5047_hp_master_sw_put,
1065 .private_value = 0x13,
1071 static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1073 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1074 .name = "Capture Source",
1075 .info = conexant_mux_enum_info,
1076 .get = conexant_mux_enum_get,
1077 .put = conexant_mux_enum_put
1079 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1080 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1081 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1082 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1083 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1084 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1086 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1087 .name = "Master Playback Volume",
1088 .info = snd_hda_mixer_amp_volume_info,
1089 .get = snd_hda_mixer_amp_volume_get,
1090 .put = cxt5047_hp_master_vol_put,
1091 .private_value = HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1094 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1095 .name = "Master Playback Switch",
1096 .info = cxt_eapd_info,
1097 .get = cxt_eapd_get,
1098 .put = cxt5047_hp_master_sw_put,
1099 .private_value = 0x13,
1105 static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1107 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1108 .name = "Capture Source",
1109 .info = conexant_mux_enum_info,
1110 .get = conexant_mux_enum_get,
1111 .put = conexant_mux_enum_put
1113 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1114 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1115 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1116 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1117 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1118 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1119 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1121 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1122 .name = "Master Playback Switch",
1123 .info = cxt_eapd_info,
1124 .get = cxt_eapd_get,
1125 .put = cxt5047_hp_master_sw_put,
1126 .private_value = 0x13,
1131 static struct hda_verb cxt5047_init_verbs[] = {
1132 /* Line in, Mic, Built-in Mic */
1133 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1134 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1135 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1136 /* HP, Amp, Speaker */
1137 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1138 {0x1A, AC_VERB_SET_CONNECT_SEL,0x00},
1139 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1140 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1141 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1142 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1143 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1144 /* Record selector: Front mic */
1145 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1146 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1147 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1148 /* SPDIF route: PCM */
1149 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1150 /* Enable unsolicited events */
1151 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1152 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1156 /* configuration for Toshiba Laptops */
1157 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1158 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1159 /* pin sensing on HP and Mic jacks */
1160 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1161 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1162 /* Speaker routing */
1163 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1164 /* Change default to ExtMic for recording */
1165 {0x1a, AC_VERB_SET_CONNECT_SEL,0x2},
1169 /* configuration for HP Laptops */
1170 static struct hda_verb cxt5047_hp_init_verbs[] = {
1171 /* pin sensing on HP jack */
1172 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1173 /* Record selector: Ext Mic */
1174 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1175 {0x1a, AC_VERB_SET_CONNECT_SEL,0x02},
1176 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1177 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1178 /* Speaker routing */
1179 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1183 /* Test configuration for debugging, modelled after the ALC260 test
1186 #ifdef CONFIG_SND_DEBUG
1187 static struct hda_input_mux cxt5047_test_capture_source = {
1190 { "LINE1 pin", 0x0 },
1191 { "MIC1 pin", 0x1 },
1192 { "MIC2 pin", 0x2 },
1197 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1199 /* Output only controls */
1200 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1201 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1202 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1203 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1204 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1205 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1206 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1207 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1208 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1209 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1210 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1211 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1213 /* Modes for retasking pin widgets */
1214 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1215 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1217 /* EAPD Switch Control */
1218 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1220 /* Loopback mixer controls */
1221 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1222 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1223 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1224 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1225 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1226 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1227 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1228 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1230 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1231 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1232 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1233 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1234 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1235 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1236 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1237 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1239 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1240 .name = "Input Source",
1241 .info = conexant_mux_enum_info,
1242 .get = conexant_mux_enum_get,
1243 .put = conexant_mux_enum_put,
1245 /* Controls for GPIO pins, assuming they exist and are configured
1248 CXT_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
1249 CXT_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
1250 CXT_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
1251 CXT_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
1256 static struct hda_verb cxt5047_test_init_verbs[] = {
1257 /* Enable retasking pins as output, initially without power amp */
1258 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1259 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1260 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1262 /* Disable digital (SPDIF) pins initially, but users can enable
1263 * them via a mixer switch. In the case of SPDIF-out, this initverb
1264 * payload also sets the generation to 0, output to be in "consumer"
1265 * PCM format, copyright asserted, no pre-emphasis and no validity
1268 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1270 /* Ensure mic1, mic2, line1 pin widgets take input from the
1271 * OUT1 sum bus when acting as an output.
1273 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1274 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1276 /* Start with output sum widgets muted and their output gains at min */
1277 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1278 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1280 /* Unmute retasking pin widget output buffers since the default
1281 * state appears to be output. As the pin mode is changed by the
1282 * user the pin mode control will take care of enabling the pin's
1283 * input/output buffers as needed.
1285 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1286 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1287 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1289 /* Mute capture amp left and right */
1290 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1292 /* Set ADC connection select to match default mixer setting (mic1
1295 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1297 /* Mute all inputs to mixer widget (even unconnected ones) */
1298 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1299 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1300 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1301 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1302 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1303 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1304 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1305 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1312 /* initialize jack-sensing, too */
1313 static int cxt5047_hp_init(struct hda_codec *codec)
1315 conexant_init(codec);
1316 cxt5047_hp_automute(codec);
1322 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1323 CXT5047_LAPTOP_HP, /* Some HP laptops */
1324 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1325 #ifdef CONFIG_SND_DEBUG
1331 static const char *cxt5047_models[CXT5047_MODELS] = {
1332 [CXT5047_LAPTOP] = "laptop",
1333 [CXT5047_LAPTOP_HP] = "laptop-hp",
1334 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1335 #ifdef CONFIG_SND_DEBUG
1336 [CXT5047_TEST] = "test",
1340 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1341 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1342 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
1343 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
1344 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1345 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1349 static int patch_cxt5047(struct hda_codec *codec)
1351 struct conexant_spec *spec;
1354 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1357 mutex_init(&spec->amp_mutex);
1360 spec->multiout.max_channels = 2;
1361 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1362 spec->multiout.dac_nids = cxt5047_dac_nids;
1363 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1364 spec->num_adc_nids = 1;
1365 spec->adc_nids = cxt5047_adc_nids;
1366 spec->capsrc_nids = cxt5047_capsrc_nids;
1367 spec->input_mux = &cxt5047_capture_source;
1368 spec->num_mixers = 1;
1369 spec->mixers[0] = cxt5047_mixers;
1370 spec->num_init_verbs = 1;
1371 spec->init_verbs[0] = cxt5047_init_verbs;
1372 spec->spdif_route = 0;
1373 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1374 spec->channel_mode = cxt5047_modes,
1376 codec->patch_ops = conexant_patch_ops;
1377 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1379 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1382 switch (board_config) {
1383 case CXT5047_LAPTOP:
1385 case CXT5047_LAPTOP_HP:
1386 spec->input_mux = &cxt5047_hp_capture_source;
1387 spec->num_init_verbs = 2;
1388 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1389 spec->mixers[0] = cxt5047_hp_mixers;
1390 codec->patch_ops.init = cxt5047_hp_init;
1392 case CXT5047_LAPTOP_EAPD:
1393 spec->input_mux = &cxt5047_toshiba_capture_source;
1394 spec->num_init_verbs = 2;
1395 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1396 spec->mixers[0] = cxt5047_toshiba_mixers;
1398 #ifdef CONFIG_SND_DEBUG
1400 spec->input_mux = &cxt5047_test_capture_source;
1401 spec->mixers[0] = cxt5047_test_mixer;
1402 spec->init_verbs[0] = cxt5047_test_init_verbs;
1408 struct hda_codec_preset snd_hda_preset_conexant[] = {
1409 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1410 .patch = patch_cxt5045 },
1411 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1412 .patch = patch_cxt5047 },