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"
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)
58 struct conexant_spec
{
60 const struct snd_kcontrol_new
*mixers
[5];
62 hda_nid_t vmaster_nid
;
64 const struct hda_verb
*init_verbs
[5]; /* initialization verbs
68 unsigned int num_init_verbs
;
71 struct hda_multi_out multiout
; /* playback set-up
72 * max_channels, dacs must be set
73 * dig_out_nid and hp_nid are optional
75 unsigned int cur_eapd
;
76 unsigned int hp_present
;
77 unsigned int auto_mic
;
78 int auto_mic_ext
; /* imux_pins[] index for ext mic */
79 unsigned int need_dac_fix
;
80 hda_nid_t slave_dig_outs
[2];
83 unsigned int num_adc_nids
;
84 const hda_nid_t
*adc_nids
;
85 hda_nid_t dig_in_nid
; /* digital-in NID; optional */
87 unsigned int cur_adc_idx
;
89 unsigned int cur_adc_stream_tag
;
90 unsigned int cur_adc_format
;
92 const struct hda_pcm_stream
*capture_stream
;
95 const struct hda_input_mux
*input_mux
;
96 const hda_nid_t
*capsrc_nids
;
97 unsigned int cur_mux
[3];
100 const struct hda_channel_mode
*channel_mode
;
101 int num_channel_mode
;
103 /* PCM information */
104 struct hda_pcm pcm_rec
[2]; /* used in build_pcms() */
106 unsigned int spdif_route
;
108 /* dynamic controls, init_verbs and input_mux */
109 struct auto_pin_cfg autocfg
;
110 struct hda_input_mux private_imux
;
111 int imux_cfg_idx
[HDA_MAX_NUM_INPUTS
]; /* corresponding autocfg.input */
112 hda_nid_t imux_adcs
[HDA_MAX_NUM_INPUTS
];
113 hda_nid_t imux_pins
[HDA_MAX_NUM_INPUTS
];
114 hda_nid_t private_adc_nids
[HDA_MAX_NUM_INPUTS
];
115 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
116 struct pin_dac_pair dac_info
[8];
119 unsigned int port_d_mode
;
120 unsigned int auto_mute
:1; /* used in auto-parser */
121 unsigned int dell_automute
:1;
122 unsigned int dell_vostro
:1;
123 unsigned int ideapad
:1;
124 unsigned int thinkpad
:1;
125 unsigned int hp_laptop
:1;
128 unsigned int adc_switching
:1;
130 unsigned int ext_mic_present
;
131 unsigned int recording
;
132 void (*capture_prepare
)(struct hda_codec
*codec
);
133 void (*capture_cleanup
)(struct hda_codec
*codec
);
135 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
136 * through the microphone jack.
137 * When the user enables this through a mixer switch, both internal and
138 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
139 * we also allow the bias to be configured through a separate mixer
141 unsigned int dc_enable
;
142 unsigned int dc_input_bias
; /* offset into cxt5066_olpc_dc_bias */
143 unsigned int mic_boost
; /* offset into cxt5066_analog_mic_boost */
145 unsigned int beep_amp
;
148 static int conexant_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
149 struct hda_codec
*codec
,
150 struct snd_pcm_substream
*substream
)
152 struct conexant_spec
*spec
= codec
->spec
;
153 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
157 static int conexant_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
158 struct hda_codec
*codec
,
159 unsigned int stream_tag
,
161 struct snd_pcm_substream
*substream
)
163 struct conexant_spec
*spec
= codec
->spec
;
164 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
169 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
170 struct hda_codec
*codec
,
171 struct snd_pcm_substream
*substream
)
173 struct conexant_spec
*spec
= codec
->spec
;
174 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
180 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
181 struct hda_codec
*codec
,
182 struct snd_pcm_substream
*substream
)
184 struct conexant_spec
*spec
= codec
->spec
;
185 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
188 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
189 struct hda_codec
*codec
,
190 struct snd_pcm_substream
*substream
)
192 struct conexant_spec
*spec
= codec
->spec
;
193 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
196 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
197 struct hda_codec
*codec
,
198 unsigned int stream_tag
,
200 struct snd_pcm_substream
*substream
)
202 struct conexant_spec
*spec
= codec
->spec
;
203 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
211 static int conexant_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
212 struct hda_codec
*codec
,
213 unsigned int stream_tag
,
215 struct snd_pcm_substream
*substream
)
217 struct conexant_spec
*spec
= codec
->spec
;
218 if (spec
->capture_prepare
)
219 spec
->capture_prepare(codec
);
220 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
221 stream_tag
, 0, format
);
225 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
226 struct hda_codec
*codec
,
227 struct snd_pcm_substream
*substream
)
229 struct conexant_spec
*spec
= codec
->spec
;
230 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
231 if (spec
->capture_cleanup
)
232 spec
->capture_cleanup(codec
);
238 static const struct hda_pcm_stream conexant_pcm_analog_playback
= {
242 .nid
= 0, /* fill later */
244 .open
= conexant_playback_pcm_open
,
245 .prepare
= conexant_playback_pcm_prepare
,
246 .cleanup
= conexant_playback_pcm_cleanup
250 static const struct hda_pcm_stream conexant_pcm_analog_capture
= {
254 .nid
= 0, /* fill later */
256 .prepare
= conexant_capture_pcm_prepare
,
257 .cleanup
= conexant_capture_pcm_cleanup
262 static const struct hda_pcm_stream conexant_pcm_digital_playback
= {
266 .nid
= 0, /* fill later */
268 .open
= conexant_dig_playback_pcm_open
,
269 .close
= conexant_dig_playback_pcm_close
,
270 .prepare
= conexant_dig_playback_pcm_prepare
274 static const struct hda_pcm_stream conexant_pcm_digital_capture
= {
278 /* NID is set in alc_build_pcms */
281 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
282 struct hda_codec
*codec
,
283 unsigned int stream_tag
,
285 struct snd_pcm_substream
*substream
)
287 struct conexant_spec
*spec
= codec
->spec
;
288 spec
->cur_adc
= spec
->adc_nids
[spec
->cur_adc_idx
];
289 spec
->cur_adc_stream_tag
= stream_tag
;
290 spec
->cur_adc_format
= format
;
291 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
295 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
296 struct hda_codec
*codec
,
297 struct snd_pcm_substream
*substream
)
299 struct conexant_spec
*spec
= codec
->spec
;
300 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
305 static const struct hda_pcm_stream cx5051_pcm_analog_capture
= {
309 .nid
= 0, /* fill later */
311 .prepare
= cx5051_capture_pcm_prepare
,
312 .cleanup
= cx5051_capture_pcm_cleanup
316 static int conexant_build_pcms(struct hda_codec
*codec
)
318 struct conexant_spec
*spec
= codec
->spec
;
319 struct hda_pcm
*info
= spec
->pcm_rec
;
322 codec
->pcm_info
= info
;
324 info
->name
= "CONEXANT Analog";
325 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = conexant_pcm_analog_playback
;
326 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
327 spec
->multiout
.max_channels
;
328 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
329 spec
->multiout
.dac_nids
[0];
330 if (spec
->capture_stream
)
331 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *spec
->capture_stream
;
333 if (codec
->vendor_id
== 0x14f15051)
334 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
335 cx5051_pcm_analog_capture
;
337 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
338 conexant_pcm_analog_capture
;
339 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
343 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
345 if (spec
->multiout
.dig_out_nid
) {
348 info
->name
= "Conexant Digital";
349 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
350 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
351 conexant_pcm_digital_playback
;
352 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
353 spec
->multiout
.dig_out_nid
;
354 if (spec
->dig_in_nid
) {
355 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
356 conexant_pcm_digital_capture
;
357 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
360 if (spec
->slave_dig_outs
[0])
361 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
367 static int conexant_mux_enum_info(struct snd_kcontrol
*kcontrol
,
368 struct snd_ctl_elem_info
*uinfo
)
370 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
371 struct conexant_spec
*spec
= codec
->spec
;
373 return snd_hda_input_mux_info(spec
->input_mux
, uinfo
);
376 static int conexant_mux_enum_get(struct snd_kcontrol
*kcontrol
,
377 struct snd_ctl_elem_value
*ucontrol
)
379 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
380 struct conexant_spec
*spec
= codec
->spec
;
381 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
383 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
387 static int conexant_mux_enum_put(struct snd_kcontrol
*kcontrol
,
388 struct snd_ctl_elem_value
*ucontrol
)
390 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
391 struct conexant_spec
*spec
= codec
->spec
;
392 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
394 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
395 spec
->capsrc_nids
[adc_idx
],
396 &spec
->cur_mux
[adc_idx
]);
399 static int conexant_init_jacks(struct hda_codec
*codec
)
401 #ifdef CONFIG_SND_HDA_INPUT_JACK
402 struct conexant_spec
*spec
= codec
->spec
;
405 for (i
= 0; i
< spec
->num_init_verbs
; i
++) {
406 const struct hda_verb
*hv
;
408 hv
= spec
->init_verbs
[i
];
411 switch (hv
->param
^ AC_USRSP_EN
) {
412 case CONEXANT_HP_EVENT
:
413 err
= snd_hda_input_jack_add(codec
, hv
->nid
,
414 SND_JACK_HEADPHONE
, NULL
);
415 snd_hda_input_jack_report(codec
, hv
->nid
);
417 case CXT5051_PORTC_EVENT
:
418 case CONEXANT_MIC_EVENT
:
419 err
= snd_hda_input_jack_add(codec
, hv
->nid
,
420 SND_JACK_MICROPHONE
, NULL
);
421 snd_hda_input_jack_report(codec
, hv
->nid
);
429 #endif /* CONFIG_SND_HDA_INPUT_JACK */
433 static int conexant_init(struct hda_codec
*codec
)
435 struct conexant_spec
*spec
= codec
->spec
;
438 for (i
= 0; i
< spec
->num_init_verbs
; i
++)
439 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
443 static void conexant_free(struct hda_codec
*codec
)
445 snd_hda_input_jack_free(codec
);
446 snd_hda_detach_beep_device(codec
);
450 static const struct snd_kcontrol_new cxt_capture_mixers
[] = {
452 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
453 .name
= "Capture Source",
454 .info
= conexant_mux_enum_info
,
455 .get
= conexant_mux_enum_get
,
456 .put
= conexant_mux_enum_put
461 #ifdef CONFIG_SND_HDA_INPUT_BEEP
462 /* additional beep mixers; the actual parameters are overwritten at build */
463 static const struct snd_kcontrol_new cxt_beep_mixer
[] = {
464 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT
),
465 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT
),
470 static const char * const slave_vols
[] = {
471 "Headphone Playback Volume",
472 "Speaker Playback Volume",
476 static const char * const slave_sws
[] = {
477 "Headphone Playback Switch",
478 "Speaker Playback Switch",
482 static int conexant_build_controls(struct hda_codec
*codec
)
484 struct conexant_spec
*spec
= codec
->spec
;
488 for (i
= 0; i
< spec
->num_mixers
; i
++) {
489 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
493 if (spec
->multiout
.dig_out_nid
) {
494 err
= snd_hda_create_spdif_out_ctls(codec
,
495 spec
->multiout
.dig_out_nid
);
498 err
= snd_hda_create_spdif_share_sw(codec
,
502 spec
->multiout
.share_spdif
= 1;
504 if (spec
->dig_in_nid
) {
505 err
= snd_hda_create_spdif_in_ctls(codec
,spec
->dig_in_nid
);
510 /* if we have no master control, let's create it */
511 if (spec
->vmaster_nid
&&
512 !snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
513 unsigned int vmaster_tlv
[4];
514 snd_hda_set_vmaster_tlv(codec
, spec
->vmaster_nid
,
515 HDA_OUTPUT
, vmaster_tlv
);
516 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
517 vmaster_tlv
, slave_vols
);
521 if (spec
->vmaster_nid
&&
522 !snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
523 err
= snd_hda_add_vmaster(codec
, "Master Playback Switch",
529 if (spec
->input_mux
) {
530 err
= snd_hda_add_new_ctls(codec
, cxt_capture_mixers
);
535 #ifdef CONFIG_SND_HDA_INPUT_BEEP
536 /* create beep controls if needed */
537 if (spec
->beep_amp
) {
538 const struct snd_kcontrol_new
*knew
;
539 for (knew
= cxt_beep_mixer
; knew
->name
; knew
++) {
540 struct snd_kcontrol
*kctl
;
541 kctl
= snd_ctl_new1(knew
, codec
);
544 kctl
->private_value
= spec
->beep_amp
;
545 err
= snd_hda_ctl_add(codec
, 0, kctl
);
555 #ifdef CONFIG_SND_HDA_POWER_SAVE
556 static int conexant_suspend(struct hda_codec
*codec
, pm_message_t state
)
558 snd_hda_shutup_pins(codec
);
563 static const struct hda_codec_ops conexant_patch_ops
= {
564 .build_controls
= conexant_build_controls
,
565 .build_pcms
= conexant_build_pcms
,
566 .init
= conexant_init
,
567 .free
= conexant_free
,
568 #ifdef CONFIG_SND_HDA_POWER_SAVE
569 .suspend
= conexant_suspend
,
571 .reboot_notify
= snd_hda_shutup_pins
,
574 #ifdef CONFIG_SND_HDA_INPUT_BEEP
575 #define set_beep_amp(spec, nid, idx, dir) \
576 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
578 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
581 static int patch_conexant_auto(struct hda_codec
*codec
);
584 * the private value = nid | (invert << 8)
587 #define cxt_eapd_info snd_ctl_boolean_mono_info
589 static int cxt_eapd_get(struct snd_kcontrol
*kcontrol
,
590 struct snd_ctl_elem_value
*ucontrol
)
592 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
593 struct conexant_spec
*spec
= codec
->spec
;
594 int invert
= (kcontrol
->private_value
>> 8) & 1;
596 ucontrol
->value
.integer
.value
[0] = !spec
->cur_eapd
;
598 ucontrol
->value
.integer
.value
[0] = spec
->cur_eapd
;
603 static int cxt_eapd_put(struct snd_kcontrol
*kcontrol
,
604 struct snd_ctl_elem_value
*ucontrol
)
606 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
607 struct conexant_spec
*spec
= codec
->spec
;
608 int invert
= (kcontrol
->private_value
>> 8) & 1;
609 hda_nid_t nid
= kcontrol
->private_value
& 0xff;
612 eapd
= !!ucontrol
->value
.integer
.value
[0];
615 if (eapd
== spec
->cur_eapd
)
618 spec
->cur_eapd
= eapd
;
619 snd_hda_codec_write_cache(codec
, nid
,
620 0, AC_VERB_SET_EAPD_BTLENABLE
,
625 /* controls for test mode */
626 #ifdef CONFIG_SND_DEBUG
628 #define CXT_EAPD_SWITCH(xname, nid, mask) \
629 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
630 .info = cxt_eapd_info, \
631 .get = cxt_eapd_get, \
632 .put = cxt_eapd_put, \
633 .private_value = nid | (mask<<16) }
637 static int conexant_ch_mode_info(struct snd_kcontrol
*kcontrol
,
638 struct snd_ctl_elem_info
*uinfo
)
640 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
641 struct conexant_spec
*spec
= codec
->spec
;
642 return snd_hda_ch_mode_info(codec
, uinfo
, spec
->channel_mode
,
643 spec
->num_channel_mode
);
646 static int conexant_ch_mode_get(struct snd_kcontrol
*kcontrol
,
647 struct snd_ctl_elem_value
*ucontrol
)
649 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
650 struct conexant_spec
*spec
= codec
->spec
;
651 return snd_hda_ch_mode_get(codec
, ucontrol
, spec
->channel_mode
,
652 spec
->num_channel_mode
,
653 spec
->multiout
.max_channels
);
656 static int conexant_ch_mode_put(struct snd_kcontrol
*kcontrol
,
657 struct snd_ctl_elem_value
*ucontrol
)
659 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
660 struct conexant_spec
*spec
= codec
->spec
;
661 int err
= snd_hda_ch_mode_put(codec
, ucontrol
, spec
->channel_mode
,
662 spec
->num_channel_mode
,
663 &spec
->multiout
.max_channels
);
664 if (err
>= 0 && spec
->need_dac_fix
)
665 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
669 #define CXT_PIN_MODE(xname, nid, dir) \
670 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
671 .info = conexant_ch_mode_info, \
672 .get = conexant_ch_mode_get, \
673 .put = conexant_ch_mode_put, \
674 .private_value = nid | (dir<<16) }
676 #endif /* CONFIG_SND_DEBUG */
678 /* Conexant 5045 specific */
680 static const hda_nid_t cxt5045_dac_nids
[1] = { 0x19 };
681 static const hda_nid_t cxt5045_adc_nids
[1] = { 0x1a };
682 static const hda_nid_t cxt5045_capsrc_nids
[1] = { 0x1a };
683 #define CXT5045_SPDIF_OUT 0x18
685 static const struct hda_channel_mode cxt5045_modes
[1] = {
689 static const struct hda_input_mux cxt5045_capture_source
= {
697 static const struct hda_input_mux cxt5045_capture_source_benq
= {
708 static const struct hda_input_mux cxt5045_capture_source_hp530
= {
716 /* turn on/off EAPD (+ mute HP) as a master switch */
717 static int cxt5045_hp_master_sw_put(struct snd_kcontrol
*kcontrol
,
718 struct snd_ctl_elem_value
*ucontrol
)
720 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
721 struct conexant_spec
*spec
= codec
->spec
;
724 if (!cxt_eapd_put(kcontrol
, ucontrol
))
727 /* toggle internal speakers mute depending of presence of
730 bits
= (!spec
->hp_present
&& spec
->cur_eapd
) ? 0 : HDA_AMP_MUTE
;
731 snd_hda_codec_amp_stereo(codec
, 0x10, HDA_OUTPUT
, 0,
734 bits
= spec
->cur_eapd
? 0 : HDA_AMP_MUTE
;
735 snd_hda_codec_amp_stereo(codec
, 0x11, HDA_OUTPUT
, 0,
740 /* bind volumes of both NID 0x10 and 0x11 */
741 static const struct hda_bind_ctls cxt5045_hp_bind_master_vol
= {
742 .ops
= &snd_hda_bind_vol
,
744 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
),
745 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT
),
750 /* toggle input of built-in and mic jack appropriately */
751 static void cxt5045_hp_automic(struct hda_codec
*codec
)
753 static const struct hda_verb mic_jack_on
[] = {
754 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, 0xb080},
755 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, 0xb000},
758 static const struct hda_verb mic_jack_off
[] = {
759 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, 0xb080},
760 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, 0xb000},
763 unsigned int present
;
765 present
= snd_hda_jack_detect(codec
, 0x12);
767 snd_hda_sequence_write(codec
, mic_jack_on
);
769 snd_hda_sequence_write(codec
, mic_jack_off
);
773 /* mute internal speaker if HP is plugged */
774 static void cxt5045_hp_automute(struct hda_codec
*codec
)
776 struct conexant_spec
*spec
= codec
->spec
;
779 spec
->hp_present
= snd_hda_jack_detect(codec
, 0x11);
781 bits
= (spec
->hp_present
|| !spec
->cur_eapd
) ? HDA_AMP_MUTE
: 0;
782 snd_hda_codec_amp_stereo(codec
, 0x10, HDA_OUTPUT
, 0,
786 /* unsolicited event for HP jack sensing */
787 static void cxt5045_hp_unsol_event(struct hda_codec
*codec
,
792 case CONEXANT_HP_EVENT
:
793 cxt5045_hp_automute(codec
);
795 case CONEXANT_MIC_EVENT
:
796 cxt5045_hp_automic(codec
);
802 static const struct snd_kcontrol_new cxt5045_mixers
[] = {
803 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT
),
804 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT
),
805 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT
),
806 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT
),
807 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT
),
808 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT
),
809 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT
),
810 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT
),
811 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT
),
812 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT
),
813 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol
),
815 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
816 .name
= "Master Playback Switch",
817 .info
= cxt_eapd_info
,
819 .put
= cxt5045_hp_master_sw_put
,
820 .private_value
= 0x10,
826 static const struct snd_kcontrol_new cxt5045_benq_mixers
[] = {
827 HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT
),
828 HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT
),
829 HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT
),
830 HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT
),
832 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT
),
833 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT
),
834 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT
),
835 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT
),
837 HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT
),
838 HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT
),
843 static const struct snd_kcontrol_new cxt5045_mixers_hp530
[] = {
844 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT
),
845 HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT
),
846 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT
),
847 HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT
),
848 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT
),
849 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT
),
850 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT
),
851 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT
),
852 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT
),
853 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT
),
854 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol
),
856 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
857 .name
= "Master Playback Switch",
858 .info
= cxt_eapd_info
,
860 .put
= cxt5045_hp_master_sw_put
,
861 .private_value
= 0x10,
867 static const struct hda_verb cxt5045_init_verbs
[] = {
869 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
|AC_PINCTL_VREF_80
},
870 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
|AC_PINCTL_VREF_80
},
872 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
873 {0x10, AC_VERB_SET_CONNECT_SEL
, 0x1},
874 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
875 {0x11, AC_VERB_SET_CONNECT_SEL
, 0x1},
876 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
877 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
878 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
879 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
880 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
881 /* Record selector: Internal mic */
882 {0x1a, AC_VERB_SET_CONNECT_SEL
,0x1},
883 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
,
884 AC_AMP_SET_INPUT
|AC_AMP_SET_RIGHT
|AC_AMP_SET_LEFT
|0x17},
885 /* SPDIF route: PCM */
886 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
887 { 0x13, AC_VERB_SET_CONNECT_SEL
, 0x0 },
889 {0x10, AC_VERB_SET_EAPD_BTLENABLE
, 0x2 }, /* default on */
893 static const struct hda_verb cxt5045_benq_init_verbs
[] = {
894 /* Internal Mic, Mic */
895 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
|AC_PINCTL_VREF_80
},
896 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
|AC_PINCTL_VREF_80
},
897 /* Line In,HP, Amp */
898 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
899 {0x10, AC_VERB_SET_CONNECT_SEL
, 0x1},
900 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
901 {0x11, AC_VERB_SET_CONNECT_SEL
, 0x1},
902 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
903 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
904 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
905 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
906 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
907 /* Record selector: Internal mic */
908 {0x1a, AC_VERB_SET_CONNECT_SEL
, 0x1},
909 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
,
910 AC_AMP_SET_INPUT
|AC_AMP_SET_RIGHT
|AC_AMP_SET_LEFT
|0x17},
911 /* SPDIF route: PCM */
912 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
913 {0x13, AC_VERB_SET_CONNECT_SEL
, 0x0},
915 {0x10, AC_VERB_SET_EAPD_BTLENABLE
, 0x2}, /* default on */
919 static const struct hda_verb cxt5045_hp_sense_init_verbs
[] = {
920 /* pin sensing on HP jack */
921 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_HP_EVENT
},
925 static const struct hda_verb cxt5045_mic_sense_init_verbs
[] = {
926 /* pin sensing on HP jack */
927 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_MIC_EVENT
},
931 #ifdef CONFIG_SND_DEBUG
932 /* Test configuration for debugging, modelled after the ALC260 test
935 static const struct hda_input_mux cxt5045_test_capture_source
= {
940 { "LINE1 pin", 0x2 },
941 { "HP-OUT pin", 0x3 },
946 static const struct snd_kcontrol_new cxt5045_test_mixer
[] = {
948 /* Output controls */
949 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT
),
950 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT
),
951 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT
),
952 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT
),
953 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT
),
954 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT
),
956 /* Modes for retasking pin widgets */
957 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT
),
958 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT
),
960 /* EAPD Switch Control */
961 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
963 /* Loopback mixer controls */
965 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT
),
966 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT
),
967 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT
),
968 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT
),
969 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT
),
970 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT
),
971 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT
),
972 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT
),
973 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT
),
974 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT
),
976 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
977 .name
= "Input Source",
978 .info
= conexant_mux_enum_info
,
979 .get
= conexant_mux_enum_get
,
980 .put
= conexant_mux_enum_put
,
982 /* Audio input controls */
983 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT
),
984 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT
),
985 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT
),
986 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT
),
987 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT
),
988 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT
),
989 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT
),
990 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT
),
991 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT
),
992 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT
),
996 static const struct hda_verb cxt5045_test_init_verbs
[] = {
997 /* Set connections */
998 { 0x10, AC_VERB_SET_CONNECT_SEL
, 0x0 },
999 { 0x11, AC_VERB_SET_CONNECT_SEL
, 0x0 },
1000 { 0x12, AC_VERB_SET_CONNECT_SEL
, 0x0 },
1001 /* Enable retasking pins as output, initially without power amp */
1002 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1003 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1005 /* Disable digital (SPDIF) pins initially, but users can enable
1006 * them via a mixer switch. In the case of SPDIF-out, this initverb
1007 * payload also sets the generation to 0, output to be in "consumer"
1008 * PCM format, copyright asserted, no pre-emphasis and no validity
1011 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1012 {0x18, AC_VERB_SET_DIGI_CONVERT_1
, 0},
1014 /* Start with output sum widgets muted and their output gains at min */
1015 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
1016 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
1018 /* Unmute retasking pin widget output buffers since the default
1019 * state appears to be output. As the pin mode is changed by the
1020 * user the pin mode control will take care of enabling the pin's
1021 * input/output buffers as needed.
1023 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
1024 {0x11, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
1026 /* Mute capture amp left and right */
1027 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
1029 /* Set ADC connection select to match default mixer setting (mic1
1032 {0x1a, AC_VERB_SET_CONNECT_SEL
, 0x00},
1033 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x00},
1035 /* Mute all inputs to mixer widget (even unconnected ones) */
1036 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)}, /* Mixer pin */
1037 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)}, /* Mic1 pin */
1038 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)}, /* Line pin */
1039 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)}, /* HP pin */
1040 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)}, /* CD pin */
1047 /* initialize jack-sensing, too */
1048 static int cxt5045_init(struct hda_codec
*codec
)
1050 conexant_init(codec
);
1051 cxt5045_hp_automute(codec
);
1057 CXT5045_LAPTOP_HPSENSE
,
1058 CXT5045_LAPTOP_MICSENSE
,
1059 CXT5045_LAPTOP_HPMICSENSE
,
1061 CXT5045_LAPTOP_HP530
,
1062 #ifdef CONFIG_SND_DEBUG
1069 static const char * const cxt5045_models
[CXT5045_MODELS
] = {
1070 [CXT5045_LAPTOP_HPSENSE
] = "laptop-hpsense",
1071 [CXT5045_LAPTOP_MICSENSE
] = "laptop-micsense",
1072 [CXT5045_LAPTOP_HPMICSENSE
] = "laptop-hpmicsense",
1073 [CXT5045_BENQ
] = "benq",
1074 [CXT5045_LAPTOP_HP530
] = "laptop-hp530",
1075 #ifdef CONFIG_SND_DEBUG
1076 [CXT5045_TEST
] = "test",
1078 [CXT5045_AUTO
] = "auto",
1081 static const struct snd_pci_quirk cxt5045_cfg_tbl
[] = {
1082 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530
),
1083 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1084 CXT5045_LAPTOP_HPSENSE
),
1085 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE
),
1086 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ
),
1087 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE
),
1088 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE
),
1089 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
1090 CXT5045_LAPTOP_HPMICSENSE
),
1091 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE
),
1092 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE
),
1093 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE
),
1094 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1095 CXT5045_LAPTOP_HPMICSENSE
),
1096 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE
),
1100 static int patch_cxt5045(struct hda_codec
*codec
)
1102 struct conexant_spec
*spec
;
1105 board_config
= snd_hda_check_board_config(codec
, CXT5045_MODELS
,
1108 #if 0 /* use the old method just for safety */
1109 if (board_config
< 0)
1110 board_config
= CXT5045_AUTO
;
1112 if (board_config
== CXT5045_AUTO
)
1113 return patch_conexant_auto(codec
);
1115 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1119 codec
->pin_amp_workaround
= 1;
1121 spec
->multiout
.max_channels
= 2;
1122 spec
->multiout
.num_dacs
= ARRAY_SIZE(cxt5045_dac_nids
);
1123 spec
->multiout
.dac_nids
= cxt5045_dac_nids
;
1124 spec
->multiout
.dig_out_nid
= CXT5045_SPDIF_OUT
;
1125 spec
->num_adc_nids
= 1;
1126 spec
->adc_nids
= cxt5045_adc_nids
;
1127 spec
->capsrc_nids
= cxt5045_capsrc_nids
;
1128 spec
->input_mux
= &cxt5045_capture_source
;
1129 spec
->num_mixers
= 1;
1130 spec
->mixers
[0] = cxt5045_mixers
;
1131 spec
->num_init_verbs
= 1;
1132 spec
->init_verbs
[0] = cxt5045_init_verbs
;
1133 spec
->spdif_route
= 0;
1134 spec
->num_channel_mode
= ARRAY_SIZE(cxt5045_modes
);
1135 spec
->channel_mode
= cxt5045_modes
;
1137 set_beep_amp(spec
, 0x16, 0, 1);
1139 codec
->patch_ops
= conexant_patch_ops
;
1141 switch (board_config
) {
1142 case CXT5045_LAPTOP_HPSENSE
:
1143 codec
->patch_ops
.unsol_event
= cxt5045_hp_unsol_event
;
1144 spec
->input_mux
= &cxt5045_capture_source
;
1145 spec
->num_init_verbs
= 2;
1146 spec
->init_verbs
[1] = cxt5045_hp_sense_init_verbs
;
1147 spec
->mixers
[0] = cxt5045_mixers
;
1148 codec
->patch_ops
.init
= cxt5045_init
;
1150 case CXT5045_LAPTOP_MICSENSE
:
1151 codec
->patch_ops
.unsol_event
= cxt5045_hp_unsol_event
;
1152 spec
->input_mux
= &cxt5045_capture_source
;
1153 spec
->num_init_verbs
= 2;
1154 spec
->init_verbs
[1] = cxt5045_mic_sense_init_verbs
;
1155 spec
->mixers
[0] = cxt5045_mixers
;
1156 codec
->patch_ops
.init
= cxt5045_init
;
1159 case CXT5045_LAPTOP_HPMICSENSE
:
1160 codec
->patch_ops
.unsol_event
= cxt5045_hp_unsol_event
;
1161 spec
->input_mux
= &cxt5045_capture_source
;
1162 spec
->num_init_verbs
= 3;
1163 spec
->init_verbs
[1] = cxt5045_hp_sense_init_verbs
;
1164 spec
->init_verbs
[2] = cxt5045_mic_sense_init_verbs
;
1165 spec
->mixers
[0] = cxt5045_mixers
;
1166 codec
->patch_ops
.init
= cxt5045_init
;
1169 codec
->patch_ops
.unsol_event
= cxt5045_hp_unsol_event
;
1170 spec
->input_mux
= &cxt5045_capture_source_benq
;
1171 spec
->num_init_verbs
= 1;
1172 spec
->init_verbs
[0] = cxt5045_benq_init_verbs
;
1173 spec
->mixers
[0] = cxt5045_mixers
;
1174 spec
->mixers
[1] = cxt5045_benq_mixers
;
1175 spec
->num_mixers
= 2;
1176 codec
->patch_ops
.init
= cxt5045_init
;
1178 case CXT5045_LAPTOP_HP530
:
1179 codec
->patch_ops
.unsol_event
= cxt5045_hp_unsol_event
;
1180 spec
->input_mux
= &cxt5045_capture_source_hp530
;
1181 spec
->num_init_verbs
= 2;
1182 spec
->init_verbs
[1] = cxt5045_hp_sense_init_verbs
;
1183 spec
->mixers
[0] = cxt5045_mixers_hp530
;
1184 codec
->patch_ops
.init
= cxt5045_init
;
1186 #ifdef CONFIG_SND_DEBUG
1188 spec
->input_mux
= &cxt5045_test_capture_source
;
1189 spec
->mixers
[0] = cxt5045_test_mixer
;
1190 spec
->init_verbs
[0] = cxt5045_test_init_verbs
;
1196 switch (codec
->subsystem_id
>> 16) {
1201 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1202 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
1203 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
1205 snd_hda_override_amp_caps(codec
, 0x17, HDA_INPUT
,
1206 (0x14 << AC_AMPCAP_OFFSET_SHIFT
) |
1207 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
1208 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
1209 (1 << AC_AMPCAP_MUTE_SHIFT
));
1214 snd_hda_attach_beep_device(codec
, spec
->beep_amp
);
1220 /* Conexant 5047 specific */
1221 #define CXT5047_SPDIF_OUT 0x11
1223 static const hda_nid_t cxt5047_dac_nids
[1] = { 0x10 }; /* 0x1c */
1224 static const hda_nid_t cxt5047_adc_nids
[1] = { 0x12 };
1225 static const hda_nid_t cxt5047_capsrc_nids
[1] = { 0x1a };
1227 static const struct hda_channel_mode cxt5047_modes
[1] = {
1231 static const struct hda_input_mux cxt5047_toshiba_capture_source
= {
1239 /* turn on/off EAPD (+ mute HP) as a master switch */
1240 static int cxt5047_hp_master_sw_put(struct snd_kcontrol
*kcontrol
,
1241 struct snd_ctl_elem_value
*ucontrol
)
1243 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1244 struct conexant_spec
*spec
= codec
->spec
;
1247 if (!cxt_eapd_put(kcontrol
, ucontrol
))
1250 /* toggle internal speakers mute depending of presence of
1251 * the headphone jack
1253 bits
= (!spec
->hp_present
&& spec
->cur_eapd
) ? 0 : HDA_AMP_MUTE
;
1254 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1255 * pin widgets unlike other codecs. In this case, we need to
1256 * set index 0x01 for the volume from the mixer amp 0x19.
1258 snd_hda_codec_amp_stereo(codec
, 0x1d, HDA_OUTPUT
, 0x01,
1259 HDA_AMP_MUTE
, bits
);
1260 bits
= spec
->cur_eapd
? 0 : HDA_AMP_MUTE
;
1261 snd_hda_codec_amp_stereo(codec
, 0x13, HDA_OUTPUT
, 0,
1262 HDA_AMP_MUTE
, bits
);
1266 /* mute internal speaker if HP is plugged */
1267 static void cxt5047_hp_automute(struct hda_codec
*codec
)
1269 struct conexant_spec
*spec
= codec
->spec
;
1272 spec
->hp_present
= snd_hda_jack_detect(codec
, 0x13);
1274 bits
= (spec
->hp_present
|| !spec
->cur_eapd
) ? HDA_AMP_MUTE
: 0;
1275 /* See the note in cxt5047_hp_master_sw_put */
1276 snd_hda_codec_amp_stereo(codec
, 0x1d, HDA_OUTPUT
, 0x01,
1277 HDA_AMP_MUTE
, bits
);
1280 /* toggle input of built-in and mic jack appropriately */
1281 static void cxt5047_hp_automic(struct hda_codec
*codec
)
1283 static const struct hda_verb mic_jack_on
[] = {
1284 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_MUTE
},
1285 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
1288 static const struct hda_verb mic_jack_off
[] = {
1289 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_MUTE
},
1290 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
1293 unsigned int present
;
1295 present
= snd_hda_jack_detect(codec
, 0x15);
1297 snd_hda_sequence_write(codec
, mic_jack_on
);
1299 snd_hda_sequence_write(codec
, mic_jack_off
);
1302 /* unsolicited event for HP jack sensing */
1303 static void cxt5047_hp_unsol_event(struct hda_codec
*codec
,
1306 switch (res
>> 26) {
1307 case CONEXANT_HP_EVENT
:
1308 cxt5047_hp_automute(codec
);
1310 case CONEXANT_MIC_EVENT
:
1311 cxt5047_hp_automic(codec
);
1316 static const struct snd_kcontrol_new cxt5047_base_mixers
[] = {
1317 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT
),
1318 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT
),
1319 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT
),
1320 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT
),
1321 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT
),
1322 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT
),
1323 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT
),
1325 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1326 .name
= "Master Playback Switch",
1327 .info
= cxt_eapd_info
,
1328 .get
= cxt_eapd_get
,
1329 .put
= cxt5047_hp_master_sw_put
,
1330 .private_value
= 0x13,
1336 static const struct snd_kcontrol_new cxt5047_hp_spk_mixers
[] = {
1337 /* See the note in cxt5047_hp_master_sw_put */
1338 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT
),
1339 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT
),
1343 static const struct snd_kcontrol_new cxt5047_hp_only_mixers
[] = {
1344 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT
),
1348 static const struct hda_verb cxt5047_init_verbs
[] = {
1349 /* Line in, Mic, Built-in Mic */
1350 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
1351 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
|AC_PINCTL_VREF_50
},
1352 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
|AC_PINCTL_VREF_50
},
1354 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
1355 {0x13, AC_VERB_SET_CONNECT_SEL
, 0x0}, /* mixer(0x19) */
1356 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x1}, /* mixer(0x19) */
1357 /* Record selector: Mic */
1358 {0x12, AC_VERB_SET_CONNECT_SEL
,0x03},
1359 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
,
1360 AC_AMP_SET_INPUT
|AC_AMP_SET_RIGHT
|AC_AMP_SET_LEFT
|0x17},
1361 {0x1A, AC_VERB_SET_CONNECT_SEL
,0x02},
1362 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
,
1363 AC_AMP_SET_OUTPUT
|AC_AMP_SET_RIGHT
|AC_AMP_SET_LEFT
|0x00},
1364 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
,
1365 AC_AMP_SET_OUTPUT
|AC_AMP_SET_RIGHT
|AC_AMP_SET_LEFT
|0x03},
1366 /* SPDIF route: PCM */
1367 { 0x18, AC_VERB_SET_CONNECT_SEL
, 0x0 },
1368 /* Enable unsolicited events */
1369 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_HP_EVENT
},
1370 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_MIC_EVENT
},
1374 /* configuration for Toshiba Laptops */
1375 static const struct hda_verb cxt5047_toshiba_init_verbs
[] = {
1376 {0x13, AC_VERB_SET_EAPD_BTLENABLE
, 0x0}, /* default off */
1380 /* Test configuration for debugging, modelled after the ALC260 test
1383 #ifdef CONFIG_SND_DEBUG
1384 static const struct hda_input_mux cxt5047_test_capture_source
= {
1387 { "LINE1 pin", 0x0 },
1388 { "MIC1 pin", 0x1 },
1389 { "MIC2 pin", 0x2 },
1394 static const struct snd_kcontrol_new cxt5047_test_mixer
[] = {
1396 /* Output only controls */
1397 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT
),
1398 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT
),
1399 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT
),
1400 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT
),
1401 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT
),
1402 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT
),
1403 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT
),
1404 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT
),
1405 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT
),
1406 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT
),
1407 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT
),
1408 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT
),
1410 /* Modes for retasking pin widgets */
1411 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT
),
1412 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT
),
1414 /* EAPD Switch Control */
1415 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1417 /* Loopback mixer controls */
1418 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT
),
1419 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT
),
1420 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT
),
1421 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT
),
1422 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT
),
1423 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT
),
1424 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT
),
1425 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT
),
1427 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT
),
1428 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT
),
1429 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT
),
1430 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT
),
1431 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT
),
1432 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT
),
1433 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT
),
1434 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT
),
1436 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1437 .name
= "Input Source",
1438 .info
= conexant_mux_enum_info
,
1439 .get
= conexant_mux_enum_get
,
1440 .put
= conexant_mux_enum_put
,
1442 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT
),
1447 static const struct hda_verb cxt5047_test_init_verbs
[] = {
1448 /* Enable retasking pins as output, initially without power amp */
1449 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1450 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1451 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1453 /* Disable digital (SPDIF) pins initially, but users can enable
1454 * them via a mixer switch. In the case of SPDIF-out, this initverb
1455 * payload also sets the generation to 0, output to be in "consumer"
1456 * PCM format, copyright asserted, no pre-emphasis and no validity
1459 {0x18, AC_VERB_SET_DIGI_CONVERT_1
, 0},
1461 /* Ensure mic1, mic2, line1 pin widgets take input from the
1462 * OUT1 sum bus when acting as an output.
1464 {0x1a, AC_VERB_SET_CONNECT_SEL
, 0},
1465 {0x1b, AC_VERB_SET_CONNECT_SEL
, 0},
1467 /* Start with output sum widgets muted and their output gains at min */
1468 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
1469 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
1471 /* Unmute retasking pin widget output buffers since the default
1472 * state appears to be output. As the pin mode is changed by the
1473 * user the pin mode control will take care of enabling the pin's
1474 * input/output buffers as needed.
1476 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
1477 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
1478 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
1480 /* Mute capture amp left and right */
1481 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
1483 /* Set ADC connection select to match default mixer setting (mic1
1486 {0x12, AC_VERB_SET_CONNECT_SEL
, 0x00},
1488 /* Mute all inputs to mixer widget (even unconnected ones) */
1489 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)}, /* mic1 pin */
1490 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)}, /* mic2 pin */
1491 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)}, /* line1 pin */
1492 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)}, /* line2 pin */
1493 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)}, /* CD pin */
1494 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1495 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(6)}, /* Line-out pin */
1496 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(7)}, /* HP-pin pin */
1503 /* initialize jack-sensing, too */
1504 static int cxt5047_hp_init(struct hda_codec
*codec
)
1506 conexant_init(codec
);
1507 cxt5047_hp_automute(codec
);
1513 CXT5047_LAPTOP
, /* Laptops w/o EAPD support */
1514 CXT5047_LAPTOP_HP
, /* Some HP laptops */
1515 CXT5047_LAPTOP_EAPD
, /* Laptops with EAPD support */
1516 #ifdef CONFIG_SND_DEBUG
1523 static const char * const cxt5047_models
[CXT5047_MODELS
] = {
1524 [CXT5047_LAPTOP
] = "laptop",
1525 [CXT5047_LAPTOP_HP
] = "laptop-hp",
1526 [CXT5047_LAPTOP_EAPD
] = "laptop-eapd",
1527 #ifdef CONFIG_SND_DEBUG
1528 [CXT5047_TEST
] = "test",
1530 [CXT5047_AUTO
] = "auto",
1533 static const struct snd_pci_quirk cxt5047_cfg_tbl
[] = {
1534 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP
),
1535 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1537 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD
),
1541 static int patch_cxt5047(struct hda_codec
*codec
)
1543 struct conexant_spec
*spec
;
1546 board_config
= snd_hda_check_board_config(codec
, CXT5047_MODELS
,
1549 #if 0 /* not enabled as default, as BIOS often broken for this codec */
1550 if (board_config
< 0)
1551 board_config
= CXT5047_AUTO
;
1553 if (board_config
== CXT5047_AUTO
)
1554 return patch_conexant_auto(codec
);
1556 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1560 codec
->pin_amp_workaround
= 1;
1562 spec
->multiout
.max_channels
= 2;
1563 spec
->multiout
.num_dacs
= ARRAY_SIZE(cxt5047_dac_nids
);
1564 spec
->multiout
.dac_nids
= cxt5047_dac_nids
;
1565 spec
->multiout
.dig_out_nid
= CXT5047_SPDIF_OUT
;
1566 spec
->num_adc_nids
= 1;
1567 spec
->adc_nids
= cxt5047_adc_nids
;
1568 spec
->capsrc_nids
= cxt5047_capsrc_nids
;
1569 spec
->num_mixers
= 1;
1570 spec
->mixers
[0] = cxt5047_base_mixers
;
1571 spec
->num_init_verbs
= 1;
1572 spec
->init_verbs
[0] = cxt5047_init_verbs
;
1573 spec
->spdif_route
= 0;
1574 spec
->num_channel_mode
= ARRAY_SIZE(cxt5047_modes
),
1575 spec
->channel_mode
= cxt5047_modes
,
1577 codec
->patch_ops
= conexant_patch_ops
;
1579 switch (board_config
) {
1580 case CXT5047_LAPTOP
:
1581 spec
->num_mixers
= 2;
1582 spec
->mixers
[1] = cxt5047_hp_spk_mixers
;
1583 codec
->patch_ops
.unsol_event
= cxt5047_hp_unsol_event
;
1585 case CXT5047_LAPTOP_HP
:
1586 spec
->num_mixers
= 2;
1587 spec
->mixers
[1] = cxt5047_hp_only_mixers
;
1588 codec
->patch_ops
.unsol_event
= cxt5047_hp_unsol_event
;
1589 codec
->patch_ops
.init
= cxt5047_hp_init
;
1591 case CXT5047_LAPTOP_EAPD
:
1592 spec
->input_mux
= &cxt5047_toshiba_capture_source
;
1593 spec
->num_mixers
= 2;
1594 spec
->mixers
[1] = cxt5047_hp_spk_mixers
;
1595 spec
->num_init_verbs
= 2;
1596 spec
->init_verbs
[1] = cxt5047_toshiba_init_verbs
;
1597 codec
->patch_ops
.unsol_event
= cxt5047_hp_unsol_event
;
1599 #ifdef CONFIG_SND_DEBUG
1601 spec
->input_mux
= &cxt5047_test_capture_source
;
1602 spec
->mixers
[0] = cxt5047_test_mixer
;
1603 spec
->init_verbs
[0] = cxt5047_test_init_verbs
;
1604 codec
->patch_ops
.unsol_event
= cxt5047_hp_unsol_event
;
1607 spec
->vmaster_nid
= 0x13;
1609 switch (codec
->subsystem_id
>> 16) {
1611 /* HP laptops have really bad sound over 0 dB on NID 0x10.
1612 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1613 * with 0 dB offset 0x17)
1615 snd_hda_override_amp_caps(codec
, 0x10, HDA_INPUT
,
1616 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
1617 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
1618 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
1619 (1 << AC_AMPCAP_MUTE_SHIFT
));
1626 /* Conexant 5051 specific */
1627 static const hda_nid_t cxt5051_dac_nids
[1] = { 0x10 };
1628 static const hda_nid_t cxt5051_adc_nids
[2] = { 0x14, 0x15 };
1630 static const struct hda_channel_mode cxt5051_modes
[1] = {
1634 static void cxt5051_update_speaker(struct hda_codec
*codec
)
1636 struct conexant_spec
*spec
= codec
->spec
;
1637 unsigned int pinctl
;
1639 pinctl
= (spec
->hp_present
&& spec
->cur_eapd
) ? PIN_HP
: 0;
1640 snd_hda_codec_write(codec
, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
1643 pinctl
= (!spec
->hp_present
&& spec
->cur_eapd
) ? PIN_OUT
: 0;
1644 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
1646 /* on ideapad there is an aditional speaker (subwoofer) to mute */
1648 snd_hda_codec_write(codec
, 0x1b, 0,
1649 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1653 /* turn on/off EAPD (+ mute HP) as a master switch */
1654 static int cxt5051_hp_master_sw_put(struct snd_kcontrol
*kcontrol
,
1655 struct snd_ctl_elem_value
*ucontrol
)
1657 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1659 if (!cxt_eapd_put(kcontrol
, ucontrol
))
1661 cxt5051_update_speaker(codec
);
1665 /* toggle input of built-in and mic jack appropriately */
1666 static void cxt5051_portb_automic(struct hda_codec
*codec
)
1668 struct conexant_spec
*spec
= codec
->spec
;
1669 unsigned int present
;
1671 if (!(spec
->auto_mic
& AUTO_MIC_PORTB
))
1673 present
= snd_hda_jack_detect(codec
, 0x17);
1674 snd_hda_codec_write(codec
, 0x14, 0,
1675 AC_VERB_SET_CONNECT_SEL
,
1676 present
? 0x01 : 0x00);
1679 /* switch the current ADC according to the jack state */
1680 static void cxt5051_portc_automic(struct hda_codec
*codec
)
1682 struct conexant_spec
*spec
= codec
->spec
;
1683 unsigned int present
;
1686 if (!(spec
->auto_mic
& AUTO_MIC_PORTC
))
1688 present
= snd_hda_jack_detect(codec
, 0x18);
1690 spec
->cur_adc_idx
= 1;
1692 spec
->cur_adc_idx
= 0;
1693 new_adc
= spec
->adc_nids
[spec
->cur_adc_idx
];
1694 if (spec
->cur_adc
&& spec
->cur_adc
!= new_adc
) {
1695 /* stream is running, let's swap the current ADC */
1696 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
1697 spec
->cur_adc
= new_adc
;
1698 snd_hda_codec_setup_stream(codec
, new_adc
,
1699 spec
->cur_adc_stream_tag
, 0,
1700 spec
->cur_adc_format
);
1704 /* mute internal speaker if HP is plugged */
1705 static void cxt5051_hp_automute(struct hda_codec
*codec
)
1707 struct conexant_spec
*spec
= codec
->spec
;
1709 spec
->hp_present
= snd_hda_jack_detect(codec
, 0x16);
1710 cxt5051_update_speaker(codec
);
1713 /* unsolicited event for HP jack sensing */
1714 static void cxt5051_hp_unsol_event(struct hda_codec
*codec
,
1717 int nid
= (res
& AC_UNSOL_RES_SUBTAG
) >> 20;
1718 switch (res
>> 26) {
1719 case CONEXANT_HP_EVENT
:
1720 cxt5051_hp_automute(codec
);
1722 case CXT5051_PORTB_EVENT
:
1723 cxt5051_portb_automic(codec
);
1725 case CXT5051_PORTC_EVENT
:
1726 cxt5051_portc_automic(codec
);
1729 snd_hda_input_jack_report(codec
, nid
);
1732 static const struct snd_kcontrol_new cxt5051_playback_mixers
[] = {
1733 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT
),
1735 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1736 .name
= "Master Playback Switch",
1737 .info
= cxt_eapd_info
,
1738 .get
= cxt_eapd_get
,
1739 .put
= cxt5051_hp_master_sw_put
,
1740 .private_value
= 0x1a,
1745 static const struct snd_kcontrol_new cxt5051_capture_mixers
[] = {
1746 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT
),
1747 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT
),
1748 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT
),
1749 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT
),
1750 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT
),
1751 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT
),
1755 static const struct snd_kcontrol_new cxt5051_hp_mixers
[] = {
1756 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT
),
1757 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT
),
1758 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT
),
1759 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT
),
1763 static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers
[] = {
1764 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT
),
1765 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT
),
1769 static const struct snd_kcontrol_new cxt5051_f700_mixers
[] = {
1770 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT
),
1771 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT
),
1775 static const struct snd_kcontrol_new cxt5051_toshiba_mixers
[] = {
1776 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT
),
1777 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT
),
1778 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT
),
1779 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT
),
1783 static const struct hda_verb cxt5051_init_verbs
[] = {
1785 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x03},
1786 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
1787 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x03},
1788 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
1789 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
1790 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x03},
1792 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1793 {0x1a, AC_VERB_SET_CONNECT_SEL
, 0x00},
1795 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
1796 {0x16, AC_VERB_SET_CONNECT_SEL
, 0x00},
1798 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
1799 /* Record selector: Internal mic */
1800 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x44},
1801 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1) | 0x44},
1802 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x44},
1803 /* SPDIF route: PCM */
1804 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1805 {0x1c, AC_VERB_SET_CONNECT_SEL
, 0x0},
1807 {0x1a, AC_VERB_SET_EAPD_BTLENABLE
, 0x2}, /* default on */
1808 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
|CONEXANT_HP_EVENT
},
1812 static const struct hda_verb cxt5051_hp_dv6736_init_verbs
[] = {
1814 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x03},
1815 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
1816 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x0},
1817 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x0},
1819 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1820 {0x1a, AC_VERB_SET_CONNECT_SEL
, 0x00},
1822 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
1823 {0x16, AC_VERB_SET_CONNECT_SEL
, 0x00},
1825 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
1826 /* Record selector: Internal mic */
1827 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1) | 0x44},
1828 {0x14, AC_VERB_SET_CONNECT_SEL
, 0x1},
1829 /* SPDIF route: PCM */
1830 {0x1c, AC_VERB_SET_CONNECT_SEL
, 0x0},
1832 {0x1a, AC_VERB_SET_EAPD_BTLENABLE
, 0x2}, /* default on */
1833 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
|CONEXANT_HP_EVENT
},
1837 static const struct hda_verb cxt5051_lenovo_x200_init_verbs
[] = {
1839 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x03},
1840 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
1841 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x03},
1842 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
1843 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
1844 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x03},
1846 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1847 {0x1a, AC_VERB_SET_CONNECT_SEL
, 0x00},
1849 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
1850 {0x16, AC_VERB_SET_CONNECT_SEL
, 0x00},
1852 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
1853 {0x19, AC_VERB_SET_CONNECT_SEL
, 0x00},
1855 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
1856 /* Record selector: Internal mic */
1857 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x44},
1858 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1) | 0x44},
1859 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x44},
1860 /* SPDIF route: PCM */
1861 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
}, /* needed for W500 Advanced Mini Dock 250410 */
1862 {0x1c, AC_VERB_SET_CONNECT_SEL
, 0x0},
1864 {0x1a, AC_VERB_SET_EAPD_BTLENABLE
, 0x2}, /* default on */
1865 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
|CONEXANT_HP_EVENT
},
1866 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
|CONEXANT_HP_EVENT
},
1870 static const struct hda_verb cxt5051_f700_init_verbs
[] = {
1872 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x03},
1873 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
1874 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x0},
1875 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x0},
1877 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1878 {0x1a, AC_VERB_SET_CONNECT_SEL
, 0x00},
1880 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
1881 {0x16, AC_VERB_SET_CONNECT_SEL
, 0x00},
1883 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
1884 /* Record selector: Internal mic */
1885 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1) | 0x44},
1886 {0x14, AC_VERB_SET_CONNECT_SEL
, 0x1},
1887 /* SPDIF route: PCM */
1888 {0x1c, AC_VERB_SET_CONNECT_SEL
, 0x0},
1890 {0x1a, AC_VERB_SET_EAPD_BTLENABLE
, 0x2}, /* default on */
1891 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
|CONEXANT_HP_EVENT
},
1895 static void cxt5051_init_mic_port(struct hda_codec
*codec
, hda_nid_t nid
,
1898 snd_hda_codec_write(codec
, nid
, 0,
1899 AC_VERB_SET_UNSOLICITED_ENABLE
,
1900 AC_USRSP_EN
| event
);
1901 snd_hda_input_jack_add(codec
, nid
, SND_JACK_MICROPHONE
, NULL
);
1902 snd_hda_input_jack_report(codec
, nid
);
1905 static const struct hda_verb cxt5051_ideapad_init_verbs
[] = {
1907 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
1908 {0x1b, AC_VERB_SET_CONNECT_SEL
, 0x00},
1912 /* initialize jack-sensing, too */
1913 static int cxt5051_init(struct hda_codec
*codec
)
1915 struct conexant_spec
*spec
= codec
->spec
;
1917 conexant_init(codec
);
1918 conexant_init_jacks(codec
);
1920 if (spec
->auto_mic
& AUTO_MIC_PORTB
)
1921 cxt5051_init_mic_port(codec
, 0x17, CXT5051_PORTB_EVENT
);
1922 if (spec
->auto_mic
& AUTO_MIC_PORTC
)
1923 cxt5051_init_mic_port(codec
, 0x18, CXT5051_PORTC_EVENT
);
1925 if (codec
->patch_ops
.unsol_event
) {
1926 cxt5051_hp_automute(codec
);
1927 cxt5051_portb_automic(codec
);
1928 cxt5051_portc_automic(codec
);
1935 CXT5051_LAPTOP
, /* Laptops w/ EAPD support */
1936 CXT5051_HP
, /* no docking */
1937 CXT5051_HP_DV6736
, /* HP without mic switch */
1938 CXT5051_LENOVO_X200
, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1939 CXT5051_F700
, /* HP Compaq Presario F700 */
1940 CXT5051_TOSHIBA
, /* Toshiba M300 & co */
1941 CXT5051_IDEAPAD
, /* Lenovo IdeaPad Y430 */
1942 CXT5051_AUTO
, /* auto-parser */
1946 static const char *const cxt5051_models
[CXT5051_MODELS
] = {
1947 [CXT5051_LAPTOP
] = "laptop",
1948 [CXT5051_HP
] = "hp",
1949 [CXT5051_HP_DV6736
] = "hp-dv6736",
1950 [CXT5051_LENOVO_X200
] = "lenovo-x200",
1951 [CXT5051_F700
] = "hp-700",
1952 [CXT5051_TOSHIBA
] = "toshiba",
1953 [CXT5051_IDEAPAD
] = "ideapad",
1954 [CXT5051_AUTO
] = "auto",
1957 static const struct snd_pci_quirk cxt5051_cfg_tbl
[] = {
1958 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736
),
1959 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP
),
1960 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700
),
1961 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA
),
1962 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1964 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP
),
1965 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200
),
1966 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD
),
1970 static int patch_cxt5051(struct hda_codec
*codec
)
1972 struct conexant_spec
*spec
;
1975 board_config
= snd_hda_check_board_config(codec
, CXT5051_MODELS
,
1978 #if 0 /* use the old method just for safety */
1979 if (board_config
< 0)
1980 board_config
= CXT5051_AUTO
;
1982 if (board_config
== CXT5051_AUTO
)
1983 return patch_conexant_auto(codec
);
1985 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1989 codec
->pin_amp_workaround
= 1;
1991 codec
->patch_ops
= conexant_patch_ops
;
1992 codec
->patch_ops
.init
= cxt5051_init
;
1994 spec
->multiout
.max_channels
= 2;
1995 spec
->multiout
.num_dacs
= ARRAY_SIZE(cxt5051_dac_nids
);
1996 spec
->multiout
.dac_nids
= cxt5051_dac_nids
;
1997 spec
->multiout
.dig_out_nid
= CXT5051_SPDIF_OUT
;
1998 spec
->num_adc_nids
= 1; /* not 2; via auto-mic switch */
1999 spec
->adc_nids
= cxt5051_adc_nids
;
2000 spec
->num_mixers
= 2;
2001 spec
->mixers
[0] = cxt5051_capture_mixers
;
2002 spec
->mixers
[1] = cxt5051_playback_mixers
;
2003 spec
->num_init_verbs
= 1;
2004 spec
->init_verbs
[0] = cxt5051_init_verbs
;
2005 spec
->spdif_route
= 0;
2006 spec
->num_channel_mode
= ARRAY_SIZE(cxt5051_modes
);
2007 spec
->channel_mode
= cxt5051_modes
;
2009 spec
->cur_adc_idx
= 0;
2011 set_beep_amp(spec
, 0x13, 0, HDA_OUTPUT
);
2013 codec
->patch_ops
.unsol_event
= cxt5051_hp_unsol_event
;
2015 spec
->auto_mic
= AUTO_MIC_PORTB
| AUTO_MIC_PORTC
;
2016 switch (board_config
) {
2018 spec
->mixers
[0] = cxt5051_hp_mixers
;
2020 case CXT5051_HP_DV6736
:
2021 spec
->init_verbs
[0] = cxt5051_hp_dv6736_init_verbs
;
2022 spec
->mixers
[0] = cxt5051_hp_dv6736_mixers
;
2025 case CXT5051_LENOVO_X200
:
2026 spec
->init_verbs
[0] = cxt5051_lenovo_x200_init_verbs
;
2027 /* Thinkpad X301 does not have S/PDIF wired and no ability
2028 to use a docking station. */
2029 if (codec
->subsystem_id
== 0x17aa211f)
2030 spec
->multiout
.dig_out_nid
= 0;
2033 spec
->init_verbs
[0] = cxt5051_f700_init_verbs
;
2034 spec
->mixers
[0] = cxt5051_f700_mixers
;
2037 case CXT5051_TOSHIBA
:
2038 spec
->mixers
[0] = cxt5051_toshiba_mixers
;
2039 spec
->auto_mic
= AUTO_MIC_PORTB
;
2041 case CXT5051_IDEAPAD
:
2042 spec
->init_verbs
[spec
->num_init_verbs
++] =
2043 cxt5051_ideapad_init_verbs
;
2049 snd_hda_attach_beep_device(codec
, spec
->beep_amp
);
2054 /* Conexant 5066 specific */
2056 static const hda_nid_t cxt5066_dac_nids
[1] = { 0x10 };
2057 static const hda_nid_t cxt5066_adc_nids
[3] = { 0x14, 0x15, 0x16 };
2058 static const hda_nid_t cxt5066_capsrc_nids
[1] = { 0x17 };
2059 static const hda_nid_t cxt5066_digout_pin_nids
[2] = { 0x20, 0x22 };
2061 /* OLPC's microphone port is DC coupled for use with external sensors,
2062 * therefore we use a 50% mic bias in order to center the input signal with
2063 * the DC input range of the codec. */
2064 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2066 static const struct hda_channel_mode cxt5066_modes
[1] = {
2070 #define HP_PRESENT_PORT_A (1 << 0)
2071 #define HP_PRESENT_PORT_D (1 << 1)
2072 #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
2073 #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
2075 static void cxt5066_update_speaker(struct hda_codec
*codec
)
2077 struct conexant_spec
*spec
= codec
->spec
;
2078 unsigned int pinctl
;
2080 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
2081 spec
->hp_present
, spec
->cur_eapd
);
2084 pinctl
= (hp_port_a_present(spec
) && spec
->cur_eapd
) ? PIN_HP
: 0;
2085 snd_hda_codec_write(codec
, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
2088 /* Port D (HP/LO) */
2089 pinctl
= spec
->cur_eapd
? spec
->port_d_mode
: 0;
2090 if (spec
->dell_automute
|| spec
->thinkpad
) {
2091 /* Mute if Port A is connected */
2092 if (hp_port_a_present(spec
))
2095 /* Thinkpad/Dell doesn't give pin-D status */
2096 if (!hp_port_d_present(spec
))
2099 snd_hda_codec_write(codec
, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
2103 pinctl
= (!spec
->hp_present
&& spec
->cur_eapd
) ? PIN_OUT
: 0;
2104 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
2108 /* turn on/off EAPD (+ mute HP) as a master switch */
2109 static int cxt5066_hp_master_sw_put(struct snd_kcontrol
*kcontrol
,
2110 struct snd_ctl_elem_value
*ucontrol
)
2112 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2114 if (!cxt_eapd_put(kcontrol
, ucontrol
))
2117 cxt5066_update_speaker(codec
);
2121 static const struct hda_input_mux cxt5066_olpc_dc_bias
= {
2125 { "50%", PIN_VREF50
},
2126 { "80%", PIN_VREF80
},
2130 static int cxt5066_set_olpc_dc_bias(struct hda_codec
*codec
)
2132 struct conexant_spec
*spec
= codec
->spec
;
2133 /* Even though port F is the DC input, the bias is controlled on port B.
2134 * we also leave that port as an active input (but unselected) in DC mode
2135 * just in case that is necessary to make the bias setting take effect. */
2136 return snd_hda_codec_write_cache(codec
, 0x1a, 0,
2137 AC_VERB_SET_PIN_WIDGET_CONTROL
,
2138 cxt5066_olpc_dc_bias
.items
[spec
->dc_input_bias
].index
);
2141 /* OLPC defers mic widget control until when capture is started because the
2142 * microphone LED comes on as soon as these settings are put in place. if we
2143 * did this before recording, it would give the false indication that recording
2144 * is happening when it is not. */
2145 static void cxt5066_olpc_select_mic(struct hda_codec
*codec
)
2147 struct conexant_spec
*spec
= codec
->spec
;
2148 if (!spec
->recording
)
2151 if (spec
->dc_enable
) {
2152 /* in DC mode we ignore presence detection and just use the jack
2153 * through our special DC port */
2154 const struct hda_verb enable_dc_mode
[] = {
2155 /* disble internal mic, port C */
2156 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2158 /* enable DC capture, port F */
2159 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
2163 snd_hda_sequence_write(codec
, enable_dc_mode
);
2164 /* port B input disabled (and bias set) through the following call */
2165 cxt5066_set_olpc_dc_bias(codec
);
2169 /* disable DC (port F) */
2170 snd_hda_codec_write(codec
, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0);
2172 /* external mic, port B */
2173 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
2174 spec
->ext_mic_present
? CXT5066_OLPC_EXT_MIC_BIAS
: 0);
2176 /* internal mic, port C */
2177 snd_hda_codec_write(codec
, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
2178 spec
->ext_mic_present
? 0 : PIN_VREF80
);
2181 /* toggle input of built-in and mic jack appropriately */
2182 static void cxt5066_olpc_automic(struct hda_codec
*codec
)
2184 struct conexant_spec
*spec
= codec
->spec
;
2185 unsigned int present
;
2187 if (spec
->dc_enable
) /* don't do presence detection in DC mode */
2190 present
= snd_hda_codec_read(codec
, 0x1a, 0,
2191 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
2193 snd_printdd("CXT5066: external microphone detected\n");
2195 snd_printdd("CXT5066: external microphone absent\n");
2197 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_CONNECT_SEL
,
2199 spec
->ext_mic_present
= !!present
;
2201 cxt5066_olpc_select_mic(codec
);
2204 /* toggle input of built-in digital mic and mic jack appropriately */
2205 static void cxt5066_vostro_automic(struct hda_codec
*codec
)
2207 unsigned int present
;
2209 struct hda_verb ext_mic_present
[] = {
2210 /* enable external mic, port B */
2211 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
2213 /* switch to external mic input */
2214 {0x17, AC_VERB_SET_CONNECT_SEL
, 0},
2215 {0x14, AC_VERB_SET_CONNECT_SEL
, 0},
2217 /* disable internal digital mic */
2218 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2221 static const struct hda_verb ext_mic_absent
[] = {
2222 /* enable internal mic, port C */
2223 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
2225 /* switch to internal mic input */
2226 {0x14, AC_VERB_SET_CONNECT_SEL
, 2},
2228 /* disable external mic, port B */
2229 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2233 present
= snd_hda_jack_detect(codec
, 0x1a);
2235 snd_printdd("CXT5066: external microphone detected\n");
2236 snd_hda_sequence_write(codec
, ext_mic_present
);
2238 snd_printdd("CXT5066: external microphone absent\n");
2239 snd_hda_sequence_write(codec
, ext_mic_absent
);
2243 /* toggle input of built-in digital mic and mic jack appropriately */
2244 static void cxt5066_ideapad_automic(struct hda_codec
*codec
)
2246 unsigned int present
;
2248 struct hda_verb ext_mic_present
[] = {
2249 {0x14, AC_VERB_SET_CONNECT_SEL
, 0},
2250 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
2251 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2254 static const struct hda_verb ext_mic_absent
[] = {
2255 {0x14, AC_VERB_SET_CONNECT_SEL
, 2},
2256 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
2257 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2261 present
= snd_hda_jack_detect(codec
, 0x1b);
2263 snd_printdd("CXT5066: external microphone detected\n");
2264 snd_hda_sequence_write(codec
, ext_mic_present
);
2266 snd_printdd("CXT5066: external microphone absent\n");
2267 snd_hda_sequence_write(codec
, ext_mic_absent
);
2272 /* toggle input of built-in digital mic and mic jack appropriately */
2273 static void cxt5066_asus_automic(struct hda_codec
*codec
)
2275 unsigned int present
;
2277 present
= snd_hda_jack_detect(codec
, 0x1b);
2278 snd_printdd("CXT5066: external microphone present=%d\n", present
);
2279 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_CONNECT_SEL
,
2284 /* toggle input of built-in digital mic and mic jack appropriately */
2285 static void cxt5066_hp_laptop_automic(struct hda_codec
*codec
)
2287 unsigned int present
;
2289 present
= snd_hda_jack_detect(codec
, 0x1b);
2290 snd_printdd("CXT5066: external microphone present=%d\n", present
);
2291 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_CONNECT_SEL
,
2296 /* toggle input of built-in digital mic and mic jack appropriately
2297 order is: external mic -> dock mic -> interal mic */
2298 static void cxt5066_thinkpad_automic(struct hda_codec
*codec
)
2300 unsigned int ext_present
, dock_present
;
2302 static const struct hda_verb ext_mic_present
[] = {
2303 {0x14, AC_VERB_SET_CONNECT_SEL
, 0},
2304 {0x17, AC_VERB_SET_CONNECT_SEL
, 1},
2305 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
2306 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2307 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2310 static const struct hda_verb dock_mic_present
[] = {
2311 {0x14, AC_VERB_SET_CONNECT_SEL
, 0},
2312 {0x17, AC_VERB_SET_CONNECT_SEL
, 0},
2313 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
},
2314 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2315 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2318 static const struct hda_verb ext_mic_absent
[] = {
2319 {0x14, AC_VERB_SET_CONNECT_SEL
, 2},
2320 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
2321 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2322 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2326 ext_present
= snd_hda_jack_detect(codec
, 0x1b);
2327 dock_present
= snd_hda_jack_detect(codec
, 0x1a);
2329 snd_printdd("CXT5066: external microphone detected\n");
2330 snd_hda_sequence_write(codec
, ext_mic_present
);
2331 } else if (dock_present
) {
2332 snd_printdd("CXT5066: dock microphone detected\n");
2333 snd_hda_sequence_write(codec
, dock_mic_present
);
2335 snd_printdd("CXT5066: external microphone absent\n");
2336 snd_hda_sequence_write(codec
, ext_mic_absent
);
2340 /* mute internal speaker if HP is plugged */
2341 static void cxt5066_hp_automute(struct hda_codec
*codec
)
2343 struct conexant_spec
*spec
= codec
->spec
;
2344 unsigned int portA
, portD
;
2347 portA
= snd_hda_jack_detect(codec
, 0x19);
2350 portD
= snd_hda_jack_detect(codec
, 0x1c);
2352 spec
->hp_present
= portA
? HP_PRESENT_PORT_A
: 0;
2353 spec
->hp_present
|= portD
? HP_PRESENT_PORT_D
: 0;
2354 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
2355 portA
, portD
, spec
->hp_present
);
2356 cxt5066_update_speaker(codec
);
2359 /* Dispatch the right mic autoswitch function */
2360 static void cxt5066_automic(struct hda_codec
*codec
)
2362 struct conexant_spec
*spec
= codec
->spec
;
2364 if (spec
->dell_vostro
)
2365 cxt5066_vostro_automic(codec
);
2366 else if (spec
->ideapad
)
2367 cxt5066_ideapad_automic(codec
);
2368 else if (spec
->thinkpad
)
2369 cxt5066_thinkpad_automic(codec
);
2370 else if (spec
->hp_laptop
)
2371 cxt5066_hp_laptop_automic(codec
);
2372 else if (spec
->asus
)
2373 cxt5066_asus_automic(codec
);
2376 /* unsolicited event for jack sensing */
2377 static void cxt5066_olpc_unsol_event(struct hda_codec
*codec
, unsigned int res
)
2379 struct conexant_spec
*spec
= codec
->spec
;
2380 snd_printdd("CXT5066: unsol event %x (%x)\n", res
, res
>> 26);
2381 switch (res
>> 26) {
2382 case CONEXANT_HP_EVENT
:
2383 cxt5066_hp_automute(codec
);
2385 case CONEXANT_MIC_EVENT
:
2386 /* ignore mic events in DC mode; we're always using the jack */
2387 if (!spec
->dc_enable
)
2388 cxt5066_olpc_automic(codec
);
2393 /* unsolicited event for jack sensing */
2394 static void cxt5066_unsol_event(struct hda_codec
*codec
, unsigned int res
)
2396 snd_printdd("CXT5066: unsol event %x (%x)\n", res
, res
>> 26);
2397 switch (res
>> 26) {
2398 case CONEXANT_HP_EVENT
:
2399 cxt5066_hp_automute(codec
);
2401 case CONEXANT_MIC_EVENT
:
2402 cxt5066_automic(codec
);
2408 static const struct hda_input_mux cxt5066_analog_mic_boost
= {
2419 static void cxt5066_set_mic_boost(struct hda_codec
*codec
)
2421 struct conexant_spec
*spec
= codec
->spec
;
2422 snd_hda_codec_write_cache(codec
, 0x17, 0,
2423 AC_VERB_SET_AMP_GAIN_MUTE
,
2424 AC_AMP_SET_RIGHT
| AC_AMP_SET_LEFT
| AC_AMP_SET_OUTPUT
|
2425 cxt5066_analog_mic_boost
.items
[spec
->mic_boost
].index
);
2426 if (spec
->ideapad
|| spec
->thinkpad
) {
2427 /* adjust the internal mic as well...it is not through 0x17 */
2428 snd_hda_codec_write_cache(codec
, 0x23, 0,
2429 AC_VERB_SET_AMP_GAIN_MUTE
,
2430 AC_AMP_SET_RIGHT
| AC_AMP_SET_LEFT
| AC_AMP_SET_INPUT
|
2431 cxt5066_analog_mic_boost
.
2432 items
[spec
->mic_boost
].index
);
2436 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol
*kcontrol
,
2437 struct snd_ctl_elem_info
*uinfo
)
2439 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost
, uinfo
);
2442 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol
*kcontrol
,
2443 struct snd_ctl_elem_value
*ucontrol
)
2445 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2446 struct conexant_spec
*spec
= codec
->spec
;
2447 ucontrol
->value
.enumerated
.item
[0] = spec
->mic_boost
;
2451 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol
*kcontrol
,
2452 struct snd_ctl_elem_value
*ucontrol
)
2454 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2455 struct conexant_spec
*spec
= codec
->spec
;
2456 const struct hda_input_mux
*imux
= &cxt5066_analog_mic_boost
;
2458 idx
= ucontrol
->value
.enumerated
.item
[0];
2459 if (idx
>= imux
->num_items
)
2460 idx
= imux
->num_items
- 1;
2462 spec
->mic_boost
= idx
;
2463 if (!spec
->dc_enable
)
2464 cxt5066_set_mic_boost(codec
);
2468 static void cxt5066_enable_dc(struct hda_codec
*codec
)
2470 const struct hda_verb enable_dc_mode
[] = {
2472 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
2474 /* switch to DC input */
2475 {0x17, AC_VERB_SET_CONNECT_SEL
, 3},
2479 /* configure as input source */
2480 snd_hda_sequence_write(codec
, enable_dc_mode
);
2481 cxt5066_olpc_select_mic(codec
); /* also sets configured bias */
2484 static void cxt5066_disable_dc(struct hda_codec
*codec
)
2486 /* reconfigure input source */
2487 cxt5066_set_mic_boost(codec
);
2488 /* automic also selects the right mic if we're recording */
2489 cxt5066_olpc_automic(codec
);
2492 static int cxt5066_olpc_dc_get(struct snd_kcontrol
*kcontrol
,
2493 struct snd_ctl_elem_value
*ucontrol
)
2495 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2496 struct conexant_spec
*spec
= codec
->spec
;
2497 ucontrol
->value
.integer
.value
[0] = spec
->dc_enable
;
2501 static int cxt5066_olpc_dc_put(struct snd_kcontrol
*kcontrol
,
2502 struct snd_ctl_elem_value
*ucontrol
)
2504 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2505 struct conexant_spec
*spec
= codec
->spec
;
2506 int dc_enable
= !!ucontrol
->value
.integer
.value
[0];
2508 if (dc_enable
== spec
->dc_enable
)
2511 spec
->dc_enable
= dc_enable
;
2513 cxt5066_enable_dc(codec
);
2515 cxt5066_disable_dc(codec
);
2520 static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol
*kcontrol
,
2521 struct snd_ctl_elem_info
*uinfo
)
2523 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias
, uinfo
);
2526 static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol
*kcontrol
,
2527 struct snd_ctl_elem_value
*ucontrol
)
2529 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2530 struct conexant_spec
*spec
= codec
->spec
;
2531 ucontrol
->value
.enumerated
.item
[0] = spec
->dc_input_bias
;
2535 static int cxt5066_olpc_dc_bias_enum_put(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 const struct hda_input_mux
*imux
= &cxt5066_analog_mic_boost
;
2543 idx
= ucontrol
->value
.enumerated
.item
[0];
2544 if (idx
>= imux
->num_items
)
2545 idx
= imux
->num_items
- 1;
2547 spec
->dc_input_bias
= idx
;
2548 if (spec
->dc_enable
)
2549 cxt5066_set_olpc_dc_bias(codec
);
2553 static void cxt5066_olpc_capture_prepare(struct hda_codec
*codec
)
2555 struct conexant_spec
*spec
= codec
->spec
;
2556 /* mark as recording and configure the microphone widget so that the
2557 * recording LED comes on. */
2558 spec
->recording
= 1;
2559 cxt5066_olpc_select_mic(codec
);
2562 static void cxt5066_olpc_capture_cleanup(struct hda_codec
*codec
)
2564 struct conexant_spec
*spec
= codec
->spec
;
2565 const struct hda_verb disable_mics
[] = {
2566 /* disable external mic, port B */
2567 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2569 /* disble internal mic, port C */
2570 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2572 /* disable DC capture, port F */
2573 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2577 snd_hda_sequence_write(codec
, disable_mics
);
2578 spec
->recording
= 0;
2581 static void conexant_check_dig_outs(struct hda_codec
*codec
,
2582 const hda_nid_t
*dig_pins
,
2585 struct conexant_spec
*spec
= codec
->spec
;
2586 hda_nid_t
*nid_loc
= &spec
->multiout
.dig_out_nid
;
2589 for (i
= 0; i
< num_pins
; i
++, dig_pins
++) {
2590 unsigned int cfg
= snd_hda_codec_get_pincfg(codec
, *dig_pins
);
2591 if (get_defcfg_connect(cfg
) == AC_JACK_PORT_NONE
)
2593 if (snd_hda_get_connections(codec
, *dig_pins
, nid_loc
, 1) != 1)
2595 if (spec
->slave_dig_outs
[0])
2598 nid_loc
= spec
->slave_dig_outs
;
2602 static const struct hda_input_mux cxt5066_capture_source
= {
2612 static const struct hda_bind_ctls cxt5066_bind_capture_vol_others
= {
2613 .ops
= &snd_hda_bind_vol
,
2615 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT
),
2616 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT
),
2621 static const struct hda_bind_ctls cxt5066_bind_capture_sw_others
= {
2622 .ops
= &snd_hda_bind_sw
,
2624 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT
),
2625 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT
),
2630 static const struct snd_kcontrol_new cxt5066_mixer_master
[] = {
2631 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT
),
2635 static const struct snd_kcontrol_new cxt5066_mixer_master_olpc
[] = {
2637 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2638 .name
= "Master Playback Volume",
2639 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
2640 SNDRV_CTL_ELEM_ACCESS_TLV_READ
|
2641 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
,
2642 .subdevice
= HDA_SUBDEV_AMP_FLAG
,
2643 .info
= snd_hda_mixer_amp_volume_info
,
2644 .get
= snd_hda_mixer_amp_volume_get
,
2645 .put
= snd_hda_mixer_amp_volume_put
,
2646 .tlv
= { .c
= snd_hda_mixer_amp_tlv
},
2647 /* offset by 28 volume steps to limit minimum gain to -46dB */
2649 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT
, 28),
2654 static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc
[] = {
2656 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2657 .name
= "DC Mode Enable Switch",
2658 .info
= snd_ctl_boolean_mono_info
,
2659 .get
= cxt5066_olpc_dc_get
,
2660 .put
= cxt5066_olpc_dc_put
,
2663 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2664 .name
= "DC Input Bias Enum",
2665 .info
= cxt5066_olpc_dc_bias_enum_info
,
2666 .get
= cxt5066_olpc_dc_bias_enum_get
,
2667 .put
= cxt5066_olpc_dc_bias_enum_put
,
2672 static const struct snd_kcontrol_new cxt5066_mixers
[] = {
2674 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2675 .name
= "Master Playback Switch",
2676 .info
= cxt_eapd_info
,
2677 .get
= cxt_eapd_get
,
2678 .put
= cxt5066_hp_master_sw_put
,
2679 .private_value
= 0x1d,
2683 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2684 .name
= "Analog Mic Boost Capture Enum",
2685 .info
= cxt5066_mic_boost_mux_enum_info
,
2686 .get
= cxt5066_mic_boost_mux_enum_get
,
2687 .put
= cxt5066_mic_boost_mux_enum_put
,
2690 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others
),
2691 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others
),
2695 static const struct snd_kcontrol_new cxt5066_vostro_mixers
[] = {
2697 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2698 .name
= "Internal Mic Boost Capture Enum",
2699 .info
= cxt5066_mic_boost_mux_enum_info
,
2700 .get
= cxt5066_mic_boost_mux_enum_get
,
2701 .put
= cxt5066_mic_boost_mux_enum_put
,
2702 .private_value
= 0x23 | 0x100,
2707 static const struct hda_verb cxt5066_init_verbs
[] = {
2708 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
}, /* Port B */
2709 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
}, /* Port C */
2710 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
}, /* Port F */
2711 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
}, /* Port E */
2714 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
2715 {0x1f, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2718 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
2719 {0x19, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2721 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
2722 {0x1c, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2725 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
2727 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2728 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x50},
2729 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
2730 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2) | 0x50},
2731 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
2732 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
2734 /* no digital microphone support yet */
2735 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2737 /* Audio input selector */
2738 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
| 0x3},
2740 /* SPDIF route: PCM */
2741 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x0},
2742 {0x22, AC_VERB_SET_CONNECT_SEL
, 0x0},
2744 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
2745 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
2748 {0x1d, AC_VERB_SET_EAPD_BTLENABLE
, 0x2}, /* default on */
2750 /* not handling these yet */
2751 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, 0},
2752 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, 0},
2753 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, 0},
2754 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, 0},
2755 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
, 0},
2756 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, 0},
2757 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
, 0},
2758 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, 0},
2762 static const struct hda_verb cxt5066_init_verbs_olpc
[] = {
2763 /* Port A: headphones */
2764 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
2765 {0x19, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2767 /* Port B: external microphone */
2768 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2770 /* Port C: internal microphone */
2771 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2773 /* Port D: unused */
2774 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2776 /* Port E: unused, but has primary EAPD */
2777 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2778 {0x1d, AC_VERB_SET_EAPD_BTLENABLE
, 0x2}, /* default on */
2780 /* Port F: external DC input through microphone port */
2781 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2783 /* Port G: internal speakers */
2784 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
2785 {0x1f, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2788 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
2791 {0x11, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_MUTE
},
2793 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x50},
2794 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
2795 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
2796 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
2797 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
2798 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
2799 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
2800 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
2801 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
2802 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
2803 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
2804 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
2806 /* Disable digital microphone port */
2807 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2809 /* Audio input selectors */
2810 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
| 0x3},
2811 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_MUTE
},
2814 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2815 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2817 /* enable unsolicited events for Port A and B */
2818 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_HP_EVENT
},
2819 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_MIC_EVENT
},
2823 static const struct hda_verb cxt5066_init_verbs_vostro
[] = {
2824 /* Port A: headphones */
2825 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2826 {0x19, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2828 /* Port B: external microphone */
2829 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2831 /* Port C: unused */
2832 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2834 /* Port D: unused */
2835 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2837 /* Port E: unused, but has primary EAPD */
2838 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2839 {0x1d, AC_VERB_SET_EAPD_BTLENABLE
, 0x2}, /* default on */
2841 /* Port F: unused */
2842 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2844 /* Port G: internal speakers */
2845 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
2846 {0x1f, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2849 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
2852 {0x11, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_MUTE
},
2854 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
2855 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
2856 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
2857 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
2858 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
2859 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
2860 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
2861 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
2862 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
2863 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
2864 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
2865 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
2867 /* Digital microphone port */
2868 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
},
2870 /* Audio input selectors */
2871 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
| 0x3},
2872 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_MUTE
},
2875 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2876 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2878 /* enable unsolicited events for Port A and B */
2879 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_HP_EVENT
},
2880 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_MIC_EVENT
},
2884 static const struct hda_verb cxt5066_init_verbs_ideapad
[] = {
2885 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
}, /* Port B */
2886 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_VREF80
}, /* Port C */
2887 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
}, /* Port F */
2888 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
}, /* Port E */
2891 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
2892 {0x1f, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2895 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
2896 {0x19, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2898 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
},
2899 {0x1c, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2902 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
2904 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2905 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x50},
2906 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
2907 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2) | 0x50},
2908 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
2909 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
2910 {0x14, AC_VERB_SET_CONNECT_SEL
, 2}, /* default to internal mic */
2912 /* Audio input selector */
2913 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
| 0x2},
2914 {0x17, AC_VERB_SET_CONNECT_SEL
, 1}, /* route ext mic */
2916 /* SPDIF route: PCM */
2917 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x0},
2918 {0x22, AC_VERB_SET_CONNECT_SEL
, 0x0},
2920 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
2921 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
2923 /* internal microphone */
2924 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
}, /* enable internal mic */
2927 {0x1d, AC_VERB_SET_EAPD_BTLENABLE
, 0x2}, /* default on */
2929 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_HP_EVENT
},
2930 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_MIC_EVENT
},
2934 static const struct hda_verb cxt5066_init_verbs_thinkpad
[] = {
2935 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
}, /* Port F */
2936 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
}, /* Port E */
2938 /* Port G: internal speakers */
2939 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
2940 {0x1f, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2942 /* Port A: HP, Amp */
2943 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2944 {0x19, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2946 /* Port B: Mic Dock */
2947 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2950 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2952 /* Port D: HP Dock, Amp */
2953 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0},
2954 {0x1c, AC_VERB_SET_CONNECT_SEL
, 0x00}, /* DAC1 */
2957 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
2959 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2960 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0) | 0x50},
2961 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
2962 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2) | 0x50},
2963 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
2964 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
2965 {0x14, AC_VERB_SET_CONNECT_SEL
, 2}, /* default to internal mic */
2967 /* Audio input selector */
2968 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
| 0x2},
2969 {0x17, AC_VERB_SET_CONNECT_SEL
, 1}, /* route ext mic */
2971 /* SPDIF route: PCM */
2972 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x0},
2973 {0x22, AC_VERB_SET_CONNECT_SEL
, 0x0},
2975 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
2976 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
2978 /* internal microphone */
2979 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
}, /* enable internal mic */
2982 {0x1d, AC_VERB_SET_EAPD_BTLENABLE
, 0x2}, /* default on */
2984 /* enable unsolicited events for Port A, B, C and D */
2985 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_HP_EVENT
},
2986 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_HP_EVENT
},
2987 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_MIC_EVENT
},
2988 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_MIC_EVENT
},
2992 static const struct hda_verb cxt5066_init_verbs_portd_lo
[] = {
2993 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
},
2998 static const struct hda_verb cxt5066_init_verbs_hp_laptop
[] = {
2999 {0x14, AC_VERB_SET_CONNECT_SEL
, 0x0},
3000 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_HP_EVENT
},
3001 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| CONEXANT_MIC_EVENT
},
3005 /* initialize jack-sensing, too */
3006 static int cxt5066_init(struct hda_codec
*codec
)
3008 snd_printdd("CXT5066: init\n");
3009 conexant_init(codec
);
3010 if (codec
->patch_ops
.unsol_event
) {
3011 cxt5066_hp_automute(codec
);
3012 cxt5066_automic(codec
);
3014 cxt5066_set_mic_boost(codec
);
3018 static int cxt5066_olpc_init(struct hda_codec
*codec
)
3020 struct conexant_spec
*spec
= codec
->spec
;
3021 snd_printdd("CXT5066: init\n");
3022 conexant_init(codec
);
3023 cxt5066_hp_automute(codec
);
3024 if (!spec
->dc_enable
) {
3025 cxt5066_set_mic_boost(codec
);
3026 cxt5066_olpc_automic(codec
);
3028 cxt5066_enable_dc(codec
);
3034 CXT5066_LAPTOP
, /* Laptops w/ EAPD support */
3035 CXT5066_DELL_LAPTOP
, /* Dell Laptop */
3036 CXT5066_OLPC_XO_1_5
, /* OLPC XO 1.5 */
3037 CXT5066_DELL_VOSTRO
, /* Dell Vostro 1015i */
3038 CXT5066_IDEAPAD
, /* Lenovo IdeaPad U150 */
3039 CXT5066_THINKPAD
, /* Lenovo ThinkPad T410s, others? */
3040 CXT5066_ASUS
, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
3041 CXT5066_HP_LAPTOP
, /* HP Laptop */
3045 static const char * const cxt5066_models
[CXT5066_MODELS
] = {
3046 [CXT5066_LAPTOP
] = "laptop",
3047 [CXT5066_DELL_LAPTOP
] = "dell-laptop",
3048 [CXT5066_OLPC_XO_1_5
] = "olpc-xo-1_5",
3049 [CXT5066_DELL_VOSTRO
] = "dell-vostro",
3050 [CXT5066_IDEAPAD
] = "ideapad",
3051 [CXT5066_THINKPAD
] = "thinkpad",
3052 [CXT5066_ASUS
] = "asus",
3053 [CXT5066_HP_LAPTOP
] = "hp-laptop",
3056 static const struct snd_pci_quirk cxt5066_cfg_tbl
[] = {
3057 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD
),
3058 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO
),
3059 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD
),
3060 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO
),
3061 SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO
),
3062 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD
),
3063 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD
),
3064 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD
),
3065 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP
),
3066 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS
),
3067 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS
),
3068 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS
),
3069 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD
),
3070 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5
),
3071 SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5
),
3072 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
3074 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5
),
3075 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD
),
3076 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD
),
3077 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS
),
3078 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD
),
3079 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD
),
3080 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD
),
3081 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS
),
3082 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD
), /* Fallback for Lenovos without dock mic */
3086 static int patch_cxt5066(struct hda_codec
*codec
)
3088 struct conexant_spec
*spec
;
3091 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3096 codec
->patch_ops
= conexant_patch_ops
;
3097 codec
->patch_ops
.init
= conexant_init
;
3099 spec
->dell_automute
= 0;
3100 spec
->multiout
.max_channels
= 2;
3101 spec
->multiout
.num_dacs
= ARRAY_SIZE(cxt5066_dac_nids
);
3102 spec
->multiout
.dac_nids
= cxt5066_dac_nids
;
3103 conexant_check_dig_outs(codec
, cxt5066_digout_pin_nids
,
3104 ARRAY_SIZE(cxt5066_digout_pin_nids
));
3105 spec
->num_adc_nids
= 1;
3106 spec
->adc_nids
= cxt5066_adc_nids
;
3107 spec
->capsrc_nids
= cxt5066_capsrc_nids
;
3108 spec
->input_mux
= &cxt5066_capture_source
;
3110 spec
->port_d_mode
= PIN_HP
;
3112 spec
->num_init_verbs
= 1;
3113 spec
->init_verbs
[0] = cxt5066_init_verbs
;
3114 spec
->num_channel_mode
= ARRAY_SIZE(cxt5066_modes
);
3115 spec
->channel_mode
= cxt5066_modes
;
3117 spec
->cur_adc_idx
= 0;
3119 set_beep_amp(spec
, 0x13, 0, HDA_OUTPUT
);
3121 board_config
= snd_hda_check_board_config(codec
, CXT5066_MODELS
,
3122 cxt5066_models
, cxt5066_cfg_tbl
);
3123 switch (board_config
) {
3125 case CXT5066_LAPTOP
:
3126 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixer_master
;
3127 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixers
;
3129 case CXT5066_DELL_LAPTOP
:
3130 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixer_master
;
3131 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixers
;
3133 spec
->port_d_mode
= PIN_OUT
;
3134 spec
->init_verbs
[spec
->num_init_verbs
] = cxt5066_init_verbs_portd_lo
;
3135 spec
->num_init_verbs
++;
3136 spec
->dell_automute
= 1;
3139 case CXT5066_HP_LAPTOP
:
3140 codec
->patch_ops
.init
= cxt5066_init
;
3141 codec
->patch_ops
.unsol_event
= cxt5066_unsol_event
;
3142 spec
->init_verbs
[spec
->num_init_verbs
] =
3143 cxt5066_init_verbs_hp_laptop
;
3144 spec
->num_init_verbs
++;
3145 spec
->hp_laptop
= board_config
== CXT5066_HP_LAPTOP
;
3146 spec
->asus
= board_config
== CXT5066_ASUS
;
3147 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixer_master
;
3148 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixers
;
3150 if (board_config
== CXT5066_HP_LAPTOP
)
3151 spec
->multiout
.dig_out_nid
= 0;
3152 /* input source automatically selected */
3153 spec
->input_mux
= NULL
;
3154 spec
->port_d_mode
= 0;
3155 spec
->mic_boost
= 3; /* default 30dB gain */
3158 case CXT5066_OLPC_XO_1_5
:
3159 codec
->patch_ops
.init
= cxt5066_olpc_init
;
3160 codec
->patch_ops
.unsol_event
= cxt5066_olpc_unsol_event
;
3161 spec
->init_verbs
[0] = cxt5066_init_verbs_olpc
;
3162 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixer_master_olpc
;
3163 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixer_olpc_dc
;
3164 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixers
;
3165 spec
->port_d_mode
= 0;
3166 spec
->mic_boost
= 3; /* default 30dB gain */
3169 spec
->multiout
.dig_out_nid
= 0;
3171 /* input source automatically selected */
3172 spec
->input_mux
= NULL
;
3174 /* our capture hooks which allow us to turn on the microphone LED
3175 * at the right time */
3176 spec
->capture_prepare
= cxt5066_olpc_capture_prepare
;
3177 spec
->capture_cleanup
= cxt5066_olpc_capture_cleanup
;
3179 case CXT5066_DELL_VOSTRO
:
3180 codec
->patch_ops
.init
= cxt5066_init
;
3181 codec
->patch_ops
.unsol_event
= cxt5066_unsol_event
;
3182 spec
->init_verbs
[0] = cxt5066_init_verbs_vostro
;
3183 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixer_master_olpc
;
3184 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixers
;
3185 spec
->mixers
[spec
->num_mixers
++] = cxt5066_vostro_mixers
;
3186 spec
->port_d_mode
= 0;
3187 spec
->dell_vostro
= 1;
3188 spec
->mic_boost
= 3; /* default 30dB gain */
3191 spec
->multiout
.dig_out_nid
= 0;
3193 /* input source automatically selected */
3194 spec
->input_mux
= NULL
;
3196 case CXT5066_IDEAPAD
:
3197 codec
->patch_ops
.init
= cxt5066_init
;
3198 codec
->patch_ops
.unsol_event
= cxt5066_unsol_event
;
3199 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixer_master
;
3200 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixers
;
3201 spec
->init_verbs
[0] = cxt5066_init_verbs_ideapad
;
3202 spec
->port_d_mode
= 0;
3204 spec
->mic_boost
= 2; /* default 20dB gain */
3207 spec
->multiout
.dig_out_nid
= 0;
3209 /* input source automatically selected */
3210 spec
->input_mux
= NULL
;
3212 case CXT5066_THINKPAD
:
3213 codec
->patch_ops
.init
= cxt5066_init
;
3214 codec
->patch_ops
.unsol_event
= cxt5066_unsol_event
;
3215 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixer_master
;
3216 spec
->mixers
[spec
->num_mixers
++] = cxt5066_mixers
;
3217 spec
->init_verbs
[0] = cxt5066_init_verbs_thinkpad
;
3219 spec
->port_d_mode
= PIN_OUT
;
3220 spec
->mic_boost
= 2; /* default 20dB gain */
3223 spec
->multiout
.dig_out_nid
= 0;
3225 /* input source automatically selected */
3226 spec
->input_mux
= NULL
;
3231 snd_hda_attach_beep_device(codec
, spec
->beep_amp
);
3237 * Automatic parser for CX20641 & co
3240 static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
3241 struct hda_codec
*codec
,
3242 unsigned int stream_tag
,
3243 unsigned int format
,
3244 struct snd_pcm_substream
*substream
)
3246 struct conexant_spec
*spec
= codec
->spec
;
3247 hda_nid_t adc
= spec
->imux_adcs
[spec
->cur_mux
[0]];
3248 if (spec
->adc_switching
) {
3249 spec
->cur_adc
= adc
;
3250 spec
->cur_adc_stream_tag
= stream_tag
;
3251 spec
->cur_adc_format
= format
;
3253 snd_hda_codec_setup_stream(codec
, adc
, stream_tag
, 0, format
);
3257 static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
3258 struct hda_codec
*codec
,
3259 struct snd_pcm_substream
*substream
)
3261 struct conexant_spec
*spec
= codec
->spec
;
3262 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
3267 static const struct hda_pcm_stream cx_auto_pcm_analog_capture
= {
3271 .nid
= 0, /* fill later */
3273 .prepare
= cx_auto_capture_pcm_prepare
,
3274 .cleanup
= cx_auto_capture_pcm_cleanup
3278 static const hda_nid_t cx_auto_adc_nids
[] = { 0x14 };
3280 /* get the connection index of @nid in the widget @mux */
3281 static int get_connection_index(struct hda_codec
*codec
, hda_nid_t mux
,
3284 hda_nid_t conn
[HDA_MAX_NUM_INPUTS
];
3287 nums
= snd_hda_get_connections(codec
, mux
, conn
, ARRAY_SIZE(conn
));
3288 for (i
= 0; i
< nums
; i
++)
3294 /* get an unassigned DAC from the given list.
3295 * Return the nid if found and reduce the DAC list, or return zero if
3298 static hda_nid_t
get_unassigned_dac(struct hda_codec
*codec
, hda_nid_t pin
,
3299 hda_nid_t
*dacs
, int *num_dacs
)
3301 int i
, nums
= *num_dacs
;
3304 for (i
= 0; i
< nums
; i
++) {
3305 if (get_connection_index(codec
, pin
, dacs
[i
]) >= 0) {
3313 memmove(dacs
, dacs
+ 1, nums
* sizeof(hda_nid_t
));
3318 #define MAX_AUTO_DACS 5
3320 /* fill analog DAC list from the widget tree */
3321 static int fill_cx_auto_dacs(struct hda_codec
*codec
, hda_nid_t
*dacs
)
3323 hda_nid_t nid
, end_nid
;
3326 end_nid
= codec
->start_nid
+ codec
->num_nodes
;
3327 for (nid
= codec
->start_nid
; nid
< end_nid
; nid
++) {
3328 unsigned int wcaps
= get_wcaps(codec
, nid
);
3329 unsigned int type
= get_wcaps_type(wcaps
);
3330 if (type
== AC_WID_AUD_OUT
&& !(wcaps
& AC_WCAP_DIGITAL
)) {
3332 if (nums
>= MAX_AUTO_DACS
)
3339 /* fill pin_dac_pair list from the pin and dac list */
3340 static int fill_dacs_for_pins(struct hda_codec
*codec
, hda_nid_t
*pins
,
3341 int num_pins
, hda_nid_t
*dacs
, int *rest
,
3342 struct pin_dac_pair
*filled
, int type
)
3347 for (i
= 0; i
< num_pins
; i
++) {
3348 filled
[nums
].pin
= pins
[i
];
3349 filled
[nums
].type
= type
;
3350 filled
[nums
].dac
= get_unassigned_dac(codec
, pins
[i
], dacs
, rest
);
3356 /* parse analog output paths */
3357 static void cx_auto_parse_output(struct hda_codec
*codec
)
3359 struct conexant_spec
*spec
= codec
->spec
;
3360 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3361 hda_nid_t dacs
[MAX_AUTO_DACS
];
3362 int i
, j
, nums
, rest
;
3364 rest
= fill_cx_auto_dacs(codec
, dacs
);
3365 /* parse all analog output pins */
3366 nums
= fill_dacs_for_pins(codec
, cfg
->line_out_pins
, cfg
->line_outs
,
3367 dacs
, &rest
, spec
->dac_info
,
3369 nums
+= fill_dacs_for_pins(codec
, cfg
->hp_pins
, cfg
->hp_outs
,
3370 dacs
, &rest
, spec
->dac_info
+ nums
,
3372 nums
+= fill_dacs_for_pins(codec
, cfg
->speaker_pins
, cfg
->speaker_outs
,
3373 dacs
, &rest
, spec
->dac_info
+ nums
,
3374 AUTO_PIN_SPEAKER_OUT
);
3375 spec
->dac_info_filled
= nums
;
3376 /* fill multiout struct */
3377 for (i
= 0; i
< nums
; i
++) {
3378 hda_nid_t dac
= spec
->dac_info
[i
].dac
;
3381 switch (spec
->dac_info
[i
].type
) {
3382 case AUTO_PIN_LINE_OUT
:
3383 spec
->private_dac_nids
[spec
->multiout
.num_dacs
] = dac
;
3384 spec
->multiout
.num_dacs
++;
3386 case AUTO_PIN_HP_OUT
:
3387 case AUTO_PIN_SPEAKER_OUT
:
3388 if (!spec
->multiout
.hp_nid
) {
3389 spec
->multiout
.hp_nid
= dac
;
3392 for (j
= 0; j
< ARRAY_SIZE(spec
->multiout
.extra_out_nid
); j
++)
3393 if (!spec
->multiout
.extra_out_nid
[j
]) {
3394 spec
->multiout
.extra_out_nid
[j
] = dac
;
3400 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3401 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3403 if (cfg
->hp_outs
> 0)
3404 spec
->auto_mute
= 1;
3405 spec
->vmaster_nid
= spec
->private_dac_nids
[0];
3408 static void cx_auto_turn_eapd(struct hda_codec
*codec
, int num_pins
,
3409 hda_nid_t
*pins
, bool on
);
3411 /* auto-mute/unmute speaker and line outs according to headphone jack */
3412 static void cx_auto_hp_automute(struct hda_codec
*codec
)
3414 struct conexant_spec
*spec
= codec
->spec
;
3415 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3418 if (!spec
->auto_mute
)
3421 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
3422 if (snd_hda_jack_detect(codec
, cfg
->hp_pins
[i
])) {
3427 cx_auto_turn_eapd(codec
, cfg
->hp_outs
, cfg
->hp_pins
, present
);
3428 for (i
= 0; i
< cfg
->line_outs
; i
++) {
3429 snd_hda_codec_write(codec
, cfg
->line_out_pins
[i
], 0,
3430 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3431 present
? 0 : PIN_OUT
);
3433 cx_auto_turn_eapd(codec
, cfg
->line_outs
, cfg
->line_out_pins
, !present
);
3434 for (i
= 0; !present
&& i
< cfg
->line_outs
; i
++)
3435 if (snd_hda_jack_detect(codec
, cfg
->line_out_pins
[i
]))
3437 for (i
= 0; i
< cfg
->speaker_outs
; i
++) {
3438 snd_hda_codec_write(codec
, cfg
->speaker_pins
[i
], 0,
3439 AC_VERB_SET_PIN_WIDGET_CONTROL
,
3440 present
? 0 : PIN_OUT
);
3442 cx_auto_turn_eapd(codec
, cfg
->speaker_outs
, cfg
->speaker_pins
, !present
);
3445 static int cx_auto_mux_enum_info(struct snd_kcontrol
*kcontrol
,
3446 struct snd_ctl_elem_info
*uinfo
)
3448 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3449 struct conexant_spec
*spec
= codec
->spec
;
3451 return snd_hda_input_mux_info(&spec
->private_imux
, uinfo
);
3454 static int cx_auto_mux_enum_get(struct snd_kcontrol
*kcontrol
,
3455 struct snd_ctl_elem_value
*ucontrol
)
3457 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3458 struct conexant_spec
*spec
= codec
->spec
;
3460 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[0];
3464 /* look for the route the given pin from mux and return the index;
3465 * if do_select is set, actually select the route.
3467 static int __select_input_connection(struct hda_codec
*codec
, hda_nid_t mux
,
3468 hda_nid_t pin
, hda_nid_t
*srcp
,
3469 bool do_select
, int depth
)
3471 hda_nid_t conn
[HDA_MAX_NUM_INPUTS
];
3474 switch (get_wcaps_type(get_wcaps(codec
, mux
))) {
3476 case AC_WID_AUD_SEL
:
3477 case AC_WID_AUD_MIX
:
3483 nums
= snd_hda_get_connections(codec
, mux
, conn
, ARRAY_SIZE(conn
));
3484 for (i
= 0; i
< nums
; i
++)
3485 if (conn
[i
] == pin
) {
3487 snd_hda_codec_write(codec
, mux
, 0,
3488 AC_VERB_SET_CONNECT_SEL
, i
);
3496 for (i
= 0; i
< nums
; i
++) {
3497 int ret
= __select_input_connection(codec
, conn
[i
], pin
, srcp
,
3501 snd_hda_codec_write(codec
, mux
, 0,
3502 AC_VERB_SET_CONNECT_SEL
, i
);
3509 static void select_input_connection(struct hda_codec
*codec
, hda_nid_t mux
,
3512 __select_input_connection(codec
, mux
, pin
, NULL
, true, 0);
3515 static int get_input_connection(struct hda_codec
*codec
, hda_nid_t mux
,
3518 return __select_input_connection(codec
, mux
, pin
, NULL
, false, 0);
3521 static int cx_auto_mux_enum_update(struct hda_codec
*codec
,
3522 const struct hda_input_mux
*imux
,
3525 struct conexant_spec
*spec
= codec
->spec
;
3528 if (!imux
->num_items
)
3530 if (idx
>= imux
->num_items
)
3531 idx
= imux
->num_items
- 1;
3532 if (spec
->cur_mux
[0] == idx
)
3534 adc
= spec
->imux_adcs
[idx
];
3535 select_input_connection(codec
, spec
->imux_adcs
[idx
],
3536 spec
->imux_pins
[idx
]);
3537 if (spec
->cur_adc
&& spec
->cur_adc
!= adc
) {
3538 /* stream is running, let's swap the current ADC */
3539 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
3540 spec
->cur_adc
= adc
;
3541 snd_hda_codec_setup_stream(codec
, adc
,
3542 spec
->cur_adc_stream_tag
, 0,
3543 spec
->cur_adc_format
);
3545 spec
->cur_mux
[0] = idx
;
3549 static int cx_auto_mux_enum_put(struct snd_kcontrol
*kcontrol
,
3550 struct snd_ctl_elem_value
*ucontrol
)
3552 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3553 struct conexant_spec
*spec
= codec
->spec
;
3555 return cx_auto_mux_enum_update(codec
, &spec
->private_imux
,
3556 ucontrol
->value
.enumerated
.item
[0]);
3559 static const struct snd_kcontrol_new cx_auto_capture_mixers
[] = {
3561 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3562 .name
= "Capture Source",
3563 .info
= cx_auto_mux_enum_info
,
3564 .get
= cx_auto_mux_enum_get
,
3565 .put
= cx_auto_mux_enum_put
3570 /* automatic switch internal and external mic */
3571 static void cx_auto_automic(struct hda_codec
*codec
)
3573 struct conexant_spec
*spec
= codec
->spec
;
3574 int ext_idx
= spec
->auto_mic_ext
;
3576 if (!spec
->auto_mic
)
3578 if (snd_hda_jack_detect(codec
, spec
->imux_pins
[ext_idx
]))
3579 cx_auto_mux_enum_update(codec
, &spec
->private_imux
, ext_idx
);
3581 cx_auto_mux_enum_update(codec
, &spec
->private_imux
, !ext_idx
);
3584 static void cx_auto_unsol_event(struct hda_codec
*codec
, unsigned int res
)
3586 int nid
= (res
& AC_UNSOL_RES_SUBTAG
) >> 20;
3587 switch (res
>> 26) {
3588 case CONEXANT_HP_EVENT
:
3589 cx_auto_hp_automute(codec
);
3590 snd_hda_input_jack_report(codec
, nid
);
3592 case CONEXANT_MIC_EVENT
:
3593 cx_auto_automic(codec
);
3594 snd_hda_input_jack_report(codec
, nid
);
3599 /* return true if it's an internal-mic pin */
3600 static int is_int_mic(struct hda_codec
*codec
, hda_nid_t pin
)
3602 unsigned int def_conf
= snd_hda_codec_get_pincfg(codec
, pin
);
3603 return get_defcfg_device(def_conf
) == AC_JACK_MIC_IN
&&
3604 snd_hda_get_input_pin_attr(def_conf
) == INPUT_PIN_ATTR_INT
;
3607 /* return true if it's an external-mic pin */
3608 static int is_ext_mic(struct hda_codec
*codec
, hda_nid_t pin
)
3610 unsigned int def_conf
= snd_hda_codec_get_pincfg(codec
, pin
);
3611 return get_defcfg_device(def_conf
) == AC_JACK_MIC_IN
&&
3612 snd_hda_get_input_pin_attr(def_conf
) >= INPUT_PIN_ATTR_NORMAL
&&
3613 (snd_hda_query_pin_caps(codec
, pin
) & AC_PINCAP_PRES_DETECT
);
3616 /* check whether the pin config is suitable for auto-mic switching;
3617 * auto-mic is enabled only when one int-mic and one-ext mic exist
3619 static void cx_auto_check_auto_mic(struct hda_codec
*codec
)
3621 struct conexant_spec
*spec
= codec
->spec
;
3623 if (is_ext_mic(codec
, spec
->imux_pins
[0]) &&
3624 is_int_mic(codec
, spec
->imux_pins
[1])) {
3626 spec
->auto_mic_ext
= 0;
3629 if (is_int_mic(codec
, spec
->imux_pins
[0]) &&
3630 is_ext_mic(codec
, spec
->imux_pins
[1])) {
3632 spec
->auto_mic_ext
= 1;
3637 static void cx_auto_parse_input(struct hda_codec
*codec
)
3639 struct conexant_spec
*spec
= codec
->spec
;
3640 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3641 struct hda_input_mux
*imux
;
3644 imux
= &spec
->private_imux
;
3645 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3646 for (j
= 0; j
< spec
->num_adc_nids
; j
++) {
3647 hda_nid_t adc
= spec
->adc_nids
[j
];
3648 int idx
= get_input_connection(codec
, adc
,
3649 cfg
->inputs
[i
].pin
);
3652 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
3653 spec
->imux_cfg_idx
[imux
->num_items
] = i
;
3654 spec
->imux_adcs
[imux
->num_items
] = adc
;
3655 spec
->imux_pins
[imux
->num_items
] =
3657 snd_hda_add_imux_item(imux
, label
, idx
, NULL
);
3662 if (imux
->num_items
== 2 && cfg
->num_inputs
== 2)
3663 cx_auto_check_auto_mic(codec
);
3664 if (imux
->num_items
> 1 && !spec
->auto_mic
) {
3665 for (i
= 1; i
< imux
->num_items
; i
++) {
3666 if (spec
->imux_adcs
[i
] != spec
->imux_adcs
[0]) {
3667 spec
->adc_switching
= 1;
3674 /* get digital-input audio widget corresponding to the given pin */
3675 static hda_nid_t
cx_auto_get_dig_in(struct hda_codec
*codec
, hda_nid_t pin
)
3677 hda_nid_t nid
, end_nid
;
3679 end_nid
= codec
->start_nid
+ codec
->num_nodes
;
3680 for (nid
= codec
->start_nid
; nid
< end_nid
; nid
++) {
3681 unsigned int wcaps
= get_wcaps(codec
, nid
);
3682 unsigned int type
= get_wcaps_type(wcaps
);
3683 if (type
== AC_WID_AUD_IN
&& (wcaps
& AC_WCAP_DIGITAL
)) {
3684 if (get_connection_index(codec
, nid
, pin
) >= 0)
3691 static void cx_auto_parse_digital(struct hda_codec
*codec
)
3693 struct conexant_spec
*spec
= codec
->spec
;
3694 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3697 if (cfg
->dig_outs
&&
3698 snd_hda_get_connections(codec
, cfg
->dig_out_pins
[0], &nid
, 1) == 1)
3699 spec
->multiout
.dig_out_nid
= nid
;
3700 if (cfg
->dig_in_pin
)
3701 spec
->dig_in_nid
= cx_auto_get_dig_in(codec
, cfg
->dig_in_pin
);
3704 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3705 static void cx_auto_parse_beep(struct hda_codec
*codec
)
3707 struct conexant_spec
*spec
= codec
->spec
;
3708 hda_nid_t nid
, end_nid
;
3710 end_nid
= codec
->start_nid
+ codec
->num_nodes
;
3711 for (nid
= codec
->start_nid
; nid
< end_nid
; nid
++)
3712 if (get_wcaps_type(get_wcaps(codec
, nid
)) == AC_WID_BEEP
) {
3713 set_beep_amp(spec
, nid
, 0, HDA_OUTPUT
);
3718 #define cx_auto_parse_beep(codec)
3721 static int cx_auto_parse_auto_config(struct hda_codec
*codec
)
3723 struct conexant_spec
*spec
= codec
->spec
;
3726 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3730 cx_auto_parse_output(codec
);
3731 cx_auto_parse_input(codec
);
3732 cx_auto_parse_digital(codec
);
3733 cx_auto_parse_beep(codec
);
3737 static void cx_auto_turn_eapd(struct hda_codec
*codec
, int num_pins
,
3738 hda_nid_t
*pins
, bool on
)
3741 for (i
= 0; i
< num_pins
; i
++) {
3742 if (snd_hda_query_pin_caps(codec
, pins
[i
]) & AC_PINCAP_EAPD
)
3743 snd_hda_codec_write(codec
, pins
[i
], 0,
3744 AC_VERB_SET_EAPD_BTLENABLE
,
3749 static void select_connection(struct hda_codec
*codec
, hda_nid_t pin
,
3752 int idx
= get_connection_index(codec
, pin
, src
);
3754 snd_hda_codec_write(codec
, pin
, 0,
3755 AC_VERB_SET_CONNECT_SEL
, idx
);
3758 static void mute_outputs(struct hda_codec
*codec
, int num_nids
,
3759 const hda_nid_t
*nids
)
3763 for (i
= 0; i
< num_nids
; i
++) {
3764 hda_nid_t nid
= nids
[i
];
3765 if (!(get_wcaps(codec
, nid
) & AC_WCAP_OUT_AMP
))
3767 if (query_amp_caps(codec
, nid
, HDA_OUTPUT
) & AC_AMPCAP_MUTE
)
3771 snd_hda_codec_write(codec
, nid
, 0,
3772 AC_VERB_SET_AMP_GAIN_MUTE
, val
);
3776 static void cx_auto_init_output(struct hda_codec
*codec
)
3778 struct conexant_spec
*spec
= codec
->spec
;
3779 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3783 mute_outputs(codec
, spec
->multiout
.num_dacs
, spec
->multiout
.dac_nids
);
3784 for (i
= 0; i
< cfg
->hp_outs
; i
++)
3785 snd_hda_codec_write(codec
, cfg
->hp_pins
[i
], 0,
3786 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
);
3787 mute_outputs(codec
, cfg
->hp_outs
, cfg
->hp_pins
);
3788 mute_outputs(codec
, cfg
->line_outs
, cfg
->line_out_pins
);
3789 mute_outputs(codec
, cfg
->speaker_outs
, cfg
->speaker_pins
);
3790 if (spec
->auto_mute
) {
3791 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
3792 snd_hda_codec_write(codec
, cfg
->hp_pins
[i
], 0,
3793 AC_VERB_SET_UNSOLICITED_ENABLE
,
3794 AC_USRSP_EN
| CONEXANT_HP_EVENT
);
3796 cx_auto_hp_automute(codec
);
3798 for (i
= 0; i
< cfg
->line_outs
; i
++)
3799 snd_hda_codec_write(codec
, cfg
->line_out_pins
[i
], 0,
3800 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
3801 for (i
= 0; i
< cfg
->speaker_outs
; i
++)
3802 snd_hda_codec_write(codec
, cfg
->speaker_pins
[i
], 0,
3803 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
3805 cx_auto_turn_eapd(codec
, cfg
->line_outs
, cfg
->line_out_pins
,
3807 cx_auto_turn_eapd(codec
, cfg
->hp_outs
, cfg
->hp_pins
,
3809 cx_auto_turn_eapd(codec
, cfg
->speaker_outs
, cfg
->speaker_pins
,
3813 for (i
= 0; i
< spec
->dac_info_filled
; i
++) {
3814 nid
= spec
->dac_info
[i
].dac
;
3816 nid
= spec
->multiout
.dac_nids
[0];
3817 select_connection(codec
, spec
->dac_info
[i
].pin
, nid
);
3821 static void cx_auto_init_input(struct hda_codec
*codec
)
3823 struct conexant_spec
*spec
= codec
->spec
;
3824 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3827 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
3828 hda_nid_t nid
= spec
->adc_nids
[i
];
3829 if (!(get_wcaps(codec
, nid
) & AC_WCAP_IN_AMP
))
3831 if (query_amp_caps(codec
, nid
, HDA_INPUT
) & AC_AMPCAP_MUTE
)
3832 val
= AMP_IN_MUTE(0);
3834 val
= AMP_IN_UNMUTE(0);
3835 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
3839 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3841 if (cfg
->inputs
[i
].type
== AUTO_PIN_MIC
)
3845 snd_hda_codec_write(codec
, cfg
->inputs
[i
].pin
, 0,
3846 AC_VERB_SET_PIN_WIDGET_CONTROL
, type
);
3849 if (spec
->auto_mic
) {
3850 int ext_idx
= spec
->auto_mic_ext
;
3851 snd_hda_codec_write(codec
, cfg
->inputs
[ext_idx
].pin
, 0,
3852 AC_VERB_SET_UNSOLICITED_ENABLE
,
3853 AC_USRSP_EN
| CONEXANT_MIC_EVENT
);
3854 cx_auto_automic(codec
);
3856 select_input_connection(codec
, spec
->imux_adcs
[0],
3857 spec
->imux_pins
[0]);
3861 static void cx_auto_init_digital(struct hda_codec
*codec
)
3863 struct conexant_spec
*spec
= codec
->spec
;
3864 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3866 if (spec
->multiout
.dig_out_nid
)
3867 snd_hda_codec_write(codec
, cfg
->dig_out_pins
[0], 0,
3868 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_OUT
);
3869 if (spec
->dig_in_nid
)
3870 snd_hda_codec_write(codec
, cfg
->dig_in_pin
, 0,
3871 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
3874 static int cx_auto_init(struct hda_codec
*codec
)
3876 /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3877 cx_auto_init_output(codec
);
3878 cx_auto_init_input(codec
);
3879 cx_auto_init_digital(codec
);
3883 static int cx_auto_add_volume_idx(struct hda_codec
*codec
, const char *basename
,
3884 const char *dir
, int cidx
,
3885 hda_nid_t nid
, int hda_dir
, int amp_idx
)
3887 static char name
[32];
3888 static struct snd_kcontrol_new knew
[] = {
3889 HDA_CODEC_VOLUME(name
, 0, 0, 0),
3890 HDA_CODEC_MUTE(name
, 0, 0, 0),
3892 static const char * const sfx
[2] = { "Volume", "Switch" };
3895 for (i
= 0; i
< 2; i
++) {
3896 struct snd_kcontrol
*kctl
;
3897 knew
[i
].private_value
= HDA_COMPOSE_AMP_VAL(nid
, 3, amp_idx
,
3899 knew
[i
].subdevice
= HDA_SUBDEV_AMP_FLAG
;
3900 knew
[i
].index
= cidx
;
3901 snprintf(name
, sizeof(name
), "%s%s %s", basename
, dir
, sfx
[i
]);
3902 kctl
= snd_ctl_new1(&knew
[i
], codec
);
3905 err
= snd_hda_ctl_add(codec
, nid
, kctl
);
3908 if (!(query_amp_caps(codec
, nid
, hda_dir
) & AC_AMPCAP_MUTE
))
3914 #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
3915 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3917 #define cx_auto_add_pb_volume(codec, nid, str, idx) \
3918 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3920 static int try_add_pb_volume(struct hda_codec
*codec
, hda_nid_t dac
,
3921 hda_nid_t pin
, const char *name
, int idx
)
3924 caps
= query_amp_caps(codec
, dac
, HDA_OUTPUT
);
3925 if (caps
& AC_AMPCAP_NUM_STEPS
)
3926 return cx_auto_add_pb_volume(codec
, dac
, name
, idx
);
3927 caps
= query_amp_caps(codec
, pin
, HDA_OUTPUT
);
3928 if (caps
& AC_AMPCAP_NUM_STEPS
)
3929 return cx_auto_add_pb_volume(codec
, pin
, name
, idx
);
3933 static int cx_auto_build_output_controls(struct hda_codec
*codec
)
3935 struct conexant_spec
*spec
= codec
->spec
;
3937 int num_line
= 0, num_hp
= 0, num_spk
= 0;
3938 static const char * const texts
[3] = { "Front", "Surround", "CLFE" };
3940 if (spec
->dac_info_filled
== 1)
3941 return try_add_pb_volume(codec
, spec
->dac_info
[0].dac
,
3942 spec
->dac_info
[0].pin
,
3945 for (i
= 0; i
< spec
->dac_info_filled
; i
++) {
3948 if (!spec
->dac_info
[i
].dac
)
3950 type
= spec
->dac_info
[i
].type
;
3951 if (type
== AUTO_PIN_LINE_OUT
)
3952 type
= spec
->autocfg
.line_out_type
;
3954 case AUTO_PIN_LINE_OUT
:
3956 label
= texts
[num_line
++];
3959 case AUTO_PIN_HP_OUT
:
3960 label
= "Headphone";
3963 case AUTO_PIN_SPEAKER_OUT
:
3968 err
= try_add_pb_volume(codec
, spec
->dac_info
[i
].dac
,
3969 spec
->dac_info
[i
].pin
,
3977 static int cx_auto_add_capture_volume(struct hda_codec
*codec
, hda_nid_t nid
,
3978 const char *label
, const char *pfx
,
3981 struct conexant_spec
*spec
= codec
->spec
;
3984 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
3985 hda_nid_t adc_nid
= spec
->adc_nids
[i
];
3986 int idx
= get_input_connection(codec
, adc_nid
, nid
);
3989 return cx_auto_add_volume_idx(codec
, label
, pfx
,
3990 cidx
, adc_nid
, HDA_INPUT
, idx
);
3995 static int cx_auto_add_boost_volume(struct hda_codec
*codec
, int idx
,
3996 const char *label
, int cidx
)
3998 struct conexant_spec
*spec
= codec
->spec
;
4002 nid
= spec
->imux_pins
[idx
];
4003 if (get_wcaps(codec
, nid
) & AC_WCAP_IN_AMP
)
4004 return cx_auto_add_volume(codec
, label
, " Boost", cidx
,
4006 con
= __select_input_connection(codec
, spec
->imux_adcs
[idx
], nid
, &mux
,
4010 if (get_wcaps(codec
, mux
) & AC_WCAP_OUT_AMP
)
4011 return cx_auto_add_volume(codec
, label
, " Boost", 0,
4016 static int cx_auto_build_input_controls(struct hda_codec
*codec
)
4018 struct conexant_spec
*spec
= codec
->spec
;
4019 struct hda_input_mux
*imux
= &spec
->private_imux
;
4020 const char *prev_label
;
4021 int input_conn
[HDA_MAX_NUM_INPUTS
];
4023 int multi_connection
;
4025 multi_connection
= 0;
4026 for (i
= 0; i
< imux
->num_items
; i
++) {
4027 cidx
= get_input_connection(codec
, spec
->imux_adcs
[i
],
4028 spec
->imux_pins
[i
]);
4029 input_conn
[i
] = (spec
->imux_adcs
[i
] << 8) | cidx
;
4030 if (i
> 0 && input_conn
[i
] != input_conn
[0])
4031 multi_connection
= 1;
4036 for (i
= 0; i
< imux
->num_items
; i
++) {
4037 hda_nid_t nid
= spec
->imux_pins
[i
];
4040 label
= hda_get_autocfg_input_label(codec
, &spec
->autocfg
,
4041 spec
->imux_cfg_idx
[i
]);
4042 if (label
== prev_label
)
4048 err
= cx_auto_add_boost_volume(codec
, i
, label
, cidx
);
4052 if (!multi_connection
) {
4053 err
= cx_auto_add_capture_volume(codec
, nid
,
4054 "Capture", "", cidx
);
4056 err
= cx_auto_add_capture_volume(codec
, nid
,
4057 label
, " Capture", cidx
);
4063 if (spec
->private_imux
.num_items
> 1 && !spec
->auto_mic
) {
4064 err
= snd_hda_add_new_ctls(codec
, cx_auto_capture_mixers
);
4072 static int cx_auto_build_controls(struct hda_codec
*codec
)
4076 err
= cx_auto_build_output_controls(codec
);
4079 err
= cx_auto_build_input_controls(codec
);
4082 return conexant_build_controls(codec
);
4085 static int cx_auto_search_adcs(struct hda_codec
*codec
)
4087 struct conexant_spec
*spec
= codec
->spec
;
4088 hda_nid_t nid
, end_nid
;
4090 end_nid
= codec
->start_nid
+ codec
->num_nodes
;
4091 for (nid
= codec
->start_nid
; nid
< end_nid
; nid
++) {
4092 unsigned int caps
= get_wcaps(codec
, nid
);
4093 if (get_wcaps_type(caps
) != AC_WID_AUD_IN
)
4095 if (caps
& AC_WCAP_DIGITAL
)
4097 if (snd_BUG_ON(spec
->num_adc_nids
>=
4098 ARRAY_SIZE(spec
->private_adc_nids
)))
4100 spec
->private_adc_nids
[spec
->num_adc_nids
++] = nid
;
4102 spec
->adc_nids
= spec
->private_adc_nids
;
4107 static const struct hda_codec_ops cx_auto_patch_ops
= {
4108 .build_controls
= cx_auto_build_controls
,
4109 .build_pcms
= conexant_build_pcms
,
4110 .init
= cx_auto_init
,
4111 .free
= conexant_free
,
4112 .unsol_event
= cx_auto_unsol_event
,
4113 #ifdef CONFIG_SND_HDA_POWER_SAVE
4114 .suspend
= conexant_suspend
,
4116 .reboot_notify
= snd_hda_shutup_pins
,
4119 static int patch_conexant_auto(struct hda_codec
*codec
)
4121 struct conexant_spec
*spec
;
4124 printk(KERN_INFO
"hda_codec: %s: BIOS auto-probing.\n",
4127 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4131 codec
->pin_amp_workaround
= 1;
4132 err
= cx_auto_search_adcs(codec
);
4135 err
= cx_auto_parse_auto_config(codec
);
4141 spec
->capture_stream
= &cx_auto_pcm_analog_capture
;
4142 codec
->patch_ops
= cx_auto_patch_ops
;
4144 snd_hda_attach_beep_device(codec
, spec
->beep_amp
);
4151 static const struct hda_codec_preset snd_hda_preset_conexant
[] = {
4152 { .id
= 0x14f15045, .name
= "CX20549 (Venice)",
4153 .patch
= patch_cxt5045
},
4154 { .id
= 0x14f15047, .name
= "CX20551 (Waikiki)",
4155 .patch
= patch_cxt5047
},
4156 { .id
= 0x14f15051, .name
= "CX20561 (Hermosa)",
4157 .patch
= patch_cxt5051
},
4158 { .id
= 0x14f15066, .name
= "CX20582 (Pebble)",
4159 .patch
= patch_cxt5066
},
4160 { .id
= 0x14f15067, .name
= "CX20583 (Pebble HSF)",
4161 .patch
= patch_cxt5066
},
4162 { .id
= 0x14f15068, .name
= "CX20584",
4163 .patch
= patch_cxt5066
},
4164 { .id
= 0x14f15069, .name
= "CX20585",
4165 .patch
= patch_cxt5066
},
4166 { .id
= 0x14f1506e, .name
= "CX20590",
4167 .patch
= patch_cxt5066
},
4168 { .id
= 0x14f15097, .name
= "CX20631",
4169 .patch
= patch_conexant_auto
},
4170 { .id
= 0x14f15098, .name
= "CX20632",
4171 .patch
= patch_conexant_auto
},
4172 { .id
= 0x14f150a1, .name
= "CX20641",
4173 .patch
= patch_conexant_auto
},
4174 { .id
= 0x14f150a2, .name
= "CX20642",
4175 .patch
= patch_conexant_auto
},
4176 { .id
= 0x14f150ab, .name
= "CX20651",
4177 .patch
= patch_conexant_auto
},
4178 { .id
= 0x14f150ac, .name
= "CX20652",
4179 .patch
= patch_conexant_auto
},
4180 { .id
= 0x14f150b8, .name
= "CX20664",
4181 .patch
= patch_conexant_auto
},
4182 { .id
= 0x14f150b9, .name
= "CX20665",
4183 .patch
= patch_conexant_auto
},
4187 MODULE_ALIAS("snd-hda-codec-id:14f15045");
4188 MODULE_ALIAS("snd-hda-codec-id:14f15047");
4189 MODULE_ALIAS("snd-hda-codec-id:14f15051");
4190 MODULE_ALIAS("snd-hda-codec-id:14f15066");
4191 MODULE_ALIAS("snd-hda-codec-id:14f15067");
4192 MODULE_ALIAS("snd-hda-codec-id:14f15068");
4193 MODULE_ALIAS("snd-hda-codec-id:14f15069");
4194 MODULE_ALIAS("snd-hda-codec-id:14f1506e");
4195 MODULE_ALIAS("snd-hda-codec-id:14f15097");
4196 MODULE_ALIAS("snd-hda-codec-id:14f15098");
4197 MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4198 MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4199 MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4200 MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4201 MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4202 MODULE_ALIAS("snd-hda-codec-id:14f150b9");
4204 MODULE_LICENSE("GPL");
4205 MODULE_DESCRIPTION("Conexant HD-audio codec");
4207 static struct hda_codec_preset_list conexant_list
= {
4208 .preset
= snd_hda_preset_conexant
,
4209 .owner
= THIS_MODULE
,
4212 static int __init
patch_conexant_init(void)
4214 return snd_hda_add_codec_preset(&conexant_list
);
4217 static void __exit
patch_conexant_exit(void)
4219 snd_hda_delete_codec_preset(&conexant_list
);
4222 module_init(patch_conexant_init
)
4223 module_exit(patch_conexant_exit
)