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;
72 unsigned int spdif_detect
:1;
73 unsigned int sense_b
:1;
75 struct hda_input_mux input_mux
;
76 unsigned int last_input
;
79 /* available models with CS420x */
90 CS420X_IMAC27_122
= CS420X_GPIO_23
,
91 CS420X_APPLE
= CS420X_GPIO_13
,
100 /* Vendor-specific processing widget */
101 #define CS420X_VENDOR_NID 0x11
102 #define CS_DIG_OUT1_PIN_NID 0x10
103 #define CS_DIG_OUT2_PIN_NID 0x15
104 #define CS_DMIC1_PIN_NID 0x12
105 #define CS_DMIC2_PIN_NID 0x0e
108 #define IDX_SPDIF_STAT 0x0000
109 #define IDX_SPDIF_CTL 0x0001
110 #define IDX_ADC_CFG 0x0002
111 /* SZC bitmask, 4 modes below:
113 * 1 = digital immediate, analog zero-cross
114 * 2 = digtail & analog soft-ramp
115 * 3 = digital soft-ramp, analog zero-cross
117 #define CS_COEF_ADC_SZC_MASK (3 << 0)
118 #define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */
119 #define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
120 /* PGA mode: 0 = differential, 1 = signle-ended */
121 #define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */
122 #define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
123 #define IDX_DAC_CFG 0x0003
124 /* SZC bitmask, 4 modes below:
128 * 3 = soft-ramp on zero-cross
130 #define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */
131 #define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */
132 #define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */
134 #define IDX_BEEP_CFG 0x0004
135 /* 0x0008 - test reg key */
136 /* 0x0009 - 0x0014 -> 12 test regs */
137 /* 0x0015 - visibility reg */
140 * Cirrus Logic CS4210
142 * 1 DAC => HP(sense) / Speakers,
143 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
144 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
146 #define CS4210_DAC_NID 0x02
147 #define CS4210_ADC_NID 0x03
148 #define CS4210_VENDOR_NID 0x0B
149 #define CS421X_DMIC_PIN_NID 0x09 /* Port E */
150 #define CS421X_SPDIF_PIN_NID 0x0A /* Port H */
152 #define CS421X_IDX_DEV_CFG 0x01
153 #define CS421X_IDX_ADC_CFG 0x02
154 #define CS421X_IDX_DAC_CFG 0x03
155 #define CS421X_IDX_SPK_CTL 0x04
157 #define SPDIF_EVENT 0x04
159 /* Cirrus Logic CS4213 is like CS4210 but does not have SPDIF input/output */
160 #define CS4213_VENDOR_NID 0x09
163 static inline int cs_vendor_coef_get(struct hda_codec
*codec
, unsigned int idx
)
165 struct cs_spec
*spec
= codec
->spec
;
166 snd_hda_codec_write(codec
, spec
->vendor_nid
, 0,
167 AC_VERB_SET_COEF_INDEX
, idx
);
168 return snd_hda_codec_read(codec
, spec
->vendor_nid
, 0,
169 AC_VERB_GET_PROC_COEF
, 0);
172 static inline void cs_vendor_coef_set(struct hda_codec
*codec
, unsigned int idx
,
175 struct cs_spec
*spec
= codec
->spec
;
176 snd_hda_codec_write(codec
, spec
->vendor_nid
, 0,
177 AC_VERB_SET_COEF_INDEX
, idx
);
178 snd_hda_codec_write(codec
, spec
->vendor_nid
, 0,
179 AC_VERB_SET_PROC_COEF
, coef
);
189 static int cs_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
190 struct hda_codec
*codec
,
191 struct snd_pcm_substream
*substream
)
193 struct cs_spec
*spec
= codec
->spec
;
194 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
198 static int cs_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
199 struct hda_codec
*codec
,
200 unsigned int stream_tag
,
202 struct snd_pcm_substream
*substream
)
204 struct cs_spec
*spec
= codec
->spec
;
205 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
206 stream_tag
, format
, substream
);
209 static int cs_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
210 struct hda_codec
*codec
,
211 struct snd_pcm_substream
*substream
)
213 struct cs_spec
*spec
= codec
->spec
;
214 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
220 static int cs_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
221 struct hda_codec
*codec
,
222 struct snd_pcm_substream
*substream
)
224 struct cs_spec
*spec
= codec
->spec
;
225 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
228 static int cs_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
229 struct hda_codec
*codec
,
230 struct snd_pcm_substream
*substream
)
232 struct cs_spec
*spec
= codec
->spec
;
233 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
236 static int cs_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
237 struct hda_codec
*codec
,
238 unsigned int stream_tag
,
240 struct snd_pcm_substream
*substream
)
242 struct cs_spec
*spec
= codec
->spec
;
243 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
, stream_tag
,
247 static int cs_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
248 struct hda_codec
*codec
,
249 struct snd_pcm_substream
*substream
)
251 struct cs_spec
*spec
= codec
->spec
;
252 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
255 static void cs_update_input_select(struct hda_codec
*codec
)
257 struct cs_spec
*spec
= codec
->spec
;
259 snd_hda_codec_write(codec
, spec
->cur_adc
, 0,
260 AC_VERB_SET_CONNECT_SEL
,
261 spec
->adc_idx
[spec
->cur_input
]);
267 static int cs_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
268 struct hda_codec
*codec
,
269 unsigned int stream_tag
,
271 struct snd_pcm_substream
*substream
)
273 struct cs_spec
*spec
= codec
->spec
;
274 spec
->cur_adc
= spec
->adc_nid
[spec
->cur_input
];
275 spec
->cur_adc_stream_tag
= stream_tag
;
276 spec
->cur_adc_format
= format
;
277 cs_update_input_select(codec
);
278 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
282 static int cs_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
283 struct hda_codec
*codec
,
284 struct snd_pcm_substream
*substream
)
286 struct cs_spec
*spec
= codec
->spec
;
287 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
294 static const struct hda_pcm_stream cs_pcm_analog_playback
= {
299 .open
= cs_playback_pcm_open
,
300 .prepare
= cs_playback_pcm_prepare
,
301 .cleanup
= cs_playback_pcm_cleanup
305 static const struct hda_pcm_stream cs_pcm_analog_capture
= {
310 .prepare
= cs_capture_pcm_prepare
,
311 .cleanup
= cs_capture_pcm_cleanup
315 static const struct hda_pcm_stream cs_pcm_digital_playback
= {
320 .open
= cs_dig_playback_pcm_open
,
321 .close
= cs_dig_playback_pcm_close
,
322 .prepare
= cs_dig_playback_pcm_prepare
,
323 .cleanup
= cs_dig_playback_pcm_cleanup
327 static const struct hda_pcm_stream cs_pcm_digital_capture
= {
333 static int cs_build_pcms(struct hda_codec
*codec
)
335 struct cs_spec
*spec
= codec
->spec
;
336 struct hda_pcm
*info
= spec
->pcm_rec
;
338 codec
->pcm_info
= info
;
341 info
->name
= "Cirrus Analog";
342 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = cs_pcm_analog_playback
;
343 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->dac_nid
[0];
344 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
345 spec
->multiout
.max_channels
;
346 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = cs_pcm_analog_capture
;
347 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
348 spec
->adc_nid
[spec
->cur_input
];
351 if (!spec
->multiout
.dig_out_nid
&& !spec
->dig_in
)
355 info
->name
= "Cirrus Digital";
356 info
->pcm_type
= spec
->autocfg
.dig_out_type
[0];
358 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
359 if (spec
->multiout
.dig_out_nid
) {
360 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
361 cs_pcm_digital_playback
;
362 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
363 spec
->multiout
.dig_out_nid
;
366 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
367 cs_pcm_digital_capture
;
368 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in
;
376 * parse codec topology
379 static hda_nid_t
get_dac(struct hda_codec
*codec
, hda_nid_t pin
)
384 if (snd_hda_get_connections(codec
, pin
, &dac
, 1) != 1)
389 static int is_ext_mic(struct hda_codec
*codec
, unsigned int idx
)
391 struct cs_spec
*spec
= codec
->spec
;
392 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
393 hda_nid_t pin
= cfg
->inputs
[idx
].pin
;
395 if (!is_jack_detectable(codec
, pin
))
397 val
= snd_hda_codec_get_pincfg(codec
, pin
);
398 return (snd_hda_get_input_pin_attr(val
) != INPUT_PIN_ATTR_INT
);
401 static hda_nid_t
get_adc(struct hda_codec
*codec
, hda_nid_t pin
,
407 nid
= codec
->start_nid
;
408 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
410 type
= get_wcaps_type(get_wcaps(codec
, nid
));
411 if (type
!= AC_WID_AUD_IN
)
413 idx
= snd_hda_get_conn_index(codec
, nid
, pin
, false);
422 static int is_active_pin(struct hda_codec
*codec
, hda_nid_t nid
)
425 val
= snd_hda_codec_get_pincfg(codec
, nid
);
426 return (get_defcfg_connect(val
) != AC_JACK_PORT_NONE
);
429 static int parse_output(struct hda_codec
*codec
)
431 struct cs_spec
*spec
= codec
->spec
;
432 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
436 for (i
= 0; i
< cfg
->line_outs
; i
++) {
437 dac
= get_dac(codec
, cfg
->line_out_pins
[i
]);
440 spec
->dac_nid
[i
] = dac
;
442 spec
->multiout
.num_dacs
= i
;
443 spec
->multiout
.dac_nids
= spec
->dac_nid
;
444 spec
->multiout
.max_channels
= i
* 2;
446 /* add HP and speakers */
448 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
449 dac
= get_dac(codec
, cfg
->hp_pins
[i
]);
453 spec
->multiout
.hp_nid
= dac
;
455 spec
->multiout
.extra_out_nid
[extra_nids
++] = dac
;
457 for (i
= 0; i
< cfg
->speaker_outs
; i
++) {
458 dac
= get_dac(codec
, cfg
->speaker_pins
[i
]);
461 spec
->multiout
.extra_out_nid
[extra_nids
++] = dac
;
464 if (cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
465 cfg
->speaker_outs
= cfg
->line_outs
;
466 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
467 sizeof(cfg
->speaker_pins
));
474 static int parse_input(struct hda_codec
*codec
)
476 struct cs_spec
*spec
= codec
->spec
;
477 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
480 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
481 hda_nid_t pin
= cfg
->inputs
[i
].pin
;
482 spec
->input_idx
[spec
->num_inputs
] = i
;
483 spec
->capsrc_idx
[i
] = spec
->num_inputs
++;
485 spec
->adc_nid
[i
] = get_adc(codec
, pin
, &spec
->adc_idx
[i
]);
487 if (!spec
->num_inputs
)
490 /* check whether the automatic mic switch is available */
491 if (spec
->num_inputs
== 2 &&
492 cfg
->inputs
[0].type
== AUTO_PIN_MIC
&&
493 cfg
->inputs
[1].type
== AUTO_PIN_MIC
) {
494 if (is_ext_mic(codec
, cfg
->inputs
[0].pin
)) {
495 if (!is_ext_mic(codec
, cfg
->inputs
[1].pin
)) {
496 spec
->mic_detect
= 1;
497 spec
->automic_idx
= 0;
500 if (is_ext_mic(codec
, cfg
->inputs
[1].pin
)) {
501 spec
->mic_detect
= 1;
502 spec
->automic_idx
= 1;
510 static int parse_digital_output(struct hda_codec
*codec
)
512 struct cs_spec
*spec
= codec
->spec
;
513 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
518 if (snd_hda_get_connections(codec
, cfg
->dig_out_pins
[0], &nid
, 1) < 1)
520 spec
->multiout
.dig_out_nid
= nid
;
521 spec
->multiout
.share_spdif
= 1;
522 if (cfg
->dig_outs
> 1 &&
523 snd_hda_get_connections(codec
, cfg
->dig_out_pins
[1], &nid
, 1) > 0) {
524 spec
->slave_dig_outs
[0] = nid
;
525 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
530 static int parse_digital_input(struct hda_codec
*codec
)
532 struct cs_spec
*spec
= codec
->spec
;
533 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
537 spec
->dig_in
= get_adc(codec
, cfg
->dig_in_pin
, &idx
);
542 * create mixer controls
545 static const char * const dir_sfx
[2] = { "Playback", "Capture" };
547 static int add_mute(struct hda_codec
*codec
, const char *name
, int index
,
548 unsigned int pval
, int dir
, struct snd_kcontrol
**kctlp
)
551 struct snd_kcontrol_new knew
=
552 HDA_CODEC_MUTE_IDX(tmp
, index
, 0, 0, HDA_OUTPUT
);
553 knew
.private_value
= pval
;
554 snprintf(tmp
, sizeof(tmp
), "%s %s Switch", name
, dir_sfx
[dir
]);
555 *kctlp
= snd_ctl_new1(&knew
, codec
);
556 (*kctlp
)->id
.subdevice
= HDA_SUBDEV_AMP_FLAG
;
557 return snd_hda_ctl_add(codec
, 0, *kctlp
);
560 static int add_volume(struct hda_codec
*codec
, const char *name
,
561 int index
, unsigned int pval
, int dir
,
562 struct snd_kcontrol
**kctlp
)
565 struct snd_kcontrol_new knew
=
566 HDA_CODEC_VOLUME_IDX(tmp
, index
, 0, 0, HDA_OUTPUT
);
567 knew
.private_value
= pval
;
568 snprintf(tmp
, sizeof(tmp
), "%s %s Volume", name
, dir_sfx
[dir
]);
569 *kctlp
= snd_ctl_new1(&knew
, codec
);
570 (*kctlp
)->id
.subdevice
= HDA_SUBDEV_AMP_FLAG
;
571 return snd_hda_ctl_add(codec
, 0, *kctlp
);
574 static void fix_volume_caps(struct hda_codec
*codec
, hda_nid_t dac
)
578 /* set the upper-limit for mixer amp to 0dB */
579 caps
= query_amp_caps(codec
, dac
, HDA_OUTPUT
);
580 caps
&= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT
);
581 caps
|= ((caps
>> AC_AMPCAP_OFFSET_SHIFT
) & 0x7f)
582 << AC_AMPCAP_NUM_STEPS_SHIFT
;
583 snd_hda_override_amp_caps(codec
, dac
, HDA_OUTPUT
, caps
);
586 static int add_vmaster(struct hda_codec
*codec
, hda_nid_t dac
)
588 struct cs_spec
*spec
= codec
->spec
;
593 snd_ctl_make_virtual_master("Master Playback Switch", NULL
);
594 err
= snd_hda_ctl_add(codec
, dac
, spec
->vmaster_sw
);
598 snd_hda_set_vmaster_tlv(codec
, dac
, HDA_OUTPUT
, tlv
);
600 snd_ctl_make_virtual_master("Master Playback Volume", tlv
);
601 err
= snd_hda_ctl_add(codec
, dac
, spec
->vmaster_vol
);
607 static int add_output(struct hda_codec
*codec
, hda_nid_t dac
, int idx
,
608 int num_ctls
, int type
)
610 struct cs_spec
*spec
= codec
->spec
;
613 struct snd_kcontrol
*kctl
;
614 static const char * const speakers
[] = {
615 "Front Speaker", "Surround Speaker", "Bass Speaker"
617 static const char * const line_outs
[] = {
618 "Front Line Out", "Surround Line Out", "Bass Line Out"
621 fix_volume_caps(codec
, dac
);
622 if (!spec
->vmaster_sw
) {
623 err
= add_vmaster(codec
, dac
);
630 case AUTO_PIN_HP_OUT
:
634 case AUTO_PIN_SPEAKER_OUT
:
636 name
= speakers
[idx
];
642 name
= line_outs
[idx
];
648 err
= add_mute(codec
, name
, index
,
649 HDA_COMPOSE_AMP_VAL(dac
, 3, 0, HDA_OUTPUT
), 0, &kctl
);
652 err
= snd_ctl_add_slave(spec
->vmaster_sw
, kctl
);
656 err
= add_volume(codec
, name
, index
,
657 HDA_COMPOSE_AMP_VAL(dac
, 3, 0, HDA_OUTPUT
), 0, &kctl
);
660 err
= snd_ctl_add_slave(spec
->vmaster_vol
, kctl
);
667 static int build_output(struct hda_codec
*codec
)
669 struct cs_spec
*spec
= codec
->spec
;
670 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
673 for (i
= 0; i
< cfg
->line_outs
; i
++) {
674 err
= add_output(codec
, get_dac(codec
, cfg
->line_out_pins
[i
]),
675 i
, cfg
->line_outs
, cfg
->line_out_type
);
679 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
680 err
= add_output(codec
, get_dac(codec
, cfg
->hp_pins
[i
]),
681 i
, cfg
->hp_outs
, AUTO_PIN_HP_OUT
);
685 for (i
= 0; i
< cfg
->speaker_outs
; i
++) {
686 err
= add_output(codec
, get_dac(codec
, cfg
->speaker_pins
[i
]),
687 i
, cfg
->speaker_outs
, AUTO_PIN_SPEAKER_OUT
);
697 static const struct snd_kcontrol_new cs_capture_ctls
[] = {
698 HDA_BIND_SW("Capture Switch", 0),
699 HDA_BIND_VOL("Capture Volume", 0),
702 static int change_cur_input(struct hda_codec
*codec
, unsigned int idx
,
705 struct cs_spec
*spec
= codec
->spec
;
707 if (spec
->cur_input
== idx
&& !force
)
709 if (spec
->cur_adc
&& spec
->cur_adc
!= spec
->adc_nid
[idx
]) {
710 /* stream is running, let's swap the current ADC */
711 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
712 spec
->cur_adc
= spec
->adc_nid
[idx
];
713 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
,
714 spec
->cur_adc_stream_tag
, 0,
715 spec
->cur_adc_format
);
717 spec
->cur_input
= idx
;
718 cs_update_input_select(codec
);
722 static int cs_capture_source_info(struct snd_kcontrol
*kcontrol
,
723 struct snd_ctl_elem_info
*uinfo
)
725 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
726 struct cs_spec
*spec
= codec
->spec
;
727 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
730 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
732 uinfo
->value
.enumerated
.items
= spec
->num_inputs
;
733 if (uinfo
->value
.enumerated
.item
>= spec
->num_inputs
)
734 uinfo
->value
.enumerated
.item
= spec
->num_inputs
- 1;
735 idx
= spec
->input_idx
[uinfo
->value
.enumerated
.item
];
736 snd_hda_get_pin_label(codec
, cfg
->inputs
[idx
].pin
, cfg
,
737 uinfo
->value
.enumerated
.name
,
738 sizeof(uinfo
->value
.enumerated
.name
), NULL
);
742 static int cs_capture_source_get(struct snd_kcontrol
*kcontrol
,
743 struct snd_ctl_elem_value
*ucontrol
)
745 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
746 struct cs_spec
*spec
= codec
->spec
;
747 ucontrol
->value
.enumerated
.item
[0] = spec
->capsrc_idx
[spec
->cur_input
];
751 static int cs_capture_source_put(struct snd_kcontrol
*kcontrol
,
752 struct snd_ctl_elem_value
*ucontrol
)
754 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
755 struct cs_spec
*spec
= codec
->spec
;
756 unsigned int idx
= ucontrol
->value
.enumerated
.item
[0];
758 if (idx
>= spec
->num_inputs
)
760 idx
= spec
->input_idx
[idx
];
761 return change_cur_input(codec
, idx
, 0);
764 static const struct snd_kcontrol_new cs_capture_source
= {
765 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
766 .name
= "Capture Source",
767 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
768 .info
= cs_capture_source_info
,
769 .get
= cs_capture_source_get
,
770 .put
= cs_capture_source_put
,
773 static const struct hda_bind_ctls
*make_bind_capture(struct hda_codec
*codec
,
774 struct hda_ctl_ops
*ops
)
776 struct cs_spec
*spec
= codec
->spec
;
777 struct hda_bind_ctls
*bind
;
780 bind
= kzalloc(sizeof(*bind
) + sizeof(long) * (spec
->num_inputs
+ 1),
786 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
787 if (!spec
->adc_nid
[i
])
790 HDA_COMPOSE_AMP_VAL(spec
->adc_nid
[i
], 3,
791 spec
->adc_idx
[i
], HDA_INPUT
);
796 /* add a (input-boost) volume control to the given input pin */
797 static int add_input_volume_control(struct hda_codec
*codec
,
798 struct auto_pin_cfg
*cfg
,
801 hda_nid_t pin
= cfg
->inputs
[item
].pin
;
804 struct snd_kcontrol
*kctl
;
806 if (!(get_wcaps(codec
, pin
) & AC_WCAP_IN_AMP
))
808 caps
= query_amp_caps(codec
, pin
, HDA_INPUT
);
809 caps
= (caps
& AC_AMPCAP_NUM_STEPS
) >> AC_AMPCAP_NUM_STEPS_SHIFT
;
812 label
= hda_get_autocfg_input_label(codec
, cfg
, item
);
813 return add_volume(codec
, label
, 0,
814 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_INPUT
), 1, &kctl
);
817 static int build_input(struct hda_codec
*codec
)
819 struct cs_spec
*spec
= codec
->spec
;
822 if (!spec
->num_inputs
)
825 /* make bind-capture */
826 spec
->capture_bind
[0] = make_bind_capture(codec
, &snd_hda_bind_sw
);
827 spec
->capture_bind
[1] = make_bind_capture(codec
, &snd_hda_bind_vol
);
828 for (i
= 0; i
< 2; i
++) {
829 struct snd_kcontrol
*kctl
;
831 if (!spec
->capture_bind
[i
])
833 kctl
= snd_ctl_new1(&cs_capture_ctls
[i
], codec
);
836 kctl
->private_value
= (long)spec
->capture_bind
[i
];
837 err
= snd_hda_ctl_add(codec
, 0, kctl
);
840 for (n
= 0; n
< AUTO_PIN_LAST
; n
++) {
841 if (!spec
->adc_nid
[n
])
843 err
= snd_hda_add_nid(codec
, kctl
, 0, spec
->adc_nid
[n
]);
849 if (spec
->num_inputs
> 1 && !spec
->mic_detect
) {
850 err
= snd_hda_ctl_add(codec
, 0,
851 snd_ctl_new1(&cs_capture_source
, codec
));
856 for (i
= 0; i
< spec
->num_inputs
; i
++) {
857 err
= add_input_volume_control(codec
, &spec
->autocfg
, i
);
868 static int build_digital_output(struct hda_codec
*codec
)
870 struct cs_spec
*spec
= codec
->spec
;
873 if (!spec
->multiout
.dig_out_nid
)
876 err
= snd_hda_create_spdif_out_ctls(codec
, spec
->multiout
.dig_out_nid
,
877 spec
->multiout
.dig_out_nid
);
880 err
= snd_hda_create_spdif_share_sw(codec
, &spec
->multiout
);
886 static int build_digital_input(struct hda_codec
*codec
)
888 struct cs_spec
*spec
= codec
->spec
;
890 return snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in
);
895 * auto-mute and auto-mic switching
896 * CS421x auto-output redirecting
900 static void cs_automute(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
)
902 struct cs_spec
*spec
= codec
->spec
;
903 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
904 unsigned int hp_present
;
905 unsigned int spdif_present
;
911 nid
= cfg
->dig_out_pins
[0];
912 if (is_jack_detectable(codec
, nid
)) {
914 TODO: SPDIF output redirect when SENSE_B is enabled.
915 Shared (SENSE_A) jack (e.g HP/mini-TOSLINK)
918 if (snd_hda_jack_detect(codec
, nid
)
919 /* && spec->sense_b */)
925 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
926 nid
= cfg
->hp_pins
[i
];
927 if (!is_jack_detectable(codec
, nid
))
929 hp_present
= snd_hda_jack_detect(codec
, nid
);
934 /* mute speakers if spdif or hp jack is plugged in */
935 for (i
= 0; i
< cfg
->speaker_outs
; i
++) {
936 int pin_ctl
= hp_present
? 0 : PIN_OUT
;
937 /* detect on spdif is specific to CS4210 */
938 if (spdif_present
&& (spec
->vendor_nid
== CS4210_VENDOR_NID
))
941 nid
= cfg
->speaker_pins
[i
];
942 snd_hda_set_pin_ctl(codec
, nid
, pin_ctl
);
944 if (spec
->gpio_eapd_hp
) {
945 unsigned int gpio
= hp_present
?
946 spec
->gpio_eapd_hp
: spec
->gpio_eapd_speaker
;
947 snd_hda_codec_write(codec
, 0x01, 0,
948 AC_VERB_SET_GPIO_DATA
, gpio
);
951 /* specific to CS4210 */
952 if (spec
->vendor_nid
== CS4210_VENDOR_NID
) {
953 /* mute HPs if spdif jack (SENSE_B) is present */
954 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
955 nid
= cfg
->hp_pins
[i
];
956 snd_hda_set_pin_ctl(codec
, nid
,
957 (spdif_present
&& spec
->sense_b
) ? 0 : PIN_HP
);
960 /* SPDIF TX on/off */
962 nid
= cfg
->dig_out_pins
[0];
963 snd_hda_set_pin_ctl(codec
, nid
,
964 spdif_present
? PIN_OUT
: 0);
967 /* Update board GPIOs if neccessary ... */
972 * Auto-input redirect for CS421x
973 * Switch max 3 inputs of a single ADC (nid 3)
976 static void cs_automic(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
)
978 struct cs_spec
*spec
= codec
->spec
;
979 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
981 unsigned int present
;
983 nid
= cfg
->inputs
[spec
->automic_idx
].pin
;
984 present
= snd_hda_jack_detect(codec
, nid
);
986 /* specific to CS421x, single ADC */
987 if (spec
->vendor_nid
== CS420X_VENDOR_NID
) {
989 change_cur_input(codec
, spec
->automic_idx
, 0);
991 change_cur_input(codec
, !spec
->automic_idx
, 0);
994 if (spec
->cur_input
!= spec
->automic_idx
) {
995 spec
->last_input
= spec
->cur_input
;
996 spec
->cur_input
= spec
->automic_idx
;
999 spec
->cur_input
= spec
->last_input
;
1001 cs_update_input_select(codec
);
1008 static void init_output(struct hda_codec
*codec
)
1010 struct cs_spec
*spec
= codec
->spec
;
1011 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1015 for (i
= 0; i
< spec
->multiout
.num_dacs
; i
++)
1016 snd_hda_codec_write(codec
, spec
->multiout
.dac_nids
[i
], 0,
1017 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_MUTE
);
1018 if (spec
->multiout
.hp_nid
)
1019 snd_hda_codec_write(codec
, spec
->multiout
.hp_nid
, 0,
1020 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_MUTE
);
1021 for (i
= 0; i
< ARRAY_SIZE(spec
->multiout
.extra_out_nid
); i
++) {
1022 if (!spec
->multiout
.extra_out_nid
[i
])
1024 snd_hda_codec_write(codec
, spec
->multiout
.extra_out_nid
[i
], 0,
1025 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_MUTE
);
1028 /* set appropriate pin controls */
1029 for (i
= 0; i
< cfg
->line_outs
; i
++)
1030 snd_hda_set_pin_ctl(codec
, cfg
->line_out_pins
[i
], PIN_OUT
);
1032 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
1033 hda_nid_t nid
= cfg
->hp_pins
[i
];
1034 snd_hda_set_pin_ctl(codec
, nid
, PIN_HP
);
1035 if (!cfg
->speaker_outs
)
1037 if (get_wcaps(codec
, nid
) & AC_WCAP_UNSOL_CAP
) {
1038 snd_hda_jack_detect_enable_callback(codec
, nid
, HP_EVENT
, cs_automute
);
1039 spec
->hp_detect
= 1;
1044 for (i
= 0; i
< cfg
->speaker_outs
; i
++)
1045 snd_hda_set_pin_ctl(codec
, cfg
->speaker_pins
[i
], PIN_OUT
);
1047 /* SPDIF is enabled on presence detect for CS421x */
1048 if (spec
->hp_detect
|| spec
->spdif_detect
)
1049 cs_automute(codec
, NULL
);
1052 static void init_input(struct hda_codec
*codec
)
1054 struct cs_spec
*spec
= codec
->spec
;
1055 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1059 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1061 hda_nid_t pin
= cfg
->inputs
[i
].pin
;
1062 if (!spec
->adc_nid
[i
])
1064 /* set appropriate pin control and mute first */
1066 if (cfg
->inputs
[i
].type
== AUTO_PIN_MIC
)
1067 ctl
|= snd_hda_get_default_vref(codec
, pin
);
1068 snd_hda_set_pin_ctl(codec
, pin
, ctl
);
1069 snd_hda_codec_write(codec
, spec
->adc_nid
[i
], 0,
1070 AC_VERB_SET_AMP_GAIN_MUTE
,
1071 AMP_IN_MUTE(spec
->adc_idx
[i
]));
1072 if (spec
->mic_detect
&& spec
->automic_idx
== i
)
1073 snd_hda_jack_detect_enable_callback(codec
, pin
, MIC_EVENT
, cs_automic
);
1075 /* CS420x has multiple ADC, CS421x has single ADC */
1076 if (spec
->vendor_nid
== CS420X_VENDOR_NID
) {
1077 change_cur_input(codec
, spec
->cur_input
, 1);
1078 if (spec
->mic_detect
)
1079 cs_automic(codec
, NULL
);
1081 coef
= 0x000a; /* ADC1/2 - Digital and Analog Soft Ramp */
1082 if (is_active_pin(codec
, CS_DMIC2_PIN_NID
))
1083 coef
|= 0x0500; /* DMIC2 2 chan on, GPIO1 off */
1084 if (is_active_pin(codec
, CS_DMIC1_PIN_NID
))
1085 coef
|= 0x1800; /* DMIC1 2 chan on, GPIO0 off
1086 * No effect if SPDIF_OUT2 is
1087 * selected in IDX_SPDIF_CTL.
1089 cs_vendor_coef_set(codec
, IDX_ADC_CFG
, coef
);
1091 if (spec
->mic_detect
)
1092 cs_automic(codec
, NULL
);
1094 spec
->cur_adc
= spec
->adc_nid
[spec
->cur_input
];
1095 cs_update_input_select(codec
);
1100 static const struct hda_verb cs_coef_init_verbs
[] = {
1101 {0x11, AC_VERB_SET_PROC_STATE
, 1},
1102 {0x11, AC_VERB_SET_COEF_INDEX
, IDX_DAC_CFG
},
1103 {0x11, AC_VERB_SET_PROC_COEF
,
1104 (0x002a /* DAC1/2/3 SZCMode Soft Ramp */
1105 | 0x0040 /* Mute DACs on FIFO error */
1106 | 0x1000 /* Enable DACs High Pass Filter */
1107 | 0x0400 /* Disable Coefficient Auto increment */
1110 {0x11, AC_VERB_SET_COEF_INDEX
, IDX_BEEP_CFG
},
1111 {0x11, AC_VERB_SET_PROC_COEF
, 0x0007}, /* Enable Beep thru DAC1/2/3 */
1116 /* Errata: CS4207 rev C0/C1/C2 Silicon
1118 * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf
1120 * 6. At high temperature (TA > +85°C), the digital supply current (IVD)
1121 * may be excessive (up to an additional 200 μA), which is most easily
1122 * observed while the part is being held in reset (RESET# active low).
1124 * Root Cause: At initial powerup of the device, the logic that drives
1125 * the clock and write enable to the S/PDIF SRC RAMs is not properly
1127 * Certain random patterns will cause a steady leakage current in those
1128 * RAM cells. The issue will resolve once the SRCs are used (turned on).
1130 * Workaround: The following verb sequence briefly turns on the S/PDIF SRC
1131 * blocks, which will alleviate the issue.
1134 static const struct hda_verb cs_errata_init_verbs
[] = {
1135 {0x01, AC_VERB_SET_POWER_STATE
, 0x00}, /* AFG: D0 */
1136 {0x11, AC_VERB_SET_PROC_STATE
, 0x01}, /* VPW: processing on */
1138 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0008},
1139 {0x11, AC_VERB_SET_PROC_COEF
, 0x9999},
1140 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0017},
1141 {0x11, AC_VERB_SET_PROC_COEF
, 0xa412},
1142 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0001},
1143 {0x11, AC_VERB_SET_PROC_COEF
, 0x0009},
1145 {0x07, AC_VERB_SET_POWER_STATE
, 0x00}, /* S/PDIF Rx: D0 */
1146 {0x08, AC_VERB_SET_POWER_STATE
, 0x00}, /* S/PDIF Tx: D0 */
1148 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0017},
1149 {0x11, AC_VERB_SET_PROC_COEF
, 0x2412},
1150 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0008},
1151 {0x11, AC_VERB_SET_PROC_COEF
, 0x0000},
1152 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0001},
1153 {0x11, AC_VERB_SET_PROC_COEF
, 0x0008},
1154 {0x11, AC_VERB_SET_PROC_STATE
, 0x00},
1156 #if 0 /* Don't to set to D3 as we are in power-up sequence */
1157 {0x07, AC_VERB_SET_POWER_STATE
, 0x03}, /* S/PDIF Rx: D3 */
1158 {0x08, AC_VERB_SET_POWER_STATE
, 0x03}, /* S/PDIF Tx: D3 */
1159 /*{0x01, AC_VERB_SET_POWER_STATE, 0x03},*/ /* AFG: D3 This is already handled */
1165 static const struct hda_verb mbp101_init_verbs
[] = {
1166 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0002},
1167 {0x11, AC_VERB_SET_PROC_COEF
, 0x100a},
1168 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0004},
1169 {0x11, AC_VERB_SET_PROC_COEF
, 0x000f},
1174 static void init_digital(struct hda_codec
*codec
)
1178 coef
= 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */
1179 coef
|= 0x0008; /* Replace with mute on error */
1180 if (is_active_pin(codec
, CS_DIG_OUT2_PIN_NID
))
1181 coef
|= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2
1182 * SPDIF_OUT2 is shared with GPIO1 and
1185 cs_vendor_coef_set(codec
, IDX_SPDIF_CTL
, coef
);
1188 static int cs_init(struct hda_codec
*codec
)
1190 struct cs_spec
*spec
= codec
->spec
;
1192 /* init_verb sequence for C0/C1/C2 errata*/
1193 snd_hda_sequence_write(codec
, cs_errata_init_verbs
);
1195 snd_hda_sequence_write(codec
, cs_coef_init_verbs
);
1197 if (spec
->gpio_mask
) {
1198 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_MASK
,
1200 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION
,
1202 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DATA
,
1208 init_digital(codec
);
1213 static int cs_build_controls(struct hda_codec
*codec
)
1215 struct cs_spec
*spec
= codec
->spec
;
1218 err
= build_output(codec
);
1221 err
= build_input(codec
);
1224 err
= build_digital_output(codec
);
1227 err
= build_digital_input(codec
);
1230 err
= cs_init(codec
);
1234 err
= snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
1241 static void cs_free(struct hda_codec
*codec
)
1243 struct cs_spec
*spec
= codec
->spec
;
1244 kfree(spec
->capture_bind
[0]);
1245 kfree(spec
->capture_bind
[1]);
1246 snd_hda_gen_free(&spec
->gen
);
1250 static const struct hda_codec_ops cs_patch_ops
= {
1251 .build_controls
= cs_build_controls
,
1252 .build_pcms
= cs_build_pcms
,
1255 .unsol_event
= snd_hda_jack_unsol_event
,
1258 static int cs_parse_auto_config(struct hda_codec
*codec
)
1260 struct cs_spec
*spec
= codec
->spec
;
1263 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1267 err
= parse_output(codec
);
1270 err
= parse_input(codec
);
1273 err
= parse_digital_output(codec
);
1276 err
= parse_digital_input(codec
);
1282 static const struct hda_model_fixup cs420x_models
[] = {
1283 { .id
= CS420X_MBP53
, .name
= "mbp53" },
1284 { .id
= CS420X_MBP55
, .name
= "mbp55" },
1285 { .id
= CS420X_IMAC27
, .name
= "imac27" },
1286 { .id
= CS420X_IMAC27_122
, .name
= "imac27_122" },
1287 { .id
= CS420X_APPLE
, .name
= "apple" },
1288 { .id
= CS420X_MBP101
, .name
= "mbp101" },
1292 static const struct snd_pci_quirk cs420x_fixup_tbl
[] = {
1293 SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53
),
1294 SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55
),
1295 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55
),
1296 SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55
),
1297 /* this conflicts with too many other models */
1298 /*SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),*/
1301 SND_PCI_QUIRK(0x106b, 0x2000, "iMac 12,2", CS420X_IMAC27_122
),
1302 SND_PCI_QUIRK(0x106b, 0x2800, "MacBookPro 10,1", CS420X_MBP101
),
1303 SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS420X_APPLE
),
1307 static const struct hda_pintbl mbp53_pincfgs
[] = {
1308 { 0x09, 0x012b4050 },
1309 { 0x0a, 0x90100141 },
1310 { 0x0b, 0x90100140 },
1311 { 0x0c, 0x018b3020 },
1312 { 0x0d, 0x90a00110 },
1313 { 0x0e, 0x400000f0 },
1314 { 0x0f, 0x01cbe030 },
1315 { 0x10, 0x014be060 },
1316 { 0x12, 0x400000f0 },
1317 { 0x15, 0x400000f0 },
1321 static const struct hda_pintbl mbp55_pincfgs
[] = {
1322 { 0x09, 0x012b4030 },
1323 { 0x0a, 0x90100121 },
1324 { 0x0b, 0x90100120 },
1325 { 0x0c, 0x400000f0 },
1326 { 0x0d, 0x90a00110 },
1327 { 0x0e, 0x400000f0 },
1328 { 0x0f, 0x400000f0 },
1329 { 0x10, 0x014be040 },
1330 { 0x12, 0x400000f0 },
1331 { 0x15, 0x400000f0 },
1335 static const struct hda_pintbl imac27_pincfgs
[] = {
1336 { 0x09, 0x012b4050 },
1337 { 0x0a, 0x90100140 },
1338 { 0x0b, 0x90100142 },
1339 { 0x0c, 0x018b3020 },
1340 { 0x0d, 0x90a00110 },
1341 { 0x0e, 0x400000f0 },
1342 { 0x0f, 0x01cbe030 },
1343 { 0x10, 0x014be060 },
1344 { 0x12, 0x01ab9070 },
1345 { 0x15, 0x400000f0 },
1349 static const struct hda_pintbl mbp101_pincfgs
[] = {
1350 { 0x0d, 0x40ab90f0 },
1351 { 0x0e, 0x90a600f0 },
1352 { 0x12, 0x50a600f0 },
1356 static void cs420x_fixup_gpio_13(struct hda_codec
*codec
,
1357 const struct hda_fixup
*fix
, int action
)
1359 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
1360 struct cs_spec
*spec
= codec
->spec
;
1361 spec
->gpio_eapd_hp
= 2; /* GPIO1 = headphones */
1362 spec
->gpio_eapd_speaker
= 8; /* GPIO3 = speakers */
1363 spec
->gpio_mask
= spec
->gpio_dir
=
1364 spec
->gpio_eapd_hp
| spec
->gpio_eapd_speaker
;
1368 static void cs420x_fixup_gpio_23(struct hda_codec
*codec
,
1369 const struct hda_fixup
*fix
, int action
)
1371 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
1372 struct cs_spec
*spec
= codec
->spec
;
1373 spec
->gpio_eapd_hp
= 4; /* GPIO2 = headphones */
1374 spec
->gpio_eapd_speaker
= 8; /* GPIO3 = speakers */
1375 spec
->gpio_mask
= spec
->gpio_dir
=
1376 spec
->gpio_eapd_hp
| spec
->gpio_eapd_speaker
;
1380 static const struct hda_fixup cs420x_fixups
[] = {
1382 .type
= HDA_FIXUP_PINS
,
1383 .v
.pins
= mbp53_pincfgs
,
1385 .chain_id
= CS420X_APPLE
,
1388 .type
= HDA_FIXUP_PINS
,
1389 .v
.pins
= mbp55_pincfgs
,
1391 .chain_id
= CS420X_GPIO_13
,
1394 .type
= HDA_FIXUP_PINS
,
1395 .v
.pins
= imac27_pincfgs
,
1397 .chain_id
= CS420X_GPIO_13
,
1399 [CS420X_GPIO_13
] = {
1400 .type
= HDA_FIXUP_FUNC
,
1401 .v
.func
= cs420x_fixup_gpio_13
,
1403 [CS420X_GPIO_23
] = {
1404 .type
= HDA_FIXUP_FUNC
,
1405 .v
.func
= cs420x_fixup_gpio_23
,
1408 .type
= HDA_FIXUP_PINS
,
1409 .v
.pins
= mbp101_pincfgs
,
1411 .chain_id
= CS420X_MBP101_COEF
,
1413 [CS420X_MBP101_COEF
] = {
1414 .type
= HDA_FIXUP_VERBS
,
1415 .v
.verbs
= mbp101_init_verbs
,
1417 .chain_id
= CS420X_GPIO_13
,
1421 static int patch_cs420x(struct hda_codec
*codec
)
1423 struct cs_spec
*spec
;
1426 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1430 snd_hda_gen_init(&spec
->gen
);
1432 spec
->vendor_nid
= CS420X_VENDOR_NID
;
1434 snd_hda_pick_fixup(codec
, cs420x_models
, cs420x_fixup_tbl
,
1436 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
1438 err
= cs_parse_auto_config(codec
);
1442 codec
->patch_ops
= cs_patch_ops
;
1444 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
1455 * Cirrus Logic CS4210
1457 * 1 DAC => HP(sense) / Speakers,
1458 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
1459 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
1462 /* CS4210 board names */
1463 static const struct hda_model_fixup cs421x_models
[] = {
1464 { .id
= CS421X_CDB4210
, .name
= "cdb4210" },
1468 static const struct snd_pci_quirk cs421x_fixup_tbl
[] = {
1469 /* Test Intel board + CDB2410 */
1470 SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210
),
1474 /* CS4210 board pinconfigs */
1475 /* Default CS4210 (CDB4210)*/
1476 static const struct hda_pintbl cdb4210_pincfgs
[] = {
1477 { 0x05, 0x0321401f },
1478 { 0x06, 0x90170010 },
1479 { 0x07, 0x03813031 },
1480 { 0x08, 0xb7a70037 },
1481 { 0x09, 0xb7a6003e },
1482 { 0x0a, 0x034510f0 },
1486 /* Setup GPIO/SENSE for each board (if used) */
1487 static void cs421x_fixup_sense_b(struct hda_codec
*codec
,
1488 const struct hda_fixup
*fix
, int action
)
1490 struct cs_spec
*spec
= codec
->spec
;
1491 if (action
== HDA_FIXUP_ACT_PRE_PROBE
)
1495 static const struct hda_fixup cs421x_fixups
[] = {
1496 [CS421X_CDB4210
] = {
1497 .type
= HDA_FIXUP_PINS
,
1498 .v
.pins
= cdb4210_pincfgs
,
1500 .chain_id
= CS421X_SENSE_B
,
1502 [CS421X_SENSE_B
] = {
1503 .type
= HDA_FIXUP_FUNC
,
1504 .v
.func
= cs421x_fixup_sense_b
,
1508 static const struct hda_verb cs421x_coef_init_verbs
[] = {
1509 {0x0B, AC_VERB_SET_PROC_STATE
, 1},
1510 {0x0B, AC_VERB_SET_COEF_INDEX
, CS421X_IDX_DEV_CFG
},
1512 Disable Coefficient Index Auto-Increment(DAI)=1,
1515 {0x0B, AC_VERB_SET_PROC_COEF
, 0x0001 },
1517 {0x0B, AC_VERB_SET_COEF_INDEX
, CS421X_IDX_ADC_CFG
},
1518 /* ADC SZCMode = Digital Soft Ramp */
1519 {0x0B, AC_VERB_SET_PROC_COEF
, 0x0002 },
1521 {0x0B, AC_VERB_SET_COEF_INDEX
, CS421X_IDX_DAC_CFG
},
1522 {0x0B, AC_VERB_SET_PROC_COEF
,
1523 (0x0002 /* DAC SZCMode = Digital Soft Ramp */
1524 | 0x0004 /* Mute DAC on FIFO error */
1525 | 0x0008 /* Enable DAC High Pass Filter */
1530 /* Errata: CS4210 rev A1 Silicon
1532 * http://www.cirrus.com/en/pubs/errata/
1535 * 1. Performance degredation is present in the ADC.
1536 * 2. Speaker output is not completely muted upon HP detect.
1537 * 3. Noise is present when clipping occurs on the amplified
1541 * The following verb sequence written to the registers during
1542 * initialization will correct the issues listed above.
1545 static const struct hda_verb cs421x_coef_init_verbs_A1_silicon_fixes
[] = {
1546 {0x0B, AC_VERB_SET_PROC_STATE
, 0x01}, /* VPW: processing on */
1548 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x0006},
1549 {0x0B, AC_VERB_SET_PROC_COEF
, 0x9999}, /* Test mode: on */
1551 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x000A},
1552 {0x0B, AC_VERB_SET_PROC_COEF
, 0x14CB}, /* Chop double */
1554 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x0011},
1555 {0x0B, AC_VERB_SET_PROC_COEF
, 0xA2D0}, /* Increase ADC current */
1557 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x001A},
1558 {0x0B, AC_VERB_SET_PROC_COEF
, 0x02A9}, /* Mute speaker */
1560 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x001B},
1561 {0x0B, AC_VERB_SET_PROC_COEF
, 0X1006}, /* Remove noise */
1566 /* Speaker Amp Gain is controlled by the vendor widget's coef 4 */
1567 static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale
, 900, 300, 0);
1569 static int cs421x_boost_vol_info(struct snd_kcontrol
*kcontrol
,
1570 struct snd_ctl_elem_info
*uinfo
)
1572 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1574 uinfo
->value
.integer
.min
= 0;
1575 uinfo
->value
.integer
.max
= 3;
1579 static int cs421x_boost_vol_get(struct snd_kcontrol
*kcontrol
,
1580 struct snd_ctl_elem_value
*ucontrol
)
1582 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1584 ucontrol
->value
.integer
.value
[0] =
1585 cs_vendor_coef_get(codec
, CS421X_IDX_SPK_CTL
) & 0x0003;
1589 static int cs421x_boost_vol_put(struct snd_kcontrol
*kcontrol
,
1590 struct snd_ctl_elem_value
*ucontrol
)
1592 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1594 unsigned int vol
= ucontrol
->value
.integer
.value
[0];
1596 cs_vendor_coef_get(codec
, CS421X_IDX_SPK_CTL
);
1597 unsigned int original_coef
= coef
;
1600 coef
|= (vol
& 0x0003);
1601 if (original_coef
== coef
)
1604 cs_vendor_coef_set(codec
, CS421X_IDX_SPK_CTL
, coef
);
1609 static const struct snd_kcontrol_new cs421x_speaker_bost_ctl
= {
1611 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1612 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1613 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
1614 .name
= "Speaker Boost Playback Volume",
1615 .info
= cs421x_boost_vol_info
,
1616 .get
= cs421x_boost_vol_get
,
1617 .put
= cs421x_boost_vol_put
,
1618 .tlv
= { .p
= cs421x_speaker_boost_db_scale
},
1621 static void cs4210_pinmux_init(struct hda_codec
*codec
)
1623 struct cs_spec
*spec
= codec
->spec
;
1624 unsigned int def_conf
, coef
;
1626 /* GPIO, DMIC_SCL, DMIC_SDA and SENSE_B are multiplexed */
1627 coef
= cs_vendor_coef_get(codec
, CS421X_IDX_DEV_CFG
);
1629 if (spec
->gpio_mask
)
1630 coef
|= 0x0008; /* B1,B2 are GPIOs */
1635 coef
|= 0x0010; /* B2 is SENSE_B, not inverted */
1639 cs_vendor_coef_set(codec
, CS421X_IDX_DEV_CFG
, coef
);
1641 if ((spec
->gpio_mask
|| spec
->sense_b
) &&
1642 is_active_pin(codec
, CS421X_DMIC_PIN_NID
)) {
1645 GPIO or SENSE_B forced - disconnect the DMIC pin.
1647 def_conf
= snd_hda_codec_get_pincfg(codec
, CS421X_DMIC_PIN_NID
);
1648 def_conf
&= ~AC_DEFCFG_PORT_CONN
;
1649 def_conf
|= (AC_JACK_PORT_NONE
<< AC_DEFCFG_PORT_CONN_SHIFT
);
1650 snd_hda_codec_set_pincfg(codec
, CS421X_DMIC_PIN_NID
, def_conf
);
1654 static void init_cs421x_digital(struct hda_codec
*codec
)
1656 struct cs_spec
*spec
= codec
->spec
;
1657 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1661 for (i
= 0; i
< cfg
->dig_outs
; i
++) {
1662 hda_nid_t nid
= cfg
->dig_out_pins
[i
];
1663 if (!cfg
->speaker_outs
)
1665 if (get_wcaps(codec
, nid
) & AC_WCAP_UNSOL_CAP
) {
1666 snd_hda_jack_detect_enable_callback(codec
, nid
, SPDIF_EVENT
, cs_automute
);
1667 spec
->spdif_detect
= 1;
1672 static int cs421x_init(struct hda_codec
*codec
)
1674 struct cs_spec
*spec
= codec
->spec
;
1676 if (spec
->vendor_nid
== CS4210_VENDOR_NID
) {
1677 snd_hda_sequence_write(codec
, cs421x_coef_init_verbs
);
1678 snd_hda_sequence_write(codec
, cs421x_coef_init_verbs_A1_silicon_fixes
);
1679 cs4210_pinmux_init(codec
);
1682 if (spec
->gpio_mask
) {
1683 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_MASK
,
1685 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION
,
1687 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DATA
,
1693 init_cs421x_digital(codec
);
1699 * CS4210 Input MUX (1 ADC)
1701 static int cs421x_mux_enum_info(struct snd_kcontrol
*kcontrol
,
1702 struct snd_ctl_elem_info
*uinfo
)
1704 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1705 struct cs_spec
*spec
= codec
->spec
;
1707 return snd_hda_input_mux_info(&spec
->input_mux
, uinfo
);
1710 static int cs421x_mux_enum_get(struct snd_kcontrol
*kcontrol
,
1711 struct snd_ctl_elem_value
*ucontrol
)
1713 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1714 struct cs_spec
*spec
= codec
->spec
;
1716 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_input
;
1720 static int cs421x_mux_enum_put(struct snd_kcontrol
*kcontrol
,
1721 struct snd_ctl_elem_value
*ucontrol
)
1723 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1724 struct cs_spec
*spec
= codec
->spec
;
1726 return snd_hda_input_mux_put(codec
, &spec
->input_mux
, ucontrol
,
1727 spec
->adc_nid
[0], &spec
->cur_input
);
1731 static struct snd_kcontrol_new cs421x_capture_source
= {
1733 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1734 .name
= "Capture Source",
1735 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
1736 .info
= cs421x_mux_enum_info
,
1737 .get
= cs421x_mux_enum_get
,
1738 .put
= cs421x_mux_enum_put
,
1741 static int cs421x_add_input_volume_control(struct hda_codec
*codec
, int item
)
1743 struct cs_spec
*spec
= codec
->spec
;
1744 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1745 const struct hda_input_mux
*imux
= &spec
->input_mux
;
1746 hda_nid_t pin
= cfg
->inputs
[item
].pin
;
1747 struct snd_kcontrol
*kctl
;
1750 if (!(get_wcaps(codec
, pin
) & AC_WCAP_IN_AMP
))
1753 caps
= query_amp_caps(codec
, pin
, HDA_INPUT
);
1754 caps
= (caps
& AC_AMPCAP_NUM_STEPS
) >> AC_AMPCAP_NUM_STEPS_SHIFT
;
1758 return add_volume(codec
, imux
->items
[item
].label
, 0,
1759 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_INPUT
), 1, &kctl
);
1762 /* add a (input-boost) volume control to the given input pin */
1763 static int build_cs421x_input(struct hda_codec
*codec
)
1765 struct cs_spec
*spec
= codec
->spec
;
1766 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1767 struct hda_input_mux
*imux
= &spec
->input_mux
;
1768 int i
, err
, type_idx
;
1771 if (!spec
->num_inputs
)
1774 /* make bind-capture */
1775 spec
->capture_bind
[0] = make_bind_capture(codec
, &snd_hda_bind_sw
);
1776 spec
->capture_bind
[1] = make_bind_capture(codec
, &snd_hda_bind_vol
);
1777 for (i
= 0; i
< 2; i
++) {
1778 struct snd_kcontrol
*kctl
;
1780 if (!spec
->capture_bind
[i
])
1782 kctl
= snd_ctl_new1(&cs_capture_ctls
[i
], codec
);
1785 kctl
->private_value
= (long)spec
->capture_bind
[i
];
1786 err
= snd_hda_ctl_add(codec
, 0, kctl
);
1789 for (n
= 0; n
< AUTO_PIN_LAST
; n
++) {
1790 if (!spec
->adc_nid
[n
])
1792 err
= snd_hda_add_nid(codec
, kctl
, 0, spec
->adc_nid
[n
]);
1798 /* Add Input MUX Items + Capture Volume/Switch */
1799 for (i
= 0; i
< spec
->num_inputs
; i
++) {
1800 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
1801 snd_hda_add_imux_item(imux
, label
, spec
->adc_idx
[i
], &type_idx
);
1803 err
= cs421x_add_input_volume_control(codec
, i
);
1809 Add 'Capture Source' Switch if
1810 * 2 inputs and no mic detec
1813 if ((spec
->num_inputs
== 2 && !spec
->mic_detect
) ||
1814 (spec
->num_inputs
== 3)) {
1816 err
= snd_hda_ctl_add(codec
, spec
->adc_nid
[0],
1817 snd_ctl_new1(&cs421x_capture_source
, codec
));
1825 /* Single DAC (Mute/Gain) */
1826 static int build_cs421x_output(struct hda_codec
*codec
)
1828 hda_nid_t dac
= CS4210_DAC_NID
;
1829 struct cs_spec
*spec
= codec
->spec
;
1830 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1831 struct snd_kcontrol
*kctl
;
1833 char *name
= "Master";
1835 fix_volume_caps(codec
, dac
);
1837 err
= add_mute(codec
, name
, 0,
1838 HDA_COMPOSE_AMP_VAL(dac
, 3, 0, HDA_OUTPUT
), 0, &kctl
);
1842 err
= add_volume(codec
, name
, 0,
1843 HDA_COMPOSE_AMP_VAL(dac
, 3, 0, HDA_OUTPUT
), 0, &kctl
);
1847 if (cfg
->speaker_outs
&& (spec
->vendor_nid
== CS4210_VENDOR_NID
)) {
1848 err
= snd_hda_ctl_add(codec
, 0,
1849 snd_ctl_new1(&cs421x_speaker_bost_ctl
, codec
));
1856 static int cs421x_build_controls(struct hda_codec
*codec
)
1858 struct cs_spec
*spec
= codec
->spec
;
1861 err
= build_cs421x_output(codec
);
1864 err
= build_cs421x_input(codec
);
1867 err
= build_digital_output(codec
);
1870 err
= cs421x_init(codec
);
1874 err
= snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
1881 static int parse_cs421x_input(struct hda_codec
*codec
)
1883 struct cs_spec
*spec
= codec
->spec
;
1884 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1887 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1888 hda_nid_t pin
= cfg
->inputs
[i
].pin
;
1889 spec
->adc_nid
[i
] = get_adc(codec
, pin
, &spec
->adc_idx
[i
]);
1890 spec
->cur_input
= spec
->last_input
= i
;
1893 /* check whether the automatic mic switch is available */
1894 if (is_ext_mic(codec
, i
) && cfg
->num_inputs
>= 2) {
1895 spec
->mic_detect
= 1;
1896 spec
->automic_idx
= i
;
1902 static int cs421x_parse_auto_config(struct hda_codec
*codec
)
1904 struct cs_spec
*spec
= codec
->spec
;
1907 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1910 err
= parse_output(codec
);
1913 err
= parse_cs421x_input(codec
);
1916 err
= parse_digital_output(codec
);
1924 Manage PDREF, when transitioning to D3hot
1925 (DAC,ADC) -> D3, PDREF=1, AFG->D3
1927 static int cs421x_suspend(struct hda_codec
*codec
)
1929 struct cs_spec
*spec
= codec
->spec
;
1932 snd_hda_shutup_pins(codec
);
1934 snd_hda_codec_write(codec
, CS4210_DAC_NID
, 0,
1935 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
1936 snd_hda_codec_write(codec
, CS4210_ADC_NID
, 0,
1937 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
1939 if (spec
->vendor_nid
== CS4210_VENDOR_NID
) {
1940 coef
= cs_vendor_coef_get(codec
, CS421X_IDX_DEV_CFG
);
1941 coef
|= 0x0004; /* PDREF */
1942 cs_vendor_coef_set(codec
, CS421X_IDX_DEV_CFG
, coef
);
1949 static struct hda_codec_ops cs421x_patch_ops
= {
1950 .build_controls
= cs421x_build_controls
,
1951 .build_pcms
= cs_build_pcms
,
1952 .init
= cs421x_init
,
1954 .unsol_event
= snd_hda_jack_unsol_event
,
1956 .suspend
= cs421x_suspend
,
1960 static int patch_cs4210(struct hda_codec
*codec
)
1962 struct cs_spec
*spec
;
1965 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1969 snd_hda_gen_init(&spec
->gen
);
1971 spec
->vendor_nid
= CS4210_VENDOR_NID
;
1973 snd_hda_pick_fixup(codec
, cs421x_models
, cs421x_fixup_tbl
,
1975 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
1978 Update the GPIO/DMIC/SENSE_B pinmux before the configuration
1979 is auto-parsed. If GPIO or SENSE_B is forced, DMIC input
1982 cs4210_pinmux_init(codec
);
1984 err
= cs421x_parse_auto_config(codec
);
1988 codec
->patch_ops
= cs421x_patch_ops
;
1990 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
2000 static int patch_cs4213(struct hda_codec
*codec
)
2002 struct cs_spec
*spec
;
2005 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2009 snd_hda_gen_init(&spec
->gen
);
2011 spec
->vendor_nid
= CS4213_VENDOR_NID
;
2013 err
= cs421x_parse_auto_config(codec
);
2017 codec
->patch_ops
= cs421x_patch_ops
;
2030 static const struct hda_codec_preset snd_hda_preset_cirrus
[] = {
2031 { .id
= 0x10134206, .name
= "CS4206", .patch
= patch_cs420x
},
2032 { .id
= 0x10134207, .name
= "CS4207", .patch
= patch_cs420x
},
2033 { .id
= 0x10134210, .name
= "CS4210", .patch
= patch_cs4210
},
2034 { .id
= 0x10134213, .name
= "CS4213", .patch
= patch_cs4213
},
2038 MODULE_ALIAS("snd-hda-codec-id:10134206");
2039 MODULE_ALIAS("snd-hda-codec-id:10134207");
2040 MODULE_ALIAS("snd-hda-codec-id:10134210");
2041 MODULE_ALIAS("snd-hda-codec-id:10134213");
2043 MODULE_LICENSE("GPL");
2044 MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
2046 static struct hda_codec_preset_list cirrus_list
= {
2047 .preset
= snd_hda_preset_cirrus
,
2048 .owner
= THIS_MODULE
,
2051 static int __init
patch_cirrus_init(void)
2053 return snd_hda_add_codec_preset(&cirrus_list
);
2056 static void __exit
patch_cirrus_exit(void)
2058 snd_hda_delete_codec_preset(&cirrus_list
);
2061 module_init(patch_cirrus_init
)
2062 module_exit(patch_cirrus_exit
)