xhci: Fix cycle bit calculation during stall handling.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / pci / hda / patch_conexant.c
blob7c0d81062bd8fb2e2a57862f719808f74a55dec2
1 /*
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"
32 #include "hda_beep.h"
34 #define CXT_PIN_DIR_IN 0x00
35 #define CXT_PIN_DIR_OUT 0x01
36 #define CXT_PIN_DIR_INOUT 0x02
37 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
38 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
40 #define CONEXANT_HP_EVENT 0x37
41 #define CONEXANT_MIC_EVENT 0x38
43 /* Conexant 5051 specific */
45 #define CXT5051_SPDIF_OUT 0x1C
46 #define CXT5051_PORTB_EVENT 0x38
47 #define CXT5051_PORTC_EVENT 0x39
50 struct conexant_jack {
52 hda_nid_t nid;
53 int type;
54 struct snd_jack *jack;
58 struct conexant_spec {
60 struct snd_kcontrol_new *mixers[5];
61 int num_mixers;
62 hda_nid_t vmaster_nid;
64 const struct hda_verb *init_verbs[5]; /* initialization verbs
65 * don't forget NULL
66 * termination!
68 unsigned int num_init_verbs;
70 /* playback */
71 struct hda_multi_out multiout; /* playback set-up
72 * max_channels, dacs must be set
73 * dig_out_nid and hp_nid are optional
75 unsigned int cur_eapd;
76 unsigned int hp_present;
77 unsigned int no_auto_mic;
78 unsigned int need_dac_fix;
80 /* capture */
81 unsigned int num_adc_nids;
82 hda_nid_t *adc_nids;
83 hda_nid_t dig_in_nid; /* digital-in NID; optional */
85 unsigned int cur_adc_idx;
86 hda_nid_t cur_adc;
87 unsigned int cur_adc_stream_tag;
88 unsigned int cur_adc_format;
90 /* capture source */
91 const struct hda_input_mux *input_mux;
92 hda_nid_t *capsrc_nids;
93 unsigned int cur_mux[3];
95 /* channel model */
96 const struct hda_channel_mode *channel_mode;
97 int num_channel_mode;
99 /* PCM information */
100 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
102 unsigned int spdif_route;
104 /* jack detection */
105 struct snd_array jacks;
107 /* dynamic controls, init_verbs and input_mux */
108 struct auto_pin_cfg autocfg;
109 struct hda_input_mux private_imux;
110 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
112 unsigned int dell_automute;
113 unsigned int port_d_mode;
114 unsigned char ext_mic_bias;
115 unsigned int dell_vostro;
118 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
119 struct hda_codec *codec,
120 struct snd_pcm_substream *substream)
122 struct conexant_spec *spec = codec->spec;
123 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
124 hinfo);
127 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
128 struct hda_codec *codec,
129 unsigned int stream_tag,
130 unsigned int format,
131 struct snd_pcm_substream *substream)
133 struct conexant_spec *spec = codec->spec;
134 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
135 stream_tag,
136 format, substream);
139 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
140 struct hda_codec *codec,
141 struct snd_pcm_substream *substream)
143 struct conexant_spec *spec = codec->spec;
144 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
148 * Digital out
150 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
151 struct hda_codec *codec,
152 struct snd_pcm_substream *substream)
154 struct conexant_spec *spec = codec->spec;
155 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
158 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
159 struct hda_codec *codec,
160 struct snd_pcm_substream *substream)
162 struct conexant_spec *spec = codec->spec;
163 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
166 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
167 struct hda_codec *codec,
168 unsigned int stream_tag,
169 unsigned int format,
170 struct snd_pcm_substream *substream)
172 struct conexant_spec *spec = codec->spec;
173 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
174 stream_tag,
175 format, substream);
179 * Analog capture
181 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
182 struct hda_codec *codec,
183 unsigned int stream_tag,
184 unsigned int format,
185 struct snd_pcm_substream *substream)
187 struct conexant_spec *spec = codec->spec;
188 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
189 stream_tag, 0, format);
190 return 0;
193 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
194 struct hda_codec *codec,
195 struct snd_pcm_substream *substream)
197 struct conexant_spec *spec = codec->spec;
198 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
199 return 0;
204 static struct hda_pcm_stream conexant_pcm_analog_playback = {
205 .substreams = 1,
206 .channels_min = 2,
207 .channels_max = 2,
208 .nid = 0, /* fill later */
209 .ops = {
210 .open = conexant_playback_pcm_open,
211 .prepare = conexant_playback_pcm_prepare,
212 .cleanup = conexant_playback_pcm_cleanup
216 static struct hda_pcm_stream conexant_pcm_analog_capture = {
217 .substreams = 1,
218 .channels_min = 2,
219 .channels_max = 2,
220 .nid = 0, /* fill later */
221 .ops = {
222 .prepare = conexant_capture_pcm_prepare,
223 .cleanup = conexant_capture_pcm_cleanup
228 static struct hda_pcm_stream conexant_pcm_digital_playback = {
229 .substreams = 1,
230 .channels_min = 2,
231 .channels_max = 2,
232 .nid = 0, /* fill later */
233 .ops = {
234 .open = conexant_dig_playback_pcm_open,
235 .close = conexant_dig_playback_pcm_close,
236 .prepare = conexant_dig_playback_pcm_prepare
240 static struct hda_pcm_stream conexant_pcm_digital_capture = {
241 .substreams = 1,
242 .channels_min = 2,
243 .channels_max = 2,
244 /* NID is set in alc_build_pcms */
247 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
248 struct hda_codec *codec,
249 unsigned int stream_tag,
250 unsigned int format,
251 struct snd_pcm_substream *substream)
253 struct conexant_spec *spec = codec->spec;
254 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
255 spec->cur_adc_stream_tag = stream_tag;
256 spec->cur_adc_format = format;
257 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
258 return 0;
261 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
262 struct hda_codec *codec,
263 struct snd_pcm_substream *substream)
265 struct conexant_spec *spec = codec->spec;
266 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
267 spec->cur_adc = 0;
268 return 0;
271 static struct hda_pcm_stream cx5051_pcm_analog_capture = {
272 .substreams = 1,
273 .channels_min = 2,
274 .channels_max = 2,
275 .nid = 0, /* fill later */
276 .ops = {
277 .prepare = cx5051_capture_pcm_prepare,
278 .cleanup = cx5051_capture_pcm_cleanup
282 static int conexant_build_pcms(struct hda_codec *codec)
284 struct conexant_spec *spec = codec->spec;
285 struct hda_pcm *info = spec->pcm_rec;
287 codec->num_pcms = 1;
288 codec->pcm_info = info;
290 info->name = "CONEXANT Analog";
291 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
292 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
293 spec->multiout.max_channels;
294 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
295 spec->multiout.dac_nids[0];
296 if (codec->vendor_id == 0x14f15051)
297 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
298 cx5051_pcm_analog_capture;
299 else
300 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
301 conexant_pcm_analog_capture;
302 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
303 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
305 if (spec->multiout.dig_out_nid) {
306 info++;
307 codec->num_pcms++;
308 info->name = "Conexant Digital";
309 info->pcm_type = HDA_PCM_TYPE_SPDIF;
310 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
311 conexant_pcm_digital_playback;
312 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
313 spec->multiout.dig_out_nid;
314 if (spec->dig_in_nid) {
315 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
316 conexant_pcm_digital_capture;
317 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
318 spec->dig_in_nid;
322 return 0;
325 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
326 struct snd_ctl_elem_info *uinfo)
328 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
329 struct conexant_spec *spec = codec->spec;
331 return snd_hda_input_mux_info(spec->input_mux, uinfo);
334 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
335 struct snd_ctl_elem_value *ucontrol)
337 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
338 struct conexant_spec *spec = codec->spec;
339 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
341 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
342 return 0;
345 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
346 struct snd_ctl_elem_value *ucontrol)
348 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
349 struct conexant_spec *spec = codec->spec;
350 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
352 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
353 spec->capsrc_nids[adc_idx],
354 &spec->cur_mux[adc_idx]);
357 #ifdef CONFIG_SND_HDA_INPUT_JACK
358 static void conexant_free_jack_priv(struct snd_jack *jack)
360 struct conexant_jack *jacks = jack->private_data;
361 jacks->nid = 0;
362 jacks->jack = NULL;
365 static int conexant_add_jack(struct hda_codec *codec,
366 hda_nid_t nid, int type)
368 struct conexant_spec *spec;
369 struct conexant_jack *jack;
370 const char *name;
371 int i, err;
373 spec = codec->spec;
374 snd_array_init(&spec->jacks, sizeof(*jack), 32);
376 jack = spec->jacks.list;
377 for (i = 0; i < spec->jacks.used; i++, jack++)
378 if (jack->nid == nid)
379 return 0 ; /* already present */
381 jack = snd_array_new(&spec->jacks);
382 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
384 if (!jack)
385 return -ENOMEM;
387 jack->nid = nid;
388 jack->type = type;
390 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
391 if (err < 0)
392 return err;
393 jack->jack->private_data = jack;
394 jack->jack->private_free = conexant_free_jack_priv;
395 return 0;
398 static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
400 struct conexant_spec *spec = codec->spec;
401 struct conexant_jack *jacks = spec->jacks.list;
403 if (jacks) {
404 int i;
405 for (i = 0; i < spec->jacks.used; i++) {
406 if (jacks->nid == nid) {
407 unsigned int present;
408 present = snd_hda_jack_detect(codec, nid);
410 present = (present) ? jacks->type : 0 ;
412 snd_jack_report(jacks->jack,
413 present);
415 jacks++;
420 static int conexant_init_jacks(struct hda_codec *codec)
422 struct conexant_spec *spec = codec->spec;
423 int i;
425 for (i = 0; i < spec->num_init_verbs; i++) {
426 const struct hda_verb *hv;
428 hv = spec->init_verbs[i];
429 while (hv->nid) {
430 int err = 0;
431 switch (hv->param ^ AC_USRSP_EN) {
432 case CONEXANT_HP_EVENT:
433 err = conexant_add_jack(codec, hv->nid,
434 SND_JACK_HEADPHONE);
435 conexant_report_jack(codec, hv->nid);
436 break;
437 case CXT5051_PORTC_EVENT:
438 case CONEXANT_MIC_EVENT:
439 err = conexant_add_jack(codec, hv->nid,
440 SND_JACK_MICROPHONE);
441 conexant_report_jack(codec, hv->nid);
442 break;
444 if (err < 0)
445 return err;
446 ++hv;
449 return 0;
452 #else
453 static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
457 static inline int conexant_init_jacks(struct hda_codec *codec)
459 return 0;
461 #endif
463 static int conexant_init(struct hda_codec *codec)
465 struct conexant_spec *spec = codec->spec;
466 int i;
468 for (i = 0; i < spec->num_init_verbs; i++)
469 snd_hda_sequence_write(codec, spec->init_verbs[i]);
470 return 0;
473 static void conexant_free(struct hda_codec *codec)
475 #ifdef CONFIG_SND_HDA_INPUT_JACK
476 struct conexant_spec *spec = codec->spec;
477 if (spec->jacks.list) {
478 struct conexant_jack *jacks = spec->jacks.list;
479 int i;
480 for (i = 0; i < spec->jacks.used; i++, jacks++) {
481 if (jacks->jack)
482 snd_device_free(codec->bus->card, jacks->jack);
484 snd_array_free(&spec->jacks);
486 #endif
487 snd_hda_detach_beep_device(codec);
488 kfree(codec->spec);
491 static struct snd_kcontrol_new cxt_capture_mixers[] = {
493 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
494 .name = "Capture Source",
495 .info = conexant_mux_enum_info,
496 .get = conexant_mux_enum_get,
497 .put = conexant_mux_enum_put
502 static const char *slave_vols[] = {
503 "Headphone Playback Volume",
504 "Speaker Playback Volume",
505 NULL
508 static const char *slave_sws[] = {
509 "Headphone Playback Switch",
510 "Speaker Playback Switch",
511 NULL
514 static int conexant_build_controls(struct hda_codec *codec)
516 struct conexant_spec *spec = codec->spec;
517 unsigned int i;
518 int err;
520 for (i = 0; i < spec->num_mixers; i++) {
521 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
522 if (err < 0)
523 return err;
525 if (spec->multiout.dig_out_nid) {
526 err = snd_hda_create_spdif_out_ctls(codec,
527 spec->multiout.dig_out_nid);
528 if (err < 0)
529 return err;
530 err = snd_hda_create_spdif_share_sw(codec,
531 &spec->multiout);
532 if (err < 0)
533 return err;
534 spec->multiout.share_spdif = 1;
536 if (spec->dig_in_nid) {
537 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
538 if (err < 0)
539 return err;
542 /* if we have no master control, let's create it */
543 if (spec->vmaster_nid &&
544 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
545 unsigned int vmaster_tlv[4];
546 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
547 HDA_OUTPUT, vmaster_tlv);
548 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
549 vmaster_tlv, slave_vols);
550 if (err < 0)
551 return err;
553 if (spec->vmaster_nid &&
554 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
555 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
556 NULL, slave_sws);
557 if (err < 0)
558 return err;
561 if (spec->input_mux) {
562 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
563 if (err < 0)
564 return err;
567 return 0;
570 static struct hda_codec_ops conexant_patch_ops = {
571 .build_controls = conexant_build_controls,
572 .build_pcms = conexant_build_pcms,
573 .init = conexant_init,
574 .free = conexant_free,
578 * EAPD control
579 * the private value = nid | (invert << 8)
582 #define cxt_eapd_info snd_ctl_boolean_mono_info
584 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
585 struct snd_ctl_elem_value *ucontrol)
587 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
588 struct conexant_spec *spec = codec->spec;
589 int invert = (kcontrol->private_value >> 8) & 1;
590 if (invert)
591 ucontrol->value.integer.value[0] = !spec->cur_eapd;
592 else
593 ucontrol->value.integer.value[0] = spec->cur_eapd;
594 return 0;
598 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
599 struct snd_ctl_elem_value *ucontrol)
601 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
602 struct conexant_spec *spec = codec->spec;
603 int invert = (kcontrol->private_value >> 8) & 1;
604 hda_nid_t nid = kcontrol->private_value & 0xff;
605 unsigned int eapd;
607 eapd = !!ucontrol->value.integer.value[0];
608 if (invert)
609 eapd = !eapd;
610 if (eapd == spec->cur_eapd)
611 return 0;
613 spec->cur_eapd = eapd;
614 snd_hda_codec_write_cache(codec, nid,
615 0, AC_VERB_SET_EAPD_BTLENABLE,
616 eapd ? 0x02 : 0x00);
617 return 1;
620 /* controls for test mode */
621 #ifdef CONFIG_SND_DEBUG
623 #define CXT_EAPD_SWITCH(xname, nid, mask) \
624 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
625 .info = cxt_eapd_info, \
626 .get = cxt_eapd_get, \
627 .put = cxt_eapd_put, \
628 .private_value = nid | (mask<<16) }
632 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_info *uinfo)
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct conexant_spec *spec = codec->spec;
637 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
638 spec->num_channel_mode);
641 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
642 struct snd_ctl_elem_value *ucontrol)
644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
645 struct conexant_spec *spec = codec->spec;
646 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
647 spec->num_channel_mode,
648 spec->multiout.max_channels);
651 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
652 struct snd_ctl_elem_value *ucontrol)
654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
655 struct conexant_spec *spec = codec->spec;
656 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
657 spec->num_channel_mode,
658 &spec->multiout.max_channels);
659 if (err >= 0 && spec->need_dac_fix)
660 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
661 return err;
664 #define CXT_PIN_MODE(xname, nid, dir) \
665 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
666 .info = conexant_ch_mode_info, \
667 .get = conexant_ch_mode_get, \
668 .put = conexant_ch_mode_put, \
669 .private_value = nid | (dir<<16) }
671 #endif /* CONFIG_SND_DEBUG */
673 /* Conexant 5045 specific */
675 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
676 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
677 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
678 #define CXT5045_SPDIF_OUT 0x18
680 static struct hda_channel_mode cxt5045_modes[1] = {
681 { 2, NULL },
684 static struct hda_input_mux cxt5045_capture_source = {
685 .num_items = 2,
686 .items = {
687 { "IntMic", 0x1 },
688 { "ExtMic", 0x2 },
692 static struct hda_input_mux cxt5045_capture_source_benq = {
693 .num_items = 5,
694 .items = {
695 { "IntMic", 0x1 },
696 { "ExtMic", 0x2 },
697 { "LineIn", 0x3 },
698 { "CD", 0x4 },
699 { "Mixer", 0x0 },
703 static struct hda_input_mux cxt5045_capture_source_hp530 = {
704 .num_items = 2,
705 .items = {
706 { "ExtMic", 0x1 },
707 { "IntMic", 0x2 },
711 /* turn on/off EAPD (+ mute HP) as a master switch */
712 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
713 struct snd_ctl_elem_value *ucontrol)
715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
716 struct conexant_spec *spec = codec->spec;
717 unsigned int bits;
719 if (!cxt_eapd_put(kcontrol, ucontrol))
720 return 0;
722 /* toggle internal speakers mute depending of presence of
723 * the headphone jack
725 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
726 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
727 HDA_AMP_MUTE, bits);
729 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
730 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
731 HDA_AMP_MUTE, bits);
732 return 1;
735 /* bind volumes of both NID 0x10 and 0x11 */
736 static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
737 .ops = &snd_hda_bind_vol,
738 .values = {
739 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
740 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
745 /* toggle input of built-in and mic jack appropriately */
746 static void cxt5045_hp_automic(struct hda_codec *codec)
748 static struct hda_verb mic_jack_on[] = {
749 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
750 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
753 static struct hda_verb mic_jack_off[] = {
754 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
755 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
758 unsigned int present;
760 present = snd_hda_jack_detect(codec, 0x12);
761 if (present)
762 snd_hda_sequence_write(codec, mic_jack_on);
763 else
764 snd_hda_sequence_write(codec, mic_jack_off);
768 /* mute internal speaker if HP is plugged */
769 static void cxt5045_hp_automute(struct hda_codec *codec)
771 struct conexant_spec *spec = codec->spec;
772 unsigned int bits;
774 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
776 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
777 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
778 HDA_AMP_MUTE, bits);
781 /* unsolicited event for HP jack sensing */
782 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
783 unsigned int res)
785 res >>= 26;
786 switch (res) {
787 case CONEXANT_HP_EVENT:
788 cxt5045_hp_automute(codec);
789 break;
790 case CONEXANT_MIC_EVENT:
791 cxt5045_hp_automic(codec);
792 break;
797 static struct snd_kcontrol_new cxt5045_mixers[] = {
798 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
799 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
800 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
801 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
802 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
803 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
804 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
805 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
806 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
807 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
808 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
810 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
811 .name = "Master Playback Switch",
812 .info = cxt_eapd_info,
813 .get = cxt_eapd_get,
814 .put = cxt5045_hp_master_sw_put,
815 .private_value = 0x10,
821 static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
822 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
823 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
824 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
825 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
827 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
828 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
829 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
830 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
832 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
833 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
838 static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
839 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
840 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
841 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
842 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
843 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
844 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
845 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
846 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
847 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
848 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
849 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
851 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
852 .name = "Master Playback Switch",
853 .info = cxt_eapd_info,
854 .get = cxt_eapd_get,
855 .put = cxt5045_hp_master_sw_put,
856 .private_value = 0x10,
862 static struct hda_verb cxt5045_init_verbs[] = {
863 /* Line in, Mic */
864 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
865 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
866 /* HP, Amp */
867 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
868 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
869 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
870 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
871 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
872 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
873 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
874 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
875 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
876 /* Record selector: Int mic */
877 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
878 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
879 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
880 /* SPDIF route: PCM */
881 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
882 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
883 /* EAPD */
884 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
885 { } /* end */
888 static struct hda_verb cxt5045_benq_init_verbs[] = {
889 /* Int Mic, Mic */
890 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
891 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
892 /* Line In,HP, Amp */
893 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
894 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
895 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
896 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
897 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
898 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
899 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
900 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
901 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
902 /* Record selector: Int mic */
903 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
904 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
905 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
906 /* SPDIF route: PCM */
907 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
908 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
909 /* EAPD */
910 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
911 { } /* end */
914 static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
915 /* pin sensing on HP jack */
916 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
917 { } /* end */
920 static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
921 /* pin sensing on HP jack */
922 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
923 { } /* end */
926 #ifdef CONFIG_SND_DEBUG
927 /* Test configuration for debugging, modelled after the ALC260 test
928 * configuration.
930 static struct hda_input_mux cxt5045_test_capture_source = {
931 .num_items = 5,
932 .items = {
933 { "MIXER", 0x0 },
934 { "MIC1 pin", 0x1 },
935 { "LINE1 pin", 0x2 },
936 { "HP-OUT pin", 0x3 },
937 { "CD pin", 0x4 },
941 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
943 /* Output controls */
944 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
945 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
946 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
947 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
948 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
949 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
951 /* Modes for retasking pin widgets */
952 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
953 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
955 /* EAPD Switch Control */
956 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
958 /* Loopback mixer controls */
960 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
961 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
962 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
963 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
964 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
965 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
966 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
967 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
968 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
969 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
971 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
972 .name = "Input Source",
973 .info = conexant_mux_enum_info,
974 .get = conexant_mux_enum_get,
975 .put = conexant_mux_enum_put,
977 /* Audio input controls */
978 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
979 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
980 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
981 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
982 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
983 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
984 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
985 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
986 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
987 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
988 { } /* end */
991 static struct hda_verb cxt5045_test_init_verbs[] = {
992 /* Set connections */
993 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
994 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
995 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
996 /* Enable retasking pins as output, initially without power amp */
997 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
998 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1000 /* Disable digital (SPDIF) pins initially, but users can enable
1001 * them via a mixer switch. In the case of SPDIF-out, this initverb
1002 * payload also sets the generation to 0, output to be in "consumer"
1003 * PCM format, copyright asserted, no pre-emphasis and no validity
1004 * control.
1006 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1007 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1009 /* Start with output sum widgets muted and their output gains at min */
1010 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1011 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1013 /* Unmute retasking pin widget output buffers since the default
1014 * state appears to be output. As the pin mode is changed by the
1015 * user the pin mode control will take care of enabling the pin's
1016 * input/output buffers as needed.
1018 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1019 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1021 /* Mute capture amp left and right */
1022 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1024 /* Set ADC connection select to match default mixer setting (mic1
1025 * pin)
1027 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1028 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1030 /* Mute all inputs to mixer widget (even unconnected ones) */
1031 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1032 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1033 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1034 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1035 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1039 #endif
1042 /* initialize jack-sensing, too */
1043 static int cxt5045_init(struct hda_codec *codec)
1045 conexant_init(codec);
1046 cxt5045_hp_automute(codec);
1047 return 0;
1051 enum {
1052 CXT5045_LAPTOP_HPSENSE,
1053 CXT5045_LAPTOP_MICSENSE,
1054 CXT5045_LAPTOP_HPMICSENSE,
1055 CXT5045_BENQ,
1056 CXT5045_LAPTOP_HP530,
1057 #ifdef CONFIG_SND_DEBUG
1058 CXT5045_TEST,
1059 #endif
1060 CXT5045_MODELS
1063 static const char *cxt5045_models[CXT5045_MODELS] = {
1064 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1065 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1066 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1067 [CXT5045_BENQ] = "benq",
1068 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1069 #ifdef CONFIG_SND_DEBUG
1070 [CXT5045_TEST] = "test",
1071 #endif
1074 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1075 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1076 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1077 CXT5045_LAPTOP_HPSENSE),
1078 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1079 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1080 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1081 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1082 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1083 CXT5045_LAPTOP_HPMICSENSE),
1084 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1085 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1086 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1087 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1088 CXT5045_LAPTOP_HPMICSENSE),
1089 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1093 static int patch_cxt5045(struct hda_codec *codec)
1095 struct conexant_spec *spec;
1096 int board_config;
1098 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1099 if (!spec)
1100 return -ENOMEM;
1101 codec->spec = spec;
1102 codec->pin_amp_workaround = 1;
1104 spec->multiout.max_channels = 2;
1105 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1106 spec->multiout.dac_nids = cxt5045_dac_nids;
1107 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1108 spec->num_adc_nids = 1;
1109 spec->adc_nids = cxt5045_adc_nids;
1110 spec->capsrc_nids = cxt5045_capsrc_nids;
1111 spec->input_mux = &cxt5045_capture_source;
1112 spec->num_mixers = 1;
1113 spec->mixers[0] = cxt5045_mixers;
1114 spec->num_init_verbs = 1;
1115 spec->init_verbs[0] = cxt5045_init_verbs;
1116 spec->spdif_route = 0;
1117 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1118 spec->channel_mode = cxt5045_modes,
1121 codec->patch_ops = conexant_patch_ops;
1123 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1124 cxt5045_models,
1125 cxt5045_cfg_tbl);
1126 switch (board_config) {
1127 case CXT5045_LAPTOP_HPSENSE:
1128 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1129 spec->input_mux = &cxt5045_capture_source;
1130 spec->num_init_verbs = 2;
1131 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1132 spec->mixers[0] = cxt5045_mixers;
1133 codec->patch_ops.init = cxt5045_init;
1134 break;
1135 case CXT5045_LAPTOP_MICSENSE:
1136 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1137 spec->input_mux = &cxt5045_capture_source;
1138 spec->num_init_verbs = 2;
1139 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1140 spec->mixers[0] = cxt5045_mixers;
1141 codec->patch_ops.init = cxt5045_init;
1142 break;
1143 default:
1144 case CXT5045_LAPTOP_HPMICSENSE:
1145 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1146 spec->input_mux = &cxt5045_capture_source;
1147 spec->num_init_verbs = 3;
1148 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1149 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1150 spec->mixers[0] = cxt5045_mixers;
1151 codec->patch_ops.init = cxt5045_init;
1152 break;
1153 case CXT5045_BENQ:
1154 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1155 spec->input_mux = &cxt5045_capture_source_benq;
1156 spec->num_init_verbs = 1;
1157 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1158 spec->mixers[0] = cxt5045_mixers;
1159 spec->mixers[1] = cxt5045_benq_mixers;
1160 spec->num_mixers = 2;
1161 codec->patch_ops.init = cxt5045_init;
1162 break;
1163 case CXT5045_LAPTOP_HP530:
1164 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1165 spec->input_mux = &cxt5045_capture_source_hp530;
1166 spec->num_init_verbs = 2;
1167 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1168 spec->mixers[0] = cxt5045_mixers_hp530;
1169 codec->patch_ops.init = cxt5045_init;
1170 break;
1171 #ifdef CONFIG_SND_DEBUG
1172 case CXT5045_TEST:
1173 spec->input_mux = &cxt5045_test_capture_source;
1174 spec->mixers[0] = cxt5045_test_mixer;
1175 spec->init_verbs[0] = cxt5045_test_init_verbs;
1176 break;
1178 #endif
1181 switch (codec->subsystem_id >> 16) {
1182 case 0x103c:
1183 case 0x1631:
1184 case 0x1734:
1185 case 0x17aa:
1186 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1187 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1188 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1190 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1191 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1192 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1193 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1194 (1 << AC_AMPCAP_MUTE_SHIFT));
1195 break;
1198 return 0;
1202 /* Conexant 5047 specific */
1203 #define CXT5047_SPDIF_OUT 0x11
1205 static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1206 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1207 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1209 static struct hda_channel_mode cxt5047_modes[1] = {
1210 { 2, NULL },
1213 static struct hda_input_mux cxt5047_toshiba_capture_source = {
1214 .num_items = 2,
1215 .items = {
1216 { "ExtMic", 0x2 },
1217 { "Line-In", 0x1 },
1221 /* turn on/off EAPD (+ mute HP) as a master switch */
1222 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1223 struct snd_ctl_elem_value *ucontrol)
1225 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1226 struct conexant_spec *spec = codec->spec;
1227 unsigned int bits;
1229 if (!cxt_eapd_put(kcontrol, ucontrol))
1230 return 0;
1232 /* toggle internal speakers mute depending of presence of
1233 * the headphone jack
1235 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1236 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1237 * pin widgets unlike other codecs. In this case, we need to
1238 * set index 0x01 for the volume from the mixer amp 0x19.
1240 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1241 HDA_AMP_MUTE, bits);
1242 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1243 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1244 HDA_AMP_MUTE, bits);
1245 return 1;
1248 /* mute internal speaker if HP is plugged */
1249 static void cxt5047_hp_automute(struct hda_codec *codec)
1251 struct conexant_spec *spec = codec->spec;
1252 unsigned int bits;
1254 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1256 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1257 /* See the note in cxt5047_hp_master_sw_put */
1258 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1259 HDA_AMP_MUTE, bits);
1262 /* toggle input of built-in and mic jack appropriately */
1263 static void cxt5047_hp_automic(struct hda_codec *codec)
1265 static struct hda_verb mic_jack_on[] = {
1266 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1267 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1270 static struct hda_verb mic_jack_off[] = {
1271 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1272 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1275 unsigned int present;
1277 present = snd_hda_jack_detect(codec, 0x15);
1278 if (present)
1279 snd_hda_sequence_write(codec, mic_jack_on);
1280 else
1281 snd_hda_sequence_write(codec, mic_jack_off);
1284 /* unsolicited event for HP jack sensing */
1285 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1286 unsigned int res)
1288 switch (res >> 26) {
1289 case CONEXANT_HP_EVENT:
1290 cxt5047_hp_automute(codec);
1291 break;
1292 case CONEXANT_MIC_EVENT:
1293 cxt5047_hp_automic(codec);
1294 break;
1298 static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1299 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1300 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1301 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
1302 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1303 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1304 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1305 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1307 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1308 .name = "Master Playback Switch",
1309 .info = cxt_eapd_info,
1310 .get = cxt_eapd_get,
1311 .put = cxt5047_hp_master_sw_put,
1312 .private_value = 0x13,
1318 static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1319 /* See the note in cxt5047_hp_master_sw_put */
1320 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1321 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1325 static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1326 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1327 { } /* end */
1330 static struct hda_verb cxt5047_init_verbs[] = {
1331 /* Line in, Mic, Built-in Mic */
1332 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1333 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1334 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1335 /* HP, Speaker */
1336 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1337 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1338 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1339 /* Record selector: Mic */
1340 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1341 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1342 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1343 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1344 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1345 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1346 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1347 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1348 /* SPDIF route: PCM */
1349 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1350 /* Enable unsolicited events */
1351 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1352 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1353 { } /* end */
1356 /* configuration for Toshiba Laptops */
1357 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1358 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1362 /* Test configuration for debugging, modelled after the ALC260 test
1363 * configuration.
1365 #ifdef CONFIG_SND_DEBUG
1366 static struct hda_input_mux cxt5047_test_capture_source = {
1367 .num_items = 4,
1368 .items = {
1369 { "LINE1 pin", 0x0 },
1370 { "MIC1 pin", 0x1 },
1371 { "MIC2 pin", 0x2 },
1372 { "CD pin", 0x3 },
1376 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1378 /* Output only controls */
1379 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1380 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1381 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1382 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1383 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1384 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1385 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1386 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1387 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1388 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1389 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1390 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1392 /* Modes for retasking pin widgets */
1393 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1394 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1396 /* EAPD Switch Control */
1397 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1399 /* Loopback mixer controls */
1400 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1401 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1402 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1403 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1404 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1405 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1406 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1407 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1409 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1410 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1411 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1412 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1413 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1414 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1415 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1416 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1418 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1419 .name = "Input Source",
1420 .info = conexant_mux_enum_info,
1421 .get = conexant_mux_enum_get,
1422 .put = conexant_mux_enum_put,
1424 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1426 { } /* end */
1429 static struct hda_verb cxt5047_test_init_verbs[] = {
1430 /* Enable retasking pins as output, initially without power amp */
1431 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1432 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1433 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1435 /* Disable digital (SPDIF) pins initially, but users can enable
1436 * them via a mixer switch. In the case of SPDIF-out, this initverb
1437 * payload also sets the generation to 0, output to be in "consumer"
1438 * PCM format, copyright asserted, no pre-emphasis and no validity
1439 * control.
1441 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1443 /* Ensure mic1, mic2, line1 pin widgets take input from the
1444 * OUT1 sum bus when acting as an output.
1446 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1447 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1449 /* Start with output sum widgets muted and their output gains at min */
1450 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1451 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1453 /* Unmute retasking pin widget output buffers since the default
1454 * state appears to be output. As the pin mode is changed by the
1455 * user the pin mode control will take care of enabling the pin's
1456 * input/output buffers as needed.
1458 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1459 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1460 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1462 /* Mute capture amp left and right */
1463 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1465 /* Set ADC connection select to match default mixer setting (mic1
1466 * pin)
1468 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1470 /* Mute all inputs to mixer widget (even unconnected ones) */
1471 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1472 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1473 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1474 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1475 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1476 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1477 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1478 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1482 #endif
1485 /* initialize jack-sensing, too */
1486 static int cxt5047_hp_init(struct hda_codec *codec)
1488 conexant_init(codec);
1489 cxt5047_hp_automute(codec);
1490 return 0;
1494 enum {
1495 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1496 CXT5047_LAPTOP_HP, /* Some HP laptops */
1497 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1498 #ifdef CONFIG_SND_DEBUG
1499 CXT5047_TEST,
1500 #endif
1501 CXT5047_MODELS
1504 static const char *cxt5047_models[CXT5047_MODELS] = {
1505 [CXT5047_LAPTOP] = "laptop",
1506 [CXT5047_LAPTOP_HP] = "laptop-hp",
1507 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1508 #ifdef CONFIG_SND_DEBUG
1509 [CXT5047_TEST] = "test",
1510 #endif
1513 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1514 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1515 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1516 CXT5047_LAPTOP),
1517 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1521 static int patch_cxt5047(struct hda_codec *codec)
1523 struct conexant_spec *spec;
1524 int board_config;
1526 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1527 if (!spec)
1528 return -ENOMEM;
1529 codec->spec = spec;
1530 codec->pin_amp_workaround = 1;
1532 spec->multiout.max_channels = 2;
1533 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1534 spec->multiout.dac_nids = cxt5047_dac_nids;
1535 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1536 spec->num_adc_nids = 1;
1537 spec->adc_nids = cxt5047_adc_nids;
1538 spec->capsrc_nids = cxt5047_capsrc_nids;
1539 spec->num_mixers = 1;
1540 spec->mixers[0] = cxt5047_base_mixers;
1541 spec->num_init_verbs = 1;
1542 spec->init_verbs[0] = cxt5047_init_verbs;
1543 spec->spdif_route = 0;
1544 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1545 spec->channel_mode = cxt5047_modes,
1547 codec->patch_ops = conexant_patch_ops;
1549 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1550 cxt5047_models,
1551 cxt5047_cfg_tbl);
1552 switch (board_config) {
1553 case CXT5047_LAPTOP:
1554 spec->num_mixers = 2;
1555 spec->mixers[1] = cxt5047_hp_spk_mixers;
1556 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1557 break;
1558 case CXT5047_LAPTOP_HP:
1559 spec->num_mixers = 2;
1560 spec->mixers[1] = cxt5047_hp_only_mixers;
1561 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1562 codec->patch_ops.init = cxt5047_hp_init;
1563 break;
1564 case CXT5047_LAPTOP_EAPD:
1565 spec->input_mux = &cxt5047_toshiba_capture_source;
1566 spec->num_mixers = 2;
1567 spec->mixers[1] = cxt5047_hp_spk_mixers;
1568 spec->num_init_verbs = 2;
1569 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1570 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1571 break;
1572 #ifdef CONFIG_SND_DEBUG
1573 case CXT5047_TEST:
1574 spec->input_mux = &cxt5047_test_capture_source;
1575 spec->mixers[0] = cxt5047_test_mixer;
1576 spec->init_verbs[0] = cxt5047_test_init_verbs;
1577 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1578 #endif
1580 spec->vmaster_nid = 0x13;
1582 switch (codec->subsystem_id >> 16) {
1583 case 0x103c:
1584 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1585 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1586 * with 0 dB offset 0x17)
1588 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1589 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1590 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1591 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1592 (1 << AC_AMPCAP_MUTE_SHIFT));
1593 break;
1596 return 0;
1599 /* Conexant 5051 specific */
1600 static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1601 static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1603 static struct hda_channel_mode cxt5051_modes[1] = {
1604 { 2, NULL },
1607 static void cxt5051_update_speaker(struct hda_codec *codec)
1609 struct conexant_spec *spec = codec->spec;
1610 unsigned int pinctl;
1611 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1612 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1613 pinctl);
1616 /* turn on/off EAPD (+ mute HP) as a master switch */
1617 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1618 struct snd_ctl_elem_value *ucontrol)
1620 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1622 if (!cxt_eapd_put(kcontrol, ucontrol))
1623 return 0;
1624 cxt5051_update_speaker(codec);
1625 return 1;
1628 /* toggle input of built-in and mic jack appropriately */
1629 static void cxt5051_portb_automic(struct hda_codec *codec)
1631 struct conexant_spec *spec = codec->spec;
1632 unsigned int present;
1634 if (spec->no_auto_mic)
1635 return;
1636 present = snd_hda_jack_detect(codec, 0x17);
1637 snd_hda_codec_write(codec, 0x14, 0,
1638 AC_VERB_SET_CONNECT_SEL,
1639 present ? 0x01 : 0x00);
1642 /* switch the current ADC according to the jack state */
1643 static void cxt5051_portc_automic(struct hda_codec *codec)
1645 struct conexant_spec *spec = codec->spec;
1646 unsigned int present;
1647 hda_nid_t new_adc;
1649 if (spec->no_auto_mic)
1650 return;
1651 present = snd_hda_jack_detect(codec, 0x18);
1652 if (present)
1653 spec->cur_adc_idx = 1;
1654 else
1655 spec->cur_adc_idx = 0;
1656 new_adc = spec->adc_nids[spec->cur_adc_idx];
1657 if (spec->cur_adc && spec->cur_adc != new_adc) {
1658 /* stream is running, let's swap the current ADC */
1659 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1660 spec->cur_adc = new_adc;
1661 snd_hda_codec_setup_stream(codec, new_adc,
1662 spec->cur_adc_stream_tag, 0,
1663 spec->cur_adc_format);
1667 /* mute internal speaker if HP is plugged */
1668 static void cxt5051_hp_automute(struct hda_codec *codec)
1670 struct conexant_spec *spec = codec->spec;
1672 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1673 cxt5051_update_speaker(codec);
1676 /* unsolicited event for HP jack sensing */
1677 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1678 unsigned int res)
1680 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1681 switch (res >> 26) {
1682 case CONEXANT_HP_EVENT:
1683 cxt5051_hp_automute(codec);
1684 break;
1685 case CXT5051_PORTB_EVENT:
1686 cxt5051_portb_automic(codec);
1687 break;
1688 case CXT5051_PORTC_EVENT:
1689 cxt5051_portc_automic(codec);
1690 break;
1692 conexant_report_jack(codec, nid);
1695 static struct snd_kcontrol_new cxt5051_mixers[] = {
1696 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1697 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1698 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1699 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1700 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1701 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1702 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1704 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1705 .name = "Master Playback Switch",
1706 .info = cxt_eapd_info,
1707 .get = cxt_eapd_get,
1708 .put = cxt5051_hp_master_sw_put,
1709 .private_value = 0x1a,
1715 static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1716 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1717 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1718 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1719 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1720 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1723 .name = "Master Playback Switch",
1724 .info = cxt_eapd_info,
1725 .get = cxt_eapd_get,
1726 .put = cxt5051_hp_master_sw_put,
1727 .private_value = 0x1a,
1733 static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1734 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1735 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1736 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1738 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1739 .name = "Master Playback Switch",
1740 .info = cxt_eapd_info,
1741 .get = cxt_eapd_get,
1742 .put = cxt5051_hp_master_sw_put,
1743 .private_value = 0x1a,
1749 static struct hda_verb cxt5051_init_verbs[] = {
1750 /* Line in, Mic */
1751 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1752 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1753 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1754 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1755 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1756 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1757 /* SPK */
1758 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1759 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1760 /* HP, Amp */
1761 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1762 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1763 /* DAC1 */
1764 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1765 /* Record selector: Int mic */
1766 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1767 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1768 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1769 /* SPDIF route: PCM */
1770 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1771 /* EAPD */
1772 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1773 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1774 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1775 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1776 { } /* end */
1779 static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1780 /* Line in, Mic */
1781 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1782 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1783 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1784 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1785 /* SPK */
1786 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1787 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1788 /* HP, Amp */
1789 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1790 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1791 /* DAC1 */
1792 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1793 /* Record selector: Int mic */
1794 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1795 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1796 /* SPDIF route: PCM */
1797 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1798 /* EAPD */
1799 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1800 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1801 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1802 { } /* end */
1805 static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1806 /* Line in, Mic */
1807 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1808 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1809 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1810 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1811 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1812 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1813 /* SPK */
1814 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1815 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1816 /* HP, Amp */
1817 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1818 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1819 /* Docking HP */
1820 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1821 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1822 /* DAC1 */
1823 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1824 /* Record selector: Int mic */
1825 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1826 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1827 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1828 /* SPDIF route: PCM */
1829 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1830 /* EAPD */
1831 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1832 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1833 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1834 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1835 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1836 { } /* end */
1839 /* initialize jack-sensing, too */
1840 static int cxt5051_init(struct hda_codec *codec)
1842 conexant_init(codec);
1843 conexant_init_jacks(codec);
1844 if (codec->patch_ops.unsol_event) {
1845 cxt5051_hp_automute(codec);
1846 cxt5051_portb_automic(codec);
1847 cxt5051_portc_automic(codec);
1849 return 0;
1853 enum {
1854 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1855 CXT5051_HP, /* no docking */
1856 CXT5051_HP_DV6736, /* HP without mic switch */
1857 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
1858 CXT5051_MODELS
1861 static const char *cxt5051_models[CXT5051_MODELS] = {
1862 [CXT5051_LAPTOP] = "laptop",
1863 [CXT5051_HP] = "hp",
1864 [CXT5051_HP_DV6736] = "hp-dv6736",
1865 [CXT5051_LENOVO_X200] = "lenovo-x200",
1868 static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1869 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1870 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1871 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1872 CXT5051_LAPTOP),
1873 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1874 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1878 static int patch_cxt5051(struct hda_codec *codec)
1880 struct conexant_spec *spec;
1881 int board_config;
1883 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1884 if (!spec)
1885 return -ENOMEM;
1886 codec->spec = spec;
1887 codec->pin_amp_workaround = 1;
1889 codec->patch_ops = conexant_patch_ops;
1890 codec->patch_ops.init = cxt5051_init;
1892 spec->multiout.max_channels = 2;
1893 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1894 spec->multiout.dac_nids = cxt5051_dac_nids;
1895 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1896 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1897 spec->adc_nids = cxt5051_adc_nids;
1898 spec->num_mixers = 1;
1899 spec->mixers[0] = cxt5051_mixers;
1900 spec->num_init_verbs = 1;
1901 spec->init_verbs[0] = cxt5051_init_verbs;
1902 spec->spdif_route = 0;
1903 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1904 spec->channel_mode = cxt5051_modes;
1905 spec->cur_adc = 0;
1906 spec->cur_adc_idx = 0;
1908 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1910 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1911 cxt5051_models,
1912 cxt5051_cfg_tbl);
1913 switch (board_config) {
1914 case CXT5051_HP:
1915 spec->mixers[0] = cxt5051_hp_mixers;
1916 break;
1917 case CXT5051_HP_DV6736:
1918 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1919 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1920 spec->no_auto_mic = 1;
1921 break;
1922 case CXT5051_LENOVO_X200:
1923 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1924 break;
1927 return 0;
1930 /* Conexant 5066 specific */
1932 static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1933 static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1934 static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1935 #define CXT5066_SPDIF_OUT 0x21
1937 /* OLPC's microphone port is DC coupled for use with external sensors,
1938 * therefore we use a 50% mic bias in order to center the input signal with
1939 * the DC input range of the codec. */
1940 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1942 static struct hda_channel_mode cxt5066_modes[1] = {
1943 { 2, NULL },
1946 static void cxt5066_update_speaker(struct hda_codec *codec)
1948 struct conexant_spec *spec = codec->spec;
1949 unsigned int pinctl;
1951 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
1952 spec->hp_present);
1954 /* Port A (HP) */
1955 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
1956 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1957 pinctl);
1959 /* Port D (HP/LO) */
1960 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
1961 ? spec->port_d_mode : 0;
1962 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1963 pinctl);
1965 /* CLASS_D AMP */
1966 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1967 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1968 pinctl);
1970 if (spec->dell_automute) {
1971 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
1972 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
1973 ? PIN_OUT : 0;
1974 snd_hda_codec_write(codec, 0x1c, 0,
1975 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
1979 /* turn on/off EAPD (+ mute HP) as a master switch */
1980 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1981 struct snd_ctl_elem_value *ucontrol)
1983 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1985 if (!cxt_eapd_put(kcontrol, ucontrol))
1986 return 0;
1988 cxt5066_update_speaker(codec);
1989 return 1;
1992 /* toggle input of built-in and mic jack appropriately */
1993 static void cxt5066_automic(struct hda_codec *codec)
1995 struct conexant_spec *spec = codec->spec;
1996 struct hda_verb ext_mic_present[] = {
1997 /* enable external mic, port B */
1998 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
2000 /* switch to external mic input */
2001 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2003 /* disable internal mic, port C */
2004 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2007 static struct hda_verb ext_mic_absent[] = {
2008 /* enable internal mic, port C */
2009 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2011 /* switch to internal mic input */
2012 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2014 /* disable external mic, port B */
2015 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2018 unsigned int present;
2020 present = snd_hda_jack_detect(codec, 0x1a);
2021 if (present) {
2022 snd_printdd("CXT5066: external microphone detected\n");
2023 snd_hda_sequence_write(codec, ext_mic_present);
2024 } else {
2025 snd_printdd("CXT5066: external microphone absent\n");
2026 snd_hda_sequence_write(codec, ext_mic_absent);
2030 /* toggle input of built-in digital mic and mic jack appropriately */
2031 static void cxt5066_vostro_automic(struct hda_codec *codec)
2033 struct conexant_spec *spec = codec->spec;
2034 unsigned int present;
2036 struct hda_verb ext_mic_present[] = {
2037 /* enable external mic, port B */
2038 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
2040 /* switch to external mic input */
2041 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2042 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2044 /* disable internal digital mic */
2045 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2048 static struct hda_verb ext_mic_absent[] = {
2049 /* enable internal mic, port C */
2050 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2052 /* switch to internal mic input */
2053 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2055 /* disable external mic, port B */
2056 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2060 present = snd_hda_jack_detect(codec, 0x1a);
2061 if (present) {
2062 snd_printdd("CXT5066: external microphone detected\n");
2063 snd_hda_sequence_write(codec, ext_mic_present);
2064 } else {
2065 snd_printdd("CXT5066: external microphone absent\n");
2066 snd_hda_sequence_write(codec, ext_mic_absent);
2070 /* mute internal speaker if HP is plugged */
2071 static void cxt5066_hp_automute(struct hda_codec *codec)
2073 struct conexant_spec *spec = codec->spec;
2074 unsigned int portA, portD;
2076 /* Port A */
2077 portA = snd_hda_jack_detect(codec, 0x19);
2079 /* Port D */
2080 portD = snd_hda_jack_detect(codec, 0x1c);
2082 spec->hp_present = !!(portA | portD);
2083 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2084 portA, portD, spec->hp_present);
2085 cxt5066_update_speaker(codec);
2088 /* unsolicited event for jack sensing */
2089 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2091 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2092 switch (res >> 26) {
2093 case CONEXANT_HP_EVENT:
2094 cxt5066_hp_automute(codec);
2095 break;
2096 case CONEXANT_MIC_EVENT:
2097 cxt5066_automic(codec);
2098 break;
2102 /* unsolicited event for jack sensing */
2103 static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2105 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2106 switch (res >> 26) {
2107 case CONEXANT_HP_EVENT:
2108 cxt5066_hp_automute(codec);
2109 break;
2110 case CONEXANT_MIC_EVENT:
2111 cxt5066_vostro_automic(codec);
2112 break;
2116 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2117 .num_items = 5,
2118 .items = {
2119 { "0dB", 0 },
2120 { "10dB", 1 },
2121 { "20dB", 2 },
2122 { "30dB", 3 },
2123 { "40dB", 4 },
2127 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2128 struct snd_ctl_elem_info *uinfo)
2130 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2133 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2134 struct snd_ctl_elem_value *ucontrol)
2136 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2137 int val;
2138 hda_nid_t nid = kcontrol->private_value & 0xff;
2139 int inout = (kcontrol->private_value & 0x100) ?
2140 AC_AMP_GET_INPUT : AC_AMP_GET_OUTPUT;
2142 val = snd_hda_codec_read(codec, nid, 0,
2143 AC_VERB_GET_AMP_GAIN_MUTE, inout);
2145 ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
2146 return 0;
2149 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2150 struct snd_ctl_elem_value *ucontrol)
2152 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2153 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2154 unsigned int idx;
2155 hda_nid_t nid = kcontrol->private_value & 0xff;
2156 int inout = (kcontrol->private_value & 0x100) ?
2157 AC_AMP_SET_INPUT : AC_AMP_SET_OUTPUT;
2159 if (!imux->num_items)
2160 return 0;
2161 idx = ucontrol->value.enumerated.item[0];
2162 if (idx >= imux->num_items)
2163 idx = imux->num_items - 1;
2165 snd_hda_codec_write_cache(codec, nid, 0,
2166 AC_VERB_SET_AMP_GAIN_MUTE,
2167 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | inout |
2168 imux->items[idx].index);
2170 return 1;
2173 static struct hda_input_mux cxt5066_capture_source = {
2174 .num_items = 4,
2175 .items = {
2176 { "Mic B", 0 },
2177 { "Mic C", 1 },
2178 { "Mic E", 2 },
2179 { "Mic F", 3 },
2183 static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2184 .ops = &snd_hda_bind_vol,
2185 .values = {
2186 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2187 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2192 static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2193 .ops = &snd_hda_bind_sw,
2194 .values = {
2195 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2196 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2201 static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2202 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2206 static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2208 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2209 .name = "Master Playback Volume",
2210 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2211 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2212 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2213 .info = snd_hda_mixer_amp_volume_info,
2214 .get = snd_hda_mixer_amp_volume_get,
2215 .put = snd_hda_mixer_amp_volume_put,
2216 .tlv = { .c = snd_hda_mixer_amp_tlv },
2217 /* offset by 28 volume steps to limit minimum gain to -46dB */
2218 .private_value =
2219 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2224 static struct snd_kcontrol_new cxt5066_mixers[] = {
2226 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2227 .name = "Master Playback Switch",
2228 .info = cxt_eapd_info,
2229 .get = cxt_eapd_get,
2230 .put = cxt5066_hp_master_sw_put,
2231 .private_value = 0x1d,
2235 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2236 .name = "Ext Mic Boost Capture Enum",
2237 .info = cxt5066_mic_boost_mux_enum_info,
2238 .get = cxt5066_mic_boost_mux_enum_get,
2239 .put = cxt5066_mic_boost_mux_enum_put,
2240 .private_value = 0x17,
2243 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2244 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2248 static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2250 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2251 .name = "Int Mic Boost Capture Enum",
2252 .info = cxt5066_mic_boost_mux_enum_info,
2253 .get = cxt5066_mic_boost_mux_enum_get,
2254 .put = cxt5066_mic_boost_mux_enum_put,
2255 .private_value = 0x23 | 0x100,
2257 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
2261 static struct hda_verb cxt5066_init_verbs[] = {
2262 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2263 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2264 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2265 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2267 /* Speakers */
2268 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2269 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2271 /* HP, Amp */
2272 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2273 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2275 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2276 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2278 /* DAC1 */
2279 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2281 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2282 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2283 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2284 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2285 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2286 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2288 /* no digital microphone support yet */
2289 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2291 /* Audio input selector */
2292 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2294 /* SPDIF route: PCM */
2295 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2296 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2298 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2299 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2301 /* EAPD */
2302 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2304 /* not handling these yet */
2305 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2306 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2307 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2308 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2309 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2310 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2311 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2312 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2313 { } /* end */
2316 static struct hda_verb cxt5066_init_verbs_olpc[] = {
2317 /* Port A: headphones */
2318 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2319 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2321 /* Port B: external microphone */
2322 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, CXT5066_OLPC_EXT_MIC_BIAS},
2324 /* Port C: internal microphone */
2325 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2327 /* Port D: unused */
2328 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2330 /* Port E: unused, but has primary EAPD */
2331 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2332 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2334 /* Port F: unused */
2335 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2337 /* Port G: internal speakers */
2338 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2339 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2341 /* DAC1 */
2342 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2344 /* DAC2: unused */
2345 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2347 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2348 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2349 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2350 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2351 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2352 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2353 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2354 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2355 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2356 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2357 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2358 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2360 /* Disable digital microphone port */
2361 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2363 /* Audio input selectors */
2364 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2365 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2367 /* Disable SPDIF */
2368 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2369 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2371 /* enable unsolicited events for Port A and B */
2372 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2373 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2374 { } /* end */
2377 static struct hda_verb cxt5066_init_verbs_vostro[] = {
2378 /* Port A: headphones */
2379 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2380 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2382 /* Port B: external microphone */
2383 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2385 /* Port C: unused */
2386 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2388 /* Port D: unused */
2389 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2391 /* Port E: unused, but has primary EAPD */
2392 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2393 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2395 /* Port F: unused */
2396 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2398 /* Port G: internal speakers */
2399 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2400 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2402 /* DAC1 */
2403 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2405 /* DAC2: unused */
2406 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2408 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2409 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2410 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2411 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2412 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2413 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2414 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2415 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2416 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2417 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2418 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2419 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2421 /* Digital microphone port */
2422 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2424 /* Audio input selectors */
2425 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2426 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2428 /* Disable SPDIF */
2429 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2430 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2432 /* enable unsolicited events for Port A and B */
2433 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2434 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2435 { } /* end */
2438 static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2439 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2440 { } /* end */
2443 /* initialize jack-sensing, too */
2444 static int cxt5066_init(struct hda_codec *codec)
2446 struct conexant_spec *spec = codec->spec;
2448 snd_printdd("CXT5066: init\n");
2449 conexant_init(codec);
2450 if (codec->patch_ops.unsol_event) {
2451 cxt5066_hp_automute(codec);
2452 if (spec->dell_vostro)
2453 cxt5066_vostro_automic(codec);
2454 else
2455 cxt5066_automic(codec);
2457 return 0;
2460 enum {
2461 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2462 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2463 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
2464 CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
2465 CXT5066_MODELS
2468 static const char *cxt5066_models[CXT5066_MODELS] = {
2469 [CXT5066_LAPTOP] = "laptop",
2470 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2471 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
2472 [CXT5066_DELL_VOSTO] = "dell-vostro"
2475 static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2476 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2477 CXT5066_LAPTOP),
2478 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2479 CXT5066_DELL_LAPTOP),
2480 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
2481 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
2482 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
2483 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
2487 static int patch_cxt5066(struct hda_codec *codec)
2489 struct conexant_spec *spec;
2490 int board_config;
2492 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2493 if (!spec)
2494 return -ENOMEM;
2495 codec->spec = spec;
2497 codec->patch_ops = conexant_patch_ops;
2498 codec->patch_ops.init = cxt5066_init;
2500 spec->dell_automute = 0;
2501 spec->multiout.max_channels = 2;
2502 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2503 spec->multiout.dac_nids = cxt5066_dac_nids;
2504 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
2505 spec->num_adc_nids = 1;
2506 spec->adc_nids = cxt5066_adc_nids;
2507 spec->capsrc_nids = cxt5066_capsrc_nids;
2508 spec->input_mux = &cxt5066_capture_source;
2510 spec->port_d_mode = PIN_HP;
2511 spec->ext_mic_bias = PIN_VREF80;
2513 spec->num_init_verbs = 1;
2514 spec->init_verbs[0] = cxt5066_init_verbs;
2515 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2516 spec->channel_mode = cxt5066_modes;
2517 spec->cur_adc = 0;
2518 spec->cur_adc_idx = 0;
2520 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2521 cxt5066_models, cxt5066_cfg_tbl);
2522 switch (board_config) {
2523 default:
2524 case CXT5066_LAPTOP:
2525 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2526 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2527 break;
2528 case CXT5066_DELL_LAPTOP:
2529 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2530 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2532 spec->port_d_mode = PIN_OUT;
2533 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
2534 spec->num_init_verbs++;
2535 spec->dell_automute = 1;
2536 break;
2537 case CXT5066_OLPC_XO_1_5:
2538 codec->patch_ops.unsol_event = cxt5066_unsol_event;
2539 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
2540 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2541 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2542 spec->port_d_mode = 0;
2543 spec->ext_mic_bias = CXT5066_OLPC_EXT_MIC_BIAS;
2545 /* no S/PDIF out */
2546 spec->multiout.dig_out_nid = 0;
2548 /* input source automatically selected */
2549 spec->input_mux = NULL;
2550 break;
2551 case CXT5066_DELL_VOSTO:
2552 codec->patch_ops.unsol_event = cxt5066_vostro_event;
2553 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
2554 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2555 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2556 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
2557 spec->port_d_mode = 0;
2558 spec->dell_vostro = 1;
2559 snd_hda_attach_beep_device(codec, 0x13);
2561 /* no S/PDIF out */
2562 spec->multiout.dig_out_nid = 0;
2564 /* input source automatically selected */
2565 spec->input_mux = NULL;
2566 break;
2569 return 0;
2575 static struct hda_codec_preset snd_hda_preset_conexant[] = {
2576 { .id = 0x14f15045, .name = "CX20549 (Venice)",
2577 .patch = patch_cxt5045 },
2578 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
2579 .patch = patch_cxt5047 },
2580 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
2581 .patch = patch_cxt5051 },
2582 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
2583 .patch = patch_cxt5066 },
2584 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
2585 .patch = patch_cxt5066 },
2586 {} /* terminator */
2589 MODULE_ALIAS("snd-hda-codec-id:14f15045");
2590 MODULE_ALIAS("snd-hda-codec-id:14f15047");
2591 MODULE_ALIAS("snd-hda-codec-id:14f15051");
2592 MODULE_ALIAS("snd-hda-codec-id:14f15066");
2593 MODULE_ALIAS("snd-hda-codec-id:14f15067");
2595 MODULE_LICENSE("GPL");
2596 MODULE_DESCRIPTION("Conexant HD-audio codec");
2598 static struct hda_codec_preset_list conexant_list = {
2599 .preset = snd_hda_preset_conexant,
2600 .owner = THIS_MODULE,
2603 static int __init patch_conexant_init(void)
2605 return snd_hda_add_codec_preset(&conexant_list);
2608 static void __exit patch_conexant_exit(void)
2610 snd_hda_delete_codec_preset(&conexant_list);
2613 module_init(patch_conexant_init)
2614 module_exit(patch_conexant_exit)