initial commit with v2.6.32.60
[linux-2.6.32.60-moxart.git] / sound / pci / hda / patch_conexant.c
blobd68aaf4ba338b5768fc2907959aed6852c2e0bfe
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"
33 #define CXT_PIN_DIR_IN 0x00
34 #define CXT_PIN_DIR_OUT 0x01
35 #define CXT_PIN_DIR_INOUT 0x02
36 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
37 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39 #define CONEXANT_HP_EVENT 0x37
40 #define CONEXANT_MIC_EVENT 0x38
42 /* Conexant 5051 specific */
44 #define CXT5051_SPDIF_OUT 0x1C
45 #define CXT5051_PORTB_EVENT 0x38
46 #define CXT5051_PORTC_EVENT 0x39
49 struct conexant_jack {
51 hda_nid_t nid;
52 int type;
53 struct snd_jack *jack;
57 struct conexant_spec {
59 struct snd_kcontrol_new *mixers[5];
60 int num_mixers;
61 hda_nid_t vmaster_nid;
63 const struct hda_verb *init_verbs[5]; /* initialization verbs
64 * don't forget NULL
65 * termination!
67 unsigned int num_init_verbs;
69 /* playback */
70 struct hda_multi_out multiout; /* playback set-up
71 * max_channels, dacs must be set
72 * dig_out_nid and hp_nid are optional
74 unsigned int cur_eapd;
75 unsigned int hp_present;
76 unsigned int no_auto_mic;
77 unsigned int need_dac_fix;
79 /* capture */
80 unsigned int num_adc_nids;
81 hda_nid_t *adc_nids;
82 hda_nid_t dig_in_nid; /* digital-in NID; optional */
84 unsigned int cur_adc_idx;
85 hda_nid_t cur_adc;
86 unsigned int cur_adc_stream_tag;
87 unsigned int cur_adc_format;
89 /* capture source */
90 const struct hda_input_mux *input_mux;
91 hda_nid_t *capsrc_nids;
92 unsigned int cur_mux[3];
94 /* channel model */
95 const struct hda_channel_mode *channel_mode;
96 int num_channel_mode;
98 /* PCM information */
99 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
101 unsigned int spdif_route;
103 /* jack detection */
104 struct snd_array jacks;
106 /* dynamic controls, init_verbs and input_mux */
107 struct auto_pin_cfg autocfg;
108 struct hda_input_mux private_imux;
109 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
111 unsigned int dell_automute;
112 unsigned int port_d_mode;
113 unsigned char ext_mic_bias;
116 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
117 struct hda_codec *codec,
118 struct snd_pcm_substream *substream)
120 struct conexant_spec *spec = codec->spec;
121 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
122 hinfo);
125 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
126 struct hda_codec *codec,
127 unsigned int stream_tag,
128 unsigned int format,
129 struct snd_pcm_substream *substream)
131 struct conexant_spec *spec = codec->spec;
132 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
133 stream_tag,
134 format, substream);
137 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
138 struct hda_codec *codec,
139 struct snd_pcm_substream *substream)
141 struct conexant_spec *spec = codec->spec;
142 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
146 * Digital out
148 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
149 struct hda_codec *codec,
150 struct snd_pcm_substream *substream)
152 struct conexant_spec *spec = codec->spec;
153 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
156 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
157 struct hda_codec *codec,
158 struct snd_pcm_substream *substream)
160 struct conexant_spec *spec = codec->spec;
161 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
164 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
165 struct hda_codec *codec,
166 unsigned int stream_tag,
167 unsigned int format,
168 struct snd_pcm_substream *substream)
170 struct conexant_spec *spec = codec->spec;
171 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
172 stream_tag,
173 format, substream);
177 * Analog capture
179 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
181 unsigned int stream_tag,
182 unsigned int format,
183 struct snd_pcm_substream *substream)
185 struct conexant_spec *spec = codec->spec;
186 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
187 stream_tag, 0, format);
188 return 0;
191 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
192 struct hda_codec *codec,
193 struct snd_pcm_substream *substream)
195 struct conexant_spec *spec = codec->spec;
196 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
197 return 0;
202 static struct hda_pcm_stream conexant_pcm_analog_playback = {
203 .substreams = 1,
204 .channels_min = 2,
205 .channels_max = 2,
206 .nid = 0, /* fill later */
207 .ops = {
208 .open = conexant_playback_pcm_open,
209 .prepare = conexant_playback_pcm_prepare,
210 .cleanup = conexant_playback_pcm_cleanup
214 static struct hda_pcm_stream conexant_pcm_analog_capture = {
215 .substreams = 1,
216 .channels_min = 2,
217 .channels_max = 2,
218 .nid = 0, /* fill later */
219 .ops = {
220 .prepare = conexant_capture_pcm_prepare,
221 .cleanup = conexant_capture_pcm_cleanup
226 static struct hda_pcm_stream conexant_pcm_digital_playback = {
227 .substreams = 1,
228 .channels_min = 2,
229 .channels_max = 2,
230 .nid = 0, /* fill later */
231 .ops = {
232 .open = conexant_dig_playback_pcm_open,
233 .close = conexant_dig_playback_pcm_close,
234 .prepare = conexant_dig_playback_pcm_prepare
238 static struct hda_pcm_stream conexant_pcm_digital_capture = {
239 .substreams = 1,
240 .channels_min = 2,
241 .channels_max = 2,
242 /* NID is set in alc_build_pcms */
245 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
246 struct hda_codec *codec,
247 unsigned int stream_tag,
248 unsigned int format,
249 struct snd_pcm_substream *substream)
251 struct conexant_spec *spec = codec->spec;
252 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
253 spec->cur_adc_stream_tag = stream_tag;
254 spec->cur_adc_format = format;
255 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
256 return 0;
259 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
260 struct hda_codec *codec,
261 struct snd_pcm_substream *substream)
263 struct conexant_spec *spec = codec->spec;
264 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
265 spec->cur_adc = 0;
266 return 0;
269 static struct hda_pcm_stream cx5051_pcm_analog_capture = {
270 .substreams = 1,
271 .channels_min = 2,
272 .channels_max = 2,
273 .nid = 0, /* fill later */
274 .ops = {
275 .prepare = cx5051_capture_pcm_prepare,
276 .cleanup = cx5051_capture_pcm_cleanup
280 static int conexant_build_pcms(struct hda_codec *codec)
282 struct conexant_spec *spec = codec->spec;
283 struct hda_pcm *info = spec->pcm_rec;
285 codec->num_pcms = 1;
286 codec->pcm_info = info;
288 info->name = "CONEXANT Analog";
289 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
290 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
291 spec->multiout.max_channels;
292 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
293 spec->multiout.dac_nids[0];
294 if (codec->vendor_id == 0x14f15051)
295 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
296 cx5051_pcm_analog_capture;
297 else
298 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
299 conexant_pcm_analog_capture;
300 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
301 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
303 if (spec->multiout.dig_out_nid) {
304 info++;
305 codec->num_pcms++;
306 info->name = "Conexant Digital";
307 info->pcm_type = HDA_PCM_TYPE_SPDIF;
308 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
309 conexant_pcm_digital_playback;
310 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
311 spec->multiout.dig_out_nid;
312 if (spec->dig_in_nid) {
313 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
314 conexant_pcm_digital_capture;
315 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
316 spec->dig_in_nid;
320 return 0;
323 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
324 struct snd_ctl_elem_info *uinfo)
326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327 struct conexant_spec *spec = codec->spec;
329 return snd_hda_input_mux_info(spec->input_mux, uinfo);
332 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
333 struct snd_ctl_elem_value *ucontrol)
335 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
336 struct conexant_spec *spec = codec->spec;
337 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
339 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
340 return 0;
343 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
344 struct snd_ctl_elem_value *ucontrol)
346 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
347 struct conexant_spec *spec = codec->spec;
348 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
350 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
351 spec->capsrc_nids[adc_idx],
352 &spec->cur_mux[adc_idx]);
355 #ifdef CONFIG_SND_HDA_INPUT_JACK
356 static void conexant_free_jack_priv(struct snd_jack *jack)
358 struct conexant_jack *jacks = jack->private_data;
359 jacks->nid = 0;
360 jacks->jack = NULL;
363 static int conexant_add_jack(struct hda_codec *codec,
364 hda_nid_t nid, int type)
366 struct conexant_spec *spec;
367 struct conexant_jack *jack;
368 const char *name;
369 int i, err;
371 spec = codec->spec;
372 snd_array_init(&spec->jacks, sizeof(*jack), 32);
374 jack = spec->jacks.list;
375 for (i = 0; i < spec->jacks.used; i++, jack++)
376 if (jack->nid == nid)
377 return 0 ; /* already present */
379 jack = snd_array_new(&spec->jacks);
380 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
382 if (!jack)
383 return -ENOMEM;
385 jack->nid = nid;
386 jack->type = type;
388 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
389 if (err < 0)
390 return err;
391 jack->jack->private_data = jack;
392 jack->jack->private_free = conexant_free_jack_priv;
393 return 0;
396 static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
398 struct conexant_spec *spec = codec->spec;
399 struct conexant_jack *jacks = spec->jacks.list;
401 if (jacks) {
402 int i;
403 for (i = 0; i < spec->jacks.used; i++) {
404 if (jacks->nid == nid) {
405 unsigned int present;
406 present = snd_hda_codec_read(codec, nid, 0,
407 AC_VERB_GET_PIN_SENSE, 0) &
408 AC_PINSENSE_PRESENCE;
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 kfree(codec->spec);
490 static struct snd_kcontrol_new cxt_capture_mixers[] = {
492 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
493 .name = "Capture Source",
494 .info = conexant_mux_enum_info,
495 .get = conexant_mux_enum_get,
496 .put = conexant_mux_enum_put
501 static const char *slave_vols[] = {
502 "Headphone Playback Volume",
503 "Speaker Playback Volume",
504 NULL
507 static const char *slave_sws[] = {
508 "Headphone Playback Switch",
509 "Speaker Playback Switch",
510 NULL
513 static int conexant_build_controls(struct hda_codec *codec)
515 struct conexant_spec *spec = codec->spec;
516 unsigned int i;
517 int err;
519 for (i = 0; i < spec->num_mixers; i++) {
520 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
521 if (err < 0)
522 return err;
524 if (spec->multiout.dig_out_nid) {
525 err = snd_hda_create_spdif_out_ctls(codec,
526 spec->multiout.dig_out_nid);
527 if (err < 0)
528 return err;
529 err = snd_hda_create_spdif_share_sw(codec,
530 &spec->multiout);
531 if (err < 0)
532 return err;
533 spec->multiout.share_spdif = 1;
535 if (spec->dig_in_nid) {
536 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
537 if (err < 0)
538 return err;
541 /* if we have no master control, let's create it */
542 if (spec->vmaster_nid &&
543 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
544 unsigned int vmaster_tlv[4];
545 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
546 HDA_OUTPUT, vmaster_tlv);
547 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
548 vmaster_tlv, slave_vols);
549 if (err < 0)
550 return err;
552 if (spec->vmaster_nid &&
553 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
554 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
555 NULL, slave_sws);
556 if (err < 0)
557 return err;
560 if (spec->input_mux) {
561 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
562 if (err < 0)
563 return err;
566 return 0;
569 static struct hda_codec_ops conexant_patch_ops = {
570 .build_controls = conexant_build_controls,
571 .build_pcms = conexant_build_pcms,
572 .init = conexant_init,
573 .free = conexant_free,
577 * EAPD control
578 * the private value = nid | (invert << 8)
581 #define cxt_eapd_info snd_ctl_boolean_mono_info
583 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
584 struct snd_ctl_elem_value *ucontrol)
586 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
587 struct conexant_spec *spec = codec->spec;
588 int invert = (kcontrol->private_value >> 8) & 1;
589 if (invert)
590 ucontrol->value.integer.value[0] = !spec->cur_eapd;
591 else
592 ucontrol->value.integer.value[0] = spec->cur_eapd;
593 return 0;
597 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
598 struct snd_ctl_elem_value *ucontrol)
600 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
601 struct conexant_spec *spec = codec->spec;
602 int invert = (kcontrol->private_value >> 8) & 1;
603 hda_nid_t nid = kcontrol->private_value & 0xff;
604 unsigned int eapd;
606 eapd = !!ucontrol->value.integer.value[0];
607 if (invert)
608 eapd = !eapd;
609 if (eapd == spec->cur_eapd)
610 return 0;
612 spec->cur_eapd = eapd;
613 snd_hda_codec_write_cache(codec, nid,
614 0, AC_VERB_SET_EAPD_BTLENABLE,
615 eapd ? 0x02 : 0x00);
616 return 1;
619 /* controls for test mode */
620 #ifdef CONFIG_SND_DEBUG
622 #define CXT_EAPD_SWITCH(xname, nid, mask) \
623 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
624 .info = cxt_eapd_info, \
625 .get = cxt_eapd_get, \
626 .put = cxt_eapd_put, \
627 .private_value = nid | (mask<<16) }
631 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
632 struct snd_ctl_elem_info *uinfo)
634 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
635 struct conexant_spec *spec = codec->spec;
636 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
637 spec->num_channel_mode);
640 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
641 struct snd_ctl_elem_value *ucontrol)
643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
644 struct conexant_spec *spec = codec->spec;
645 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
646 spec->num_channel_mode,
647 spec->multiout.max_channels);
650 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
651 struct snd_ctl_elem_value *ucontrol)
653 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
654 struct conexant_spec *spec = codec->spec;
655 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
656 spec->num_channel_mode,
657 &spec->multiout.max_channels);
658 if (err >= 0 && spec->need_dac_fix)
659 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
660 return err;
663 #define CXT_PIN_MODE(xname, nid, dir) \
664 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
665 .info = conexant_ch_mode_info, \
666 .get = conexant_ch_mode_get, \
667 .put = conexant_ch_mode_put, \
668 .private_value = nid | (dir<<16) }
670 #endif /* CONFIG_SND_DEBUG */
672 /* Conexant 5045 specific */
674 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
675 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
676 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
677 #define CXT5045_SPDIF_OUT 0x18
679 static struct hda_channel_mode cxt5045_modes[1] = {
680 { 2, NULL },
683 static struct hda_input_mux cxt5045_capture_source = {
684 .num_items = 2,
685 .items = {
686 { "IntMic", 0x1 },
687 { "ExtMic", 0x2 },
691 static struct hda_input_mux cxt5045_capture_source_benq = {
692 .num_items = 5,
693 .items = {
694 { "IntMic", 0x1 },
695 { "ExtMic", 0x2 },
696 { "LineIn", 0x3 },
697 { "CD", 0x4 },
698 { "Mixer", 0x0 },
702 static struct hda_input_mux cxt5045_capture_source_hp530 = {
703 .num_items = 2,
704 .items = {
705 { "ExtMic", 0x1 },
706 { "IntMic", 0x2 },
710 /* turn on/off EAPD (+ mute HP) as a master switch */
711 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
712 struct snd_ctl_elem_value *ucontrol)
714 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
715 struct conexant_spec *spec = codec->spec;
716 unsigned int bits;
718 if (!cxt_eapd_put(kcontrol, ucontrol))
719 return 0;
721 /* toggle internal speakers mute depending of presence of
722 * the headphone jack
724 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
725 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
726 HDA_AMP_MUTE, bits);
728 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
729 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
730 HDA_AMP_MUTE, bits);
731 return 1;
734 /* bind volumes of both NID 0x10 and 0x11 */
735 static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
736 .ops = &snd_hda_bind_vol,
737 .values = {
738 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
739 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
744 /* toggle input of built-in and mic jack appropriately */
745 static void cxt5045_hp_automic(struct hda_codec *codec)
747 static struct hda_verb mic_jack_on[] = {
748 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
749 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
752 static struct hda_verb mic_jack_off[] = {
753 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
754 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
757 unsigned int present;
759 present = snd_hda_codec_read(codec, 0x12, 0,
760 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
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_codec_read(codec, 0x11, 0,
775 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
777 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
778 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
779 HDA_AMP_MUTE, bits);
782 /* unsolicited event for HP jack sensing */
783 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
784 unsigned int res)
786 res >>= 26;
787 switch (res) {
788 case CONEXANT_HP_EVENT:
789 cxt5045_hp_automute(codec);
790 break;
791 case CONEXANT_MIC_EVENT:
792 cxt5045_hp_automic(codec);
793 break;
798 static struct snd_kcontrol_new cxt5045_mixers[] = {
799 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
800 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
801 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
802 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
803 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
804 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
805 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
806 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
807 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
808 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
809 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
811 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
812 .name = "Master Playback Switch",
813 .info = cxt_eapd_info,
814 .get = cxt_eapd_get,
815 .put = cxt5045_hp_master_sw_put,
816 .private_value = 0x10,
822 static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
823 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
824 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
825 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
826 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
828 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
829 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
830 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
831 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
833 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
834 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
839 static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
840 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
841 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
842 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
843 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
844 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
845 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
846 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
847 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
848 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
849 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
850 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
852 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
853 .name = "Master Playback Switch",
854 .info = cxt_eapd_info,
855 .get = cxt_eapd_get,
856 .put = cxt5045_hp_master_sw_put,
857 .private_value = 0x10,
863 static struct hda_verb cxt5045_init_verbs[] = {
864 /* Line in, Mic */
865 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
866 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
867 /* HP, Amp */
868 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
869 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
870 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
871 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
872 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
873 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
874 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
875 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
876 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
877 /* Record selector: Int mic */
878 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
879 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
880 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
881 /* SPDIF route: PCM */
882 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
883 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
884 /* EAPD */
885 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
886 { } /* end */
889 static struct hda_verb cxt5045_benq_init_verbs[] = {
890 /* Int Mic, Mic */
891 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
892 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
893 /* Line In,HP, Amp */
894 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
895 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
896 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
897 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
898 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
899 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
900 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
901 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
902 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
903 /* Record selector: Int mic */
904 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
905 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
906 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
907 /* SPDIF route: PCM */
908 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
909 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
910 /* EAPD */
911 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
912 { } /* end */
915 static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
916 /* pin sensing on HP jack */
917 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
918 { } /* end */
921 static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
922 /* pin sensing on HP jack */
923 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
924 { } /* end */
927 #ifdef CONFIG_SND_DEBUG
928 /* Test configuration for debugging, modelled after the ALC260 test
929 * configuration.
931 static struct hda_input_mux cxt5045_test_capture_source = {
932 .num_items = 5,
933 .items = {
934 { "MIXER", 0x0 },
935 { "MIC1 pin", 0x1 },
936 { "LINE1 pin", 0x2 },
937 { "HP-OUT pin", 0x3 },
938 { "CD pin", 0x4 },
942 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
944 /* Output controls */
945 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
946 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
947 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
948 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
949 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
950 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
952 /* Modes for retasking pin widgets */
953 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
954 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
956 /* EAPD Switch Control */
957 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
959 /* Loopback mixer controls */
961 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
962 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
963 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
964 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
965 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
966 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
967 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
968 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
969 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
970 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
972 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
973 .name = "Input Source",
974 .info = conexant_mux_enum_info,
975 .get = conexant_mux_enum_get,
976 .put = conexant_mux_enum_put,
978 /* Audio input controls */
979 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
980 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
981 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
982 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
983 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
984 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
985 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
986 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
987 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
988 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
989 { } /* end */
992 static struct hda_verb cxt5045_test_init_verbs[] = {
993 /* Set connections */
994 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
995 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
996 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
997 /* Enable retasking pins as output, initially without power amp */
998 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
999 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1001 /* Disable digital (SPDIF) pins initially, but users can enable
1002 * them via a mixer switch. In the case of SPDIF-out, this initverb
1003 * payload also sets the generation to 0, output to be in "consumer"
1004 * PCM format, copyright asserted, no pre-emphasis and no validity
1005 * control.
1007 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1008 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1010 /* Start with output sum widgets muted and their output gains at min */
1011 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1012 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1014 /* Unmute retasking pin widget output buffers since the default
1015 * state appears to be output. As the pin mode is changed by the
1016 * user the pin mode control will take care of enabling the pin's
1017 * input/output buffers as needed.
1019 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1020 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1022 /* Mute capture amp left and right */
1023 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1025 /* Set ADC connection select to match default mixer setting (mic1
1026 * pin)
1028 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1029 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1031 /* Mute all inputs to mixer widget (even unconnected ones) */
1032 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1033 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1034 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1035 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1036 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1040 #endif
1043 /* initialize jack-sensing, too */
1044 static int cxt5045_init(struct hda_codec *codec)
1046 conexant_init(codec);
1047 cxt5045_hp_automute(codec);
1048 return 0;
1052 enum {
1053 CXT5045_LAPTOP_HPSENSE,
1054 CXT5045_LAPTOP_MICSENSE,
1055 CXT5045_LAPTOP_HPMICSENSE,
1056 CXT5045_BENQ,
1057 CXT5045_LAPTOP_HP530,
1058 #ifdef CONFIG_SND_DEBUG
1059 CXT5045_TEST,
1060 #endif
1061 CXT5045_MODELS
1064 static const char *cxt5045_models[CXT5045_MODELS] = {
1065 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1066 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1067 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1068 [CXT5045_BENQ] = "benq",
1069 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1070 #ifdef CONFIG_SND_DEBUG
1071 [CXT5045_TEST] = "test",
1072 #endif
1075 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1076 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1077 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1078 CXT5045_LAPTOP_HPSENSE),
1079 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1080 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1081 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1082 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1083 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1084 CXT5045_LAPTOP_HPMICSENSE),
1085 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1086 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1087 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1088 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1089 CXT5045_LAPTOP_HPMICSENSE),
1090 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1094 static int patch_cxt5045(struct hda_codec *codec)
1096 struct conexant_spec *spec;
1097 int board_config;
1099 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1100 if (!spec)
1101 return -ENOMEM;
1102 codec->spec = spec;
1103 codec->pin_amp_workaround = 1;
1105 spec->multiout.max_channels = 2;
1106 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1107 spec->multiout.dac_nids = cxt5045_dac_nids;
1108 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1109 spec->num_adc_nids = 1;
1110 spec->adc_nids = cxt5045_adc_nids;
1111 spec->capsrc_nids = cxt5045_capsrc_nids;
1112 spec->input_mux = &cxt5045_capture_source;
1113 spec->num_mixers = 1;
1114 spec->mixers[0] = cxt5045_mixers;
1115 spec->num_init_verbs = 1;
1116 spec->init_verbs[0] = cxt5045_init_verbs;
1117 spec->spdif_route = 0;
1118 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
1119 spec->channel_mode = cxt5045_modes,
1122 codec->patch_ops = conexant_patch_ops;
1124 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1125 cxt5045_models,
1126 cxt5045_cfg_tbl);
1127 switch (board_config) {
1128 case CXT5045_LAPTOP_HPSENSE:
1129 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1130 spec->input_mux = &cxt5045_capture_source;
1131 spec->num_init_verbs = 2;
1132 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1133 spec->mixers[0] = cxt5045_mixers;
1134 codec->patch_ops.init = cxt5045_init;
1135 break;
1136 case CXT5045_LAPTOP_MICSENSE:
1137 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1138 spec->input_mux = &cxt5045_capture_source;
1139 spec->num_init_verbs = 2;
1140 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1141 spec->mixers[0] = cxt5045_mixers;
1142 codec->patch_ops.init = cxt5045_init;
1143 break;
1144 default:
1145 case CXT5045_LAPTOP_HPMICSENSE:
1146 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1147 spec->input_mux = &cxt5045_capture_source;
1148 spec->num_init_verbs = 3;
1149 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1150 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1151 spec->mixers[0] = cxt5045_mixers;
1152 codec->patch_ops.init = cxt5045_init;
1153 break;
1154 case CXT5045_BENQ:
1155 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1156 spec->input_mux = &cxt5045_capture_source_benq;
1157 spec->num_init_verbs = 1;
1158 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1159 spec->mixers[0] = cxt5045_mixers;
1160 spec->mixers[1] = cxt5045_benq_mixers;
1161 spec->num_mixers = 2;
1162 codec->patch_ops.init = cxt5045_init;
1163 break;
1164 case CXT5045_LAPTOP_HP530:
1165 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1166 spec->input_mux = &cxt5045_capture_source_hp530;
1167 spec->num_init_verbs = 2;
1168 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1169 spec->mixers[0] = cxt5045_mixers_hp530;
1170 codec->patch_ops.init = cxt5045_init;
1171 break;
1172 #ifdef CONFIG_SND_DEBUG
1173 case CXT5045_TEST:
1174 spec->input_mux = &cxt5045_test_capture_source;
1175 spec->mixers[0] = cxt5045_test_mixer;
1176 spec->init_verbs[0] = cxt5045_test_init_verbs;
1177 break;
1179 #endif
1182 switch (codec->subsystem_id >> 16) {
1183 case 0x103c:
1184 case 0x1631:
1185 case 0x1734:
1186 case 0x17aa:
1187 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1188 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1189 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1191 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1192 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1193 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1194 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1195 (1 << AC_AMPCAP_MUTE_SHIFT));
1196 break;
1199 return 0;
1203 /* Conexant 5047 specific */
1204 #define CXT5047_SPDIF_OUT 0x11
1206 static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1207 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1208 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1210 static struct hda_channel_mode cxt5047_modes[1] = {
1211 { 2, NULL },
1214 static struct hda_input_mux cxt5047_toshiba_capture_source = {
1215 .num_items = 2,
1216 .items = {
1217 { "ExtMic", 0x2 },
1218 { "Line-In", 0x1 },
1222 /* turn on/off EAPD (+ mute HP) as a master switch */
1223 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1224 struct snd_ctl_elem_value *ucontrol)
1226 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1227 struct conexant_spec *spec = codec->spec;
1228 unsigned int bits;
1230 if (!cxt_eapd_put(kcontrol, ucontrol))
1231 return 0;
1233 /* toggle internal speakers mute depending of presence of
1234 * the headphone jack
1236 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1237 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1238 * pin widgets unlike other codecs. In this case, we need to
1239 * set index 0x01 for the volume from the mixer amp 0x19.
1241 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1242 HDA_AMP_MUTE, bits);
1243 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1244 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1245 HDA_AMP_MUTE, bits);
1246 return 1;
1249 /* mute internal speaker if HP is plugged */
1250 static void cxt5047_hp_automute(struct hda_codec *codec)
1252 struct conexant_spec *spec = codec->spec;
1253 unsigned int bits;
1255 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1256 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1258 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1259 /* See the note in cxt5047_hp_master_sw_put */
1260 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1261 HDA_AMP_MUTE, bits);
1264 /* toggle input of built-in and mic jack appropriately */
1265 static void cxt5047_hp_automic(struct hda_codec *codec)
1267 static struct hda_verb mic_jack_on[] = {
1268 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1269 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1272 static struct hda_verb mic_jack_off[] = {
1273 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1274 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1277 unsigned int present;
1279 present = snd_hda_codec_read(codec, 0x15, 0,
1280 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1281 if (present)
1282 snd_hda_sequence_write(codec, mic_jack_on);
1283 else
1284 snd_hda_sequence_write(codec, mic_jack_off);
1287 /* unsolicited event for HP jack sensing */
1288 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1289 unsigned int res)
1291 switch (res >> 26) {
1292 case CONEXANT_HP_EVENT:
1293 cxt5047_hp_automute(codec);
1294 break;
1295 case CONEXANT_MIC_EVENT:
1296 cxt5047_hp_automic(codec);
1297 break;
1301 static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1302 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1303 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1304 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
1305 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1306 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1307 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1308 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1310 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1311 .name = "Master Playback Switch",
1312 .info = cxt_eapd_info,
1313 .get = cxt_eapd_get,
1314 .put = cxt5047_hp_master_sw_put,
1315 .private_value = 0x13,
1321 static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1322 /* See the note in cxt5047_hp_master_sw_put */
1323 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1324 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1328 static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1329 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1330 { } /* end */
1333 static struct hda_verb cxt5047_init_verbs[] = {
1334 /* Line in, Mic, Built-in Mic */
1335 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1336 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1337 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1338 /* HP, Speaker */
1339 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1340 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1341 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1342 /* Record selector: Mic */
1343 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1344 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1345 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1346 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1347 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1348 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1349 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1350 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1351 /* SPDIF route: PCM */
1352 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1353 /* Enable unsolicited events */
1354 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1355 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1356 { } /* end */
1359 /* configuration for Toshiba Laptops */
1360 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1361 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1365 /* Test configuration for debugging, modelled after the ALC260 test
1366 * configuration.
1368 #ifdef CONFIG_SND_DEBUG
1369 static struct hda_input_mux cxt5047_test_capture_source = {
1370 .num_items = 4,
1371 .items = {
1372 { "LINE1 pin", 0x0 },
1373 { "MIC1 pin", 0x1 },
1374 { "MIC2 pin", 0x2 },
1375 { "CD pin", 0x3 },
1379 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1381 /* Output only controls */
1382 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1383 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1384 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1385 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1386 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1387 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1388 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1389 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1390 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1391 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1392 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1393 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1395 /* Modes for retasking pin widgets */
1396 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1397 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1399 /* EAPD Switch Control */
1400 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1402 /* Loopback mixer controls */
1403 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1404 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1405 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1406 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1407 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1408 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1409 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1410 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1412 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1413 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1414 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1415 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1416 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1417 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1418 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1419 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1421 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1422 .name = "Input Source",
1423 .info = conexant_mux_enum_info,
1424 .get = conexant_mux_enum_get,
1425 .put = conexant_mux_enum_put,
1427 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1428 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1429 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1430 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1431 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1432 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1433 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1434 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1435 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1436 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1438 { } /* end */
1441 static struct hda_verb cxt5047_test_init_verbs[] = {
1442 /* Enable retasking pins as output, initially without power amp */
1443 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1444 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1445 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1447 /* Disable digital (SPDIF) pins initially, but users can enable
1448 * them via a mixer switch. In the case of SPDIF-out, this initverb
1449 * payload also sets the generation to 0, output to be in "consumer"
1450 * PCM format, copyright asserted, no pre-emphasis and no validity
1451 * control.
1453 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1455 /* Ensure mic1, mic2, line1 pin widgets take input from the
1456 * OUT1 sum bus when acting as an output.
1458 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1459 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1461 /* Start with output sum widgets muted and their output gains at min */
1462 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1463 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1465 /* Unmute retasking pin widget output buffers since the default
1466 * state appears to be output. As the pin mode is changed by the
1467 * user the pin mode control will take care of enabling the pin's
1468 * input/output buffers as needed.
1470 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1471 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1472 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1474 /* Mute capture amp left and right */
1475 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1477 /* Set ADC connection select to match default mixer setting (mic1
1478 * pin)
1480 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1482 /* Mute all inputs to mixer widget (even unconnected ones) */
1483 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1484 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1485 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1486 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1487 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1488 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1489 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1490 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1494 #endif
1497 /* initialize jack-sensing, too */
1498 static int cxt5047_hp_init(struct hda_codec *codec)
1500 conexant_init(codec);
1501 cxt5047_hp_automute(codec);
1502 return 0;
1506 enum {
1507 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1508 CXT5047_LAPTOP_HP, /* Some HP laptops */
1509 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1510 #ifdef CONFIG_SND_DEBUG
1511 CXT5047_TEST,
1512 #endif
1513 CXT5047_MODELS
1516 static const char *cxt5047_models[CXT5047_MODELS] = {
1517 [CXT5047_LAPTOP] = "laptop",
1518 [CXT5047_LAPTOP_HP] = "laptop-hp",
1519 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1520 #ifdef CONFIG_SND_DEBUG
1521 [CXT5047_TEST] = "test",
1522 #endif
1525 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1526 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1527 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1528 CXT5047_LAPTOP),
1529 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1533 static int patch_cxt5047(struct hda_codec *codec)
1535 struct conexant_spec *spec;
1536 int board_config;
1538 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1539 if (!spec)
1540 return -ENOMEM;
1541 codec->spec = spec;
1542 codec->pin_amp_workaround = 1;
1544 spec->multiout.max_channels = 2;
1545 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1546 spec->multiout.dac_nids = cxt5047_dac_nids;
1547 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1548 spec->num_adc_nids = 1;
1549 spec->adc_nids = cxt5047_adc_nids;
1550 spec->capsrc_nids = cxt5047_capsrc_nids;
1551 spec->num_mixers = 1;
1552 spec->mixers[0] = cxt5047_base_mixers;
1553 spec->num_init_verbs = 1;
1554 spec->init_verbs[0] = cxt5047_init_verbs;
1555 spec->spdif_route = 0;
1556 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1557 spec->channel_mode = cxt5047_modes,
1559 codec->patch_ops = conexant_patch_ops;
1561 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1562 cxt5047_models,
1563 cxt5047_cfg_tbl);
1564 switch (board_config) {
1565 case CXT5047_LAPTOP:
1566 spec->num_mixers = 2;
1567 spec->mixers[1] = cxt5047_hp_spk_mixers;
1568 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1569 break;
1570 case CXT5047_LAPTOP_HP:
1571 spec->num_mixers = 2;
1572 spec->mixers[1] = cxt5047_hp_only_mixers;
1573 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1574 codec->patch_ops.init = cxt5047_hp_init;
1575 break;
1576 case CXT5047_LAPTOP_EAPD:
1577 spec->input_mux = &cxt5047_toshiba_capture_source;
1578 spec->num_mixers = 2;
1579 spec->mixers[1] = cxt5047_hp_spk_mixers;
1580 spec->num_init_verbs = 2;
1581 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1582 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1583 break;
1584 #ifdef CONFIG_SND_DEBUG
1585 case CXT5047_TEST:
1586 spec->input_mux = &cxt5047_test_capture_source;
1587 spec->mixers[0] = cxt5047_test_mixer;
1588 spec->init_verbs[0] = cxt5047_test_init_verbs;
1589 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1590 #endif
1592 spec->vmaster_nid = 0x13;
1594 switch (codec->subsystem_id >> 16) {
1595 case 0x103c:
1596 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1597 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1598 * with 0 dB offset 0x17)
1600 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1601 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1602 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1603 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1604 (1 << AC_AMPCAP_MUTE_SHIFT));
1605 break;
1608 return 0;
1611 /* Conexant 5051 specific */
1612 static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1613 static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1615 static struct hda_channel_mode cxt5051_modes[1] = {
1616 { 2, NULL },
1619 static void cxt5051_update_speaker(struct hda_codec *codec)
1621 struct conexant_spec *spec = codec->spec;
1622 unsigned int pinctl;
1623 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1624 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1625 pinctl);
1628 /* turn on/off EAPD (+ mute HP) as a master switch */
1629 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1630 struct snd_ctl_elem_value *ucontrol)
1632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1634 if (!cxt_eapd_put(kcontrol, ucontrol))
1635 return 0;
1636 cxt5051_update_speaker(codec);
1637 return 1;
1640 /* toggle input of built-in and mic jack appropriately */
1641 static void cxt5051_portb_automic(struct hda_codec *codec)
1643 struct conexant_spec *spec = codec->spec;
1644 unsigned int present;
1646 if (spec->no_auto_mic)
1647 return;
1648 present = snd_hda_codec_read(codec, 0x17, 0,
1649 AC_VERB_GET_PIN_SENSE, 0) &
1650 AC_PINSENSE_PRESENCE;
1651 snd_hda_codec_write(codec, 0x14, 0,
1652 AC_VERB_SET_CONNECT_SEL,
1653 present ? 0x01 : 0x00);
1656 /* switch the current ADC according to the jack state */
1657 static void cxt5051_portc_automic(struct hda_codec *codec)
1659 struct conexant_spec *spec = codec->spec;
1660 unsigned int present;
1661 hda_nid_t new_adc;
1663 if (spec->no_auto_mic)
1664 return;
1665 present = snd_hda_codec_read(codec, 0x18, 0,
1666 AC_VERB_GET_PIN_SENSE, 0) &
1667 AC_PINSENSE_PRESENCE;
1668 if (present)
1669 spec->cur_adc_idx = 1;
1670 else
1671 spec->cur_adc_idx = 0;
1672 new_adc = spec->adc_nids[spec->cur_adc_idx];
1673 if (spec->cur_adc && spec->cur_adc != new_adc) {
1674 /* stream is running, let's swap the current ADC */
1675 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1676 spec->cur_adc = new_adc;
1677 snd_hda_codec_setup_stream(codec, new_adc,
1678 spec->cur_adc_stream_tag, 0,
1679 spec->cur_adc_format);
1683 /* mute internal speaker if HP is plugged */
1684 static void cxt5051_hp_automute(struct hda_codec *codec)
1686 struct conexant_spec *spec = codec->spec;
1688 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1689 AC_VERB_GET_PIN_SENSE, 0) &
1690 AC_PINSENSE_PRESENCE;
1691 cxt5051_update_speaker(codec);
1694 /* unsolicited event for HP jack sensing */
1695 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1696 unsigned int res)
1698 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1699 switch (res >> 26) {
1700 case CONEXANT_HP_EVENT:
1701 cxt5051_hp_automute(codec);
1702 break;
1703 case CXT5051_PORTB_EVENT:
1704 cxt5051_portb_automic(codec);
1705 break;
1706 case CXT5051_PORTC_EVENT:
1707 cxt5051_portc_automic(codec);
1708 break;
1710 conexant_report_jack(codec, nid);
1713 static struct snd_kcontrol_new cxt5051_mixers[] = {
1714 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1715 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1716 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1717 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1718 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1719 HDA_CODEC_MUTE("Docking 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_mixers[] = {
1734 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1735 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1736 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1737 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1738 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1741 .name = "Master Playback Switch",
1742 .info = cxt_eapd_info,
1743 .get = cxt_eapd_get,
1744 .put = cxt5051_hp_master_sw_put,
1745 .private_value = 0x1a,
1751 static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1752 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1753 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1754 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1756 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1757 .name = "Master Playback Switch",
1758 .info = cxt_eapd_info,
1759 .get = cxt_eapd_get,
1760 .put = cxt5051_hp_master_sw_put,
1761 .private_value = 0x1a,
1767 static struct hda_verb cxt5051_init_verbs[] = {
1768 /* Line in, Mic */
1769 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1770 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1771 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1772 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1773 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1774 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1775 /* SPK */
1776 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1777 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1778 /* HP, Amp */
1779 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1780 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1781 /* DAC1 */
1782 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1783 /* Record selector: Int mic */
1784 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1785 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1786 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1787 /* SPDIF route: PCM */
1788 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1789 /* EAPD */
1790 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1791 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1792 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1793 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1794 { } /* end */
1797 static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1798 /* Line in, Mic */
1799 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1800 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1801 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1802 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1803 /* SPK */
1804 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1805 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1806 /* HP, Amp */
1807 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1808 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1809 /* DAC1 */
1810 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1811 /* Record selector: Int mic */
1812 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1813 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1814 /* SPDIF route: PCM */
1815 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1816 /* EAPD */
1817 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1818 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1819 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1820 { } /* end */
1823 static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1824 /* Line in, Mic */
1825 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1826 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1827 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1828 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1829 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1830 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1831 /* SPK */
1832 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1833 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1834 /* HP, Amp */
1835 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1836 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1837 /* Docking HP */
1838 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1839 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1840 /* DAC1 */
1841 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1842 /* Record selector: Int mic */
1843 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1844 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1845 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1846 /* SPDIF route: PCM */
1847 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1848 /* EAPD */
1849 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1850 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1851 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1852 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1853 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1854 { } /* end */
1857 /* initialize jack-sensing, too */
1858 static int cxt5051_init(struct hda_codec *codec)
1860 conexant_init(codec);
1861 conexant_init_jacks(codec);
1862 if (codec->patch_ops.unsol_event) {
1863 cxt5051_hp_automute(codec);
1864 cxt5051_portb_automic(codec);
1865 cxt5051_portc_automic(codec);
1867 return 0;
1871 enum {
1872 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1873 CXT5051_HP, /* no docking */
1874 CXT5051_HP_DV6736, /* HP without mic switch */
1875 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
1876 CXT5051_MODELS
1879 static const char *cxt5051_models[CXT5051_MODELS] = {
1880 [CXT5051_LAPTOP] = "laptop",
1881 [CXT5051_HP] = "hp",
1882 [CXT5051_HP_DV6736] = "hp-dv6736",
1883 [CXT5051_LENOVO_X200] = "lenovo-x200",
1886 static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1887 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1888 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1889 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1890 CXT5051_LAPTOP),
1891 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1892 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1896 static int patch_cxt5051(struct hda_codec *codec)
1898 struct conexant_spec *spec;
1899 int board_config;
1901 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1902 if (!spec)
1903 return -ENOMEM;
1904 codec->spec = spec;
1905 codec->pin_amp_workaround = 1;
1907 codec->patch_ops = conexant_patch_ops;
1908 codec->patch_ops.init = cxt5051_init;
1910 spec->multiout.max_channels = 2;
1911 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1912 spec->multiout.dac_nids = cxt5051_dac_nids;
1913 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1914 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1915 spec->adc_nids = cxt5051_adc_nids;
1916 spec->num_mixers = 1;
1917 spec->mixers[0] = cxt5051_mixers;
1918 spec->num_init_verbs = 1;
1919 spec->init_verbs[0] = cxt5051_init_verbs;
1920 spec->spdif_route = 0;
1921 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1922 spec->channel_mode = cxt5051_modes;
1923 spec->cur_adc = 0;
1924 spec->cur_adc_idx = 0;
1926 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1928 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1929 cxt5051_models,
1930 cxt5051_cfg_tbl);
1931 switch (board_config) {
1932 case CXT5051_HP:
1933 spec->mixers[0] = cxt5051_hp_mixers;
1934 break;
1935 case CXT5051_HP_DV6736:
1936 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1937 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1938 spec->no_auto_mic = 1;
1939 break;
1940 case CXT5051_LENOVO_X200:
1941 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1942 break;
1945 return 0;
1948 /* Conexant 5066 specific */
1950 static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
1951 static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1952 static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1953 #define CXT5066_SPDIF_OUT 0x21
1955 /* OLPC's microphone port is DC coupled for use with external sensors,
1956 * therefore we use a 50% mic bias in order to center the input signal with
1957 * the DC input range of the codec. */
1958 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1960 static struct hda_channel_mode cxt5066_modes[1] = {
1961 { 2, NULL },
1964 static void cxt5066_update_speaker(struct hda_codec *codec)
1966 struct conexant_spec *spec = codec->spec;
1967 unsigned int pinctl;
1969 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
1970 spec->hp_present);
1972 /* Port A (HP) */
1973 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
1974 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1975 pinctl);
1977 /* Port D (HP/LO) */
1978 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
1979 ? spec->port_d_mode : 0;
1980 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1981 pinctl);
1983 /* CLASS_D AMP */
1984 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1985 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1986 pinctl);
1988 if (spec->dell_automute) {
1989 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
1990 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
1991 ? PIN_OUT : 0;
1992 snd_hda_codec_write(codec, 0x1c, 0,
1993 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
1997 /* turn on/off EAPD (+ mute HP) as a master switch */
1998 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1999 struct snd_ctl_elem_value *ucontrol)
2001 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2003 if (!cxt_eapd_put(kcontrol, ucontrol))
2004 return 0;
2006 cxt5066_update_speaker(codec);
2007 return 1;
2010 /* toggle input of built-in and mic jack appropriately */
2011 static void cxt5066_automic(struct hda_codec *codec)
2013 struct conexant_spec *spec = codec->spec;
2014 struct hda_verb ext_mic_present[] = {
2015 /* enable external mic, port B */
2016 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
2018 /* switch to external mic input */
2019 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2021 /* disable internal mic, port C */
2022 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2025 static struct hda_verb ext_mic_absent[] = {
2026 /* enable internal mic, port C */
2027 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2029 /* switch to internal mic input */
2030 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2032 /* disable external mic, port B */
2033 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2036 unsigned int present;
2038 present = snd_hda_codec_read(codec, 0x1a, 0,
2039 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2040 if (present) {
2041 snd_printdd("CXT5066: external microphone detected\n");
2042 snd_hda_sequence_write(codec, ext_mic_present);
2043 } else {
2044 snd_printdd("CXT5066: external microphone absent\n");
2045 snd_hda_sequence_write(codec, ext_mic_absent);
2049 /* mute internal speaker if HP is plugged */
2050 static void cxt5066_hp_automute(struct hda_codec *codec)
2052 struct conexant_spec *spec = codec->spec;
2053 unsigned int portA, portD;
2055 /* Port A */
2056 portA = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0)
2057 & AC_PINSENSE_PRESENCE;
2059 /* Port D */
2060 portD = (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0)
2061 & AC_PINSENSE_PRESENCE) << 1;
2063 spec->hp_present = !!(portA | portD);
2064 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2065 portA, portD, spec->hp_present);
2066 cxt5066_update_speaker(codec);
2069 /* unsolicited event for jack sensing */
2070 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2072 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2073 switch (res >> 26) {
2074 case CONEXANT_HP_EVENT:
2075 cxt5066_hp_automute(codec);
2076 break;
2077 case CONEXANT_MIC_EVENT:
2078 cxt5066_automic(codec);
2079 break;
2083 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2084 .num_items = 5,
2085 .items = {
2086 { "0dB", 0 },
2087 { "10dB", 1 },
2088 { "20dB", 2 },
2089 { "30dB", 3 },
2090 { "40dB", 4 },
2094 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2095 struct snd_ctl_elem_info *uinfo)
2097 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2100 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2101 struct snd_ctl_elem_value *ucontrol)
2103 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2104 int val;
2106 val = snd_hda_codec_read(codec, 0x17, 0,
2107 AC_VERB_GET_AMP_GAIN_MUTE, AC_AMP_GET_OUTPUT);
2109 ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
2110 return 0;
2113 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2114 struct snd_ctl_elem_value *ucontrol)
2116 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2117 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2118 unsigned int idx;
2120 if (!imux->num_items)
2121 return 0;
2122 idx = ucontrol->value.enumerated.item[0];
2123 if (idx >= imux->num_items)
2124 idx = imux->num_items - 1;
2126 snd_hda_codec_write_cache(codec, 0x17, 0,
2127 AC_VERB_SET_AMP_GAIN_MUTE,
2128 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2129 imux->items[idx].index);
2131 return 1;
2134 static struct hda_input_mux cxt5066_capture_source = {
2135 .num_items = 4,
2136 .items = {
2137 { "Mic B", 0 },
2138 { "Mic C", 1 },
2139 { "Mic E", 2 },
2140 { "Mic F", 3 },
2144 static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2145 .ops = &snd_hda_bind_vol,
2146 .values = {
2147 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2148 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2153 static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2154 .ops = &snd_hda_bind_sw,
2155 .values = {
2156 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2157 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2162 static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2163 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2167 static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2169 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2170 .name = "Master Playback Volume",
2171 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2172 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2173 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2174 .info = snd_hda_mixer_amp_volume_info,
2175 .get = snd_hda_mixer_amp_volume_get,
2176 .put = snd_hda_mixer_amp_volume_put,
2177 .tlv = { .c = snd_hda_mixer_amp_tlv },
2178 /* offset by 28 volume steps to limit minimum gain to -46dB */
2179 .private_value =
2180 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2185 static struct snd_kcontrol_new cxt5066_mixers[] = {
2187 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2188 .name = "Master Playback Switch",
2189 .info = cxt_eapd_info,
2190 .get = cxt_eapd_get,
2191 .put = cxt5066_hp_master_sw_put,
2192 .private_value = 0x1d,
2196 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2197 .name = "Analog Mic Boost Capture Enum",
2198 .info = cxt5066_mic_boost_mux_enum_info,
2199 .get = cxt5066_mic_boost_mux_enum_get,
2200 .put = cxt5066_mic_boost_mux_enum_put,
2203 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2204 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2208 static struct hda_verb cxt5066_init_verbs[] = {
2209 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2210 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2211 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2212 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2214 /* Speakers */
2215 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2216 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2218 /* HP, Amp */
2219 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2220 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2222 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2223 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2225 /* DAC1 */
2226 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2228 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2229 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2230 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2231 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2232 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2233 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2235 /* no digital microphone support yet */
2236 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2238 /* Audio input selector */
2239 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2241 /* SPDIF route: PCM */
2242 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2243 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2245 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2246 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2248 /* EAPD */
2249 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2251 /* not handling these yet */
2252 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2253 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2254 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2255 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2256 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2257 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2258 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2259 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2260 { } /* end */
2263 static struct hda_verb cxt5066_init_verbs_olpc[] = {
2264 /* Port A: headphones */
2265 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2266 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2268 /* Port B: external microphone */
2269 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, CXT5066_OLPC_EXT_MIC_BIAS},
2271 /* Port C: internal microphone */
2272 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2274 /* Port D: unused */
2275 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2277 /* Port E: unused, but has primary EAPD */
2278 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2279 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2281 /* Port F: unused */
2282 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2284 /* Port G: internal speakers */
2285 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2286 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2288 /* DAC1 */
2289 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2291 /* DAC2: unused */
2292 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2294 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2295 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2296 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2297 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2298 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2299 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2300 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2301 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2302 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2303 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2304 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2305 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2307 /* Disable digital microphone port */
2308 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2310 /* Audio input selectors */
2311 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2312 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2314 /* Disable SPDIF */
2315 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2316 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2318 /* enable unsolicited events for Port A and B */
2319 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2320 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2321 { } /* end */
2324 static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
2325 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2326 { } /* end */
2329 /* initialize jack-sensing, too */
2330 static int cxt5066_init(struct hda_codec *codec)
2332 snd_printdd("CXT5066: init\n");
2333 conexant_init(codec);
2334 if (codec->patch_ops.unsol_event) {
2335 cxt5066_hp_automute(codec);
2336 cxt5066_automic(codec);
2338 return 0;
2341 enum {
2342 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2343 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2344 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
2345 CXT5066_MODELS
2348 static const char *cxt5066_models[CXT5066_MODELS] = {
2349 [CXT5066_LAPTOP] = "laptop",
2350 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2351 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
2354 static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2355 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2356 CXT5066_LAPTOP),
2357 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
2358 CXT5066_DELL_LAPTOP),
2359 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
2360 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
2361 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
2365 static int patch_cxt5066(struct hda_codec *codec)
2367 struct conexant_spec *spec;
2368 int board_config;
2370 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2371 if (!spec)
2372 return -ENOMEM;
2373 codec->spec = spec;
2375 codec->patch_ops = conexant_patch_ops;
2376 codec->patch_ops.init = cxt5066_init;
2378 spec->dell_automute = 0;
2379 spec->multiout.max_channels = 2;
2380 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
2381 spec->multiout.dac_nids = cxt5066_dac_nids;
2382 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
2383 spec->num_adc_nids = 1;
2384 spec->adc_nids = cxt5066_adc_nids;
2385 spec->capsrc_nids = cxt5066_capsrc_nids;
2386 spec->input_mux = &cxt5066_capture_source;
2388 spec->port_d_mode = PIN_HP;
2389 spec->ext_mic_bias = PIN_VREF80;
2391 spec->num_init_verbs = 1;
2392 spec->init_verbs[0] = cxt5066_init_verbs;
2393 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
2394 spec->channel_mode = cxt5066_modes;
2395 spec->cur_adc = 0;
2396 spec->cur_adc_idx = 0;
2398 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2399 cxt5066_models, cxt5066_cfg_tbl);
2400 switch (board_config) {
2401 default:
2402 case CXT5066_LAPTOP:
2403 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2404 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2405 break;
2406 case CXT5066_DELL_LAPTOP:
2407 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2408 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2410 spec->port_d_mode = PIN_OUT;
2411 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
2412 spec->num_init_verbs++;
2413 spec->dell_automute = 1;
2414 break;
2415 case CXT5066_OLPC_XO_1_5:
2416 codec->patch_ops.unsol_event = cxt5066_unsol_event;
2417 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
2418 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
2419 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2420 spec->port_d_mode = 0;
2421 spec->ext_mic_bias = CXT5066_OLPC_EXT_MIC_BIAS;
2423 /* no S/PDIF out */
2424 spec->multiout.dig_out_nid = 0;
2426 /* input source automatically selected */
2427 spec->input_mux = NULL;
2428 break;
2431 return 0;
2437 static struct hda_codec_preset snd_hda_preset_conexant[] = {
2438 { .id = 0x14f15045, .name = "CX20549 (Venice)",
2439 .patch = patch_cxt5045 },
2440 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
2441 .patch = patch_cxt5047 },
2442 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
2443 .patch = patch_cxt5051 },
2444 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
2445 .patch = patch_cxt5066 },
2446 {} /* terminator */
2449 MODULE_ALIAS("snd-hda-codec-id:14f15045");
2450 MODULE_ALIAS("snd-hda-codec-id:14f15047");
2451 MODULE_ALIAS("snd-hda-codec-id:14f15051");
2452 MODULE_ALIAS("snd-hda-codec-id:14f15066");
2454 MODULE_LICENSE("GPL");
2455 MODULE_DESCRIPTION("Conexant HD-audio codec");
2457 static struct hda_codec_preset_list conexant_list = {
2458 .preset = snd_hda_preset_conexant,
2459 .owner = THIS_MODULE,
2462 static int __init patch_conexant_init(void)
2464 return snd_hda_add_codec_preset(&conexant_list);
2467 static void __exit patch_conexant_exit(void)
2469 snd_hda_delete_codec_preset(&conexant_list);
2472 module_init(patch_conexant_init)
2473 module_exit(patch_conexant_exit)