Merge git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-sched
[wrt350n-kernel.git] / sound / pci / hda / patch_conexant.c
blob7206b30cbf9454c30e19f0c2c49e9dbe9684df2f
1 /*
2 * HD audio interface patch for Conexant HDA audio codec
4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5 * Takashi Iwai <tiwai@suse.de>
6 * Tobin Davis <tdavis@dsl-only.net>
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
27 #include <sound/core.h>
28 #include "hda_codec.h"
29 #include "hda_local.h"
31 #define CXT_PIN_DIR_IN 0x00
32 #define CXT_PIN_DIR_OUT 0x01
33 #define CXT_PIN_DIR_INOUT 0x02
34 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
35 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
37 #define CONEXANT_HP_EVENT 0x37
38 #define CONEXANT_MIC_EVENT 0x38
42 struct conexant_spec {
44 struct snd_kcontrol_new *mixers[5];
45 int num_mixers;
47 const struct hda_verb *init_verbs[5]; /* initialization verbs
48 * don't forget NULL
49 * termination!
51 unsigned int num_init_verbs;
53 /* playback */
54 struct hda_multi_out multiout; /* playback set-up
55 * max_channels, dacs must be set
56 * dig_out_nid and hp_nid are optional
58 unsigned int cur_eapd;
59 unsigned int hp_present;
60 unsigned int need_dac_fix;
62 /* capture */
63 unsigned int num_adc_nids;
64 hda_nid_t *adc_nids;
65 hda_nid_t dig_in_nid; /* digital-in NID; optional */
67 unsigned int cur_adc_idx;
68 hda_nid_t cur_adc;
69 unsigned int cur_adc_stream_tag;
70 unsigned int cur_adc_format;
72 /* capture source */
73 const struct hda_input_mux *input_mux;
74 hda_nid_t *capsrc_nids;
75 unsigned int cur_mux[3];
77 /* channel model */
78 const struct hda_channel_mode *channel_mode;
79 int num_channel_mode;
81 /* PCM information */
82 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
84 struct mutex amp_mutex; /* PCM volume/mute control mutex */
85 unsigned int spdif_route;
87 /* dynamic controls, init_verbs and input_mux */
88 struct auto_pin_cfg autocfg;
89 unsigned int num_kctl_alloc, num_kctl_used;
90 struct snd_kcontrol_new *kctl_alloc;
91 struct hda_input_mux private_imux;
92 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
96 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
97 struct hda_codec *codec,
98 struct snd_pcm_substream *substream)
100 struct conexant_spec *spec = codec->spec;
101 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
104 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
105 struct hda_codec *codec,
106 unsigned int stream_tag,
107 unsigned int format,
108 struct snd_pcm_substream *substream)
110 struct conexant_spec *spec = codec->spec;
111 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
112 stream_tag,
113 format, substream);
116 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
117 struct hda_codec *codec,
118 struct snd_pcm_substream *substream)
120 struct conexant_spec *spec = codec->spec;
121 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
125 * Digital out
127 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
128 struct hda_codec *codec,
129 struct snd_pcm_substream *substream)
131 struct conexant_spec *spec = codec->spec;
132 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
135 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
136 struct hda_codec *codec,
137 struct snd_pcm_substream *substream)
139 struct conexant_spec *spec = codec->spec;
140 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
143 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
144 struct hda_codec *codec,
145 unsigned int stream_tag,
146 unsigned int format,
147 struct snd_pcm_substream *substream)
149 struct conexant_spec *spec = codec->spec;
150 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
151 stream_tag,
152 format, substream);
156 * Analog capture
158 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
159 struct hda_codec *codec,
160 unsigned int stream_tag,
161 unsigned int format,
162 struct snd_pcm_substream *substream)
164 struct conexant_spec *spec = codec->spec;
165 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
166 stream_tag, 0, format);
167 return 0;
170 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
171 struct hda_codec *codec,
172 struct snd_pcm_substream *substream)
174 struct conexant_spec *spec = codec->spec;
175 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
176 0, 0, 0);
177 return 0;
182 static struct hda_pcm_stream conexant_pcm_analog_playback = {
183 .substreams = 1,
184 .channels_min = 2,
185 .channels_max = 2,
186 .nid = 0, /* fill later */
187 .ops = {
188 .open = conexant_playback_pcm_open,
189 .prepare = conexant_playback_pcm_prepare,
190 .cleanup = conexant_playback_pcm_cleanup
194 static struct hda_pcm_stream conexant_pcm_analog_capture = {
195 .substreams = 1,
196 .channels_min = 2,
197 .channels_max = 2,
198 .nid = 0, /* fill later */
199 .ops = {
200 .prepare = conexant_capture_pcm_prepare,
201 .cleanup = conexant_capture_pcm_cleanup
206 static struct hda_pcm_stream conexant_pcm_digital_playback = {
207 .substreams = 1,
208 .channels_min = 2,
209 .channels_max = 2,
210 .nid = 0, /* fill later */
211 .ops = {
212 .open = conexant_dig_playback_pcm_open,
213 .close = conexant_dig_playback_pcm_close,
214 .prepare = conexant_dig_playback_pcm_prepare
218 static struct hda_pcm_stream conexant_pcm_digital_capture = {
219 .substreams = 1,
220 .channels_min = 2,
221 .channels_max = 2,
222 /* NID is set in alc_build_pcms */
225 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
226 struct hda_codec *codec,
227 unsigned int stream_tag,
228 unsigned int format,
229 struct snd_pcm_substream *substream)
231 struct conexant_spec *spec = codec->spec;
232 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
233 spec->cur_adc_stream_tag = stream_tag;
234 spec->cur_adc_format = format;
235 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
236 return 0;
239 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
240 struct hda_codec *codec,
241 struct snd_pcm_substream *substream)
243 struct conexant_spec *spec = codec->spec;
244 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0);
245 spec->cur_adc = 0;
246 return 0;
249 static struct hda_pcm_stream cx5051_pcm_analog_capture = {
250 .substreams = 1,
251 .channels_min = 2,
252 .channels_max = 2,
253 .nid = 0, /* fill later */
254 .ops = {
255 .prepare = cx5051_capture_pcm_prepare,
256 .cleanup = cx5051_capture_pcm_cleanup
260 static int conexant_build_pcms(struct hda_codec *codec)
262 struct conexant_spec *spec = codec->spec;
263 struct hda_pcm *info = spec->pcm_rec;
265 codec->num_pcms = 1;
266 codec->pcm_info = info;
268 info->name = "CONEXANT Analog";
269 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
270 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
271 spec->multiout.max_channels;
272 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
273 spec->multiout.dac_nids[0];
274 if (codec->vendor_id == 0x14f15051)
275 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
276 cx5051_pcm_analog_capture;
277 else
278 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
279 conexant_pcm_analog_capture;
280 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
281 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
283 if (spec->multiout.dig_out_nid) {
284 info++;
285 codec->num_pcms++;
286 info->name = "Conexant Digital";
287 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
288 conexant_pcm_digital_playback;
289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
290 spec->multiout.dig_out_nid;
291 if (spec->dig_in_nid) {
292 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
293 conexant_pcm_digital_capture;
294 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
295 spec->dig_in_nid;
299 return 0;
302 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
303 struct snd_ctl_elem_info *uinfo)
305 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
306 struct conexant_spec *spec = codec->spec;
308 return snd_hda_input_mux_info(spec->input_mux, uinfo);
311 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
312 struct snd_ctl_elem_value *ucontrol)
314 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
315 struct conexant_spec *spec = codec->spec;
316 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
318 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
319 return 0;
322 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
323 struct snd_ctl_elem_value *ucontrol)
325 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
326 struct conexant_spec *spec = codec->spec;
327 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
329 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
330 spec->capsrc_nids[adc_idx],
331 &spec->cur_mux[adc_idx]);
334 static int conexant_init(struct hda_codec *codec)
336 struct conexant_spec *spec = codec->spec;
337 int i;
339 for (i = 0; i < spec->num_init_verbs; i++)
340 snd_hda_sequence_write(codec, spec->init_verbs[i]);
341 return 0;
344 static void conexant_free(struct hda_codec *codec)
346 struct conexant_spec *spec = codec->spec;
347 unsigned int i;
349 if (spec->kctl_alloc) {
350 for (i = 0; i < spec->num_kctl_used; i++)
351 kfree(spec->kctl_alloc[i].name);
352 kfree(spec->kctl_alloc);
355 kfree(codec->spec);
358 static int conexant_build_controls(struct hda_codec *codec)
360 struct conexant_spec *spec = codec->spec;
361 unsigned int i;
362 int err;
364 for (i = 0; i < spec->num_mixers; i++) {
365 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
366 if (err < 0)
367 return err;
369 if (spec->multiout.dig_out_nid) {
370 err = snd_hda_create_spdif_out_ctls(codec,
371 spec->multiout.dig_out_nid);
372 if (err < 0)
373 return err;
375 if (spec->dig_in_nid) {
376 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
377 if (err < 0)
378 return err;
380 return 0;
383 static struct hda_codec_ops conexant_patch_ops = {
384 .build_controls = conexant_build_controls,
385 .build_pcms = conexant_build_pcms,
386 .init = conexant_init,
387 .free = conexant_free,
391 * EAPD control
392 * the private value = nid | (invert << 8)
395 #define cxt_eapd_info snd_ctl_boolean_mono_info
397 static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
398 struct snd_ctl_elem_value *ucontrol)
400 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
401 struct conexant_spec *spec = codec->spec;
402 int invert = (kcontrol->private_value >> 8) & 1;
403 if (invert)
404 ucontrol->value.integer.value[0] = !spec->cur_eapd;
405 else
406 ucontrol->value.integer.value[0] = spec->cur_eapd;
407 return 0;
411 static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
412 struct snd_ctl_elem_value *ucontrol)
414 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
415 struct conexant_spec *spec = codec->spec;
416 int invert = (kcontrol->private_value >> 8) & 1;
417 hda_nid_t nid = kcontrol->private_value & 0xff;
418 unsigned int eapd;
420 eapd = !!ucontrol->value.integer.value[0];
421 if (invert)
422 eapd = !eapd;
423 if (eapd == spec->cur_eapd)
424 return 0;
426 spec->cur_eapd = eapd;
427 snd_hda_codec_write_cache(codec, nid,
428 0, AC_VERB_SET_EAPD_BTLENABLE,
429 eapd ? 0x02 : 0x00);
430 return 1;
433 /* controls for test mode */
434 #ifdef CONFIG_SND_DEBUG
436 #define CXT_EAPD_SWITCH(xname, nid, mask) \
437 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
438 .info = cxt_eapd_info, \
439 .get = cxt_eapd_get, \
440 .put = cxt_eapd_put, \
441 .private_value = nid | (mask<<16) }
445 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
446 struct snd_ctl_elem_info *uinfo)
448 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
449 struct conexant_spec *spec = codec->spec;
450 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
451 spec->num_channel_mode);
454 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
455 struct snd_ctl_elem_value *ucontrol)
457 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
458 struct conexant_spec *spec = codec->spec;
459 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
460 spec->num_channel_mode,
461 spec->multiout.max_channels);
464 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
465 struct snd_ctl_elem_value *ucontrol)
467 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
468 struct conexant_spec *spec = codec->spec;
469 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
470 spec->num_channel_mode,
471 &spec->multiout.max_channels);
472 if (err >= 0 && spec->need_dac_fix)
473 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
474 return err;
477 #define CXT_PIN_MODE(xname, nid, dir) \
478 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
479 .info = conexant_ch_mode_info, \
480 .get = conexant_ch_mode_get, \
481 .put = conexant_ch_mode_put, \
482 .private_value = nid | (dir<<16) }
484 #endif /* CONFIG_SND_DEBUG */
486 /* Conexant 5045 specific */
488 static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
489 static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
490 static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
491 #define CXT5045_SPDIF_OUT 0x18
493 static struct hda_channel_mode cxt5045_modes[1] = {
494 { 2, NULL },
497 static struct hda_input_mux cxt5045_capture_source = {
498 .num_items = 2,
499 .items = {
500 { "IntMic", 0x1 },
501 { "ExtMic", 0x2 },
505 static struct hda_input_mux cxt5045_capture_source_benq = {
506 .num_items = 3,
507 .items = {
508 { "IntMic", 0x1 },
509 { "ExtMic", 0x2 },
510 { "LineIn", 0x3 },
514 /* turn on/off EAPD (+ mute HP) as a master switch */
515 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
516 struct snd_ctl_elem_value *ucontrol)
518 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
519 struct conexant_spec *spec = codec->spec;
520 unsigned int bits;
522 if (!cxt_eapd_put(kcontrol, ucontrol))
523 return 0;
525 /* toggle internal speakers mute depending of presence of
526 * the headphone jack
528 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
529 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
530 HDA_AMP_MUTE, bits);
532 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
533 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
534 HDA_AMP_MUTE, bits);
535 return 1;
538 /* bind volumes of both NID 0x10 and 0x11 */
539 static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
540 .ops = &snd_hda_bind_vol,
541 .values = {
542 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
543 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
548 /* toggle input of built-in and mic jack appropriately */
549 static void cxt5045_hp_automic(struct hda_codec *codec)
551 static struct hda_verb mic_jack_on[] = {
552 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
553 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
556 static struct hda_verb mic_jack_off[] = {
557 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
558 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
561 unsigned int present;
563 present = snd_hda_codec_read(codec, 0x12, 0,
564 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
565 if (present)
566 snd_hda_sequence_write(codec, mic_jack_on);
567 else
568 snd_hda_sequence_write(codec, mic_jack_off);
572 /* mute internal speaker if HP is plugged */
573 static void cxt5045_hp_automute(struct hda_codec *codec)
575 struct conexant_spec *spec = codec->spec;
576 unsigned int bits;
578 spec->hp_present = snd_hda_codec_read(codec, 0x11, 0,
579 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
581 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
582 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
583 HDA_AMP_MUTE, bits);
586 /* unsolicited event for HP jack sensing */
587 static void cxt5045_hp_unsol_event(struct hda_codec *codec,
588 unsigned int res)
590 res >>= 26;
591 switch (res) {
592 case CONEXANT_HP_EVENT:
593 cxt5045_hp_automute(codec);
594 break;
595 case CONEXANT_MIC_EVENT:
596 cxt5045_hp_automic(codec);
597 break;
602 static struct snd_kcontrol_new cxt5045_mixers[] = {
604 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
605 .name = "Capture Source",
606 .info = conexant_mux_enum_info,
607 .get = conexant_mux_enum_get,
608 .put = conexant_mux_enum_put
610 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
611 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
612 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
613 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
614 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
615 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
616 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
617 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
618 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
619 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
620 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
622 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
623 .name = "Master Playback Switch",
624 .info = cxt_eapd_info,
625 .get = cxt_eapd_get,
626 .put = cxt5045_hp_master_sw_put,
627 .private_value = 0x10,
633 static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
634 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
635 HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
636 HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
637 HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
642 static struct hda_verb cxt5045_init_verbs[] = {
643 /* Line in, Mic */
644 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
645 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
646 /* HP, Amp */
647 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
648 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
649 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
650 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
651 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
652 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
653 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
654 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
655 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
656 /* Record selector: Int mic */
657 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
658 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
659 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
660 /* SPDIF route: PCM */
661 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
662 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
663 /* EAPD */
664 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
665 { } /* end */
668 static struct hda_verb cxt5045_benq_init_verbs[] = {
669 /* Int Mic, Mic */
670 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
671 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
672 /* Line In,HP, Amp */
673 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
674 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
675 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
676 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
677 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
678 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
679 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
680 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
681 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
682 /* Record selector: Int mic */
683 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
684 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
685 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
686 /* SPDIF route: PCM */
687 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
688 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
689 /* EAPD */
690 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
691 { } /* end */
694 static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
695 /* pin sensing on HP jack */
696 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
697 { } /* end */
700 static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
701 /* pin sensing on HP jack */
702 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
703 { } /* end */
706 #ifdef CONFIG_SND_DEBUG
707 /* Test configuration for debugging, modelled after the ALC260 test
708 * configuration.
710 static struct hda_input_mux cxt5045_test_capture_source = {
711 .num_items = 5,
712 .items = {
713 { "MIXER", 0x0 },
714 { "MIC1 pin", 0x1 },
715 { "LINE1 pin", 0x2 },
716 { "HP-OUT pin", 0x3 },
717 { "CD pin", 0x4 },
721 static struct snd_kcontrol_new cxt5045_test_mixer[] = {
723 /* Output controls */
724 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
725 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
726 HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
727 HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
728 HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
729 HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
731 /* Modes for retasking pin widgets */
732 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
733 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
735 /* EAPD Switch Control */
736 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
738 /* Loopback mixer controls */
740 HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
741 HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
742 HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
743 HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
744 HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
745 HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
746 HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
747 HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
748 HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
749 HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
751 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
752 .name = "Input Source",
753 .info = conexant_mux_enum_info,
754 .get = conexant_mux_enum_get,
755 .put = conexant_mux_enum_put,
757 /* Audio input controls */
758 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
759 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
760 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
761 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
762 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
763 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
764 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
765 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
766 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
767 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
768 { } /* end */
771 static struct hda_verb cxt5045_test_init_verbs[] = {
772 /* Set connections */
773 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
774 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
775 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
776 /* Enable retasking pins as output, initially without power amp */
777 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
778 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
780 /* Disable digital (SPDIF) pins initially, but users can enable
781 * them via a mixer switch. In the case of SPDIF-out, this initverb
782 * payload also sets the generation to 0, output to be in "consumer"
783 * PCM format, copyright asserted, no pre-emphasis and no validity
784 * control.
786 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
787 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
789 /* Start with output sum widgets muted and their output gains at min */
790 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
791 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
793 /* Unmute retasking pin widget output buffers since the default
794 * state appears to be output. As the pin mode is changed by the
795 * user the pin mode control will take care of enabling the pin's
796 * input/output buffers as needed.
798 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
799 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
801 /* Mute capture amp left and right */
802 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
804 /* Set ADC connection select to match default mixer setting (mic1
805 * pin)
807 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
808 {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
810 /* Mute all inputs to mixer widget (even unconnected ones) */
811 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
812 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
813 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
814 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
815 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
819 #endif
822 /* initialize jack-sensing, too */
823 static int cxt5045_init(struct hda_codec *codec)
825 conexant_init(codec);
826 cxt5045_hp_automute(codec);
827 return 0;
831 enum {
832 CXT5045_LAPTOP_HPSENSE,
833 CXT5045_LAPTOP_MICSENSE,
834 CXT5045_LAPTOP_HPMICSENSE,
835 CXT5045_BENQ,
836 #ifdef CONFIG_SND_DEBUG
837 CXT5045_TEST,
838 #endif
839 CXT5045_MODELS
842 static const char *cxt5045_models[CXT5045_MODELS] = {
843 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
844 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
845 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
846 [CXT5045_BENQ] = "benq",
847 #ifdef CONFIG_SND_DEBUG
848 [CXT5045_TEST] = "test",
849 #endif
852 static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
853 SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
854 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
855 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
856 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
857 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
858 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
859 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
860 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HPSENSE),
861 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
862 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
863 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
864 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
865 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPSENSE),
866 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
867 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
868 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
869 SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
870 SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE),
871 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
875 static int patch_cxt5045(struct hda_codec *codec)
877 struct conexant_spec *spec;
878 int board_config;
880 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
881 if (!spec)
882 return -ENOMEM;
883 mutex_init(&spec->amp_mutex);
884 codec->spec = spec;
886 spec->multiout.max_channels = 2;
887 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
888 spec->multiout.dac_nids = cxt5045_dac_nids;
889 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
890 spec->num_adc_nids = 1;
891 spec->adc_nids = cxt5045_adc_nids;
892 spec->capsrc_nids = cxt5045_capsrc_nids;
893 spec->input_mux = &cxt5045_capture_source;
894 spec->num_mixers = 1;
895 spec->mixers[0] = cxt5045_mixers;
896 spec->num_init_verbs = 1;
897 spec->init_verbs[0] = cxt5045_init_verbs;
898 spec->spdif_route = 0;
899 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
900 spec->channel_mode = cxt5045_modes,
903 codec->patch_ops = conexant_patch_ops;
905 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
906 cxt5045_models,
907 cxt5045_cfg_tbl);
908 switch (board_config) {
909 case CXT5045_LAPTOP_HPSENSE:
910 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
911 spec->input_mux = &cxt5045_capture_source;
912 spec->num_init_verbs = 2;
913 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
914 spec->mixers[0] = cxt5045_mixers;
915 codec->patch_ops.init = cxt5045_init;
916 break;
917 case CXT5045_LAPTOP_MICSENSE:
918 spec->input_mux = &cxt5045_capture_source;
919 spec->num_init_verbs = 2;
920 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
921 spec->mixers[0] = cxt5045_mixers;
922 codec->patch_ops.init = cxt5045_init;
923 break;
924 default:
925 case CXT5045_LAPTOP_HPMICSENSE:
926 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
927 spec->input_mux = &cxt5045_capture_source;
928 spec->num_init_verbs = 3;
929 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
930 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
931 spec->mixers[0] = cxt5045_mixers;
932 codec->patch_ops.init = cxt5045_init;
933 break;
934 case CXT5045_BENQ:
935 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
936 spec->input_mux = &cxt5045_capture_source_benq;
937 spec->num_init_verbs = 1;
938 spec->init_verbs[0] = cxt5045_benq_init_verbs;
939 spec->mixers[0] = cxt5045_mixers;
940 spec->mixers[1] = cxt5045_benq_mixers;
941 spec->num_mixers = 2;
942 codec->patch_ops.init = cxt5045_init;
943 break;
944 #ifdef CONFIG_SND_DEBUG
945 case CXT5045_TEST:
946 spec->input_mux = &cxt5045_test_capture_source;
947 spec->mixers[0] = cxt5045_test_mixer;
948 spec->init_verbs[0] = cxt5045_test_init_verbs;
949 break;
951 #endif
955 * Fix max PCM level to 0 dB
956 * (originall it has 0x2b steps with 0dB offset 0x14)
958 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
959 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
960 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
961 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
962 (1 << AC_AMPCAP_MUTE_SHIFT));
964 return 0;
968 /* Conexant 5047 specific */
969 #define CXT5047_SPDIF_OUT 0x11
971 static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c };
972 static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
973 static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
975 static struct hda_channel_mode cxt5047_modes[1] = {
976 { 2, NULL },
979 static struct hda_input_mux cxt5047_capture_source = {
980 .num_items = 1,
981 .items = {
982 { "Mic", 0x2 },
986 static struct hda_input_mux cxt5047_hp_capture_source = {
987 .num_items = 1,
988 .items = {
989 { "ExtMic", 0x2 },
993 static struct hda_input_mux cxt5047_toshiba_capture_source = {
994 .num_items = 2,
995 .items = {
996 { "ExtMic", 0x2 },
997 { "Line-In", 0x1 },
1001 /* turn on/off EAPD (+ mute HP) as a master switch */
1002 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1003 struct snd_ctl_elem_value *ucontrol)
1005 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1006 struct conexant_spec *spec = codec->spec;
1007 unsigned int bits;
1009 if (!cxt_eapd_put(kcontrol, ucontrol))
1010 return 0;
1012 /* toggle internal speakers mute depending of presence of
1013 * the headphone jack
1015 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1016 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1017 HDA_AMP_MUTE, bits);
1018 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1019 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
1020 HDA_AMP_MUTE, bits);
1021 return 1;
1024 /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
1025 static struct hda_bind_ctls cxt5047_bind_master_vol = {
1026 .ops = &snd_hda_bind_vol,
1027 .values = {
1028 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1029 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1034 /* mute internal speaker if HP is plugged */
1035 static void cxt5047_hp_automute(struct hda_codec *codec)
1037 struct conexant_spec *spec = codec->spec;
1038 unsigned int bits;
1040 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1041 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1043 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1044 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1045 HDA_AMP_MUTE, bits);
1046 /* Mute/Unmute PCM 2 for good measure - some systems need this */
1047 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1048 HDA_AMP_MUTE, bits);
1051 /* mute internal speaker if HP is plugged */
1052 static void cxt5047_hp2_automute(struct hda_codec *codec)
1054 struct conexant_spec *spec = codec->spec;
1055 unsigned int bits;
1057 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1058 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1060 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1061 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1062 HDA_AMP_MUTE, bits);
1063 /* Mute/Unmute PCM 2 for good measure - some systems need this */
1064 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1065 HDA_AMP_MUTE, bits);
1068 /* toggle input of built-in and mic jack appropriately */
1069 static void cxt5047_hp_automic(struct hda_codec *codec)
1071 static struct hda_verb mic_jack_on[] = {
1072 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1073 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1076 static struct hda_verb mic_jack_off[] = {
1077 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1078 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1081 unsigned int present;
1083 present = snd_hda_codec_read(codec, 0x15, 0,
1084 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1085 if (present)
1086 snd_hda_sequence_write(codec, mic_jack_on);
1087 else
1088 snd_hda_sequence_write(codec, mic_jack_off);
1091 /* unsolicited event for HP jack sensing */
1092 static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1093 unsigned int res)
1095 switch (res >> 26) {
1096 case CONEXANT_HP_EVENT:
1097 cxt5047_hp_automute(codec);
1098 break;
1099 case CONEXANT_MIC_EVENT:
1100 cxt5047_hp_automic(codec);
1101 break;
1105 /* unsolicited event for HP jack sensing - non-EAPD systems */
1106 static void cxt5047_hp2_unsol_event(struct hda_codec *codec,
1107 unsigned int res)
1109 res >>= 26;
1110 switch (res) {
1111 case CONEXANT_HP_EVENT:
1112 cxt5047_hp2_automute(codec);
1113 break;
1114 case CONEXANT_MIC_EVENT:
1115 cxt5047_hp_automic(codec);
1116 break;
1120 static struct snd_kcontrol_new cxt5047_mixers[] = {
1121 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1122 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1123 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1124 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
1125 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1126 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1127 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1128 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1129 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1130 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1131 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1132 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1133 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1134 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
1139 static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1141 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1142 .name = "Capture Source",
1143 .info = conexant_mux_enum_info,
1144 .get = conexant_mux_enum_get,
1145 .put = conexant_mux_enum_put
1147 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1148 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1149 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1150 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1151 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1152 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1153 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
1155 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1156 .name = "Master Playback Switch",
1157 .info = cxt_eapd_info,
1158 .get = cxt_eapd_get,
1159 .put = cxt5047_hp_master_sw_put,
1160 .private_value = 0x13,
1166 static struct snd_kcontrol_new cxt5047_hp_mixers[] = {
1168 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1169 .name = "Capture Source",
1170 .info = conexant_mux_enum_info,
1171 .get = conexant_mux_enum_get,
1172 .put = conexant_mux_enum_put
1174 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1175 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1176 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1177 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1178 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1179 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1180 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1182 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1183 .name = "Master Playback Switch",
1184 .info = cxt_eapd_info,
1185 .get = cxt_eapd_get,
1186 .put = cxt5047_hp_master_sw_put,
1187 .private_value = 0x13,
1189 { } /* end */
1192 static struct hda_verb cxt5047_init_verbs[] = {
1193 /* Line in, Mic, Built-in Mic */
1194 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1195 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1196 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1197 /* HP, Speaker */
1198 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1199 {0x13, AC_VERB_SET_CONNECT_SEL,0x1},
1200 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0},
1201 /* Record selector: Mic */
1202 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1203 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1204 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1205 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1206 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1207 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1208 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1209 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1210 /* SPDIF route: PCM */
1211 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
1212 /* Enable unsolicited events */
1213 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1214 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1215 { } /* end */
1218 /* configuration for Toshiba Laptops */
1219 static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1220 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */
1221 /* pin sensing on HP and Mic jacks */
1222 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1223 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1224 /* Speaker routing */
1225 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1229 /* configuration for HP Laptops */
1230 static struct hda_verb cxt5047_hp_init_verbs[] = {
1231 /* pin sensing on HP jack */
1232 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1233 /* 0x13 is actually shared by both HP and speaker;
1234 * setting the connection to 0 (=0x19) makes the master volume control
1235 * working mysteriouslly...
1237 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1238 /* Record selector: Ext Mic */
1239 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1240 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1241 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1242 /* Speaker routing */
1243 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1247 /* Test configuration for debugging, modelled after the ALC260 test
1248 * configuration.
1250 #ifdef CONFIG_SND_DEBUG
1251 static struct hda_input_mux cxt5047_test_capture_source = {
1252 .num_items = 4,
1253 .items = {
1254 { "LINE1 pin", 0x0 },
1255 { "MIC1 pin", 0x1 },
1256 { "MIC2 pin", 0x2 },
1257 { "CD pin", 0x3 },
1261 static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1263 /* Output only controls */
1264 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
1265 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
1266 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
1267 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1268 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1269 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1270 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1271 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1272 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
1273 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1274 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
1275 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1277 /* Modes for retasking pin widgets */
1278 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1279 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1281 /* EAPD Switch Control */
1282 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
1284 /* Loopback mixer controls */
1285 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
1286 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
1287 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
1288 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
1289 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
1290 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
1291 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
1292 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1294 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
1295 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
1296 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
1297 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
1298 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
1299 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
1300 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
1301 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1303 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1304 .name = "Input Source",
1305 .info = conexant_mux_enum_info,
1306 .get = conexant_mux_enum_get,
1307 .put = conexant_mux_enum_put,
1309 HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1310 HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1311 HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1312 HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1313 HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1314 HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1315 HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1316 HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1317 HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1318 HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1320 { } /* end */
1323 static struct hda_verb cxt5047_test_init_verbs[] = {
1324 /* Enable retasking pins as output, initially without power amp */
1325 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1326 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1327 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1329 /* Disable digital (SPDIF) pins initially, but users can enable
1330 * them via a mixer switch. In the case of SPDIF-out, this initverb
1331 * payload also sets the generation to 0, output to be in "consumer"
1332 * PCM format, copyright asserted, no pre-emphasis and no validity
1333 * control.
1335 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1337 /* Ensure mic1, mic2, line1 pin widgets take input from the
1338 * OUT1 sum bus when acting as an output.
1340 {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1341 {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1343 /* Start with output sum widgets muted and their output gains at min */
1344 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1345 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1347 /* Unmute retasking pin widget output buffers since the default
1348 * state appears to be output. As the pin mode is changed by the
1349 * user the pin mode control will take care of enabling the pin's
1350 * input/output buffers as needed.
1352 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1353 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1354 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1356 /* Mute capture amp left and right */
1357 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1359 /* Set ADC connection select to match default mixer setting (mic1
1360 * pin)
1362 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1364 /* Mute all inputs to mixer widget (even unconnected ones) */
1365 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1366 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1367 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1368 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1369 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1370 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1371 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1372 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1376 #endif
1379 /* initialize jack-sensing, too */
1380 static int cxt5047_hp_init(struct hda_codec *codec)
1382 conexant_init(codec);
1383 cxt5047_hp_automute(codec);
1384 return 0;
1388 enum {
1389 CXT5047_LAPTOP, /* Laptops w/o EAPD support */
1390 CXT5047_LAPTOP_HP, /* Some HP laptops */
1391 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
1392 #ifdef CONFIG_SND_DEBUG
1393 CXT5047_TEST,
1394 #endif
1395 CXT5047_MODELS
1398 static const char *cxt5047_models[CXT5047_MODELS] = {
1399 [CXT5047_LAPTOP] = "laptop",
1400 [CXT5047_LAPTOP_HP] = "laptop-hp",
1401 [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
1402 #ifdef CONFIG_SND_DEBUG
1403 [CXT5047_TEST] = "test",
1404 #endif
1407 static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1408 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1409 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1410 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP),
1411 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP),
1412 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1416 static int patch_cxt5047(struct hda_codec *codec)
1418 struct conexant_spec *spec;
1419 int board_config;
1421 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1422 if (!spec)
1423 return -ENOMEM;
1424 mutex_init(&spec->amp_mutex);
1425 codec->spec = spec;
1427 spec->multiout.max_channels = 2;
1428 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1429 spec->multiout.dac_nids = cxt5047_dac_nids;
1430 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1431 spec->num_adc_nids = 1;
1432 spec->adc_nids = cxt5047_adc_nids;
1433 spec->capsrc_nids = cxt5047_capsrc_nids;
1434 spec->input_mux = &cxt5047_capture_source;
1435 spec->num_mixers = 1;
1436 spec->mixers[0] = cxt5047_mixers;
1437 spec->num_init_verbs = 1;
1438 spec->init_verbs[0] = cxt5047_init_verbs;
1439 spec->spdif_route = 0;
1440 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
1441 spec->channel_mode = cxt5047_modes,
1443 codec->patch_ops = conexant_patch_ops;
1445 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1446 cxt5047_models,
1447 cxt5047_cfg_tbl);
1448 switch (board_config) {
1449 case CXT5047_LAPTOP:
1450 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event;
1451 break;
1452 case CXT5047_LAPTOP_HP:
1453 spec->input_mux = &cxt5047_hp_capture_source;
1454 spec->num_init_verbs = 2;
1455 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1456 spec->mixers[0] = cxt5047_hp_mixers;
1457 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1458 codec->patch_ops.init = cxt5047_hp_init;
1459 break;
1460 case CXT5047_LAPTOP_EAPD:
1461 spec->input_mux = &cxt5047_toshiba_capture_source;
1462 spec->num_init_verbs = 2;
1463 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1464 spec->mixers[0] = cxt5047_toshiba_mixers;
1465 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1466 break;
1467 #ifdef CONFIG_SND_DEBUG
1468 case CXT5047_TEST:
1469 spec->input_mux = &cxt5047_test_capture_source;
1470 spec->mixers[0] = cxt5047_test_mixer;
1471 spec->init_verbs[0] = cxt5047_test_init_verbs;
1472 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1473 #endif
1475 return 0;
1478 /* Conexant 5051 specific */
1479 static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1480 static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1481 #define CXT5051_SPDIF_OUT 0x1C
1482 #define CXT5051_PORTB_EVENT 0x38
1483 #define CXT5051_PORTC_EVENT 0x39
1485 static struct hda_channel_mode cxt5051_modes[1] = {
1486 { 2, NULL },
1489 static void cxt5051_update_speaker(struct hda_codec *codec)
1491 struct conexant_spec *spec = codec->spec;
1492 unsigned int pinctl;
1493 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1494 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1495 pinctl);
1498 /* turn on/off EAPD (+ mute HP) as a master switch */
1499 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1500 struct snd_ctl_elem_value *ucontrol)
1502 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1504 if (!cxt_eapd_put(kcontrol, ucontrol))
1505 return 0;
1506 cxt5051_update_speaker(codec);
1507 return 1;
1510 /* toggle input of built-in and mic jack appropriately */
1511 static void cxt5051_portb_automic(struct hda_codec *codec)
1513 unsigned int present;
1515 present = snd_hda_codec_read(codec, 0x17, 0,
1516 AC_VERB_GET_PIN_SENSE, 0) &
1517 AC_PINSENSE_PRESENCE;
1518 snd_hda_codec_write(codec, 0x14, 0,
1519 AC_VERB_SET_CONNECT_SEL,
1520 present ? 0x01 : 0x00);
1523 /* switch the current ADC according to the jack state */
1524 static void cxt5051_portc_automic(struct hda_codec *codec)
1526 struct conexant_spec *spec = codec->spec;
1527 unsigned int present;
1528 hda_nid_t new_adc;
1530 present = snd_hda_codec_read(codec, 0x18, 0,
1531 AC_VERB_GET_PIN_SENSE, 0) &
1532 AC_PINSENSE_PRESENCE;
1533 if (present)
1534 spec->cur_adc_idx = 1;
1535 else
1536 spec->cur_adc_idx = 0;
1537 new_adc = spec->adc_nids[spec->cur_adc_idx];
1538 if (spec->cur_adc && spec->cur_adc != new_adc) {
1539 /* stream is running, let's swap the current ADC */
1540 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0);
1541 spec->cur_adc = new_adc;
1542 snd_hda_codec_setup_stream(codec, new_adc,
1543 spec->cur_adc_stream_tag, 0,
1544 spec->cur_adc_format);
1548 /* mute internal speaker if HP is plugged */
1549 static void cxt5051_hp_automute(struct hda_codec *codec)
1551 struct conexant_spec *spec = codec->spec;
1553 spec->hp_present = snd_hda_codec_read(codec, 0x16, 0,
1554 AC_VERB_GET_PIN_SENSE, 0) &
1555 AC_PINSENSE_PRESENCE;
1556 cxt5051_update_speaker(codec);
1559 /* unsolicited event for HP jack sensing */
1560 static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1561 unsigned int res)
1563 switch (res >> 26) {
1564 case CONEXANT_HP_EVENT:
1565 cxt5051_hp_automute(codec);
1566 break;
1567 case CXT5051_PORTB_EVENT:
1568 cxt5051_portb_automic(codec);
1569 break;
1570 case CXT5051_PORTC_EVENT:
1571 cxt5051_portc_automic(codec);
1572 break;
1576 static struct snd_kcontrol_new cxt5051_mixers[] = {
1577 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1578 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1579 HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1580 HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1581 HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1582 HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1583 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1585 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1586 .name = "Master Playback Switch",
1587 .info = cxt_eapd_info,
1588 .get = cxt_eapd_get,
1589 .put = cxt5051_hp_master_sw_put,
1590 .private_value = 0x1a,
1596 static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1597 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1598 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1599 HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1600 HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1601 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1603 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1604 .name = "Master Playback Switch",
1605 .info = cxt_eapd_info,
1606 .get = cxt_eapd_get,
1607 .put = cxt5051_hp_master_sw_put,
1608 .private_value = 0x1a,
1614 static struct hda_verb cxt5051_init_verbs[] = {
1615 /* Line in, Mic */
1616 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1617 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1618 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1619 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1620 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1621 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1622 /* SPK */
1623 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1624 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1625 /* HP, Amp */
1626 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1627 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1628 /* DAC1 */
1629 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1630 /* Record selector: Int mic */
1631 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1632 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1633 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1634 /* SPDIF route: PCM */
1635 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1636 /* EAPD */
1637 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1638 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1639 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1640 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1641 { } /* end */
1644 /* initialize jack-sensing, too */
1645 static int cxt5051_init(struct hda_codec *codec)
1647 conexant_init(codec);
1648 if (codec->patch_ops.unsol_event) {
1649 cxt5051_hp_automute(codec);
1650 cxt5051_portb_automic(codec);
1651 cxt5051_portc_automic(codec);
1653 return 0;
1657 enum {
1658 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1659 CXT5051_HP, /* no docking */
1660 CXT5051_MODELS
1663 static const char *cxt5051_models[CXT5051_MODELS] = {
1664 [CXT5051_LAPTOP] = "laptop",
1665 [CXT5051_HP] = "hp",
1668 static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1669 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1670 CXT5051_LAPTOP),
1671 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1675 static int patch_cxt5051(struct hda_codec *codec)
1677 struct conexant_spec *spec;
1678 int board_config;
1680 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1681 if (!spec)
1682 return -ENOMEM;
1683 mutex_init(&spec->amp_mutex);
1684 codec->spec = spec;
1686 codec->patch_ops = conexant_patch_ops;
1687 codec->patch_ops.init = cxt5051_init;
1689 spec->multiout.max_channels = 2;
1690 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1691 spec->multiout.dac_nids = cxt5051_dac_nids;
1692 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1693 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1694 spec->adc_nids = cxt5051_adc_nids;
1695 spec->num_mixers = 1;
1696 spec->mixers[0] = cxt5051_mixers;
1697 spec->num_init_verbs = 1;
1698 spec->init_verbs[0] = cxt5051_init_verbs;
1699 spec->spdif_route = 0;
1700 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1701 spec->channel_mode = cxt5051_modes;
1702 spec->cur_adc = 0;
1703 spec->cur_adc_idx = 0;
1705 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1706 cxt5051_models,
1707 cxt5051_cfg_tbl);
1708 switch (board_config) {
1709 case CXT5051_HP:
1710 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1711 spec->mixers[0] = cxt5051_hp_mixers;
1712 break;
1713 default:
1714 case CXT5051_LAPTOP:
1715 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1716 break;
1719 return 0;
1726 struct hda_codec_preset snd_hda_preset_conexant[] = {
1727 { .id = 0x14f15045, .name = "CX20549 (Venice)",
1728 .patch = patch_cxt5045 },
1729 { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
1730 .patch = patch_cxt5047 },
1731 { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
1732 .patch = patch_cxt5051 },
1733 {} /* terminator */