2 * HD audio interface patch for Cirrus Logic CS420x chip
4 * Copyright (c) 2009 Takashi Iwai <tiwai@suse.de>
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This driver is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/init.h>
22 #include <linux/delay.h>
23 #include <linux/slab.h>
24 #include <linux/pci.h>
25 #include <sound/core.h>
26 #include "hda_codec.h"
27 #include "hda_local.h"
33 struct auto_pin_cfg autocfg;
34 struct hda_multi_out multiout;
35 struct snd_kcontrol *vmaster_sw;
36 struct snd_kcontrol *vmaster_vol;
38 hda_nid_t dac_nid[AUTO_CFG_MAX_OUTS];
39 hda_nid_t slave_dig_outs[2];
41 unsigned int input_idx[AUTO_PIN_LAST];
42 unsigned int capsrc_idx[AUTO_PIN_LAST];
43 hda_nid_t adc_nid[AUTO_PIN_LAST];
44 unsigned int adc_idx[AUTO_PIN_LAST];
45 unsigned int num_inputs;
46 unsigned int cur_input;
47 unsigned int automic_idx;
49 unsigned int cur_adc_stream_tag;
50 unsigned int cur_adc_format;
53 struct hda_bind_ctls *capture_bind[2];
55 struct hda_pcm pcm_rec[2]; /* PCM information */
57 unsigned int hp_detect:1;
58 unsigned int mic_detect:1;
67 static int cs_playback_pcm_open(struct hda_pcm_stream *hinfo,
68 struct hda_codec *codec,
69 struct snd_pcm_substream *substream)
71 struct cs_spec *spec = codec->spec;
72 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
76 static int cs_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
77 struct hda_codec *codec,
78 unsigned int stream_tag,
80 struct snd_pcm_substream *substream)
82 struct cs_spec *spec = codec->spec;
83 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
84 stream_tag, format, substream);
87 static int cs_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
88 struct hda_codec *codec,
89 struct snd_pcm_substream *substream)
91 struct cs_spec *spec = codec->spec;
92 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
98 static int cs_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
99 struct hda_codec *codec,
100 struct snd_pcm_substream *substream)
102 struct cs_spec *spec = codec->spec;
103 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
106 static int cs_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
107 struct hda_codec *codec,
108 struct snd_pcm_substream *substream)
110 struct cs_spec *spec = codec->spec;
111 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
114 static int cs_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
115 struct hda_codec *codec,
116 unsigned int stream_tag,
118 struct snd_pcm_substream *substream)
120 struct cs_spec *spec = codec->spec;
121 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
125 static int cs_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
126 struct hda_codec *codec,
127 struct snd_pcm_substream *substream)
129 struct cs_spec *spec = codec->spec;
130 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
136 static int cs_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
137 struct hda_codec *codec,
138 unsigned int stream_tag,
140 struct snd_pcm_substream *substream)
142 struct cs_spec *spec = codec->spec;
143 spec->cur_adc = spec->adc_nid[spec->cur_input];
144 spec->cur_adc_stream_tag = stream_tag;
145 spec->cur_adc_format = format;
146 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
150 static int cs_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
151 struct hda_codec *codec,
152 struct snd_pcm_substream *substream)
154 struct cs_spec *spec = codec->spec;
155 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
162 static struct hda_pcm_stream cs_pcm_analog_playback = {
167 .open = cs_playback_pcm_open,
168 .prepare = cs_playback_pcm_prepare,
169 .cleanup = cs_playback_pcm_cleanup
173 static struct hda_pcm_stream cs_pcm_analog_capture = {
178 .prepare = cs_capture_pcm_prepare,
179 .cleanup = cs_capture_pcm_cleanup
183 static struct hda_pcm_stream cs_pcm_digital_playback = {
188 .open = cs_dig_playback_pcm_open,
189 .close = cs_dig_playback_pcm_close,
190 .prepare = cs_dig_playback_pcm_prepare,
191 .cleanup = cs_dig_playback_pcm_cleanup
195 static struct hda_pcm_stream cs_pcm_digital_capture = {
201 static int cs_build_pcms(struct hda_codec *codec)
203 struct cs_spec *spec = codec->spec;
204 struct hda_pcm *info = spec->pcm_rec;
206 codec->pcm_info = info;
209 info->name = "Cirrus Analog";
210 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cs_pcm_analog_playback;
211 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dac_nid[0];
212 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
213 spec->multiout.max_channels;
214 info->stream[SNDRV_PCM_STREAM_CAPTURE] = cs_pcm_analog_capture;
215 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
216 spec->adc_nid[spec->cur_input];
219 if (!spec->multiout.dig_out_nid && !spec->dig_in)
223 info->name = "Cirrus Digital";
224 info->pcm_type = spec->autocfg.dig_out_type[0];
226 info->pcm_type = HDA_PCM_TYPE_SPDIF;
227 if (spec->multiout.dig_out_nid) {
228 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
229 cs_pcm_digital_playback;
230 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
231 spec->multiout.dig_out_nid;
234 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
235 cs_pcm_digital_capture;
236 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
244 * parse codec topology
247 static hda_nid_t get_dac(struct hda_codec *codec, hda_nid_t pin)
252 if (snd_hda_get_connections(codec, pin, &dac, 1) != 1)
257 static int is_ext_mic(struct hda_codec *codec, unsigned int idx)
259 struct cs_spec *spec = codec->spec;
260 struct auto_pin_cfg *cfg = &spec->autocfg;
261 hda_nid_t pin = cfg->input_pins[idx];
262 unsigned int val = snd_hda_query_pin_caps(codec, pin);
263 if (!(val & AC_PINCAP_PRES_DETECT))
265 val = snd_hda_codec_get_pincfg(codec, pin);
266 return (get_defcfg_connect(val) == AC_JACK_PORT_COMPLEX);
269 static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin,
275 nid = codec->start_nid;
276 for (i = 0; i < codec->num_nodes; i++, nid++) {
280 type = (get_wcaps(codec, nid) & AC_WCAP_TYPE)
281 >> AC_WCAP_TYPE_SHIFT;
282 if (type != AC_WID_AUD_IN)
284 nums = snd_hda_get_connections(codec, nid, pins,
288 for (j = 0; j < nums; j++) {
289 if (pins[j] == pin) {
298 static int parse_output(struct hda_codec *codec)
300 struct cs_spec *spec = codec->spec;
301 struct auto_pin_cfg *cfg = &spec->autocfg;
302 int i, err, extra_nids;
305 for (i = 0; i < cfg->line_outs; i++) {
306 dac = get_dac(codec, cfg->line_out_pins[i]);
309 spec->dac_nid[i] = dac;
311 spec->multiout.num_dacs = i;
312 spec->multiout.dac_nids = spec->dac_nid;
313 spec->multiout.max_channels = i * 2;
315 /* add HP and speakers */
317 for (i = 0; i < cfg->hp_outs; i++) {
318 dac = get_dac(codec, cfg->hp_pins[i]);
322 spec->multiout.hp_nid = dac;
324 spec->multiout.extra_out_nid[extra_nids++] = dac;
326 for (i = 0; i < cfg->speaker_outs; i++) {
327 dac = get_dac(codec, cfg->speaker_pins[i]);
330 spec->multiout.extra_out_nid[extra_nids++] = dac;
333 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
334 cfg->speaker_outs = cfg->line_outs;
335 memcpy(cfg->speaker_pins, cfg->line_out_pins,
336 sizeof(cfg->speaker_pins));
343 static int parse_input(struct hda_codec *codec)
345 struct cs_spec *spec = codec->spec;
346 struct auto_pin_cfg *cfg = &spec->autocfg;
349 for (i = 0; i < AUTO_PIN_LAST; i++) {
350 hda_nid_t pin = cfg->input_pins[i];
351 struct snd_kcontrol *kctl;
354 spec->input_idx[spec->num_inputs] = i;
355 spec->capsrc_idx[i] = spec->num_inputs++;
357 spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]);
359 if (!spec->num_inputs)
362 /* check whether the automatic mic switch is available */
363 if (spec->num_inputs == 2 &&
364 spec->adc_nid[AUTO_PIN_MIC] && spec->adc_nid[AUTO_PIN_FRONT_MIC]) {
365 if (is_ext_mic(codec, cfg->input_pins[AUTO_PIN_FRONT_MIC])) {
366 if (!is_ext_mic(codec, cfg->input_pins[AUTO_PIN_MIC])) {
367 spec->mic_detect = 1;
368 spec->automic_idx = AUTO_PIN_FRONT_MIC;
371 if (is_ext_mic(codec, cfg->input_pins[AUTO_PIN_MIC])) {
372 spec->mic_detect = 1;
373 spec->automic_idx = AUTO_PIN_MIC;
381 static int parse_digital_output(struct hda_codec *codec)
383 struct cs_spec *spec = codec->spec;
384 struct auto_pin_cfg *cfg = &spec->autocfg;
390 if (snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) < 1)
392 spec->multiout.dig_out_nid = nid;
393 spec->multiout.share_spdif = 1;
394 if (cfg->dig_outs > 1 &&
395 snd_hda_get_connections(codec, cfg->dig_out_pins[1], &nid, 1) > 0) {
396 spec->slave_dig_outs[0] = nid;
397 codec->slave_dig_outs = spec->slave_dig_outs;
402 static int parse_digital_input(struct hda_codec *codec)
404 struct cs_spec *spec = codec->spec;
405 struct auto_pin_cfg *cfg = &spec->autocfg;
408 if (!cfg->dig_in_pin)
410 spec->dig_in = get_adc(codec, cfg->dig_in_pin, &idx);
413 return snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
417 * create mixer controls
420 static const char *dir_sfx[2] = { "Playback", "Capture" };
422 static int add_mute(struct hda_codec *codec, const char *name, int index,
423 unsigned int pval, int dir, struct snd_kcontrol **kctlp)
426 struct snd_kcontrol_new knew =
427 HDA_CODEC_MUTE_IDX(tmp, index, 0, 0, HDA_OUTPUT);
428 knew.private_value = pval;
429 snprintf(tmp, sizeof(tmp), "%s %s Switch", name, dir_sfx[dir]);
430 *kctlp = snd_ctl_new1(&knew, codec);
431 return snd_hda_ctl_add(codec, *kctlp);
434 static int add_volume(struct hda_codec *codec, const char *name,
435 int index, unsigned int pval, int dir,
436 struct snd_kcontrol **kctlp)
439 struct snd_kcontrol_new knew =
440 HDA_CODEC_VOLUME_IDX(tmp, index, 0, 0, HDA_OUTPUT);
441 knew.private_value = pval;
442 snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]);
443 *kctlp = snd_ctl_new1(&knew, codec);
444 return snd_hda_ctl_add(codec, *kctlp);
447 static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
451 /* set the upper-limit for mixer amp to 0dB */
452 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
453 caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT);
454 caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f)
455 << AC_AMPCAP_NUM_STEPS_SHIFT;
456 snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps);
459 static int add_vmaster(struct hda_codec *codec, hda_nid_t dac)
461 struct cs_spec *spec = codec->spec;
466 snd_ctl_make_virtual_master("Master Playback Switch", NULL);
467 err = snd_hda_ctl_add(codec, spec->vmaster_sw);
471 snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv);
473 snd_ctl_make_virtual_master("Master Playback Volume", tlv);
474 err = snd_hda_ctl_add(codec, spec->vmaster_vol);
480 static int add_output(struct hda_codec *codec, hda_nid_t dac, int idx,
481 int num_ctls, int type)
483 struct cs_spec *spec = codec->spec;
486 struct snd_kcontrol *kctl;
487 static char *speakers[] = {
488 "Front Speaker", "Surround Speaker", "Bass Speaker"
490 static char *line_outs[] = {
491 "Front Line-Out", "Surround Line-Out", "Bass Line-Out"
494 fix_volume_caps(codec, dac);
495 if (!spec->vmaster_sw) {
496 err = add_vmaster(codec, dac);
503 case AUTO_PIN_HP_OUT:
507 case AUTO_PIN_SPEAKER_OUT:
509 name = speakers[idx];
515 name = line_outs[idx];
521 err = add_mute(codec, name, index,
522 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
525 err = snd_ctl_add_slave(spec->vmaster_sw, kctl);
529 err = add_volume(codec, name, index,
530 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
533 err = snd_ctl_add_slave(spec->vmaster_vol, kctl);
540 static int build_output(struct hda_codec *codec)
542 struct cs_spec *spec = codec->spec;
543 struct auto_pin_cfg *cfg = &spec->autocfg;
546 for (i = 0; i < cfg->line_outs; i++) {
547 err = add_output(codec, get_dac(codec, cfg->line_out_pins[i]),
548 i, cfg->line_outs, cfg->line_out_type);
552 for (i = 0; i < cfg->hp_outs; i++) {
553 err = add_output(codec, get_dac(codec, cfg->hp_pins[i]),
554 i, cfg->hp_outs, AUTO_PIN_HP_OUT);
558 for (i = 0; i < cfg->speaker_outs; i++) {
559 err = add_output(codec, get_dac(codec, cfg->speaker_pins[i]),
560 i, cfg->speaker_outs, AUTO_PIN_SPEAKER_OUT);
570 static struct snd_kcontrol_new cs_capture_ctls[] = {
571 HDA_BIND_SW("Capture Switch", 0),
572 HDA_BIND_VOL("Capture Volume", 0),
575 static int change_cur_input(struct hda_codec *codec, unsigned int idx)
577 struct cs_spec *spec = codec->spec;
578 struct auto_pin_cfg *cfg = &spec->autocfg;
580 if (spec->cur_input == idx)
582 if (spec->cur_adc && spec->cur_adc != spec->adc_nid[idx]) {
583 /* stream is running, let's swap the current ADC */
584 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
585 spec->cur_adc = spec->adc_nid[idx];
586 snd_hda_codec_setup_stream(codec, spec->cur_adc,
587 spec->cur_adc_stream_tag, 0,
588 spec->cur_adc_format);
590 snd_hda_codec_write(codec, spec->cur_adc, 0,
591 AC_VERB_SET_CONNECT_SEL,
593 spec->cur_input = idx;
597 static int cs_capture_source_info(struct snd_kcontrol *kcontrol,
598 struct snd_ctl_elem_info *uinfo)
600 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
601 struct cs_spec *spec = codec->spec;
604 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
606 uinfo->value.enumerated.items = spec->num_inputs;
607 if (uinfo->value.enumerated.item >= spec->num_inputs)
608 uinfo->value.enumerated.item = spec->num_inputs - 1;
609 idx = spec->input_idx[uinfo->value.enumerated.item];
610 strcpy(uinfo->value.enumerated.name, auto_pin_cfg_labels[idx]);
614 static int cs_capture_source_get(struct snd_kcontrol *kcontrol,
615 struct snd_ctl_elem_value *ucontrol)
617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618 struct cs_spec *spec = codec->spec;
619 ucontrol->value.enumerated.item[0] = spec->capsrc_idx[spec->cur_input];
623 static int cs_capture_source_put(struct snd_kcontrol *kcontrol,
624 struct snd_ctl_elem_value *ucontrol)
626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
627 struct cs_spec *spec = codec->spec;
628 unsigned int idx = ucontrol->value.enumerated.item[0];
630 if (idx >= spec->num_inputs)
632 idx = spec->input_idx[idx];
633 return change_cur_input(codec, idx);
636 static struct snd_kcontrol_new cs_capture_source = {
637 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
638 .name = "Capture Source",
639 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
640 .info = cs_capture_source_info,
641 .get = cs_capture_source_get,
642 .put = cs_capture_source_put,
645 static struct hda_bind_ctls *make_bind_capture(struct hda_codec *codec,
646 struct hda_ctl_ops *ops)
648 struct cs_spec *spec = codec->spec;
649 struct hda_bind_ctls *bind;
652 bind = kzalloc(sizeof(*bind) + sizeof(long) * (spec->num_inputs + 1),
658 for (i = 0; i < AUTO_PIN_LAST; i++) {
659 if (!spec->adc_nid[i])
662 HDA_COMPOSE_AMP_VAL(spec->adc_nid[i], 3,
663 spec->adc_idx[i], HDA_INPUT);
668 static int build_input(struct hda_codec *codec)
670 struct cs_spec *spec = codec->spec;
673 if (!spec->num_inputs)
676 /* make bind-capture */
677 spec->capture_bind[0] = make_bind_capture(codec, &snd_hda_bind_sw);
678 spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol);
679 for (i = 0; i < 2; i++) {
680 struct snd_kcontrol *kctl;
681 if (!spec->capture_bind[i])
683 kctl = snd_ctl_new1(&cs_capture_ctls[i], codec);
686 kctl->private_value = (long)spec->capture_bind[i];
687 err = snd_hda_ctl_add(codec, kctl);
692 if (spec->num_inputs > 1 && !spec->mic_detect) {
693 err = snd_hda_ctl_add(codec,
694 snd_ctl_new1(&cs_capture_source, codec));
705 static int build_digital_output(struct hda_codec *codec)
707 struct cs_spec *spec = codec->spec;
710 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
713 err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
719 static int build_digital_input(struct hda_codec *codec)
721 struct cs_spec *spec = codec->spec;
723 return snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
728 * auto-mute and auto-mic switching
731 static void cs_automute(struct hda_codec *codec)
733 struct cs_spec *spec = codec->spec;
734 struct auto_pin_cfg *cfg = &spec->autocfg;
735 unsigned int caps, present, hp_present;
740 for (i = 0; i < cfg->hp_outs; i++) {
741 nid = cfg->hp_pins[i];
742 caps = snd_hda_query_pin_caps(codec, nid);
743 if (!(caps & AC_PINCAP_PRES_DETECT))
745 if (caps & AC_PINCAP_TRIG_REQ)
746 snd_hda_codec_read(codec, nid, 0,
747 AC_VERB_SET_PIN_SENSE, 0);
748 present = snd_hda_codec_read(codec, nid, 0,
749 AC_VERB_GET_PIN_SENSE, 0);
750 hp_present |= (present & AC_PINSENSE_PRESENCE) != 0;
754 for (i = 0; i < cfg->speaker_outs; i++) {
755 nid = cfg->speaker_pins[i];
756 snd_hda_codec_write(codec, nid, 0,
757 AC_VERB_SET_PIN_WIDGET_CONTROL,
758 hp_present ? 0 : PIN_OUT);
762 static void cs_automic(struct hda_codec *codec)
764 struct cs_spec *spec = codec->spec;
765 struct auto_pin_cfg *cfg = &spec->autocfg;
767 unsigned int caps, present;
769 nid = cfg->input_pins[spec->automic_idx];
770 caps = snd_hda_query_pin_caps(codec, nid);
771 if (caps & AC_PINCAP_TRIG_REQ)
772 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
773 present = snd_hda_codec_read(codec, nid, 0,
774 AC_VERB_GET_PIN_SENSE, 0);
775 if (present & AC_PINSENSE_PRESENCE)
776 change_cur_input(codec, spec->automic_idx);
778 unsigned int imic = (spec->automic_idx == AUTO_PIN_MIC) ?
779 AUTO_PIN_FRONT_MIC : AUTO_PIN_MIC;
780 change_cur_input(codec, imic);
787 static void init_output(struct hda_codec *codec)
789 struct cs_spec *spec = codec->spec;
790 struct auto_pin_cfg *cfg = &spec->autocfg;
794 for (i = 0; i < spec->multiout.num_dacs; i++)
795 snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
796 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
797 if (spec->multiout.hp_nid)
798 snd_hda_codec_write(codec, spec->multiout.hp_nid, 0,
799 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
800 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
801 if (!spec->multiout.extra_out_nid[i])
803 snd_hda_codec_write(codec, spec->multiout.extra_out_nid[i], 0,
804 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
807 /* set appropriate pin controls */
808 for (i = 0; i < cfg->line_outs; i++)
809 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
810 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
811 for (i = 0; i < cfg->hp_outs; i++) {
812 hda_nid_t nid = cfg->hp_pins[i];
813 snd_hda_codec_write(codec, nid, 0,
814 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
815 if (!cfg->speaker_outs)
817 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
818 snd_hda_codec_write(codec, nid, 0,
819 AC_VERB_SET_UNSOLICITED_ENABLE,
820 AC_USRSP_EN | HP_EVENT);
824 for (i = 0; i < cfg->speaker_outs; i++)
825 snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
826 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
831 static void init_input(struct hda_codec *codec)
833 struct cs_spec *spec = codec->spec;
834 struct auto_pin_cfg *cfg = &spec->autocfg;
837 for (i = 0; i < AUTO_PIN_LAST; i++) {
839 hda_nid_t pin = cfg->input_pins[i];
840 if (!pin || !spec->adc_nid[i])
842 /* set appropriate pin control and mute first */
844 if (i <= AUTO_PIN_FRONT_MIC) {
845 unsigned int caps = snd_hda_query_pin_caps(codec, pin);
846 caps >>= AC_PINCAP_VREF_SHIFT;
847 if (caps & AC_PINCAP_VREF_80)
850 snd_hda_codec_write(codec, pin, 0,
851 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
852 snd_hda_codec_write(codec, spec->adc_nid[i], 0,
853 AC_VERB_SET_AMP_GAIN_MUTE,
854 AMP_IN_MUTE(spec->adc_idx[i]));
855 if (spec->mic_detect && spec->automic_idx == i)
856 snd_hda_codec_write(codec, pin, 0,
857 AC_VERB_SET_UNSOLICITED_ENABLE,
858 AC_USRSP_EN | MIC_EVENT);
860 if (spec->mic_detect)
864 static int cs_init(struct hda_codec *codec)
866 struct cs_spec *spec = codec->spec;
873 static int cs_build_controls(struct hda_codec *codec)
875 struct cs_spec *spec = codec->spec;
878 err = build_output(codec);
881 err = build_input(codec);
884 err = build_digital_output(codec);
887 err = build_digital_input(codec);
890 return cs_init(codec);
893 static void cs_free(struct hda_codec *codec)
895 struct cs_spec *spec = codec->spec;
896 kfree(spec->capture_bind[0]);
897 kfree(spec->capture_bind[1]);
901 static void cs_unsol_event(struct hda_codec *codec, unsigned int res)
903 switch ((res >> 26) & 0x7f) {
913 static struct hda_codec_ops cs_patch_ops = {
914 .build_controls = cs_build_controls,
915 .build_pcms = cs_build_pcms,
918 .unsol_event = cs_unsol_event,
921 static int cs_parse_auto_config(struct hda_codec *codec)
923 struct cs_spec *spec = codec->spec;
926 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
933 static int patch_cs420x(struct hda_codec *codec)
935 struct cs_spec *spec;
938 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
943 err = cs_parse_auto_config(codec);
947 err = parse_output(codec);
950 err = parse_input(codec);
953 err = parse_digital_output(codec);
956 err = parse_digital_input(codec);
960 codec->patch_ops = cs_patch_ops;
974 static struct hda_codec_preset snd_hda_preset_cirrus[] = {
975 { .id = 0x10134206, .name = "CS4206", .patch = patch_cs420x },
976 { .id = 0x10134207, .name = "CS4207", .patch = patch_cs420x },
980 MODULE_ALIAS("snd-hda-codec-id:10134206");
981 MODULE_ALIAS("snd-hda-codec-id:10134207");
983 MODULE_LICENSE("GPL");
984 MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
986 static struct hda_codec_preset_list cirrus_list = {
987 .preset = snd_hda_preset_cirrus,
988 .owner = THIS_MODULE,
991 static int __init patch_cirrus_init(void)
993 return snd_hda_add_codec_preset(&cirrus_list);
996 static void __exit patch_cirrus_exit(void)
998 snd_hda_delete_codec_preset(&cirrus_list);
1001 module_init(patch_cirrus_init)
1002 module_exit(patch_cirrus_exit)