ALSA: hda - Add a new hp-laptop model for Conexant 5066, tested on HP G60
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / pci / hda / patch_conexant.c
blob4f0619908a30bd04acf72b0db91800a8ad6b007c
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 0x12
46 #define CXT5051_PORTB_EVENT 0x38
47 #define CXT5051_PORTC_EVENT 0x39
49 #define AUTO_MIC_PORTB (1 << 1)
50 #define AUTO_MIC_PORTC (1 << 2)
52 struct conexant_jack {
54 hda_nid_t nid;
55 int type;
56 struct snd_jack *jack;
60 struct conexant_spec {
62 struct snd_kcontrol_new *mixers[5];
63 int num_mixers;
64 hda_nid_t vmaster_nid;
66 const struct hda_verb *init_verbs[5]; /* initialization verbs
67 * don't forget NULL
68 * termination!
70 unsigned int num_init_verbs;
72 /* playback */
73 struct hda_multi_out multiout; /* playback set-up
74 * max_channels, dacs must be set
75 * dig_out_nid and hp_nid are optional
77 unsigned int cur_eapd;
78 unsigned int hp_present;
79 unsigned int auto_mic;
80 unsigned int need_dac_fix;
82 /* capture */
83 unsigned int num_adc_nids;
84 hda_nid_t *adc_nids;
85 hda_nid_t dig_in_nid; /* digital-in NID; optional */
87 unsigned int cur_adc_idx;
88 hda_nid_t cur_adc;
89 unsigned int cur_adc_stream_tag;
90 unsigned int cur_adc_format;
92 /* capture source */
93 const struct hda_input_mux *input_mux;
94 hda_nid_t *capsrc_nids;
95 unsigned int cur_mux[3];
97 /* channel model */
98 const struct hda_channel_mode *channel_mode;
99 int num_channel_mode;
101 /* PCM information */
102 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
104 unsigned int spdif_route;
106 /* jack detection */
107 struct snd_array jacks;
109 /* dynamic controls, init_verbs and input_mux */
110 struct auto_pin_cfg autocfg;
111 struct hda_input_mux private_imux;
112 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
114 unsigned int dell_automute;
115 unsigned int port_d_mode;
116 unsigned int dell_vostro:1;
117 unsigned int ideapad:1;
118 unsigned int thinkpad:1;
119 unsigned int hp_laptop:1;
121 unsigned int ext_mic_present;
122 unsigned int recording;
123 void (*capture_prepare)(struct hda_codec *codec);
124 void (*capture_cleanup)(struct hda_codec *codec);
126 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
127 * through the microphone jack.
128 * When the user enables this through a mixer switch, both internal and
129 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
130 * we also allow the bias to be configured through a separate mixer
131 * control. */
132 unsigned int dc_enable;
133 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
134 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
136 unsigned int beep_amp;
139 static int conexant_playback_pcm_open(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_open(codec, &spec->multiout, substream,
145 hinfo);
148 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
149 struct hda_codec *codec,
150 unsigned int stream_tag,
151 unsigned int format,
152 struct snd_pcm_substream *substream)
154 struct conexant_spec *spec = codec->spec;
155 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
156 stream_tag,
157 format, substream);
160 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
161 struct hda_codec *codec,
162 struct snd_pcm_substream *substream)
164 struct conexant_spec *spec = codec->spec;
165 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
169 * Digital out
171 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
172 struct hda_codec *codec,
173 struct snd_pcm_substream *substream)
175 struct conexant_spec *spec = codec->spec;
176 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
179 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
181 struct snd_pcm_substream *substream)
183 struct conexant_spec *spec = codec->spec;
184 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
187 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
188 struct hda_codec *codec,
189 unsigned int stream_tag,
190 unsigned int format,
191 struct snd_pcm_substream *substream)
193 struct conexant_spec *spec = codec->spec;
194 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
195 stream_tag,
196 format, substream);
200 * Analog capture
202 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
203 struct hda_codec *codec,
204 unsigned int stream_tag,
205 unsigned int format,
206 struct snd_pcm_substream *substream)
208 struct conexant_spec *spec = codec->spec;
209 if (spec->capture_prepare)
210 spec->capture_prepare(codec);
211 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
212 stream_tag, 0, format);
213 return 0;
216 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
217 struct hda_codec *codec,
218 struct snd_pcm_substream *substream)
220 struct conexant_spec *spec = codec->spec;
221 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
222 if (spec->capture_cleanup)
223 spec->capture_cleanup(codec);
224 return 0;
229 static struct hda_pcm_stream conexant_pcm_analog_playback = {
230 .substreams = 1,
231 .channels_min = 2,
232 .channels_max = 2,
233 .nid = 0, /* fill later */
234 .ops = {
235 .open = conexant_playback_pcm_open,
236 .prepare = conexant_playback_pcm_prepare,
237 .cleanup = conexant_playback_pcm_cleanup
241 static struct hda_pcm_stream conexant_pcm_analog_capture = {
242 .substreams = 1,
243 .channels_min = 2,
244 .channels_max = 2,
245 .nid = 0, /* fill later */
246 .ops = {
247 .prepare = conexant_capture_pcm_prepare,
248 .cleanup = conexant_capture_pcm_cleanup
253 static struct hda_pcm_stream conexant_pcm_digital_playback = {
254 .substreams = 1,
255 .channels_min = 2,
256 .channels_max = 2,
257 .nid = 0, /* fill later */
258 .ops = {
259 .open = conexant_dig_playback_pcm_open,
260 .close = conexant_dig_playback_pcm_close,
261 .prepare = conexant_dig_playback_pcm_prepare
265 static struct hda_pcm_stream conexant_pcm_digital_capture = {
266 .substreams = 1,
267 .channels_min = 2,
268 .channels_max = 2,
269 /* NID is set in alc_build_pcms */
272 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
273 struct hda_codec *codec,
274 unsigned int stream_tag,
275 unsigned int format,
276 struct snd_pcm_substream *substream)
278 struct conexant_spec *spec = codec->spec;
279 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
280 spec->cur_adc_stream_tag = stream_tag;
281 spec->cur_adc_format = format;
282 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
283 return 0;
286 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
287 struct hda_codec *codec,
288 struct snd_pcm_substream *substream)
290 struct conexant_spec *spec = codec->spec;
291 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
292 spec->cur_adc = 0;
293 return 0;
296 static struct hda_pcm_stream cx5051_pcm_analog_capture = {
297 .substreams = 1,
298 .channels_min = 2,
299 .channels_max = 2,
300 .nid = 0, /* fill later */
301 .ops = {
302 .prepare = cx5051_capture_pcm_prepare,
303 .cleanup = cx5051_capture_pcm_cleanup
307 static int conexant_build_pcms(struct hda_codec *codec)
309 struct conexant_spec *spec = codec->spec;
310 struct hda_pcm *info = spec->pcm_rec;
312 codec->num_pcms = 1;
313 codec->pcm_info = info;
315 info->name = "CONEXANT Analog";
316 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
317 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
318 spec->multiout.max_channels;
319 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
320 spec->multiout.dac_nids[0];
321 if (codec->vendor_id == 0x14f15051)
322 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
323 cx5051_pcm_analog_capture;
324 else
325 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
326 conexant_pcm_analog_capture;
327 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
328 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
330 if (spec->multiout.dig_out_nid) {
331 info++;
332 codec->num_pcms++;
333 info->name = "Conexant Digital";
334 info->pcm_type = HDA_PCM_TYPE_SPDIF;
335 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
336 conexant_pcm_digital_playback;
337 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
338 spec->multiout.dig_out_nid;
339 if (spec->dig_in_nid) {
340 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
341 conexant_pcm_digital_capture;
342 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
343 spec->dig_in_nid;
347 return 0;
350 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
351 struct snd_ctl_elem_info *uinfo)
353 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
354 struct conexant_spec *spec = codec->spec;
356 return snd_hda_input_mux_info(spec->input_mux, uinfo);
359 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
360 struct snd_ctl_elem_value *ucontrol)
362 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
363 struct conexant_spec *spec = codec->spec;
364 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
366 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
367 return 0;
370 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
371 struct snd_ctl_elem_value *ucontrol)
373 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
374 struct conexant_spec *spec = codec->spec;
375 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
377 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
378 spec->capsrc_nids[adc_idx],
379 &spec->cur_mux[adc_idx]);
382 #ifdef CONFIG_SND_HDA_INPUT_JACK
383 static void conexant_free_jack_priv(struct snd_jack *jack)
385 struct conexant_jack *jacks = jack->private_data;
386 jacks->nid = 0;
387 jacks->jack = NULL;
390 static int conexant_add_jack(struct hda_codec *codec,
391 hda_nid_t nid, int type)
393 struct conexant_spec *spec;
394 struct conexant_jack *jack;
395 const char *name;
396 int err;
398 spec = codec->spec;
399 snd_array_init(&spec->jacks, sizeof(*jack), 32);
400 jack = snd_array_new(&spec->jacks);
401 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
403 if (!jack)
404 return -ENOMEM;
406 jack->nid = nid;
407 jack->type = type;
409 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
410 if (err < 0)
411 return err;
412 jack->jack->private_data = jack;
413 jack->jack->private_free = conexant_free_jack_priv;
414 return 0;
417 static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
419 struct conexant_spec *spec = codec->spec;
420 struct conexant_jack *jacks = spec->jacks.list;
422 if (jacks) {
423 int i;
424 for (i = 0; i < spec->jacks.used; i++) {
425 if (jacks->nid == nid) {
426 unsigned int present;
427 present = snd_hda_jack_detect(codec, nid);
429 present = (present) ? jacks->type : 0 ;
431 snd_jack_report(jacks->jack,
432 present);
434 jacks++;
439 static int conexant_init_jacks(struct hda_codec *codec)
441 struct conexant_spec *spec = codec->spec;
442 int i;
444 for (i = 0; i < spec->num_init_verbs; i++) {
445 const struct hda_verb *hv;
447 hv = spec->init_verbs[i];
448 while (hv->nid) {
449 int err = 0;
450 switch (hv->param ^ AC_USRSP_EN) {
451 case CONEXANT_HP_EVENT:
452 err = conexant_add_jack(codec, hv->nid,
453 SND_JACK_HEADPHONE);
454 conexant_report_jack(codec, hv->nid);
455 break;
456 case CXT5051_PORTC_EVENT:
457 case CONEXANT_MIC_EVENT:
458 err = conexant_add_jack(codec, hv->nid,
459 SND_JACK_MICROPHONE);
460 conexant_report_jack(codec, hv->nid);
461 break;
463 if (err < 0)
464 return err;
465 ++hv;
468 return 0;
471 #else
472 static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
476 static inline int conexant_init_jacks(struct hda_codec *codec)
478 return 0;
480 #endif
482 static int conexant_init(struct hda_codec *codec)
484 struct conexant_spec *spec = codec->spec;
485 int i;
487 for (i = 0; i < spec->num_init_verbs; i++)
488 snd_hda_sequence_write(codec, spec->init_verbs[i]);
489 return 0;
492 static void conexant_free(struct hda_codec *codec)
494 #ifdef CONFIG_SND_HDA_INPUT_JACK
495 struct conexant_spec *spec = codec->spec;
496 if (spec->jacks.list) {
497 struct conexant_jack *jacks = spec->jacks.list;
498 int i;
499 for (i = 0; i < spec->jacks.used; i++, jacks++) {
500 if (jacks->jack)
501 snd_device_free(codec->bus->card, jacks->jack);
503 snd_array_free(&spec->jacks);
505 #endif
506 snd_hda_detach_beep_device(codec);
507 kfree(codec->spec);
510 static struct snd_kcontrol_new cxt_capture_mixers[] = {
512 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
513 .name = "Capture Source",
514 .info = conexant_mux_enum_info,
515 .get = conexant_mux_enum_get,
516 .put = conexant_mux_enum_put
521 #ifdef CONFIG_SND_HDA_INPUT_BEEP
522 /* additional beep mixers; the actual parameters are overwritten at build */
523 static struct snd_kcontrol_new cxt_beep_mixer[] = {
524 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
525 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
526 { } /* end */
528 #endif
530 static const char *slave_vols[] = {
531 "Headphone Playback Volume",
532 "Speaker Playback Volume",
533 NULL
536 static const char *slave_sws[] = {
537 "Headphone Playback Switch",
538 "Speaker Playback Switch",
539 NULL
542 static int conexant_build_controls(struct hda_codec *codec)
544 struct conexant_spec *spec = codec->spec;
545 unsigned int i;
546 int err;
548 for (i = 0; i < spec->num_mixers; i++) {
549 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
550 if (err < 0)
551 return err;
553 if (spec->multiout.dig_out_nid) {
554 err = snd_hda_create_spdif_out_ctls(codec,
555 spec->multiout.dig_out_nid);
556 if (err < 0)
557 return err;
558 err = snd_hda_create_spdif_share_sw(codec,
559 &spec->multiout);
560 if (err < 0)
561 return err;
562 spec->multiout.share_spdif = 1;
564 if (spec->dig_in_nid) {
565 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
566 if (err < 0)
567 return err;
570 /* if we have no master control, let's create it */
571 if (spec->vmaster_nid &&
572 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
573 unsigned int vmaster_tlv[4];
574 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
575 HDA_OUTPUT, vmaster_tlv);
576 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
577 vmaster_tlv, slave_vols);
578 if (err < 0)
579 return err;
581 if (spec->vmaster_nid &&
582 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
583 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
584 NULL, slave_sws);
585 if (err < 0)
586 return err;
589 if (spec->input_mux) {
590 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
591 if (err < 0)
592 return err;
595 #ifdef CONFIG_SND_HDA_INPUT_BEEP
596 /* create beep controls if needed */
597 if (spec->beep_amp) {
598 struct snd_kcontrol_new *knew;
599 for (knew = cxt_beep_mixer; knew->name; knew++) {
600 struct snd_kcontrol *kctl;
601 kctl = snd_ctl_new1(knew, codec);
602 if (!kctl)
603 return -ENOMEM;
604 kctl->private_value = spec->beep_amp;
605 err = snd_hda_ctl_add(codec, 0, kctl);
606 if (err < 0)
607 return err;
610 #endif
612 return 0;
615 #ifdef CONFIG_SND_HDA_POWER_SAVE
616 static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
618 snd_hda_shutup_pins(codec);
619 return 0;
621 #endif
623 static struct hda_codec_ops conexant_patch_ops = {
624 .build_controls = conexant_build_controls,
625 .build_pcms = conexant_build_pcms,
626 .init = conexant_init,
627 .free = conexant_free,
628 #ifdef CONFIG_SND_HDA_POWER_SAVE
629 .suspend = conexant_suspend,
630 #endif
631 .reboot_notify = snd_hda_shutup_pins,
634 #ifdef CONFIG_SND_HDA_INPUT_BEEP
635 #define set_beep_amp(spec, nid, idx, dir) \
636 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
637 #else
638 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
639 #endif
642 * EAPD control
643 * the private value = nid | (invert << 8)
646 #define cxt_eapd_info snd_ctl_boolean_mono_info
648 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct conexant_spec *spec = codec->spec;
653 int invert = (kcontrol->private_value >> 8) & 1;
654 if (invert)
655 ucontrol->value.integer.value[0] = !spec->cur_eapd;
656 else
657 ucontrol->value.integer.value[0] = spec->cur_eapd;
658 return 0;
662 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
663 struct snd_ctl_elem_value *ucontrol)
665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
666 struct conexant_spec *spec = codec->spec;
667 int invert = (kcontrol->private_value >> 8) & 1;
668 hda_nid_t nid = kcontrol->private_value & 0xff;
669 unsigned int eapd;
671 eapd = !!ucontrol->value.integer.value[0];
672 if (invert)
673 eapd = !eapd;
674 if (eapd == spec->cur_eapd)
675 return 0;
677 spec->cur_eapd = eapd;
678 snd_hda_codec_write_cache(codec, nid,
679 0, AC_VERB_SET_EAPD_BTLENABLE,
680 eapd ? 0x02 : 0x00);
681 return 1;
684 /* controls for test mode */
685 #ifdef CONFIG_SND_DEBUG
687 #define CXT_EAPD_SWITCH(xname, nid, mask) \
688 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
689 .info = cxt_eapd_info, \
690 .get = cxt_eapd_get, \
691 .put = cxt_eapd_put, \
692 .private_value = nid | (mask<<16) }
696 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
697 struct snd_ctl_elem_info *uinfo)
699 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
700 struct conexant_spec *spec = codec->spec;
701 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
702 spec->num_channel_mode);
705 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
706 struct snd_ctl_elem_value *ucontrol)
708 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
709 struct conexant_spec *spec = codec->spec;
710 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
711 spec->num_channel_mode,
712 spec->multiout.max_channels);
715 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
716 struct snd_ctl_elem_value *ucontrol)
718 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
719 struct conexant_spec *spec = codec->spec;
720 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
721 spec->num_channel_mode,
722 &spec->multiout.max_channels);
723 if (err >= 0 && spec->need_dac_fix)
724 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
725 return err;
728 #define CXT_PIN_MODE(xname, nid, dir) \
729 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
730 .info = conexant_ch_mode_info, \
731 .get = conexant_ch_mode_get, \
732 .put = conexant_ch_mode_put, \
733 .private_value = nid | (dir<<16) }
735 #endif /* CONFIG_SND_DEBUG */
737 /* Conexant 5045 specific */
739 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
740 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
741 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
742 #define CXT5045_SPDIF_OUT 0x18
744 static struct hda_channel_mode cxt5045_modes[1] = {
745 { 2, NULL },
748 static struct hda_input_mux cxt5045_capture_source = {
749 .num_items = 2,
750 .items = {
751 { "IntMic", 0x1 },
752 { "ExtMic", 0x2 },
756 static struct hda_input_mux cxt5045_capture_source_benq = {
757 .num_items = 5,
758 .items = {
759 { "IntMic", 0x1 },
760 { "ExtMic", 0x2 },
761 { "LineIn", 0x3 },
762 { "CD", 0x4 },
763 { "Mixer", 0x0 },
767 static struct hda_input_mux cxt5045_capture_source_hp530 = {
768 .num_items = 2,
769 .items = {
770 { "ExtMic", 0x1 },
771 { "IntMic", 0x2 },
775 /* turn on/off EAPD (+ mute HP) as a master switch */
776 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
777 struct snd_ctl_elem_value *ucontrol)
779 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
780 struct conexant_spec *spec = codec->spec;
781 unsigned int bits;
783 if (!cxt_eapd_put(kcontrol, ucontrol))
784 return 0;
786 /* toggle internal speakers mute depending of presence of
787 * the headphone jack
789 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
790 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
791 HDA_AMP_MUTE, bits);
793 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
794 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
795 HDA_AMP_MUTE, bits);
796 return 1;
799 /* bind volumes of both NID 0x10 and 0x11 */
800 static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
801 .ops = &snd_hda_bind_vol,
802 .values = {
803 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
804 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
809 /* toggle input of built-in and mic jack appropriately */
810 static void cxt5045_hp_automic(struct hda_codec *codec)
812 static struct hda_verb mic_jack_on[] = {
813 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
814 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
817 static struct hda_verb mic_jack_off[] = {
818 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
819 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
822 unsigned int present;
824 present = snd_hda_jack_detect(codec, 0x12);
825 if (present)
826 snd_hda_sequence_write(codec, mic_jack_on);
827 else
828 snd_hda_sequence_write(codec, mic_jack_off);
832 /* mute internal speaker if HP is plugged */
833 static void cxt5045_hp_automute(struct hda_codec *codec)
835 struct conexant_spec *spec = codec->spec;
836 unsigned int bits;
838 spec->hp_present = snd_hda_jack_detect(codec, 0x11);
840 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
841 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
842 HDA_AMP_MUTE, bits);
845 /* unsolicited event for HP jack sensing */
846 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
847 unsigned int res)
849 res >>= 26;
850 switch (res) {
851 case CONEXANT_HP_EVENT:
852 cxt5045_hp_automute(codec);
853 break;
854 case CONEXANT_MIC_EVENT:
855 cxt5045_hp_automic(codec);
856 break;
861 static struct snd_kcontrol_new cxt5045_mixers[] = {
862 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
863 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
864 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
865 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
866 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
867 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
868 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
869 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
870 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
871 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
872 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
874 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
875 .name = "Master Playback Switch",
876 .info = cxt_eapd_info,
877 .get = cxt_eapd_get,
878 .put = cxt5045_hp_master_sw_put,
879 .private_value = 0x10,
885 static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
886 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
887 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
888 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
889 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
891 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
892 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
893 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
894 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
896 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
897 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
902 static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
903 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
904 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
905 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
906 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
907 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
908 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
909 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
910 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
911 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
912 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
913 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
915 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
916 .name = "Master Playback Switch",
917 .info = cxt_eapd_info,
918 .get = cxt_eapd_get,
919 .put = cxt5045_hp_master_sw_put,
920 .private_value = 0x10,
926 static struct hda_verb cxt5045_init_verbs[] = {
927 /* Line in, Mic */
928 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
929 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
930 /* HP, Amp */
931 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
932 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
933 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
934 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
935 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
936 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
937 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
938 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
939 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
940 /* Record selector: Int mic */
941 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
942 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
943 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
944 /* SPDIF route: PCM */
945 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
946 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
947 /* EAPD */
948 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
949 { } /* end */
952 static struct hda_verb cxt5045_benq_init_verbs[] = {
953 /* Int Mic, Mic */
954 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
955 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
956 /* Line In,HP, Amp */
957 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
958 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
959 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
960 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
961 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
962 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
963 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
964 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
965 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
966 /* Record selector: Int mic */
967 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
968 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
969 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
970 /* SPDIF route: PCM */
971 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
972 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
973 /* EAPD */
974 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
975 { } /* end */
978 static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
979 /* pin sensing on HP jack */
980 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
981 { } /* end */
984 static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
985 /* pin sensing on HP jack */
986 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
987 { } /* end */
990 #ifdef CONFIG_SND_DEBUG
991 /* Test configuration for debugging, modelled after the ALC260 test
992 * configuration.
994 static struct hda_input_mux cxt5045_test_capture_source = {
995 .num_items = 5,
996 .items = {
997 { "MIXER", 0x0 },
998 { "MIC1 pin", 0x1 },
999 { "LINE1 pin", 0x2 },
1000 { "HP-OUT pin", 0x3 },
1001 { "CD pin", 0x4 },
1005 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
1007 /* Output controls */
1008 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1009 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1010 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1011 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1012 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1013 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1015 /* Modes for retasking pin widgets */
1016 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
1017 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
1019 /* EAPD Switch Control */
1020 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
1022 /* Loopback mixer controls */
1024 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
1025 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
1026 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
1027 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
1028 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
1029 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
1030 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
1031 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
1032 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
1033 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
1035 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1036 .name = "Input Source",
1037 .info = conexant_mux_enum_info,
1038 .get = conexant_mux_enum_get,
1039 .put = conexant_mux_enum_put,
1041 /* Audio input controls */
1042 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1043 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1044 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1045 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1046 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1047 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1048 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1049 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1050 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1051 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1052 { } /* end */
1055 static struct hda_verb cxt5045_test_init_verbs[] = {
1056 /* Set connections */
1057 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
1058 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
1059 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1060 /* Enable retasking pins as output, initially without power amp */
1061 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1062 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1064 /* Disable digital (SPDIF) pins initially, but users can enable
1065 * them via a mixer switch. In the case of SPDIF-out, this initverb
1066 * payload also sets the generation to 0, output to be in "consumer"
1067 * PCM format, copyright asserted, no pre-emphasis and no validity
1068 * control.
1070 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1071 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1073 /* Start with output sum widgets muted and their output gains at min */
1074 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1075 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1077 /* Unmute retasking pin widget output buffers since the default
1078 * state appears to be output. As the pin mode is changed by the
1079 * user the pin mode control will take care of enabling the pin's
1080 * input/output buffers as needed.
1082 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1083 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1085 /* Mute capture amp left and right */
1086 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1088 /* Set ADC connection select to match default mixer setting (mic1
1089 * pin)
1091 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1092 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1094 /* Mute all inputs to mixer widget (even unconnected ones) */
1095 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1096 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1097 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1098 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1099 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1103 #endif
1106 /* initialize jack-sensing, too */
1107 static int cxt5045_init(struct hda_codec *codec)
1109 conexant_init(codec);
1110 cxt5045_hp_automute(codec);
1111 return 0;
1115 enum {
1116 CXT5045_LAPTOP_HPSENSE,
1117 CXT5045_LAPTOP_MICSENSE,
1118 CXT5045_LAPTOP_HPMICSENSE,
1119 CXT5045_BENQ,
1120 CXT5045_LAPTOP_HP530,
1121 #ifdef CONFIG_SND_DEBUG
1122 CXT5045_TEST,
1123 #endif
1124 CXT5045_MODELS
1127 static const char *cxt5045_models[CXT5045_MODELS] = {
1128 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
1129 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1130 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1131 [CXT5045_BENQ] = "benq",
1132 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1133 #ifdef CONFIG_SND_DEBUG
1134 [CXT5045_TEST] = "test",
1135 #endif
1138 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1139 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1140 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1141 CXT5045_LAPTOP_HPSENSE),
1142 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1143 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1144 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1145 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
1146 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1147 CXT5045_LAPTOP_HPMICSENSE),
1148 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1149 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1150 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1151 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1152 CXT5045_LAPTOP_HPMICSENSE),
1153 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1157 static int patch_cxt5045(struct hda_codec *codec)
1159 struct conexant_spec *spec;
1160 int board_config;
1162 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1163 if (!spec)
1164 return -ENOMEM;
1165 codec->spec = spec;
1166 codec->pin_amp_workaround = 1;
1168 spec->multiout.max_channels = 2;
1169 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1170 spec->multiout.dac_nids = cxt5045_dac_nids;
1171 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1172 spec->num_adc_nids = 1;
1173 spec->adc_nids = cxt5045_adc_nids;
1174 spec->capsrc_nids = cxt5045_capsrc_nids;
1175 spec->input_mux = &cxt5045_capture_source;
1176 spec->num_mixers = 1;
1177 spec->mixers[0] = cxt5045_mixers;
1178 spec->num_init_verbs = 1;
1179 spec->init_verbs[0] = cxt5045_init_verbs;
1180 spec->spdif_route = 0;
1181 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
1182 spec->channel_mode = cxt5045_modes;
1184 set_beep_amp(spec, 0x16, 0, 1);
1186 codec->patch_ops = conexant_patch_ops;
1188 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1189 cxt5045_models,
1190 cxt5045_cfg_tbl);
1191 switch (board_config) {
1192 case CXT5045_LAPTOP_HPSENSE:
1193 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1194 spec->input_mux = &cxt5045_capture_source;
1195 spec->num_init_verbs = 2;
1196 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1197 spec->mixers[0] = cxt5045_mixers;
1198 codec->patch_ops.init = cxt5045_init;
1199 break;
1200 case CXT5045_LAPTOP_MICSENSE:
1201 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1202 spec->input_mux = &cxt5045_capture_source;
1203 spec->num_init_verbs = 2;
1204 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1205 spec->mixers[0] = cxt5045_mixers;
1206 codec->patch_ops.init = cxt5045_init;
1207 break;
1208 default:
1209 case CXT5045_LAPTOP_HPMICSENSE:
1210 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1211 spec->input_mux = &cxt5045_capture_source;
1212 spec->num_init_verbs = 3;
1213 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1214 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
1215 spec->mixers[0] = cxt5045_mixers;
1216 codec->patch_ops.init = cxt5045_init;
1217 break;
1218 case CXT5045_BENQ:
1219 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1220 spec->input_mux = &cxt5045_capture_source_benq;
1221 spec->num_init_verbs = 1;
1222 spec->init_verbs[0] = cxt5045_benq_init_verbs;
1223 spec->mixers[0] = cxt5045_mixers;
1224 spec->mixers[1] = cxt5045_benq_mixers;
1225 spec->num_mixers = 2;
1226 codec->patch_ops.init = cxt5045_init;
1227 break;
1228 case CXT5045_LAPTOP_HP530:
1229 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1230 spec->input_mux = &cxt5045_capture_source_hp530;
1231 spec->num_init_verbs = 2;
1232 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1233 spec->mixers[0] = cxt5045_mixers_hp530;
1234 codec->patch_ops.init = cxt5045_init;
1235 break;
1236 #ifdef CONFIG_SND_DEBUG
1237 case CXT5045_TEST:
1238 spec->input_mux = &cxt5045_test_capture_source;
1239 spec->mixers[0] = cxt5045_test_mixer;
1240 spec->init_verbs[0] = cxt5045_test_init_verbs;
1241 break;
1243 #endif
1246 switch (codec->subsystem_id >> 16) {
1247 case 0x103c:
1248 case 0x1631:
1249 case 0x1734:
1250 case 0x17aa:
1251 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1252 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1253 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1255 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
1256 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
1257 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1258 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1259 (1 << AC_AMPCAP_MUTE_SHIFT));
1260 break;
1263 if (spec->beep_amp)
1264 snd_hda_attach_beep_device(codec, spec->beep_amp);
1266 return 0;
1270 /* Conexant 5047 specific */
1271 #define CXT5047_SPDIF_OUT 0x11
1273 static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1274 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1275 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1277 static struct hda_channel_mode cxt5047_modes[1] = {
1278 { 2, NULL },
1281 static struct hda_input_mux cxt5047_toshiba_capture_source = {
1282 .num_items = 2,
1283 .items = {
1284 { "ExtMic", 0x2 },
1285 { "Line-In", 0x1 },
1289 /* turn on/off EAPD (+ mute HP) as a master switch */
1290 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1291 struct snd_ctl_elem_value *ucontrol)
1293 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1294 struct conexant_spec *spec = codec->spec;
1295 unsigned int bits;
1297 if (!cxt_eapd_put(kcontrol, ucontrol))
1298 return 0;
1300 /* toggle internal speakers mute depending of presence of
1301 * the headphone jack
1303 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1304 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1305 * pin widgets unlike other codecs. In this case, we need to
1306 * set index 0x01 for the volume from the mixer amp 0x19.
1308 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1309 HDA_AMP_MUTE, bits);
1310 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1311 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1312 HDA_AMP_MUTE, bits);
1313 return 1;
1316 /* mute internal speaker if HP is plugged */
1317 static void cxt5047_hp_automute(struct hda_codec *codec)
1319 struct conexant_spec *spec = codec->spec;
1320 unsigned int bits;
1322 spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1324 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1325 /* See the note in cxt5047_hp_master_sw_put */
1326 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1327 HDA_AMP_MUTE, bits);
1330 /* toggle input of built-in and mic jack appropriately */
1331 static void cxt5047_hp_automic(struct hda_codec *codec)
1333 static struct hda_verb mic_jack_on[] = {
1334 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1335 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1338 static struct hda_verb mic_jack_off[] = {
1339 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1340 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1343 unsigned int present;
1345 present = snd_hda_jack_detect(codec, 0x15);
1346 if (present)
1347 snd_hda_sequence_write(codec, mic_jack_on);
1348 else
1349 snd_hda_sequence_write(codec, mic_jack_off);
1352 /* unsolicited event for HP jack sensing */
1353 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1354 unsigned int res)
1356 switch (res >> 26) {
1357 case CONEXANT_HP_EVENT:
1358 cxt5047_hp_automute(codec);
1359 break;
1360 case CONEXANT_MIC_EVENT:
1361 cxt5047_hp_automic(codec);
1362 break;
1366 static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1367 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1368 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1369 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
1370 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1371 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1372 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1373 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1375 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1376 .name = "Master Playback Switch",
1377 .info = cxt_eapd_info,
1378 .get = cxt_eapd_get,
1379 .put = cxt5047_hp_master_sw_put,
1380 .private_value = 0x13,
1386 static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1387 /* See the note in cxt5047_hp_master_sw_put */
1388 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1389 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1393 static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1394 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1395 { } /* end */
1398 static struct hda_verb cxt5047_init_verbs[] = {
1399 /* Line in, Mic, Built-in Mic */
1400 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1401 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1402 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1403 /* HP, Speaker */
1404 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1405 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1406 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1407 /* Record selector: Mic */
1408 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1409 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1410 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1411 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1412 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1413 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1414 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1415 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1416 /* SPDIF route: PCM */
1417 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1418 /* Enable unsolicited events */
1419 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1420 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1421 { } /* end */
1424 /* configuration for Toshiba Laptops */
1425 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1426 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1430 /* Test configuration for debugging, modelled after the ALC260 test
1431 * configuration.
1433 #ifdef CONFIG_SND_DEBUG
1434 static struct hda_input_mux cxt5047_test_capture_source = {
1435 .num_items = 4,
1436 .items = {
1437 { "LINE1 pin", 0x0 },
1438 { "MIC1 pin", 0x1 },
1439 { "MIC2 pin", 0x2 },
1440 { "CD pin", 0x3 },
1444 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1446 /* Output only controls */
1447 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1448 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1449 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1450 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1451 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1452 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1453 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1454 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1455 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1456 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1457 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1458 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1460 /* Modes for retasking pin widgets */
1461 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1462 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1464 /* EAPD Switch Control */
1465 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1467 /* Loopback mixer controls */
1468 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1469 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1470 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1471 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1472 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1473 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1474 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1475 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1477 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1478 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1479 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1480 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1481 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1482 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1483 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1484 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1486 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1487 .name = "Input Source",
1488 .info = conexant_mux_enum_info,
1489 .get = conexant_mux_enum_get,
1490 .put = conexant_mux_enum_put,
1492 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1494 { } /* end */
1497 static struct hda_verb cxt5047_test_init_verbs[] = {
1498 /* Enable retasking pins as output, initially without power amp */
1499 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1500 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1501 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1503 /* Disable digital (SPDIF) pins initially, but users can enable
1504 * them via a mixer switch. In the case of SPDIF-out, this initverb
1505 * payload also sets the generation to 0, output to be in "consumer"
1506 * PCM format, copyright asserted, no pre-emphasis and no validity
1507 * control.
1509 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1511 /* Ensure mic1, mic2, line1 pin widgets take input from the
1512 * OUT1 sum bus when acting as an output.
1514 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1515 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1517 /* Start with output sum widgets muted and their output gains at min */
1518 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1519 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1521 /* Unmute retasking pin widget output buffers since the default
1522 * state appears to be output. As the pin mode is changed by the
1523 * user the pin mode control will take care of enabling the pin's
1524 * input/output buffers as needed.
1526 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1527 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1528 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1530 /* Mute capture amp left and right */
1531 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1533 /* Set ADC connection select to match default mixer setting (mic1
1534 * pin)
1536 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1538 /* Mute all inputs to mixer widget (even unconnected ones) */
1539 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1540 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1541 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1542 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1543 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1544 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1545 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1546 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1550 #endif
1553 /* initialize jack-sensing, too */
1554 static int cxt5047_hp_init(struct hda_codec *codec)
1556 conexant_init(codec);
1557 cxt5047_hp_automute(codec);
1558 return 0;
1562 enum {
1563 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1564 CXT5047_LAPTOP_HP, /* Some HP laptops */
1565 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1566 #ifdef CONFIG_SND_DEBUG
1567 CXT5047_TEST,
1568 #endif
1569 CXT5047_MODELS
1572 static const char *cxt5047_models[CXT5047_MODELS] = {
1573 [CXT5047_LAPTOP] = "laptop",
1574 [CXT5047_LAPTOP_HP] = "laptop-hp",
1575 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1576 #ifdef CONFIG_SND_DEBUG
1577 [CXT5047_TEST] = "test",
1578 #endif
1581 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1582 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1583 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1584 CXT5047_LAPTOP),
1585 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1589 static int patch_cxt5047(struct hda_codec *codec)
1591 struct conexant_spec *spec;
1592 int board_config;
1594 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1595 if (!spec)
1596 return -ENOMEM;
1597 codec->spec = spec;
1598 codec->pin_amp_workaround = 1;
1600 spec->multiout.max_channels = 2;
1601 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1602 spec->multiout.dac_nids = cxt5047_dac_nids;
1603 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1604 spec->num_adc_nids = 1;
1605 spec->adc_nids = cxt5047_adc_nids;
1606 spec->capsrc_nids = cxt5047_capsrc_nids;
1607 spec->num_mixers = 1;
1608 spec->mixers[0] = cxt5047_base_mixers;
1609 spec->num_init_verbs = 1;
1610 spec->init_verbs[0] = cxt5047_init_verbs;
1611 spec->spdif_route = 0;
1612 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1613 spec->channel_mode = cxt5047_modes,
1615 codec->patch_ops = conexant_patch_ops;
1617 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1618 cxt5047_models,
1619 cxt5047_cfg_tbl);
1620 switch (board_config) {
1621 case CXT5047_LAPTOP:
1622 spec->num_mixers = 2;
1623 spec->mixers[1] = cxt5047_hp_spk_mixers;
1624 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1625 break;
1626 case CXT5047_LAPTOP_HP:
1627 spec->num_mixers = 2;
1628 spec->mixers[1] = cxt5047_hp_only_mixers;
1629 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1630 codec->patch_ops.init = cxt5047_hp_init;
1631 break;
1632 case CXT5047_LAPTOP_EAPD:
1633 spec->input_mux = &cxt5047_toshiba_capture_source;
1634 spec->num_mixers = 2;
1635 spec->mixers[1] = cxt5047_hp_spk_mixers;
1636 spec->num_init_verbs = 2;
1637 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1638 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1639 break;
1640 #ifdef CONFIG_SND_DEBUG
1641 case CXT5047_TEST:
1642 spec->input_mux = &cxt5047_test_capture_source;
1643 spec->mixers[0] = cxt5047_test_mixer;
1644 spec->init_verbs[0] = cxt5047_test_init_verbs;
1645 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1646 #endif
1648 spec->vmaster_nid = 0x13;
1650 switch (codec->subsystem_id >> 16) {
1651 case 0x103c:
1652 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1653 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1654 * with 0 dB offset 0x17)
1656 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1657 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1658 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1659 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1660 (1 << AC_AMPCAP_MUTE_SHIFT));
1661 break;
1664 return 0;
1667 /* Conexant 5051 specific */
1668 static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1669 static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1671 static struct hda_channel_mode cxt5051_modes[1] = {
1672 { 2, NULL },
1675 static void cxt5051_update_speaker(struct hda_codec *codec)
1677 struct conexant_spec *spec = codec->spec;
1678 unsigned int pinctl;
1679 /* headphone pin */
1680 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1681 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1682 pinctl);
1683 /* speaker pin */
1684 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1685 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1686 pinctl);
1687 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1688 if (spec->ideapad)
1689 snd_hda_codec_write(codec, 0x1b, 0,
1690 AC_VERB_SET_PIN_WIDGET_CONTROL,
1691 pinctl);
1694 /* turn on/off EAPD (+ mute HP) as a master switch */
1695 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1696 struct snd_ctl_elem_value *ucontrol)
1698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1700 if (!cxt_eapd_put(kcontrol, ucontrol))
1701 return 0;
1702 cxt5051_update_speaker(codec);
1703 return 1;
1706 /* toggle input of built-in and mic jack appropriately */
1707 static void cxt5051_portb_automic(struct hda_codec *codec)
1709 struct conexant_spec *spec = codec->spec;
1710 unsigned int present;
1712 if (!(spec->auto_mic & AUTO_MIC_PORTB))
1713 return;
1714 present = snd_hda_jack_detect(codec, 0x17);
1715 snd_hda_codec_write(codec, 0x14, 0,
1716 AC_VERB_SET_CONNECT_SEL,
1717 present ? 0x01 : 0x00);
1720 /* switch the current ADC according to the jack state */
1721 static void cxt5051_portc_automic(struct hda_codec *codec)
1723 struct conexant_spec *spec = codec->spec;
1724 unsigned int present;
1725 hda_nid_t new_adc;
1727 if (!(spec->auto_mic & AUTO_MIC_PORTC))
1728 return;
1729 present = snd_hda_jack_detect(codec, 0x18);
1730 if (present)
1731 spec->cur_adc_idx = 1;
1732 else
1733 spec->cur_adc_idx = 0;
1734 new_adc = spec->adc_nids[spec->cur_adc_idx];
1735 if (spec->cur_adc && spec->cur_adc != new_adc) {
1736 /* stream is running, let's swap the current ADC */
1737 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1738 spec->cur_adc = new_adc;
1739 snd_hda_codec_setup_stream(codec, new_adc,
1740 spec->cur_adc_stream_tag, 0,
1741 spec->cur_adc_format);
1745 /* mute internal speaker if HP is plugged */
1746 static void cxt5051_hp_automute(struct hda_codec *codec)
1748 struct conexant_spec *spec = codec->spec;
1750 spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1751 cxt5051_update_speaker(codec);
1754 /* unsolicited event for HP jack sensing */
1755 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1756 unsigned int res)
1758 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1759 switch (res >> 26) {
1760 case CONEXANT_HP_EVENT:
1761 cxt5051_hp_automute(codec);
1762 break;
1763 case CXT5051_PORTB_EVENT:
1764 cxt5051_portb_automic(codec);
1765 break;
1766 case CXT5051_PORTC_EVENT:
1767 cxt5051_portc_automic(codec);
1768 break;
1770 conexant_report_jack(codec, nid);
1773 static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1774 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1776 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1777 .name = "Master Playback Switch",
1778 .info = cxt_eapd_info,
1779 .get = cxt_eapd_get,
1780 .put = cxt5051_hp_master_sw_put,
1781 .private_value = 0x1a,
1786 static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
1787 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1788 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1789 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1790 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1791 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1792 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1796 static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1797 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1798 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1799 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1800 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1804 static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1805 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
1806 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
1810 static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
1811 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
1812 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1816 static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1817 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1818 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1819 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1820 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1824 static struct hda_verb cxt5051_init_verbs[] = {
1825 /* Line in, Mic */
1826 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1827 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1828 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1829 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1830 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1831 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1832 /* SPK */
1833 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1834 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1835 /* HP, Amp */
1836 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1837 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1838 /* DAC1 */
1839 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1840 /* Record selector: Int mic */
1841 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1842 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1843 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1844 /* SPDIF route: PCM */
1845 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1846 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1847 /* EAPD */
1848 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1849 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1850 { } /* end */
1853 static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1854 /* Line in, Mic */
1855 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1856 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1857 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1858 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1859 /* SPK */
1860 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1861 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1862 /* HP, Amp */
1863 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1864 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1865 /* DAC1 */
1866 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1867 /* Record selector: Int mic */
1868 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1869 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1870 /* SPDIF route: PCM */
1871 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1872 /* EAPD */
1873 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1874 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1875 { } /* end */
1878 static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1879 /* Line in, Mic */
1880 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1881 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1882 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1883 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1884 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1885 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1886 /* SPK */
1887 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1888 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1889 /* HP, Amp */
1890 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1891 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1892 /* Docking HP */
1893 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1894 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1895 /* DAC1 */
1896 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1897 /* Record selector: Int mic */
1898 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1899 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1900 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1901 /* SPDIF route: PCM */
1902 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
1903 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1904 /* EAPD */
1905 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1906 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1907 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1908 { } /* end */
1911 static struct hda_verb cxt5051_f700_init_verbs[] = {
1912 /* Line in, Mic */
1913 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1914 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1915 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1916 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1917 /* SPK */
1918 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1919 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1920 /* HP, Amp */
1921 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1922 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1923 /* DAC1 */
1924 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1925 /* Record selector: Int mic */
1926 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1927 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1928 /* SPDIF route: PCM */
1929 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1930 /* EAPD */
1931 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1932 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1933 { } /* end */
1936 static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1937 unsigned int event)
1939 snd_hda_codec_write(codec, nid, 0,
1940 AC_VERB_SET_UNSOLICITED_ENABLE,
1941 AC_USRSP_EN | event);
1942 #ifdef CONFIG_SND_HDA_INPUT_JACK
1943 conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
1944 conexant_report_jack(codec, nid);
1945 #endif
1948 static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1949 /* Subwoofer */
1950 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1951 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1952 { } /* end */
1955 /* initialize jack-sensing, too */
1956 static int cxt5051_init(struct hda_codec *codec)
1958 struct conexant_spec *spec = codec->spec;
1960 conexant_init(codec);
1961 conexant_init_jacks(codec);
1963 if (spec->auto_mic & AUTO_MIC_PORTB)
1964 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
1965 if (spec->auto_mic & AUTO_MIC_PORTC)
1966 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
1968 if (codec->patch_ops.unsol_event) {
1969 cxt5051_hp_automute(codec);
1970 cxt5051_portb_automic(codec);
1971 cxt5051_portc_automic(codec);
1973 return 0;
1977 enum {
1978 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1979 CXT5051_HP, /* no docking */
1980 CXT5051_HP_DV6736, /* HP without mic switch */
1981 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1982 CXT5051_F700, /* HP Compaq Presario F700 */
1983 CXT5051_TOSHIBA, /* Toshiba M300 & co */
1984 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
1985 CXT5051_MODELS
1988 static const char *cxt5051_models[CXT5051_MODELS] = {
1989 [CXT5051_LAPTOP] = "laptop",
1990 [CXT5051_HP] = "hp",
1991 [CXT5051_HP_DV6736] = "hp-dv6736",
1992 [CXT5051_LENOVO_X200] = "lenovo-x200",
1993 [CXT5051_F700] = "hp-700",
1994 [CXT5051_TOSHIBA] = "toshiba",
1995 [CXT5051_IDEAPAD] = "ideapad",
1998 static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1999 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
2000 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
2001 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
2002 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
2003 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2004 CXT5051_LAPTOP),
2005 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
2006 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
2007 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
2011 static int patch_cxt5051(struct hda_codec *codec)
2013 struct conexant_spec *spec;
2014 int board_config;
2016 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2017 if (!spec)
2018 return -ENOMEM;
2019 codec->spec = spec;
2020 codec->pin_amp_workaround = 1;
2022 codec->patch_ops = conexant_patch_ops;
2023 codec->patch_ops.init = cxt5051_init;
2025 spec->multiout.max_channels = 2;
2026 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2027 spec->multiout.dac_nids = cxt5051_dac_nids;
2028 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2029 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2030 spec->adc_nids = cxt5051_adc_nids;
2031 spec->num_mixers = 2;
2032 spec->mixers[0] = cxt5051_capture_mixers;
2033 spec->mixers[1] = cxt5051_playback_mixers;
2034 spec->num_init_verbs = 1;
2035 spec->init_verbs[0] = cxt5051_init_verbs;
2036 spec->spdif_route = 0;
2037 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2038 spec->channel_mode = cxt5051_modes;
2039 spec->cur_adc = 0;
2040 spec->cur_adc_idx = 0;
2042 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
2044 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
2046 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
2047 cxt5051_models,
2048 cxt5051_cfg_tbl);
2049 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
2050 switch (board_config) {
2051 case CXT5051_HP:
2052 spec->mixers[0] = cxt5051_hp_mixers;
2053 break;
2054 case CXT5051_HP_DV6736:
2055 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
2056 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2057 spec->auto_mic = 0;
2058 break;
2059 case CXT5051_LENOVO_X200:
2060 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
2061 /* Thinkpad X301 does not have S/PDIF wired and no ability
2062 to use a docking station. */
2063 if (codec->subsystem_id == 0x17aa211f)
2064 spec->multiout.dig_out_nid = 0;
2065 break;
2066 case CXT5051_F700:
2067 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2068 spec->mixers[0] = cxt5051_f700_mixers;
2069 spec->auto_mic = 0;
2070 break;
2071 case CXT5051_TOSHIBA:
2072 spec->mixers[0] = cxt5051_toshiba_mixers;
2073 spec->auto_mic = AUTO_MIC_PORTB;
2074 break;
2075 case CXT5051_IDEAPAD:
2076 spec->init_verbs[spec->num_init_verbs++] =
2077 cxt5051_ideapad_init_verbs;
2078 spec->ideapad = 1;
2079 break;
2082 if (spec->beep_amp)
2083 snd_hda_attach_beep_device(codec, spec->beep_amp);
2085 return 0;
2088 /* Conexant 5066 specific */
2090 static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
2091 static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
2092 static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2093 #define CXT5066_SPDIF_OUT 0x21
2095 /* OLPC's microphone port is DC coupled for use with external sensors,
2096 * therefore we use a 50% mic bias in order to center the input signal with
2097 * the DC input range of the codec. */
2098 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2100 static struct hda_channel_mode cxt5066_modes[1] = {
2101 { 2, NULL },
2104 static void cxt5066_update_speaker(struct hda_codec *codec)
2106 struct conexant_spec *spec = codec->spec;
2107 unsigned int pinctl;
2109 snd_printdd("CXT5066: update speaker, hp_present=%d\n",
2110 spec->hp_present);
2112 /* Port A (HP) */
2113 pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
2114 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2115 pinctl);
2117 /* Port D (HP/LO) */
2118 pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
2119 ? spec->port_d_mode : 0;
2120 /* Mute if Port A is connected on Thinkpad */
2121 if (spec->thinkpad && (spec->hp_present & 1))
2122 pinctl = 0;
2123 snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2124 pinctl);
2126 /* CLASS_D AMP */
2127 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
2128 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2129 pinctl);
2131 if (spec->dell_automute) {
2132 /* DELL AIO Port Rule: PortA > PortD > IntSpk */
2133 pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
2134 ? PIN_OUT : 0;
2135 snd_hda_codec_write(codec, 0x1c, 0,
2136 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
2140 /* turn on/off EAPD (+ mute HP) as a master switch */
2141 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
2142 struct snd_ctl_elem_value *ucontrol)
2144 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2146 if (!cxt_eapd_put(kcontrol, ucontrol))
2147 return 0;
2149 cxt5066_update_speaker(codec);
2150 return 1;
2153 static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2154 .num_items = 3,
2155 .items = {
2156 { "Off", PIN_IN },
2157 { "50%", PIN_VREF50 },
2158 { "80%", PIN_VREF80 },
2162 static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2164 struct conexant_spec *spec = codec->spec;
2165 /* Even though port F is the DC input, the bias is controlled on port B.
2166 * we also leave that port as an active input (but unselected) in DC mode
2167 * just in case that is necessary to make the bias setting take effect. */
2168 return snd_hda_codec_write_cache(codec, 0x1a, 0,
2169 AC_VERB_SET_PIN_WIDGET_CONTROL,
2170 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2173 /* OLPC defers mic widget control until when capture is started because the
2174 * microphone LED comes on as soon as these settings are put in place. if we
2175 * did this before recording, it would give the false indication that recording
2176 * is happening when it is not. */
2177 static void cxt5066_olpc_select_mic(struct hda_codec *codec)
2179 struct conexant_spec *spec = codec->spec;
2180 if (!spec->recording)
2181 return;
2183 if (spec->dc_enable) {
2184 /* in DC mode we ignore presence detection and just use the jack
2185 * through our special DC port */
2186 const struct hda_verb enable_dc_mode[] = {
2187 /* disble internal mic, port C */
2188 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2190 /* enable DC capture, port F */
2191 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2195 snd_hda_sequence_write(codec, enable_dc_mode);
2196 /* port B input disabled (and bias set) through the following call */
2197 cxt5066_set_olpc_dc_bias(codec);
2198 return;
2201 /* disable DC (port F) */
2202 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2204 /* external mic, port B */
2205 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2206 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
2208 /* internal mic, port C */
2209 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2210 spec->ext_mic_present ? 0 : PIN_VREF80);
2213 /* toggle input of built-in and mic jack appropriately */
2214 static void cxt5066_olpc_automic(struct hda_codec *codec)
2216 struct conexant_spec *spec = codec->spec;
2217 unsigned int present;
2219 if (spec->dc_enable) /* don't do presence detection in DC mode */
2220 return;
2222 present = snd_hda_codec_read(codec, 0x1a, 0,
2223 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2224 if (present)
2225 snd_printdd("CXT5066: external microphone detected\n");
2226 else
2227 snd_printdd("CXT5066: external microphone absent\n");
2229 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2230 present ? 0 : 1);
2231 spec->ext_mic_present = !!present;
2233 cxt5066_olpc_select_mic(codec);
2236 /* toggle input of built-in digital mic and mic jack appropriately */
2237 static void cxt5066_vostro_automic(struct hda_codec *codec)
2239 unsigned int present;
2241 struct hda_verb ext_mic_present[] = {
2242 /* enable external mic, port B */
2243 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2245 /* switch to external mic input */
2246 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2247 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2249 /* disable internal digital mic */
2250 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2253 static struct hda_verb ext_mic_absent[] = {
2254 /* enable internal mic, port C */
2255 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2257 /* switch to internal mic input */
2258 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2260 /* disable external mic, port B */
2261 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2265 present = snd_hda_jack_detect(codec, 0x1a);
2266 if (present) {
2267 snd_printdd("CXT5066: external microphone detected\n");
2268 snd_hda_sequence_write(codec, ext_mic_present);
2269 } else {
2270 snd_printdd("CXT5066: external microphone absent\n");
2271 snd_hda_sequence_write(codec, ext_mic_absent);
2275 /* toggle input of built-in digital mic and mic jack appropriately */
2276 static void cxt5066_ideapad_automic(struct hda_codec *codec)
2278 unsigned int present;
2280 struct hda_verb ext_mic_present[] = {
2281 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2282 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2283 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2286 static struct hda_verb ext_mic_absent[] = {
2287 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2288 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2289 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2293 present = snd_hda_jack_detect(codec, 0x1b);
2294 if (present) {
2295 snd_printdd("CXT5066: external microphone detected\n");
2296 snd_hda_sequence_write(codec, ext_mic_present);
2297 } else {
2298 snd_printdd("CXT5066: external microphone absent\n");
2299 snd_hda_sequence_write(codec, ext_mic_absent);
2303 /* toggle input of built-in digital mic and mic jack appropriately */
2304 static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2306 unsigned int present;
2308 present = snd_hda_jack_detect(codec, 0x1b);
2309 snd_printdd("CXT5066: external microphone present=%d\n", present);
2310 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2311 present ? 1 : 3);
2315 /* toggle input of built-in digital mic and mic jack appropriately
2316 order is: external mic -> dock mic -> interal mic */
2317 static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2319 unsigned int ext_present, dock_present;
2321 static struct hda_verb ext_mic_present[] = {
2322 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2323 {0x17, AC_VERB_SET_CONNECT_SEL, 1},
2324 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2325 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2326 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2329 static struct hda_verb dock_mic_present[] = {
2330 {0x14, AC_VERB_SET_CONNECT_SEL, 0},
2331 {0x17, AC_VERB_SET_CONNECT_SEL, 0},
2332 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2333 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2334 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2337 static struct hda_verb ext_mic_absent[] = {
2338 {0x14, AC_VERB_SET_CONNECT_SEL, 2},
2339 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2340 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2341 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2345 ext_present = snd_hda_jack_detect(codec, 0x1b);
2346 dock_present = snd_hda_jack_detect(codec, 0x1a);
2347 if (ext_present) {
2348 snd_printdd("CXT5066: external microphone detected\n");
2349 snd_hda_sequence_write(codec, ext_mic_present);
2350 } else if (dock_present) {
2351 snd_printdd("CXT5066: dock microphone detected\n");
2352 snd_hda_sequence_write(codec, dock_mic_present);
2353 } else {
2354 snd_printdd("CXT5066: external microphone absent\n");
2355 snd_hda_sequence_write(codec, ext_mic_absent);
2359 /* mute internal speaker if HP is plugged */
2360 static void cxt5066_hp_automute(struct hda_codec *codec)
2362 struct conexant_spec *spec = codec->spec;
2363 unsigned int portA, portD;
2365 /* Port A */
2366 portA = snd_hda_jack_detect(codec, 0x19);
2368 /* Port D */
2369 portD = snd_hda_jack_detect(codec, 0x1c);
2371 spec->hp_present = !!(portA);
2372 spec->hp_present |= portD ? 2 : 0;
2373 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2374 portA, portD, spec->hp_present);
2375 cxt5066_update_speaker(codec);
2378 /* unsolicited event for jack sensing */
2379 static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
2381 struct conexant_spec *spec = codec->spec;
2382 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2383 switch (res >> 26) {
2384 case CONEXANT_HP_EVENT:
2385 cxt5066_hp_automute(codec);
2386 break;
2387 case CONEXANT_MIC_EVENT:
2388 /* ignore mic events in DC mode; we're always using the jack */
2389 if (!spec->dc_enable)
2390 cxt5066_olpc_automic(codec);
2391 break;
2395 /* unsolicited event for jack sensing */
2396 static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
2398 snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
2399 switch (res >> 26) {
2400 case CONEXANT_HP_EVENT:
2401 cxt5066_hp_automute(codec);
2402 break;
2403 case CONEXANT_MIC_EVENT:
2404 cxt5066_vostro_automic(codec);
2405 break;
2409 /* unsolicited event for jack sensing */
2410 static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
2412 snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
2413 switch (res >> 26) {
2414 case CONEXANT_HP_EVENT:
2415 cxt5066_hp_automute(codec);
2416 break;
2417 case CONEXANT_MIC_EVENT:
2418 cxt5066_ideapad_automic(codec);
2419 break;
2423 /* unsolicited event for jack sensing */
2424 static void cxt5066_hp_laptop_event(struct hda_codec *codec, unsigned int res)
2426 snd_printdd("CXT5066_hp_laptop: unsol event %x (%x)\n", res, res >> 26);
2427 switch (res >> 26) {
2428 case CONEXANT_HP_EVENT:
2429 cxt5066_hp_automute(codec);
2430 break;
2431 case CONEXANT_MIC_EVENT:
2432 cxt5066_hp_laptop_automic(codec);
2433 break;
2437 /* unsolicited event for jack sensing */
2438 static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res)
2440 snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26);
2441 switch (res >> 26) {
2442 case CONEXANT_HP_EVENT:
2443 cxt5066_hp_automute(codec);
2444 break;
2445 case CONEXANT_MIC_EVENT:
2446 cxt5066_thinkpad_automic(codec);
2447 break;
2451 static const struct hda_input_mux cxt5066_analog_mic_boost = {
2452 .num_items = 5,
2453 .items = {
2454 { "0dB", 0 },
2455 { "10dB", 1 },
2456 { "20dB", 2 },
2457 { "30dB", 3 },
2458 { "40dB", 4 },
2462 static void cxt5066_set_mic_boost(struct hda_codec *codec)
2464 struct conexant_spec *spec = codec->spec;
2465 snd_hda_codec_write_cache(codec, 0x17, 0,
2466 AC_VERB_SET_AMP_GAIN_MUTE,
2467 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2468 cxt5066_analog_mic_boost.items[spec->mic_boost].index);
2469 if (spec->ideapad || spec->thinkpad) {
2470 /* adjust the internal mic as well...it is not through 0x17 */
2471 snd_hda_codec_write_cache(codec, 0x23, 0,
2472 AC_VERB_SET_AMP_GAIN_MUTE,
2473 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2474 cxt5066_analog_mic_boost.
2475 items[spec->mic_boost].index);
2479 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
2480 struct snd_ctl_elem_info *uinfo)
2482 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
2485 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
2486 struct snd_ctl_elem_value *ucontrol)
2488 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2489 struct conexant_spec *spec = codec->spec;
2490 ucontrol->value.enumerated.item[0] = spec->mic_boost;
2491 return 0;
2494 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2495 struct snd_ctl_elem_value *ucontrol)
2497 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2498 struct conexant_spec *spec = codec->spec;
2499 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2500 unsigned int idx;
2501 idx = ucontrol->value.enumerated.item[0];
2502 if (idx >= imux->num_items)
2503 idx = imux->num_items - 1;
2505 spec->mic_boost = idx;
2506 if (!spec->dc_enable)
2507 cxt5066_set_mic_boost(codec);
2508 return 1;
2511 static void cxt5066_enable_dc(struct hda_codec *codec)
2513 const struct hda_verb enable_dc_mode[] = {
2514 /* disable gain */
2515 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2517 /* switch to DC input */
2518 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2522 /* configure as input source */
2523 snd_hda_sequence_write(codec, enable_dc_mode);
2524 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2527 static void cxt5066_disable_dc(struct hda_codec *codec)
2529 /* reconfigure input source */
2530 cxt5066_set_mic_boost(codec);
2531 /* automic also selects the right mic if we're recording */
2532 cxt5066_olpc_automic(codec);
2535 static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2536 struct snd_ctl_elem_value *ucontrol)
2538 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2539 struct conexant_spec *spec = codec->spec;
2540 ucontrol->value.integer.value[0] = spec->dc_enable;
2541 return 0;
2544 static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2545 struct snd_ctl_elem_value *ucontrol)
2547 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2548 struct conexant_spec *spec = codec->spec;
2549 int dc_enable = !!ucontrol->value.integer.value[0];
2551 if (dc_enable == spec->dc_enable)
2552 return 0;
2554 spec->dc_enable = dc_enable;
2555 if (dc_enable)
2556 cxt5066_enable_dc(codec);
2557 else
2558 cxt5066_disable_dc(codec);
2560 return 1;
2563 static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2564 struct snd_ctl_elem_info *uinfo)
2566 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2569 static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2570 struct snd_ctl_elem_value *ucontrol)
2572 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2573 struct conexant_spec *spec = codec->spec;
2574 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2575 return 0;
2578 static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2579 struct snd_ctl_elem_value *ucontrol)
2581 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2582 struct conexant_spec *spec = codec->spec;
2583 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2584 unsigned int idx;
2586 idx = ucontrol->value.enumerated.item[0];
2587 if (idx >= imux->num_items)
2588 idx = imux->num_items - 1;
2590 spec->dc_input_bias = idx;
2591 if (spec->dc_enable)
2592 cxt5066_set_olpc_dc_bias(codec);
2593 return 1;
2596 static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2598 struct conexant_spec *spec = codec->spec;
2599 /* mark as recording and configure the microphone widget so that the
2600 * recording LED comes on. */
2601 spec->recording = 1;
2602 cxt5066_olpc_select_mic(codec);
2605 static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2607 struct conexant_spec *spec = codec->spec;
2608 const struct hda_verb disable_mics[] = {
2609 /* disable external mic, port B */
2610 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2612 /* disble internal mic, port C */
2613 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2615 /* disable DC capture, port F */
2616 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2620 snd_hda_sequence_write(codec, disable_mics);
2621 spec->recording = 0;
2624 static struct hda_input_mux cxt5066_capture_source = {
2625 .num_items = 4,
2626 .items = {
2627 { "Mic B", 0 },
2628 { "Mic C", 1 },
2629 { "Mic E", 2 },
2630 { "Mic F", 3 },
2634 static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
2635 .ops = &snd_hda_bind_vol,
2636 .values = {
2637 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2638 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2643 static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
2644 .ops = &snd_hda_bind_sw,
2645 .values = {
2646 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
2647 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
2652 static struct snd_kcontrol_new cxt5066_mixer_master[] = {
2653 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
2657 static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2659 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2660 .name = "Master Playback Volume",
2661 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2662 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2663 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2664 .subdevice = HDA_SUBDEV_AMP_FLAG,
2665 .info = snd_hda_mixer_amp_volume_info,
2666 .get = snd_hda_mixer_amp_volume_get,
2667 .put = snd_hda_mixer_amp_volume_put,
2668 .tlv = { .c = snd_hda_mixer_amp_tlv },
2669 /* offset by 28 volume steps to limit minimum gain to -46dB */
2670 .private_value =
2671 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2676 static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2678 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2679 .name = "DC Mode Enable Switch",
2680 .info = snd_ctl_boolean_mono_info,
2681 .get = cxt5066_olpc_dc_get,
2682 .put = cxt5066_olpc_dc_put,
2685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2686 .name = "DC Input Bias Enum",
2687 .info = cxt5066_olpc_dc_bias_enum_info,
2688 .get = cxt5066_olpc_dc_bias_enum_get,
2689 .put = cxt5066_olpc_dc_bias_enum_put,
2694 static struct snd_kcontrol_new cxt5066_mixers[] = {
2696 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2697 .name = "Master Playback Switch",
2698 .info = cxt_eapd_info,
2699 .get = cxt_eapd_get,
2700 .put = cxt5066_hp_master_sw_put,
2701 .private_value = 0x1d,
2705 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2706 .name = "Analog Mic Boost Capture Enum",
2707 .info = cxt5066_mic_boost_mux_enum_info,
2708 .get = cxt5066_mic_boost_mux_enum_get,
2709 .put = cxt5066_mic_boost_mux_enum_put,
2712 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
2713 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
2717 static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2720 .name = "Int Mic Boost Capture Enum",
2721 .info = cxt5066_mic_boost_mux_enum_info,
2722 .get = cxt5066_mic_boost_mux_enum_get,
2723 .put = cxt5066_mic_boost_mux_enum_put,
2724 .private_value = 0x23 | 0x100,
2729 static struct hda_verb cxt5066_init_verbs[] = {
2730 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2731 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2732 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2733 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2735 /* Speakers */
2736 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2737 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2739 /* HP, Amp */
2740 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2741 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2743 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2744 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2746 /* DAC1 */
2747 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2749 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2750 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2751 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2752 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2753 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2754 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2756 /* no digital microphone support yet */
2757 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2759 /* Audio input selector */
2760 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2762 /* SPDIF route: PCM */
2763 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2764 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2766 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2767 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2769 /* EAPD */
2770 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2772 /* not handling these yet */
2773 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2774 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2775 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2776 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2777 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2778 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2779 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2780 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
2781 { } /* end */
2784 static struct hda_verb cxt5066_init_verbs_olpc[] = {
2785 /* Port A: headphones */
2786 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2787 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2789 /* Port B: external microphone */
2790 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2792 /* Port C: internal microphone */
2793 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2795 /* Port D: unused */
2796 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2798 /* Port E: unused, but has primary EAPD */
2799 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2800 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2802 /* Port F: external DC input through microphone port */
2803 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2805 /* Port G: internal speakers */
2806 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2807 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2809 /* DAC1 */
2810 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2812 /* DAC2: unused */
2813 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2815 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2816 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2817 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2818 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2819 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2820 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2821 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2822 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2823 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2824 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2825 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2826 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2828 /* Disable digital microphone port */
2829 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2831 /* Audio input selectors */
2832 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2833 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2835 /* Disable SPDIF */
2836 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2837 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2839 /* enable unsolicited events for Port A and B */
2840 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2841 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2842 { } /* end */
2845 static struct hda_verb cxt5066_init_verbs_vostro[] = {
2846 /* Port A: headphones */
2847 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2848 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2850 /* Port B: external microphone */
2851 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2853 /* Port C: unused */
2854 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2856 /* Port D: unused */
2857 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2859 /* Port E: unused, but has primary EAPD */
2860 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2861 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2863 /* Port F: unused */
2864 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2866 /* Port G: internal speakers */
2867 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2868 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2870 /* DAC1 */
2871 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2873 /* DAC2: unused */
2874 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2876 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2877 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2878 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2879 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2880 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2881 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2882 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2883 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2884 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2885 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2886 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2887 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2889 /* Digital microphone port */
2890 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2892 /* Audio input selectors */
2893 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2894 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2896 /* Disable SPDIF */
2897 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2898 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2900 /* enable unsolicited events for Port A and B */
2901 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2902 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2903 { } /* end */
2906 static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2907 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2908 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2909 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2910 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2912 /* Speakers */
2913 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2914 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2916 /* HP, Amp */
2917 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2918 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2920 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2921 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2923 /* DAC1 */
2924 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2926 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2927 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2928 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2929 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2930 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2931 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2932 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2934 /* Audio input selector */
2935 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2936 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2938 /* SPDIF route: PCM */
2939 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2940 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2942 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2943 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2945 /* internal microphone */
2946 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2948 /* EAPD */
2949 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2951 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2952 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2953 { } /* end */
2956 static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
2957 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2958 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2960 /* Port G: internal speakers */
2961 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2962 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2964 /* Port A: HP, Amp */
2965 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2966 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2968 /* Port B: Mic Dock */
2969 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2971 /* Port C: Mic */
2972 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2974 /* Port D: HP Dock, Amp */
2975 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2976 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2978 /* DAC1 */
2979 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2981 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2982 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2983 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2984 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2985 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2986 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2987 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
2989 /* Audio input selector */
2990 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2991 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
2993 /* SPDIF route: PCM */
2994 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2995 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2997 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2998 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3000 /* internal microphone */
3001 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
3003 /* EAPD */
3004 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
3006 /* enable unsolicited events for Port A, B, C and D */
3007 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3008 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3009 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3010 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3011 { } /* end */
3014 static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
3015 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3016 { } /* end */
3020 static struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
3021 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3022 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3023 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3024 { } /* end */
3027 /* initialize jack-sensing, too */
3028 static int cxt5066_init(struct hda_codec *codec)
3030 struct conexant_spec *spec = codec->spec;
3032 snd_printdd("CXT5066: init\n");
3033 conexant_init(codec);
3034 if (codec->patch_ops.unsol_event) {
3035 cxt5066_hp_automute(codec);
3036 if (spec->dell_vostro)
3037 cxt5066_vostro_automic(codec);
3038 else if (spec->ideapad)
3039 cxt5066_ideapad_automic(codec);
3040 else if (spec->thinkpad)
3041 cxt5066_thinkpad_automic(codec);
3042 else if (spec->hp_laptop)
3043 cxt5066_hp_laptop_automic(codec);
3045 cxt5066_set_mic_boost(codec);
3046 return 0;
3049 static int cxt5066_olpc_init(struct hda_codec *codec)
3051 struct conexant_spec *spec = codec->spec;
3052 snd_printdd("CXT5066: init\n");
3053 conexant_init(codec);
3054 cxt5066_hp_automute(codec);
3055 if (!spec->dc_enable) {
3056 cxt5066_set_mic_boost(codec);
3057 cxt5066_olpc_automic(codec);
3058 } else {
3059 cxt5066_enable_dc(codec);
3061 return 0;
3064 enum {
3065 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
3066 CXT5066_DELL_LAPTOP, /* Dell Laptop */
3067 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
3068 CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
3069 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
3070 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
3071 CXT5066_HP_LAPTOP, /* HP Laptop */
3072 CXT5066_MODELS
3075 static const char *cxt5066_models[CXT5066_MODELS] = {
3076 [CXT5066_LAPTOP] = "laptop",
3077 [CXT5066_DELL_LAPTOP] = "dell-laptop",
3078 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
3079 [CXT5066_DELL_VOSTO] = "dell-vostro",
3080 [CXT5066_IDEAPAD] = "ideapad",
3081 [CXT5066_THINKPAD] = "thinkpad",
3082 [CXT5066_HP_LAPTOP] = "hp-laptop",
3085 static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3086 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3087 CXT5066_LAPTOP),
3088 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
3089 CXT5066_DELL_LAPTOP),
3090 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
3091 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTO),
3092 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
3093 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3094 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3095 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
3096 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
3097 SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD),
3098 SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD),
3099 SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD),
3100 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3101 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G series", CXT5066_IDEAPAD),
3102 SND_PCI_QUIRK(0x17aa, 0x390a, "Lenovo S10-3t", CXT5066_IDEAPAD),
3103 SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G series (AMD)", CXT5066_IDEAPAD),
3104 SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
3108 static int patch_cxt5066(struct hda_codec *codec)
3110 struct conexant_spec *spec;
3111 int board_config;
3113 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3114 if (!spec)
3115 return -ENOMEM;
3116 codec->spec = spec;
3118 codec->patch_ops = conexant_patch_ops;
3119 codec->patch_ops.init = conexant_init;
3121 spec->dell_automute = 0;
3122 spec->multiout.max_channels = 2;
3123 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
3124 spec->multiout.dac_nids = cxt5066_dac_nids;
3125 spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
3126 spec->num_adc_nids = 1;
3127 spec->adc_nids = cxt5066_adc_nids;
3128 spec->capsrc_nids = cxt5066_capsrc_nids;
3129 spec->input_mux = &cxt5066_capture_source;
3131 spec->port_d_mode = PIN_HP;
3133 spec->num_init_verbs = 1;
3134 spec->init_verbs[0] = cxt5066_init_verbs;
3135 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
3136 spec->channel_mode = cxt5066_modes;
3137 spec->cur_adc = 0;
3138 spec->cur_adc_idx = 0;
3140 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
3142 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3143 cxt5066_models, cxt5066_cfg_tbl);
3144 switch (board_config) {
3145 default:
3146 case CXT5066_LAPTOP:
3147 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3148 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3149 break;
3150 case CXT5066_DELL_LAPTOP:
3151 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3152 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3154 spec->port_d_mode = PIN_OUT;
3155 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
3156 spec->num_init_verbs++;
3157 spec->dell_automute = 1;
3158 break;
3159 case CXT5066_HP_LAPTOP:
3160 codec->patch_ops.init = cxt5066_init;
3161 codec->patch_ops.unsol_event = cxt5066_hp_laptop_event;
3162 spec->init_verbs[spec->num_init_verbs] =
3163 cxt5066_init_verbs_hp_laptop;
3164 spec->num_init_verbs++;
3165 spec->hp_laptop = 1;
3166 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3167 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3168 /* no S/PDIF out */
3169 spec->multiout.dig_out_nid = 0;
3170 /* input source automatically selected */
3171 spec->input_mux = NULL;
3172 spec->port_d_mode = 0;
3173 spec->mic_boost = 3; /* default 30dB gain */
3174 break;
3176 case CXT5066_OLPC_XO_1_5:
3177 codec->patch_ops.init = cxt5066_olpc_init;
3178 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
3179 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3180 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3181 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
3182 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3183 spec->port_d_mode = 0;
3184 spec->mic_boost = 3; /* default 30dB gain */
3186 /* no S/PDIF out */
3187 spec->multiout.dig_out_nid = 0;
3189 /* input source automatically selected */
3190 spec->input_mux = NULL;
3192 /* our capture hooks which allow us to turn on the microphone LED
3193 * at the right time */
3194 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3195 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
3196 break;
3197 case CXT5066_DELL_VOSTO:
3198 codec->patch_ops.init = cxt5066_init;
3199 codec->patch_ops.unsol_event = cxt5066_vostro_event;
3200 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3201 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3202 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3203 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
3204 spec->port_d_mode = 0;
3205 spec->dell_vostro = 1;
3206 spec->mic_boost = 3; /* default 30dB gain */
3208 /* no S/PDIF out */
3209 spec->multiout.dig_out_nid = 0;
3211 /* input source automatically selected */
3212 spec->input_mux = NULL;
3213 break;
3214 case CXT5066_IDEAPAD:
3215 codec->patch_ops.init = cxt5066_init;
3216 codec->patch_ops.unsol_event = cxt5066_ideapad_event;
3217 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3218 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3219 spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3220 spec->port_d_mode = 0;
3221 spec->ideapad = 1;
3222 spec->mic_boost = 2; /* default 20dB gain */
3224 /* no S/PDIF out */
3225 spec->multiout.dig_out_nid = 0;
3227 /* input source automatically selected */
3228 spec->input_mux = NULL;
3229 break;
3230 case CXT5066_THINKPAD:
3231 codec->patch_ops.init = cxt5066_init;
3232 codec->patch_ops.unsol_event = cxt5066_thinkpad_event;
3233 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3234 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3235 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
3236 spec->thinkpad = 1;
3237 spec->port_d_mode = PIN_OUT;
3238 spec->mic_boost = 2; /* default 20dB gain */
3240 /* no S/PDIF out */
3241 spec->multiout.dig_out_nid = 0;
3243 /* input source automatically selected */
3244 spec->input_mux = NULL;
3245 break;
3248 if (spec->beep_amp)
3249 snd_hda_attach_beep_device(codec, spec->beep_amp);
3251 return 0;
3257 static struct hda_codec_preset snd_hda_preset_conexant[] = {
3258 { .id = 0x14f15045, .name = "CX20549 (Venice)",
3259 .patch = patch_cxt5045 },
3260 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
3261 .patch = patch_cxt5047 },
3262 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3263 .patch = patch_cxt5051 },
3264 { .id = 0x14f15066, .name = "CX20582 (Pebble)",
3265 .patch = patch_cxt5066 },
3266 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3267 .patch = patch_cxt5066 },
3268 { .id = 0x14f15068, .name = "CX20584",
3269 .patch = patch_cxt5066 },
3270 { .id = 0x14f15069, .name = "CX20585",
3271 .patch = patch_cxt5066 },
3272 {} /* terminator */
3275 MODULE_ALIAS("snd-hda-codec-id:14f15045");
3276 MODULE_ALIAS("snd-hda-codec-id:14f15047");
3277 MODULE_ALIAS("snd-hda-codec-id:14f15051");
3278 MODULE_ALIAS("snd-hda-codec-id:14f15066");
3279 MODULE_ALIAS("snd-hda-codec-id:14f15067");
3280 MODULE_ALIAS("snd-hda-codec-id:14f15068");
3281 MODULE_ALIAS("snd-hda-codec-id:14f15069");
3283 MODULE_LICENSE("GPL");
3284 MODULE_DESCRIPTION("Conexant HD-audio codec");
3286 static struct hda_codec_preset_list conexant_list = {
3287 .preset = snd_hda_preset_conexant,
3288 .owner = THIS_MODULE,
3291 static int __init patch_conexant_init(void)
3293 return snd_hda_add_codec_preset(&conexant_list);
3296 static void __exit patch_conexant_exit(void)
3298 snd_hda_delete_codec_preset(&conexant_list);
3301 module_init(patch_conexant_init)
3302 module_exit(patch_conexant_exit)