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 <linux/module.h>
26 #include <sound/core.h>
27 #include "hda_codec.h"
28 #include "hda_local.h"
29 #include "hda_auto_parser.h"
31 #include <sound/tlv.h>
37 struct hda_gen_spec gen
;
39 struct auto_pin_cfg autocfg
;
40 struct hda_multi_out multiout
;
41 struct snd_kcontrol
*vmaster_sw
;
42 struct snd_kcontrol
*vmaster_vol
;
44 hda_nid_t dac_nid
[AUTO_CFG_MAX_OUTS
];
45 hda_nid_t slave_dig_outs
[2];
47 unsigned int input_idx
[AUTO_PIN_LAST
];
48 unsigned int capsrc_idx
[AUTO_PIN_LAST
];
49 hda_nid_t adc_nid
[AUTO_PIN_LAST
];
50 unsigned int adc_idx
[AUTO_PIN_LAST
];
51 unsigned int num_inputs
;
52 unsigned int cur_input
;
53 unsigned int automic_idx
;
55 unsigned int cur_adc_stream_tag
;
56 unsigned int cur_adc_format
;
59 const struct hda_bind_ctls
*capture_bind
[2];
61 unsigned int gpio_mask
;
62 unsigned int gpio_dir
;
63 unsigned int gpio_data
;
64 unsigned int gpio_eapd_hp
; /* EAPD GPIO bit for headphones */
65 unsigned int gpio_eapd_speaker
; /* EAPD GPIO bit for speakers */
67 struct hda_pcm pcm_rec
[2]; /* PCM information */
69 unsigned int hp_detect
:1;
70 unsigned int mic_detect
:1;
71 unsigned int speaker_2_1
:1;
73 unsigned int spdif_detect
:1;
74 unsigned int sense_b
:1;
76 struct hda_input_mux input_mux
;
77 unsigned int last_input
;
80 /* available models with CS420x */
91 CS420X_IMAC27_122
= CS420X_GPIO_23
,
92 CS420X_APPLE
= CS420X_GPIO_13
,
101 /* Vendor-specific processing widget */
102 #define CS420X_VENDOR_NID 0x11
103 #define CS_DIG_OUT1_PIN_NID 0x10
104 #define CS_DIG_OUT2_PIN_NID 0x15
105 #define CS_DMIC1_PIN_NID 0x0e
106 #define CS_DMIC2_PIN_NID 0x12
109 #define IDX_SPDIF_STAT 0x0000
110 #define IDX_SPDIF_CTL 0x0001
111 #define IDX_ADC_CFG 0x0002
112 /* SZC bitmask, 4 modes below:
114 * 1 = digital immediate, analog zero-cross
115 * 2 = digtail & analog soft-ramp
116 * 3 = digital soft-ramp, analog zero-cross
118 #define CS_COEF_ADC_SZC_MASK (3 << 0)
119 #define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */
120 #define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
121 /* PGA mode: 0 = differential, 1 = signle-ended */
122 #define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */
123 #define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
124 #define IDX_DAC_CFG 0x0003
125 /* SZC bitmask, 4 modes below:
129 * 3 = soft-ramp on zero-cross
131 #define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */
132 #define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */
133 #define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */
135 #define IDX_BEEP_CFG 0x0004
136 /* 0x0008 - test reg key */
137 /* 0x0009 - 0x0014 -> 12 test regs */
138 /* 0x0015 - visibility reg */
141 * Cirrus Logic CS4210
143 * 1 DAC => HP(sense) / Speakers,
144 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
145 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
147 #define CS4210_DAC_NID 0x02
148 #define CS4210_ADC_NID 0x03
149 #define CS4210_VENDOR_NID 0x0B
150 #define CS421X_DMIC_PIN_NID 0x09 /* Port E */
151 #define CS421X_SPDIF_PIN_NID 0x0A /* Port H */
153 #define CS421X_IDX_DEV_CFG 0x01
154 #define CS421X_IDX_ADC_CFG 0x02
155 #define CS421X_IDX_DAC_CFG 0x03
156 #define CS421X_IDX_SPK_CTL 0x04
158 #define SPDIF_EVENT 0x04
160 /* Cirrus Logic CS4213 is like CS4210 but does not have SPDIF input/output */
161 #define CS4213_VENDOR_NID 0x09
164 static inline int cs_vendor_coef_get(struct hda_codec
*codec
, unsigned int idx
)
166 struct cs_spec
*spec
= codec
->spec
;
167 snd_hda_codec_write(codec
, spec
->vendor_nid
, 0,
168 AC_VERB_SET_COEF_INDEX
, idx
);
169 return snd_hda_codec_read(codec
, spec
->vendor_nid
, 0,
170 AC_VERB_GET_PROC_COEF
, 0);
173 static inline void cs_vendor_coef_set(struct hda_codec
*codec
, unsigned int idx
,
176 struct cs_spec
*spec
= codec
->spec
;
177 snd_hda_codec_write(codec
, spec
->vendor_nid
, 0,
178 AC_VERB_SET_COEF_INDEX
, idx
);
179 snd_hda_codec_write(codec
, spec
->vendor_nid
, 0,
180 AC_VERB_SET_PROC_COEF
, coef
);
190 static int cs_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
191 struct hda_codec
*codec
,
192 struct snd_pcm_substream
*substream
)
194 struct cs_spec
*spec
= codec
->spec
;
195 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
199 static int cs_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
200 struct hda_codec
*codec
,
201 unsigned int stream_tag
,
203 struct snd_pcm_substream
*substream
)
205 struct cs_spec
*spec
= codec
->spec
;
206 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
207 stream_tag
, format
, substream
);
210 static int cs_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
211 struct hda_codec
*codec
,
212 struct snd_pcm_substream
*substream
)
214 struct cs_spec
*spec
= codec
->spec
;
215 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
221 static int cs_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
222 struct hda_codec
*codec
,
223 struct snd_pcm_substream
*substream
)
225 struct cs_spec
*spec
= codec
->spec
;
226 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
229 static int cs_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
230 struct hda_codec
*codec
,
231 struct snd_pcm_substream
*substream
)
233 struct cs_spec
*spec
= codec
->spec
;
234 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
237 static int cs_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
238 struct hda_codec
*codec
,
239 unsigned int stream_tag
,
241 struct snd_pcm_substream
*substream
)
243 struct cs_spec
*spec
= codec
->spec
;
244 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
, stream_tag
,
248 static int cs_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
249 struct hda_codec
*codec
,
250 struct snd_pcm_substream
*substream
)
252 struct cs_spec
*spec
= codec
->spec
;
253 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
256 static void cs_update_input_select(struct hda_codec
*codec
)
258 struct cs_spec
*spec
= codec
->spec
;
260 snd_hda_codec_write(codec
, spec
->cur_adc
, 0,
261 AC_VERB_SET_CONNECT_SEL
,
262 spec
->adc_idx
[spec
->cur_input
]);
268 static int cs_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
269 struct hda_codec
*codec
,
270 unsigned int stream_tag
,
272 struct snd_pcm_substream
*substream
)
274 struct cs_spec
*spec
= codec
->spec
;
275 spec
->cur_adc
= spec
->adc_nid
[spec
->cur_input
];
276 spec
->cur_adc_stream_tag
= stream_tag
;
277 spec
->cur_adc_format
= format
;
278 cs_update_input_select(codec
);
279 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
283 static int cs_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
284 struct hda_codec
*codec
,
285 struct snd_pcm_substream
*substream
)
287 struct cs_spec
*spec
= codec
->spec
;
288 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
295 static const struct hda_pcm_stream cs_pcm_analog_playback
= {
300 .open
= cs_playback_pcm_open
,
301 .prepare
= cs_playback_pcm_prepare
,
302 .cleanup
= cs_playback_pcm_cleanup
306 static const struct hda_pcm_stream cs_pcm_analog_capture
= {
311 .prepare
= cs_capture_pcm_prepare
,
312 .cleanup
= cs_capture_pcm_cleanup
316 static const struct hda_pcm_stream cs_pcm_digital_playback
= {
321 .open
= cs_dig_playback_pcm_open
,
322 .close
= cs_dig_playback_pcm_close
,
323 .prepare
= cs_dig_playback_pcm_prepare
,
324 .cleanup
= cs_dig_playback_pcm_cleanup
328 static const struct hda_pcm_stream cs_pcm_digital_capture
= {
334 static int cs_build_pcms(struct hda_codec
*codec
)
336 struct cs_spec
*spec
= codec
->spec
;
337 struct hda_pcm
*info
= spec
->pcm_rec
;
339 codec
->pcm_info
= info
;
342 info
->name
= "Cirrus Analog";
343 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = cs_pcm_analog_playback
;
344 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->dac_nid
[0];
345 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
346 spec
->multiout
.max_channels
;
347 if (spec
->speaker_2_1
)
348 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].chmap
=
350 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = cs_pcm_analog_capture
;
351 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
352 spec
->adc_nid
[spec
->cur_input
];
355 if (!spec
->multiout
.dig_out_nid
&& !spec
->dig_in
)
359 info
->name
= "Cirrus Digital";
360 info
->pcm_type
= spec
->autocfg
.dig_out_type
[0];
362 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
363 if (spec
->multiout
.dig_out_nid
) {
364 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
365 cs_pcm_digital_playback
;
366 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
367 spec
->multiout
.dig_out_nid
;
370 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
371 cs_pcm_digital_capture
;
372 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in
;
380 * parse codec topology
383 static hda_nid_t
get_dac(struct hda_codec
*codec
, hda_nid_t pin
)
388 if (snd_hda_get_connections(codec
, pin
, &dac
, 1) != 1)
393 static int is_ext_mic(struct hda_codec
*codec
, unsigned int idx
)
395 struct cs_spec
*spec
= codec
->spec
;
396 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
397 hda_nid_t pin
= cfg
->inputs
[idx
].pin
;
399 if (!is_jack_detectable(codec
, pin
))
401 val
= snd_hda_codec_get_pincfg(codec
, pin
);
402 return (snd_hda_get_input_pin_attr(val
) != INPUT_PIN_ATTR_INT
);
405 static hda_nid_t
get_adc(struct hda_codec
*codec
, hda_nid_t pin
,
411 nid
= codec
->start_nid
;
412 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
414 type
= get_wcaps_type(get_wcaps(codec
, nid
));
415 if (type
!= AC_WID_AUD_IN
)
417 idx
= snd_hda_get_conn_index(codec
, nid
, pin
, false);
426 static int is_active_pin(struct hda_codec
*codec
, hda_nid_t nid
)
429 val
= snd_hda_codec_get_pincfg(codec
, nid
);
430 return (get_defcfg_connect(val
) != AC_JACK_PORT_NONE
);
433 static int parse_output(struct hda_codec
*codec
)
435 struct cs_spec
*spec
= codec
->spec
;
436 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
440 for (i
= 0; i
< cfg
->line_outs
; i
++) {
441 dac
= get_dac(codec
, cfg
->line_out_pins
[i
]);
444 spec
->dac_nid
[i
] = dac
;
446 spec
->multiout
.num_dacs
= i
;
447 spec
->multiout
.dac_nids
= spec
->dac_nid
;
448 spec
->multiout
.max_channels
= i
* 2;
450 if (cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&& i
== 2)
451 spec
->speaker_2_1
= 1; /* assume 2.1 speakers */
453 /* add HP and speakers */
455 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
456 dac
= get_dac(codec
, cfg
->hp_pins
[i
]);
460 spec
->multiout
.hp_nid
= dac
;
462 spec
->multiout
.extra_out_nid
[extra_nids
++] = dac
;
464 for (i
= 0; i
< cfg
->speaker_outs
; i
++) {
465 dac
= get_dac(codec
, cfg
->speaker_pins
[i
]);
468 spec
->multiout
.extra_out_nid
[extra_nids
++] = dac
;
471 if (cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
472 cfg
->speaker_outs
= cfg
->line_outs
;
473 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
474 sizeof(cfg
->speaker_pins
));
476 memset(cfg
->line_out_pins
, 0, sizeof(cfg
->line_out_pins
));
482 static int parse_input(struct hda_codec
*codec
)
484 struct cs_spec
*spec
= codec
->spec
;
485 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
488 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
489 hda_nid_t pin
= cfg
->inputs
[i
].pin
;
490 spec
->input_idx
[spec
->num_inputs
] = i
;
491 spec
->capsrc_idx
[i
] = spec
->num_inputs
++;
493 spec
->adc_nid
[i
] = get_adc(codec
, pin
, &spec
->adc_idx
[i
]);
495 if (!spec
->num_inputs
)
498 /* check whether the automatic mic switch is available */
499 if (spec
->num_inputs
== 2 &&
500 cfg
->inputs
[0].type
== AUTO_PIN_MIC
&&
501 cfg
->inputs
[1].type
== AUTO_PIN_MIC
) {
502 if (is_ext_mic(codec
, cfg
->inputs
[0].pin
)) {
503 if (!is_ext_mic(codec
, cfg
->inputs
[1].pin
)) {
504 spec
->mic_detect
= 1;
505 spec
->automic_idx
= 0;
508 if (is_ext_mic(codec
, cfg
->inputs
[1].pin
)) {
509 spec
->mic_detect
= 1;
510 spec
->automic_idx
= 1;
518 static int parse_digital_output(struct hda_codec
*codec
)
520 struct cs_spec
*spec
= codec
->spec
;
521 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
526 if (snd_hda_get_connections(codec
, cfg
->dig_out_pins
[0], &nid
, 1) < 1)
528 spec
->multiout
.dig_out_nid
= nid
;
529 spec
->multiout
.share_spdif
= 1;
530 if (cfg
->dig_outs
> 1 &&
531 snd_hda_get_connections(codec
, cfg
->dig_out_pins
[1], &nid
, 1) > 0) {
532 spec
->slave_dig_outs
[0] = nid
;
533 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
538 static int parse_digital_input(struct hda_codec
*codec
)
540 struct cs_spec
*spec
= codec
->spec
;
541 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
545 spec
->dig_in
= get_adc(codec
, cfg
->dig_in_pin
, &idx
);
550 * create mixer controls
553 static const char * const dir_sfx
[2] = { "Playback", "Capture" };
555 static int add_mute(struct hda_codec
*codec
, const char *name
, int index
,
556 unsigned int pval
, int dir
, struct snd_kcontrol
**kctlp
)
559 struct snd_kcontrol_new knew
=
560 HDA_CODEC_MUTE_IDX(tmp
, index
, 0, 0, HDA_OUTPUT
);
561 knew
.private_value
= pval
;
562 snprintf(tmp
, sizeof(tmp
), "%s %s Switch", name
, dir_sfx
[dir
]);
563 *kctlp
= snd_ctl_new1(&knew
, codec
);
564 (*kctlp
)->id
.subdevice
= HDA_SUBDEV_AMP_FLAG
;
565 return snd_hda_ctl_add(codec
, 0, *kctlp
);
568 static int add_volume(struct hda_codec
*codec
, const char *name
,
569 int index
, unsigned int pval
, int dir
,
570 struct snd_kcontrol
**kctlp
)
573 struct snd_kcontrol_new knew
=
574 HDA_CODEC_VOLUME_IDX(tmp
, index
, 0, 0, HDA_OUTPUT
);
575 knew
.private_value
= pval
;
576 snprintf(tmp
, sizeof(tmp
), "%s %s Volume", name
, dir_sfx
[dir
]);
577 *kctlp
= snd_ctl_new1(&knew
, codec
);
578 (*kctlp
)->id
.subdevice
= HDA_SUBDEV_AMP_FLAG
;
579 return snd_hda_ctl_add(codec
, 0, *kctlp
);
582 static void fix_volume_caps(struct hda_codec
*codec
, hda_nid_t dac
)
586 /* set the upper-limit for mixer amp to 0dB */
587 caps
= query_amp_caps(codec
, dac
, HDA_OUTPUT
);
588 caps
&= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT
);
589 caps
|= ((caps
>> AC_AMPCAP_OFFSET_SHIFT
) & 0x7f)
590 << AC_AMPCAP_NUM_STEPS_SHIFT
;
591 snd_hda_override_amp_caps(codec
, dac
, HDA_OUTPUT
, caps
);
594 static int add_vmaster(struct hda_codec
*codec
, hda_nid_t dac
)
596 struct cs_spec
*spec
= codec
->spec
;
601 snd_ctl_make_virtual_master("Master Playback Switch", NULL
);
602 err
= snd_hda_ctl_add(codec
, dac
, spec
->vmaster_sw
);
606 snd_hda_set_vmaster_tlv(codec
, dac
, HDA_OUTPUT
, tlv
);
608 snd_ctl_make_virtual_master("Master Playback Volume", tlv
);
609 err
= snd_hda_ctl_add(codec
, dac
, spec
->vmaster_vol
);
615 static int add_output(struct hda_codec
*codec
, hda_nid_t dac
, int idx
,
616 int num_ctls
, int type
)
618 struct cs_spec
*spec
= codec
->spec
;
621 struct snd_kcontrol
*kctl
;
622 static const char * const speakers
[] = {
623 "Front Speaker", "Surround Speaker", "Bass Speaker"
625 static const char * const line_outs
[] = {
626 "Front Line Out", "Surround Line Out", "Bass Line Out"
629 fix_volume_caps(codec
, dac
);
630 if (!spec
->vmaster_sw
) {
631 err
= add_vmaster(codec
, dac
);
638 case AUTO_PIN_HP_OUT
:
642 case AUTO_PIN_SPEAKER_OUT
:
643 if (spec
->speaker_2_1
)
644 name
= idx
? "Bass Speaker" : "Speaker";
645 else if (num_ctls
> 1)
646 name
= speakers
[idx
];
652 name
= line_outs
[idx
];
658 err
= add_mute(codec
, name
, index
,
659 HDA_COMPOSE_AMP_VAL(dac
, 3, 0, HDA_OUTPUT
), 0, &kctl
);
662 err
= snd_ctl_add_slave(spec
->vmaster_sw
, kctl
);
666 err
= add_volume(codec
, name
, index
,
667 HDA_COMPOSE_AMP_VAL(dac
, 3, 0, HDA_OUTPUT
), 0, &kctl
);
670 err
= snd_ctl_add_slave(spec
->vmaster_vol
, kctl
);
677 static int build_output(struct hda_codec
*codec
)
679 struct cs_spec
*spec
= codec
->spec
;
680 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
683 for (i
= 0; i
< cfg
->line_outs
; i
++) {
684 err
= add_output(codec
, get_dac(codec
, cfg
->line_out_pins
[i
]),
685 i
, cfg
->line_outs
, cfg
->line_out_type
);
689 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
690 err
= add_output(codec
, get_dac(codec
, cfg
->hp_pins
[i
]),
691 i
, cfg
->hp_outs
, AUTO_PIN_HP_OUT
);
695 for (i
= 0; i
< cfg
->speaker_outs
; i
++) {
696 err
= add_output(codec
, get_dac(codec
, cfg
->speaker_pins
[i
]),
697 i
, cfg
->speaker_outs
, AUTO_PIN_SPEAKER_OUT
);
707 static const struct snd_kcontrol_new cs_capture_ctls
[] = {
708 HDA_BIND_SW("Capture Switch", 0),
709 HDA_BIND_VOL("Capture Volume", 0),
712 static int change_cur_input(struct hda_codec
*codec
, unsigned int idx
,
715 struct cs_spec
*spec
= codec
->spec
;
717 if (spec
->cur_input
== idx
&& !force
)
719 if (spec
->cur_adc
&& spec
->cur_adc
!= spec
->adc_nid
[idx
]) {
720 /* stream is running, let's swap the current ADC */
721 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
722 spec
->cur_adc
= spec
->adc_nid
[idx
];
723 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
,
724 spec
->cur_adc_stream_tag
, 0,
725 spec
->cur_adc_format
);
727 spec
->cur_input
= idx
;
728 cs_update_input_select(codec
);
732 static int cs_capture_source_info(struct snd_kcontrol
*kcontrol
,
733 struct snd_ctl_elem_info
*uinfo
)
735 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
736 struct cs_spec
*spec
= codec
->spec
;
737 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
740 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
742 uinfo
->value
.enumerated
.items
= spec
->num_inputs
;
743 if (uinfo
->value
.enumerated
.item
>= spec
->num_inputs
)
744 uinfo
->value
.enumerated
.item
= spec
->num_inputs
- 1;
745 idx
= spec
->input_idx
[uinfo
->value
.enumerated
.item
];
746 snd_hda_get_pin_label(codec
, cfg
->inputs
[idx
].pin
, cfg
,
747 uinfo
->value
.enumerated
.name
,
748 sizeof(uinfo
->value
.enumerated
.name
), NULL
);
752 static int cs_capture_source_get(struct snd_kcontrol
*kcontrol
,
753 struct snd_ctl_elem_value
*ucontrol
)
755 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
756 struct cs_spec
*spec
= codec
->spec
;
757 ucontrol
->value
.enumerated
.item
[0] = spec
->capsrc_idx
[spec
->cur_input
];
761 static int cs_capture_source_put(struct snd_kcontrol
*kcontrol
,
762 struct snd_ctl_elem_value
*ucontrol
)
764 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
765 struct cs_spec
*spec
= codec
->spec
;
766 unsigned int idx
= ucontrol
->value
.enumerated
.item
[0];
768 if (idx
>= spec
->num_inputs
)
770 idx
= spec
->input_idx
[idx
];
771 return change_cur_input(codec
, idx
, 0);
774 static const struct snd_kcontrol_new cs_capture_source
= {
775 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
776 .name
= "Capture Source",
777 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
778 .info
= cs_capture_source_info
,
779 .get
= cs_capture_source_get
,
780 .put
= cs_capture_source_put
,
783 static const struct hda_bind_ctls
*make_bind_capture(struct hda_codec
*codec
,
784 struct hda_ctl_ops
*ops
)
786 struct cs_spec
*spec
= codec
->spec
;
787 struct hda_bind_ctls
*bind
;
790 bind
= kzalloc(sizeof(*bind
) + sizeof(long) * (spec
->num_inputs
+ 1),
796 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
797 if (!spec
->adc_nid
[i
])
800 HDA_COMPOSE_AMP_VAL(spec
->adc_nid
[i
], 3,
801 spec
->adc_idx
[i
], HDA_INPUT
);
806 /* add a (input-boost) volume control to the given input pin */
807 static int add_input_volume_control(struct hda_codec
*codec
,
808 struct auto_pin_cfg
*cfg
,
811 hda_nid_t pin
= cfg
->inputs
[item
].pin
;
814 struct snd_kcontrol
*kctl
;
816 if (!(get_wcaps(codec
, pin
) & AC_WCAP_IN_AMP
))
818 caps
= query_amp_caps(codec
, pin
, HDA_INPUT
);
819 caps
= (caps
& AC_AMPCAP_NUM_STEPS
) >> AC_AMPCAP_NUM_STEPS_SHIFT
;
822 label
= hda_get_autocfg_input_label(codec
, cfg
, item
);
823 return add_volume(codec
, label
, 0,
824 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_INPUT
), 1, &kctl
);
827 static int build_input(struct hda_codec
*codec
)
829 struct cs_spec
*spec
= codec
->spec
;
832 if (!spec
->num_inputs
)
835 /* make bind-capture */
836 spec
->capture_bind
[0] = make_bind_capture(codec
, &snd_hda_bind_sw
);
837 spec
->capture_bind
[1] = make_bind_capture(codec
, &snd_hda_bind_vol
);
838 for (i
= 0; i
< 2; i
++) {
839 struct snd_kcontrol
*kctl
;
841 if (!spec
->capture_bind
[i
])
843 kctl
= snd_ctl_new1(&cs_capture_ctls
[i
], codec
);
846 kctl
->private_value
= (long)spec
->capture_bind
[i
];
847 err
= snd_hda_ctl_add(codec
, 0, kctl
);
850 for (n
= 0; n
< AUTO_PIN_LAST
; n
++) {
851 if (!spec
->adc_nid
[n
])
853 err
= snd_hda_add_nid(codec
, kctl
, 0, spec
->adc_nid
[n
]);
859 if (spec
->num_inputs
> 1 && !spec
->mic_detect
) {
860 err
= snd_hda_ctl_add(codec
, 0,
861 snd_ctl_new1(&cs_capture_source
, codec
));
866 for (i
= 0; i
< spec
->num_inputs
; i
++) {
867 err
= add_input_volume_control(codec
, &spec
->autocfg
, i
);
878 static int build_digital_output(struct hda_codec
*codec
)
880 struct cs_spec
*spec
= codec
->spec
;
883 if (!spec
->multiout
.dig_out_nid
)
886 err
= snd_hda_create_dig_out_ctls(codec
, spec
->multiout
.dig_out_nid
,
887 spec
->multiout
.dig_out_nid
,
888 spec
->pcm_rec
[1].pcm_type
);
891 err
= snd_hda_create_spdif_share_sw(codec
, &spec
->multiout
);
897 static int build_digital_input(struct hda_codec
*codec
)
899 struct cs_spec
*spec
= codec
->spec
;
901 return snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in
);
906 * auto-mute and auto-mic switching
907 * CS421x auto-output redirecting
911 static void cs_automute(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
)
913 struct cs_spec
*spec
= codec
->spec
;
914 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
915 unsigned int hp_present
;
916 unsigned int spdif_present
;
922 nid
= cfg
->dig_out_pins
[0];
923 if (is_jack_detectable(codec
, nid
)) {
925 TODO: SPDIF output redirect when SENSE_B is enabled.
926 Shared (SENSE_A) jack (e.g HP/mini-TOSLINK)
929 if (snd_hda_jack_detect(codec
, nid
)
930 /* && spec->sense_b */)
936 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
937 nid
= cfg
->hp_pins
[i
];
938 if (!is_jack_detectable(codec
, nid
))
940 hp_present
= snd_hda_jack_detect(codec
, nid
);
945 /* mute speakers if spdif or hp jack is plugged in */
946 for (i
= 0; i
< cfg
->speaker_outs
; i
++) {
947 int pin_ctl
= hp_present
? 0 : PIN_OUT
;
948 /* detect on spdif is specific to CS4210 */
949 if (spdif_present
&& (spec
->vendor_nid
== CS4210_VENDOR_NID
))
952 nid
= cfg
->speaker_pins
[i
];
953 snd_hda_set_pin_ctl(codec
, nid
, pin_ctl
);
955 if (spec
->gpio_eapd_hp
) {
956 unsigned int gpio
= hp_present
?
957 spec
->gpio_eapd_hp
: spec
->gpio_eapd_speaker
;
958 snd_hda_codec_write(codec
, 0x01, 0,
959 AC_VERB_SET_GPIO_DATA
, gpio
);
962 /* specific to CS4210 */
963 if (spec
->vendor_nid
== CS4210_VENDOR_NID
) {
964 /* mute HPs if spdif jack (SENSE_B) is present */
965 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
966 nid
= cfg
->hp_pins
[i
];
967 snd_hda_set_pin_ctl(codec
, nid
,
968 (spdif_present
&& spec
->sense_b
) ? 0 : PIN_HP
);
971 /* SPDIF TX on/off */
973 nid
= cfg
->dig_out_pins
[0];
974 snd_hda_set_pin_ctl(codec
, nid
,
975 spdif_present
? PIN_OUT
: 0);
978 /* Update board GPIOs if neccessary ... */
983 * Auto-input redirect for CS421x
984 * Switch max 3 inputs of a single ADC (nid 3)
987 static void cs_automic(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
)
989 struct cs_spec
*spec
= codec
->spec
;
990 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
992 unsigned int present
;
994 nid
= cfg
->inputs
[spec
->automic_idx
].pin
;
995 present
= snd_hda_jack_detect(codec
, nid
);
997 /* specific to CS421x, single ADC */
998 if (spec
->vendor_nid
== CS420X_VENDOR_NID
) {
1000 change_cur_input(codec
, spec
->automic_idx
, 0);
1002 change_cur_input(codec
, !spec
->automic_idx
, 0);
1005 if (spec
->cur_input
!= spec
->automic_idx
) {
1006 spec
->last_input
= spec
->cur_input
;
1007 spec
->cur_input
= spec
->automic_idx
;
1010 spec
->cur_input
= spec
->last_input
;
1012 cs_update_input_select(codec
);
1019 static void init_output(struct hda_codec
*codec
)
1021 struct cs_spec
*spec
= codec
->spec
;
1022 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1026 for (i
= 0; i
< spec
->multiout
.num_dacs
; i
++)
1027 snd_hda_codec_write(codec
, spec
->multiout
.dac_nids
[i
], 0,
1028 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_MUTE
);
1029 if (spec
->multiout
.hp_nid
)
1030 snd_hda_codec_write(codec
, spec
->multiout
.hp_nid
, 0,
1031 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_MUTE
);
1032 for (i
= 0; i
< ARRAY_SIZE(spec
->multiout
.extra_out_nid
); i
++) {
1033 if (!spec
->multiout
.extra_out_nid
[i
])
1035 snd_hda_codec_write(codec
, spec
->multiout
.extra_out_nid
[i
], 0,
1036 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_MUTE
);
1039 /* set appropriate pin controls */
1040 for (i
= 0; i
< cfg
->line_outs
; i
++)
1041 snd_hda_set_pin_ctl(codec
, cfg
->line_out_pins
[i
], PIN_OUT
);
1043 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
1044 hda_nid_t nid
= cfg
->hp_pins
[i
];
1045 snd_hda_set_pin_ctl(codec
, nid
, PIN_HP
);
1046 if (!cfg
->speaker_outs
)
1048 if (get_wcaps(codec
, nid
) & AC_WCAP_UNSOL_CAP
) {
1049 snd_hda_jack_detect_enable_callback(codec
, nid
, HP_EVENT
, cs_automute
);
1050 spec
->hp_detect
= 1;
1055 for (i
= 0; i
< cfg
->speaker_outs
; i
++)
1056 snd_hda_set_pin_ctl(codec
, cfg
->speaker_pins
[i
], PIN_OUT
);
1058 /* SPDIF is enabled on presence detect for CS421x */
1059 if (spec
->hp_detect
|| spec
->spdif_detect
)
1060 cs_automute(codec
, NULL
);
1063 static void init_input(struct hda_codec
*codec
)
1065 struct cs_spec
*spec
= codec
->spec
;
1066 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1070 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1072 hda_nid_t pin
= cfg
->inputs
[i
].pin
;
1073 if (!spec
->adc_nid
[i
])
1075 /* set appropriate pin control and mute first */
1077 if (cfg
->inputs
[i
].type
== AUTO_PIN_MIC
)
1078 ctl
|= snd_hda_get_default_vref(codec
, pin
);
1079 snd_hda_set_pin_ctl(codec
, pin
, ctl
);
1080 snd_hda_codec_write(codec
, spec
->adc_nid
[i
], 0,
1081 AC_VERB_SET_AMP_GAIN_MUTE
,
1082 AMP_IN_MUTE(spec
->adc_idx
[i
]));
1083 if (spec
->mic_detect
&& spec
->automic_idx
== i
)
1084 snd_hda_jack_detect_enable_callback(codec
, pin
, MIC_EVENT
, cs_automic
);
1086 /* CS420x has multiple ADC, CS421x has single ADC */
1087 if (spec
->vendor_nid
== CS420X_VENDOR_NID
) {
1088 change_cur_input(codec
, spec
->cur_input
, 1);
1089 if (spec
->mic_detect
)
1090 cs_automic(codec
, NULL
);
1092 coef
= cs_vendor_coef_get(codec
, IDX_BEEP_CFG
);
1093 if (is_active_pin(codec
, CS_DMIC2_PIN_NID
))
1094 coef
|= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */
1095 if (is_active_pin(codec
, CS_DMIC1_PIN_NID
))
1096 coef
|= 1 << 3; /* DMIC1 2 chan on, GPIO0 off
1097 * No effect if SPDIF_OUT2 is
1098 * selected in IDX_SPDIF_CTL.
1101 cs_vendor_coef_set(codec
, IDX_BEEP_CFG
, coef
);
1103 if (spec
->mic_detect
)
1104 cs_automic(codec
, NULL
);
1106 spec
->cur_adc
= spec
->adc_nid
[spec
->cur_input
];
1107 cs_update_input_select(codec
);
1112 static const struct hda_verb cs_coef_init_verbs
[] = {
1113 {0x11, AC_VERB_SET_PROC_STATE
, 1},
1114 {0x11, AC_VERB_SET_COEF_INDEX
, IDX_DAC_CFG
},
1115 {0x11, AC_VERB_SET_PROC_COEF
,
1116 (0x002a /* DAC1/2/3 SZCMode Soft Ramp */
1117 | 0x0040 /* Mute DACs on FIFO error */
1118 | 0x1000 /* Enable DACs High Pass Filter */
1119 | 0x0400 /* Disable Coefficient Auto increment */
1121 /* ADC1/2 - Digital and Analog Soft Ramp */
1122 {0x11, AC_VERB_SET_COEF_INDEX
, IDX_ADC_CFG
},
1123 {0x11, AC_VERB_SET_PROC_COEF
, 0x000a},
1125 {0x11, AC_VERB_SET_COEF_INDEX
, IDX_BEEP_CFG
},
1126 {0x11, AC_VERB_SET_PROC_COEF
, 0x0007}, /* Enable Beep thru DAC1/2/3 */
1131 /* Errata: CS4207 rev C0/C1/C2 Silicon
1133 * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf
1135 * 6. At high temperature (TA > +85°C), the digital supply current (IVD)
1136 * may be excessive (up to an additional 200 μA), which is most easily
1137 * observed while the part is being held in reset (RESET# active low).
1139 * Root Cause: At initial powerup of the device, the logic that drives
1140 * the clock and write enable to the S/PDIF SRC RAMs is not properly
1142 * Certain random patterns will cause a steady leakage current in those
1143 * RAM cells. The issue will resolve once the SRCs are used (turned on).
1145 * Workaround: The following verb sequence briefly turns on the S/PDIF SRC
1146 * blocks, which will alleviate the issue.
1149 static const struct hda_verb cs_errata_init_verbs
[] = {
1150 {0x01, AC_VERB_SET_POWER_STATE
, 0x00}, /* AFG: D0 */
1151 {0x11, AC_VERB_SET_PROC_STATE
, 0x01}, /* VPW: processing on */
1153 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0008},
1154 {0x11, AC_VERB_SET_PROC_COEF
, 0x9999},
1155 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0017},
1156 {0x11, AC_VERB_SET_PROC_COEF
, 0xa412},
1157 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0001},
1158 {0x11, AC_VERB_SET_PROC_COEF
, 0x0009},
1160 {0x07, AC_VERB_SET_POWER_STATE
, 0x00}, /* S/PDIF Rx: D0 */
1161 {0x08, AC_VERB_SET_POWER_STATE
, 0x00}, /* S/PDIF Tx: D0 */
1163 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0017},
1164 {0x11, AC_VERB_SET_PROC_COEF
, 0x2412},
1165 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0008},
1166 {0x11, AC_VERB_SET_PROC_COEF
, 0x0000},
1167 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0001},
1168 {0x11, AC_VERB_SET_PROC_COEF
, 0x0008},
1169 {0x11, AC_VERB_SET_PROC_STATE
, 0x00},
1171 #if 0 /* Don't to set to D3 as we are in power-up sequence */
1172 {0x07, AC_VERB_SET_POWER_STATE
, 0x03}, /* S/PDIF Rx: D3 */
1173 {0x08, AC_VERB_SET_POWER_STATE
, 0x03}, /* S/PDIF Tx: D3 */
1174 /*{0x01, AC_VERB_SET_POWER_STATE, 0x03},*/ /* AFG: D3 This is already handled */
1181 static void init_digital(struct hda_codec
*codec
)
1185 coef
= 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */
1186 coef
|= 0x0008; /* Replace with mute on error */
1187 if (is_active_pin(codec
, CS_DIG_OUT2_PIN_NID
))
1188 coef
|= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2
1189 * SPDIF_OUT2 is shared with GPIO1 and
1192 cs_vendor_coef_set(codec
, IDX_SPDIF_CTL
, coef
);
1195 static int cs_init(struct hda_codec
*codec
)
1197 struct cs_spec
*spec
= codec
->spec
;
1199 /* init_verb sequence for C0/C1/C2 errata*/
1200 snd_hda_sequence_write(codec
, cs_errata_init_verbs
);
1202 snd_hda_sequence_write(codec
, cs_coef_init_verbs
);
1204 snd_hda_gen_apply_verbs(codec
);
1206 if (spec
->gpio_mask
) {
1207 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_MASK
,
1209 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION
,
1211 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DATA
,
1217 init_digital(codec
);
1222 static int cs_build_controls(struct hda_codec
*codec
)
1224 struct cs_spec
*spec
= codec
->spec
;
1227 err
= build_output(codec
);
1230 err
= build_input(codec
);
1233 err
= build_digital_output(codec
);
1236 err
= build_digital_input(codec
);
1239 err
= cs_init(codec
);
1243 err
= snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
1250 static void cs_free(struct hda_codec
*codec
)
1252 struct cs_spec
*spec
= codec
->spec
;
1253 kfree(spec
->capture_bind
[0]);
1254 kfree(spec
->capture_bind
[1]);
1255 snd_hda_gen_free(&spec
->gen
);
1259 static const struct hda_codec_ops cs_patch_ops
= {
1260 .build_controls
= cs_build_controls
,
1261 .build_pcms
= cs_build_pcms
,
1264 .unsol_event
= snd_hda_jack_unsol_event
,
1267 static int cs_parse_auto_config(struct hda_codec
*codec
)
1269 struct cs_spec
*spec
= codec
->spec
;
1272 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1276 err
= parse_output(codec
);
1279 err
= parse_input(codec
);
1282 err
= parse_digital_output(codec
);
1285 err
= parse_digital_input(codec
);
1291 static const struct hda_model_fixup cs420x_models
[] = {
1292 { .id
= CS420X_MBP53
, .name
= "mbp53" },
1293 { .id
= CS420X_MBP55
, .name
= "mbp55" },
1294 { .id
= CS420X_IMAC27
, .name
= "imac27" },
1295 { .id
= CS420X_IMAC27_122
, .name
= "imac27_122" },
1296 { .id
= CS420X_APPLE
, .name
= "apple" },
1297 { .id
= CS420X_MBP101
, .name
= "mbp101" },
1298 { .id
= CS420X_MBP81
, .name
= "mbp81" },
1302 static const struct snd_pci_quirk cs420x_fixup_tbl
[] = {
1303 SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53
),
1304 SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55
),
1305 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55
),
1306 SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55
),
1307 /* this conflicts with too many other models */
1308 /*SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),*/
1311 SND_PCI_QUIRK(0x106b, 0x1c00, "MacBookPro 8,1", CS420X_MBP81
),
1312 SND_PCI_QUIRK(0x106b, 0x2000, "iMac 12,2", CS420X_IMAC27_122
),
1313 SND_PCI_QUIRK(0x106b, 0x2800, "MacBookPro 10,1", CS420X_MBP101
),
1314 SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS420X_APPLE
),
1318 static const struct hda_pintbl mbp53_pincfgs
[] = {
1319 { 0x09, 0x012b4050 },
1320 { 0x0a, 0x90100141 },
1321 { 0x0b, 0x90100140 },
1322 { 0x0c, 0x018b3020 },
1323 { 0x0d, 0x90a00110 },
1324 { 0x0e, 0x400000f0 },
1325 { 0x0f, 0x01cbe030 },
1326 { 0x10, 0x014be060 },
1327 { 0x12, 0x400000f0 },
1328 { 0x15, 0x400000f0 },
1332 static const struct hda_pintbl mbp55_pincfgs
[] = {
1333 { 0x09, 0x012b4030 },
1334 { 0x0a, 0x90100121 },
1335 { 0x0b, 0x90100120 },
1336 { 0x0c, 0x400000f0 },
1337 { 0x0d, 0x90a00110 },
1338 { 0x0e, 0x400000f0 },
1339 { 0x0f, 0x400000f0 },
1340 { 0x10, 0x014be040 },
1341 { 0x12, 0x400000f0 },
1342 { 0x15, 0x400000f0 },
1346 static const struct hda_pintbl imac27_pincfgs
[] = {
1347 { 0x09, 0x012b4050 },
1348 { 0x0a, 0x90100140 },
1349 { 0x0b, 0x90100142 },
1350 { 0x0c, 0x018b3020 },
1351 { 0x0d, 0x90a00110 },
1352 { 0x0e, 0x400000f0 },
1353 { 0x0f, 0x01cbe030 },
1354 { 0x10, 0x014be060 },
1355 { 0x12, 0x01ab9070 },
1356 { 0x15, 0x400000f0 },
1360 static const struct hda_pintbl mbp101_pincfgs
[] = {
1361 { 0x0d, 0x40ab90f0 },
1362 { 0x0e, 0x90a600f0 },
1363 { 0x12, 0x50a600f0 },
1367 static void cs420x_fixup_gpio_13(struct hda_codec
*codec
,
1368 const struct hda_fixup
*fix
, int action
)
1370 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
1371 struct cs_spec
*spec
= codec
->spec
;
1372 spec
->gpio_eapd_hp
= 2; /* GPIO1 = headphones */
1373 spec
->gpio_eapd_speaker
= 8; /* GPIO3 = speakers */
1374 spec
->gpio_mask
= spec
->gpio_dir
=
1375 spec
->gpio_eapd_hp
| spec
->gpio_eapd_speaker
;
1379 static void cs420x_fixup_gpio_23(struct hda_codec
*codec
,
1380 const struct hda_fixup
*fix
, int action
)
1382 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
1383 struct cs_spec
*spec
= codec
->spec
;
1384 spec
->gpio_eapd_hp
= 4; /* GPIO2 = headphones */
1385 spec
->gpio_eapd_speaker
= 8; /* GPIO3 = speakers */
1386 spec
->gpio_mask
= spec
->gpio_dir
=
1387 spec
->gpio_eapd_hp
| spec
->gpio_eapd_speaker
;
1391 static const struct hda_fixup cs420x_fixups
[] = {
1393 .type
= HDA_FIXUP_PINS
,
1394 .v
.pins
= mbp53_pincfgs
,
1396 .chain_id
= CS420X_APPLE
,
1399 .type
= HDA_FIXUP_PINS
,
1400 .v
.pins
= mbp55_pincfgs
,
1402 .chain_id
= CS420X_GPIO_13
,
1405 .type
= HDA_FIXUP_PINS
,
1406 .v
.pins
= imac27_pincfgs
,
1408 .chain_id
= CS420X_GPIO_13
,
1410 [CS420X_GPIO_13
] = {
1411 .type
= HDA_FIXUP_FUNC
,
1412 .v
.func
= cs420x_fixup_gpio_13
,
1414 [CS420X_GPIO_23
] = {
1415 .type
= HDA_FIXUP_FUNC
,
1416 .v
.func
= cs420x_fixup_gpio_23
,
1419 .type
= HDA_FIXUP_PINS
,
1420 .v
.pins
= mbp101_pincfgs
,
1422 .chain_id
= CS420X_GPIO_13
,
1425 .type
= HDA_FIXUP_VERBS
,
1426 .v
.verbs
= (const struct hda_verb
[]) {
1427 /* internal mic ADC2: right only, single ended */
1428 {0x11, AC_VERB_SET_COEF_INDEX
, IDX_ADC_CFG
},
1429 {0x11, AC_VERB_SET_PROC_COEF
, 0x102a},
1433 .chain_id
= CS420X_GPIO_13
,
1437 static int patch_cs420x(struct hda_codec
*codec
)
1439 struct cs_spec
*spec
;
1442 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1446 snd_hda_gen_init(&spec
->gen
);
1448 spec
->vendor_nid
= CS420X_VENDOR_NID
;
1450 snd_hda_pick_fixup(codec
, cs420x_models
, cs420x_fixup_tbl
,
1452 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
1454 err
= cs_parse_auto_config(codec
);
1458 codec
->patch_ops
= cs_patch_ops
;
1460 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
1471 * Cirrus Logic CS4210
1473 * 1 DAC => HP(sense) / Speakers,
1474 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
1475 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
1478 /* CS4210 board names */
1479 static const struct hda_model_fixup cs421x_models
[] = {
1480 { .id
= CS421X_CDB4210
, .name
= "cdb4210" },
1484 static const struct snd_pci_quirk cs421x_fixup_tbl
[] = {
1485 /* Test Intel board + CDB2410 */
1486 SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210
),
1490 /* CS4210 board pinconfigs */
1491 /* Default CS4210 (CDB4210)*/
1492 static const struct hda_pintbl cdb4210_pincfgs
[] = {
1493 { 0x05, 0x0321401f },
1494 { 0x06, 0x90170010 },
1495 { 0x07, 0x03813031 },
1496 { 0x08, 0xb7a70037 },
1497 { 0x09, 0xb7a6003e },
1498 { 0x0a, 0x034510f0 },
1502 /* Setup GPIO/SENSE for each board (if used) */
1503 static void cs421x_fixup_sense_b(struct hda_codec
*codec
,
1504 const struct hda_fixup
*fix
, int action
)
1506 struct cs_spec
*spec
= codec
->spec
;
1507 if (action
== HDA_FIXUP_ACT_PRE_PROBE
)
1511 static const struct hda_fixup cs421x_fixups
[] = {
1512 [CS421X_CDB4210
] = {
1513 .type
= HDA_FIXUP_PINS
,
1514 .v
.pins
= cdb4210_pincfgs
,
1516 .chain_id
= CS421X_SENSE_B
,
1518 [CS421X_SENSE_B
] = {
1519 .type
= HDA_FIXUP_FUNC
,
1520 .v
.func
= cs421x_fixup_sense_b
,
1524 static const struct hda_verb cs421x_coef_init_verbs
[] = {
1525 {0x0B, AC_VERB_SET_PROC_STATE
, 1},
1526 {0x0B, AC_VERB_SET_COEF_INDEX
, CS421X_IDX_DEV_CFG
},
1528 Disable Coefficient Index Auto-Increment(DAI)=1,
1531 {0x0B, AC_VERB_SET_PROC_COEF
, 0x0001 },
1533 {0x0B, AC_VERB_SET_COEF_INDEX
, CS421X_IDX_ADC_CFG
},
1534 /* ADC SZCMode = Digital Soft Ramp */
1535 {0x0B, AC_VERB_SET_PROC_COEF
, 0x0002 },
1537 {0x0B, AC_VERB_SET_COEF_INDEX
, CS421X_IDX_DAC_CFG
},
1538 {0x0B, AC_VERB_SET_PROC_COEF
,
1539 (0x0002 /* DAC SZCMode = Digital Soft Ramp */
1540 | 0x0004 /* Mute DAC on FIFO error */
1541 | 0x0008 /* Enable DAC High Pass Filter */
1546 /* Errata: CS4210 rev A1 Silicon
1548 * http://www.cirrus.com/en/pubs/errata/
1551 * 1. Performance degredation is present in the ADC.
1552 * 2. Speaker output is not completely muted upon HP detect.
1553 * 3. Noise is present when clipping occurs on the amplified
1557 * The following verb sequence written to the registers during
1558 * initialization will correct the issues listed above.
1561 static const struct hda_verb cs421x_coef_init_verbs_A1_silicon_fixes
[] = {
1562 {0x0B, AC_VERB_SET_PROC_STATE
, 0x01}, /* VPW: processing on */
1564 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x0006},
1565 {0x0B, AC_VERB_SET_PROC_COEF
, 0x9999}, /* Test mode: on */
1567 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x000A},
1568 {0x0B, AC_VERB_SET_PROC_COEF
, 0x14CB}, /* Chop double */
1570 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x0011},
1571 {0x0B, AC_VERB_SET_PROC_COEF
, 0xA2D0}, /* Increase ADC current */
1573 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x001A},
1574 {0x0B, AC_VERB_SET_PROC_COEF
, 0x02A9}, /* Mute speaker */
1576 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x001B},
1577 {0x0B, AC_VERB_SET_PROC_COEF
, 0X1006}, /* Remove noise */
1582 /* Speaker Amp Gain is controlled by the vendor widget's coef 4 */
1583 static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale
, 900, 300, 0);
1585 static int cs421x_boost_vol_info(struct snd_kcontrol
*kcontrol
,
1586 struct snd_ctl_elem_info
*uinfo
)
1588 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1590 uinfo
->value
.integer
.min
= 0;
1591 uinfo
->value
.integer
.max
= 3;
1595 static int cs421x_boost_vol_get(struct snd_kcontrol
*kcontrol
,
1596 struct snd_ctl_elem_value
*ucontrol
)
1598 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1600 ucontrol
->value
.integer
.value
[0] =
1601 cs_vendor_coef_get(codec
, CS421X_IDX_SPK_CTL
) & 0x0003;
1605 static int cs421x_boost_vol_put(struct snd_kcontrol
*kcontrol
,
1606 struct snd_ctl_elem_value
*ucontrol
)
1608 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1610 unsigned int vol
= ucontrol
->value
.integer
.value
[0];
1612 cs_vendor_coef_get(codec
, CS421X_IDX_SPK_CTL
);
1613 unsigned int original_coef
= coef
;
1616 coef
|= (vol
& 0x0003);
1617 if (original_coef
== coef
)
1620 cs_vendor_coef_set(codec
, CS421X_IDX_SPK_CTL
, coef
);
1625 static const struct snd_kcontrol_new cs421x_speaker_bost_ctl
= {
1627 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1628 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1629 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
1630 .name
= "Speaker Boost Playback Volume",
1631 .info
= cs421x_boost_vol_info
,
1632 .get
= cs421x_boost_vol_get
,
1633 .put
= cs421x_boost_vol_put
,
1634 .tlv
= { .p
= cs421x_speaker_boost_db_scale
},
1637 static void cs4210_pinmux_init(struct hda_codec
*codec
)
1639 struct cs_spec
*spec
= codec
->spec
;
1640 unsigned int def_conf
, coef
;
1642 /* GPIO, DMIC_SCL, DMIC_SDA and SENSE_B are multiplexed */
1643 coef
= cs_vendor_coef_get(codec
, CS421X_IDX_DEV_CFG
);
1645 if (spec
->gpio_mask
)
1646 coef
|= 0x0008; /* B1,B2 are GPIOs */
1651 coef
|= 0x0010; /* B2 is SENSE_B, not inverted */
1655 cs_vendor_coef_set(codec
, CS421X_IDX_DEV_CFG
, coef
);
1657 if ((spec
->gpio_mask
|| spec
->sense_b
) &&
1658 is_active_pin(codec
, CS421X_DMIC_PIN_NID
)) {
1661 GPIO or SENSE_B forced - disconnect the DMIC pin.
1663 def_conf
= snd_hda_codec_get_pincfg(codec
, CS421X_DMIC_PIN_NID
);
1664 def_conf
&= ~AC_DEFCFG_PORT_CONN
;
1665 def_conf
|= (AC_JACK_PORT_NONE
<< AC_DEFCFG_PORT_CONN_SHIFT
);
1666 snd_hda_codec_set_pincfg(codec
, CS421X_DMIC_PIN_NID
, def_conf
);
1670 static void init_cs421x_digital(struct hda_codec
*codec
)
1672 struct cs_spec
*spec
= codec
->spec
;
1673 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1677 for (i
= 0; i
< cfg
->dig_outs
; i
++) {
1678 hda_nid_t nid
= cfg
->dig_out_pins
[i
];
1679 if (!cfg
->speaker_outs
)
1681 if (get_wcaps(codec
, nid
) & AC_WCAP_UNSOL_CAP
) {
1682 snd_hda_jack_detect_enable_callback(codec
, nid
, SPDIF_EVENT
, cs_automute
);
1683 spec
->spdif_detect
= 1;
1688 static int cs421x_init(struct hda_codec
*codec
)
1690 struct cs_spec
*spec
= codec
->spec
;
1692 if (spec
->vendor_nid
== CS4210_VENDOR_NID
) {
1693 snd_hda_sequence_write(codec
, cs421x_coef_init_verbs
);
1694 snd_hda_sequence_write(codec
, cs421x_coef_init_verbs_A1_silicon_fixes
);
1695 cs4210_pinmux_init(codec
);
1698 if (spec
->gpio_mask
) {
1699 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_MASK
,
1701 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION
,
1703 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DATA
,
1709 init_cs421x_digital(codec
);
1715 * CS4210 Input MUX (1 ADC)
1717 static int cs421x_mux_enum_info(struct snd_kcontrol
*kcontrol
,
1718 struct snd_ctl_elem_info
*uinfo
)
1720 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1721 struct cs_spec
*spec
= codec
->spec
;
1723 return snd_hda_input_mux_info(&spec
->input_mux
, uinfo
);
1726 static int cs421x_mux_enum_get(struct snd_kcontrol
*kcontrol
,
1727 struct snd_ctl_elem_value
*ucontrol
)
1729 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1730 struct cs_spec
*spec
= codec
->spec
;
1732 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_input
;
1736 static int cs421x_mux_enum_put(struct snd_kcontrol
*kcontrol
,
1737 struct snd_ctl_elem_value
*ucontrol
)
1739 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1740 struct cs_spec
*spec
= codec
->spec
;
1742 return snd_hda_input_mux_put(codec
, &spec
->input_mux
, ucontrol
,
1743 spec
->adc_nid
[0], &spec
->cur_input
);
1747 static const struct snd_kcontrol_new cs421x_capture_source
= {
1748 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1749 .name
= "Capture Source",
1750 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
1751 .info
= cs421x_mux_enum_info
,
1752 .get
= cs421x_mux_enum_get
,
1753 .put
= cs421x_mux_enum_put
,
1756 static int cs421x_add_input_volume_control(struct hda_codec
*codec
, int item
)
1758 struct cs_spec
*spec
= codec
->spec
;
1759 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1760 const struct hda_input_mux
*imux
= &spec
->input_mux
;
1761 hda_nid_t pin
= cfg
->inputs
[item
].pin
;
1762 struct snd_kcontrol
*kctl
;
1765 if (!(get_wcaps(codec
, pin
) & AC_WCAP_IN_AMP
))
1768 caps
= query_amp_caps(codec
, pin
, HDA_INPUT
);
1769 caps
= (caps
& AC_AMPCAP_NUM_STEPS
) >> AC_AMPCAP_NUM_STEPS_SHIFT
;
1773 return add_volume(codec
, imux
->items
[item
].label
, 0,
1774 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_INPUT
), 1, &kctl
);
1777 /* add a (input-boost) volume control to the given input pin */
1778 static int build_cs421x_input(struct hda_codec
*codec
)
1780 struct cs_spec
*spec
= codec
->spec
;
1781 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1782 struct hda_input_mux
*imux
= &spec
->input_mux
;
1783 int i
, err
, type_idx
;
1786 if (!spec
->num_inputs
)
1789 /* make bind-capture */
1790 spec
->capture_bind
[0] = make_bind_capture(codec
, &snd_hda_bind_sw
);
1791 spec
->capture_bind
[1] = make_bind_capture(codec
, &snd_hda_bind_vol
);
1792 for (i
= 0; i
< 2; i
++) {
1793 struct snd_kcontrol
*kctl
;
1795 if (!spec
->capture_bind
[i
])
1797 kctl
= snd_ctl_new1(&cs_capture_ctls
[i
], codec
);
1800 kctl
->private_value
= (long)spec
->capture_bind
[i
];
1801 err
= snd_hda_ctl_add(codec
, 0, kctl
);
1804 for (n
= 0; n
< AUTO_PIN_LAST
; n
++) {
1805 if (!spec
->adc_nid
[n
])
1807 err
= snd_hda_add_nid(codec
, kctl
, 0, spec
->adc_nid
[n
]);
1813 /* Add Input MUX Items + Capture Volume/Switch */
1814 for (i
= 0; i
< spec
->num_inputs
; i
++) {
1815 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
1816 snd_hda_add_imux_item(imux
, label
, spec
->adc_idx
[i
], &type_idx
);
1818 err
= cs421x_add_input_volume_control(codec
, i
);
1824 Add 'Capture Source' Switch if
1825 * 2 inputs and no mic detec
1828 if ((spec
->num_inputs
== 2 && !spec
->mic_detect
) ||
1829 (spec
->num_inputs
== 3)) {
1831 err
= snd_hda_ctl_add(codec
, spec
->adc_nid
[0],
1832 snd_ctl_new1(&cs421x_capture_source
, codec
));
1840 /* Single DAC (Mute/Gain) */
1841 static int build_cs421x_output(struct hda_codec
*codec
)
1843 hda_nid_t dac
= CS4210_DAC_NID
;
1844 struct cs_spec
*spec
= codec
->spec
;
1845 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1846 struct snd_kcontrol
*kctl
;
1848 char *name
= "Master";
1850 fix_volume_caps(codec
, dac
);
1852 err
= add_mute(codec
, name
, 0,
1853 HDA_COMPOSE_AMP_VAL(dac
, 3, 0, HDA_OUTPUT
), 0, &kctl
);
1857 err
= add_volume(codec
, name
, 0,
1858 HDA_COMPOSE_AMP_VAL(dac
, 3, 0, HDA_OUTPUT
), 0, &kctl
);
1862 if (cfg
->speaker_outs
&& (spec
->vendor_nid
== CS4210_VENDOR_NID
)) {
1863 err
= snd_hda_ctl_add(codec
, 0,
1864 snd_ctl_new1(&cs421x_speaker_bost_ctl
, codec
));
1871 static int cs421x_build_controls(struct hda_codec
*codec
)
1873 struct cs_spec
*spec
= codec
->spec
;
1876 err
= build_cs421x_output(codec
);
1879 err
= build_cs421x_input(codec
);
1882 err
= build_digital_output(codec
);
1885 err
= cs421x_init(codec
);
1889 err
= snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
1896 static int parse_cs421x_input(struct hda_codec
*codec
)
1898 struct cs_spec
*spec
= codec
->spec
;
1899 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1902 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1903 hda_nid_t pin
= cfg
->inputs
[i
].pin
;
1904 spec
->adc_nid
[i
] = get_adc(codec
, pin
, &spec
->adc_idx
[i
]);
1905 spec
->cur_input
= spec
->last_input
= i
;
1908 /* check whether the automatic mic switch is available */
1909 if (is_ext_mic(codec
, i
) && cfg
->num_inputs
>= 2) {
1910 spec
->mic_detect
= 1;
1911 spec
->automic_idx
= i
;
1917 static int cs421x_parse_auto_config(struct hda_codec
*codec
)
1919 struct cs_spec
*spec
= codec
->spec
;
1922 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1925 err
= parse_output(codec
);
1928 err
= parse_cs421x_input(codec
);
1931 err
= parse_digital_output(codec
);
1939 Manage PDREF, when transitioning to D3hot
1940 (DAC,ADC) -> D3, PDREF=1, AFG->D3
1942 static int cs421x_suspend(struct hda_codec
*codec
)
1944 struct cs_spec
*spec
= codec
->spec
;
1947 snd_hda_shutup_pins(codec
);
1949 snd_hda_codec_write(codec
, CS4210_DAC_NID
, 0,
1950 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
1951 snd_hda_codec_write(codec
, CS4210_ADC_NID
, 0,
1952 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
1954 if (spec
->vendor_nid
== CS4210_VENDOR_NID
) {
1955 coef
= cs_vendor_coef_get(codec
, CS421X_IDX_DEV_CFG
);
1956 coef
|= 0x0004; /* PDREF */
1957 cs_vendor_coef_set(codec
, CS421X_IDX_DEV_CFG
, coef
);
1964 static const struct hda_codec_ops cs421x_patch_ops
= {
1965 .build_controls
= cs421x_build_controls
,
1966 .build_pcms
= cs_build_pcms
,
1967 .init
= cs421x_init
,
1969 .unsol_event
= snd_hda_jack_unsol_event
,
1971 .suspend
= cs421x_suspend
,
1975 static int patch_cs4210(struct hda_codec
*codec
)
1977 struct cs_spec
*spec
;
1980 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1984 snd_hda_gen_init(&spec
->gen
);
1986 spec
->vendor_nid
= CS4210_VENDOR_NID
;
1988 snd_hda_pick_fixup(codec
, cs421x_models
, cs421x_fixup_tbl
,
1990 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
1993 Update the GPIO/DMIC/SENSE_B pinmux before the configuration
1994 is auto-parsed. If GPIO or SENSE_B is forced, DMIC input
1997 cs4210_pinmux_init(codec
);
1999 err
= cs421x_parse_auto_config(codec
);
2003 codec
->patch_ops
= cs421x_patch_ops
;
2005 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
2015 static int patch_cs4213(struct hda_codec
*codec
)
2017 struct cs_spec
*spec
;
2020 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2024 snd_hda_gen_init(&spec
->gen
);
2026 spec
->vendor_nid
= CS4213_VENDOR_NID
;
2028 err
= cs421x_parse_auto_config(codec
);
2032 codec
->patch_ops
= cs421x_patch_ops
;
2045 static const struct hda_codec_preset snd_hda_preset_cirrus
[] = {
2046 { .id
= 0x10134206, .name
= "CS4206", .patch
= patch_cs420x
},
2047 { .id
= 0x10134207, .name
= "CS4207", .patch
= patch_cs420x
},
2048 { .id
= 0x10134210, .name
= "CS4210", .patch
= patch_cs4210
},
2049 { .id
= 0x10134213, .name
= "CS4213", .patch
= patch_cs4213
},
2053 MODULE_ALIAS("snd-hda-codec-id:10134206");
2054 MODULE_ALIAS("snd-hda-codec-id:10134207");
2055 MODULE_ALIAS("snd-hda-codec-id:10134210");
2056 MODULE_ALIAS("snd-hda-codec-id:10134213");
2058 MODULE_LICENSE("GPL");
2059 MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
2061 static struct hda_codec_preset_list cirrus_list
= {
2062 .preset
= snd_hda_preset_cirrus
,
2063 .owner
= THIS_MODULE
,
2066 static int __init
patch_cirrus_init(void)
2068 return snd_hda_add_codec_preset(&cirrus_list
);
2071 static void __exit
patch_cirrus_exit(void)
2073 snd_hda_delete_codec_preset(&cirrus_list
);
2076 module_init(patch_cirrus_init
)
2077 module_exit(patch_cirrus_exit
)