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/slab.h>
23 #include <linux/module.h>
24 #include <sound/core.h>
25 #include <sound/tlv.h>
26 #include "hda_codec.h"
27 #include "hda_local.h"
28 #include "hda_auto_parser.h"
30 #include "hda_generic.h"
36 struct hda_gen_spec gen;
38 unsigned int gpio_mask;
39 unsigned int gpio_dir;
40 unsigned int gpio_data;
41 unsigned int gpio_eapd_hp; /* EAPD GPIO bit for headphones */
42 unsigned int gpio_eapd_speaker; /* EAPD GPIO bit for speakers */
45 unsigned int spdif_detect:1;
46 unsigned int spdif_present:1;
47 unsigned int sense_b:1;
50 /* for MBP SPDIF control */
51 int (*spdif_sw_put)(struct snd_kcontrol *kcontrol,
52 struct snd_ctl_elem_value *ucontrol);
55 /* available models with CS420x */
67 CS420X_IMAC27_122 = CS420X_GPIO_23,
68 CS420X_APPLE = CS420X_GPIO_13,
78 /* Vendor-specific processing widget */
79 #define CS420X_VENDOR_NID 0x11
80 #define CS_DIG_OUT1_PIN_NID 0x10
81 #define CS_DIG_OUT2_PIN_NID 0x15
82 #define CS_DMIC1_PIN_NID 0x0e
83 #define CS_DMIC2_PIN_NID 0x12
86 #define IDX_SPDIF_STAT 0x0000
87 #define IDX_SPDIF_CTL 0x0001
88 #define IDX_ADC_CFG 0x0002
89 /* SZC bitmask, 4 modes below:
91 * 1 = digital immediate, analog zero-cross
92 * 2 = digtail & analog soft-ramp
93 * 3 = digital soft-ramp, analog zero-cross
95 #define CS_COEF_ADC_SZC_MASK (3 << 0)
96 #define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */
97 #define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
98 /* PGA mode: 0 = differential, 1 = signle-ended */
99 #define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */
100 #define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
101 #define IDX_DAC_CFG 0x0003
102 /* SZC bitmask, 4 modes below:
106 * 3 = soft-ramp on zero-cross
108 #define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */
109 #define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */
110 #define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */
112 #define IDX_BEEP_CFG 0x0004
113 /* 0x0008 - test reg key */
114 /* 0x0009 - 0x0014 -> 12 test regs */
115 /* 0x0015 - visibility reg */
117 /* Cirrus Logic CS4208 */
118 #define CS4208_VENDOR_NID 0x24
121 * Cirrus Logic CS4210
123 * 1 DAC => HP(sense) / Speakers,
124 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
125 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
127 #define CS4210_DAC_NID 0x02
128 #define CS4210_ADC_NID 0x03
129 #define CS4210_VENDOR_NID 0x0B
130 #define CS421X_DMIC_PIN_NID 0x09 /* Port E */
131 #define CS421X_SPDIF_PIN_NID 0x0A /* Port H */
133 #define CS421X_IDX_DEV_CFG 0x01
134 #define CS421X_IDX_ADC_CFG 0x02
135 #define CS421X_IDX_DAC_CFG 0x03
136 #define CS421X_IDX_SPK_CTL 0x04
138 /* Cirrus Logic CS4213 is like CS4210 but does not have SPDIF input/output */
139 #define CS4213_VENDOR_NID 0x09
142 static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx)
144 struct cs_spec *spec = codec->spec;
145 snd_hda_codec_write(codec, spec->vendor_nid, 0,
146 AC_VERB_SET_COEF_INDEX, idx);
147 return snd_hda_codec_read(codec, spec->vendor_nid, 0,
148 AC_VERB_GET_PROC_COEF, 0);
151 static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx,
154 struct cs_spec *spec = codec->spec;
155 snd_hda_codec_write(codec, spec->vendor_nid, 0,
156 AC_VERB_SET_COEF_INDEX, idx);
157 snd_hda_codec_write(codec, spec->vendor_nid, 0,
158 AC_VERB_SET_PROC_COEF, coef);
162 * auto-mute and auto-mic switching
163 * CS421x auto-output redirecting
167 static void cs_automute(struct hda_codec *codec)
169 struct cs_spec *spec = codec->spec;
171 /* mute HPs if spdif jack (SENSE_B) is present */
172 spec->gen.master_mute = !!(spec->spdif_present && spec->sense_b);
174 snd_hda_gen_update_outputs(codec);
176 if (spec->gpio_eapd_hp || spec->gpio_eapd_speaker) {
177 if (spec->gen.automute_speaker)
178 spec->gpio_data = spec->gen.hp_jack_present ?
179 spec->gpio_eapd_hp : spec->gpio_eapd_speaker;
182 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
183 snd_hda_codec_write(codec, 0x01, 0,
184 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
188 static bool is_active_pin(struct hda_codec *codec, hda_nid_t nid)
191 val = snd_hda_codec_get_pincfg(codec, nid);
192 return (get_defcfg_connect(val) != AC_JACK_PORT_NONE);
195 static void init_input_coef(struct hda_codec *codec)
197 struct cs_spec *spec = codec->spec;
200 /* CS420x has multiple ADC, CS421x has single ADC */
201 if (spec->vendor_nid == CS420X_VENDOR_NID) {
202 coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG);
203 if (is_active_pin(codec, CS_DMIC2_PIN_NID))
204 coef |= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */
205 if (is_active_pin(codec, CS_DMIC1_PIN_NID))
206 coef |= 1 << 3; /* DMIC1 2 chan on, GPIO0 off
207 * No effect if SPDIF_OUT2 is
208 * selected in IDX_SPDIF_CTL.
211 cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef);
215 static const struct hda_verb cs_coef_init_verbs[] = {
216 {0x11, AC_VERB_SET_PROC_STATE, 1},
217 {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
218 {0x11, AC_VERB_SET_PROC_COEF,
219 (0x002a /* DAC1/2/3 SZCMode Soft Ramp */
220 | 0x0040 /* Mute DACs on FIFO error */
221 | 0x1000 /* Enable DACs High Pass Filter */
222 | 0x0400 /* Disable Coefficient Auto increment */
224 /* ADC1/2 - Digital and Analog Soft Ramp */
225 {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG},
226 {0x11, AC_VERB_SET_PROC_COEF, 0x000a},
228 {0x11, AC_VERB_SET_COEF_INDEX, IDX_BEEP_CFG},
229 {0x11, AC_VERB_SET_PROC_COEF, 0x0007}, /* Enable Beep thru DAC1/2/3 */
234 static const struct hda_verb cs4208_coef_init_verbs[] = {
235 {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */
236 {0x24, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
237 {0x24, AC_VERB_SET_COEF_INDEX, 0x0033},
238 {0x24, AC_VERB_SET_PROC_COEF, 0x0001}, /* A1 ICS */
239 {0x24, AC_VERB_SET_COEF_INDEX, 0x0034},
240 {0x24, AC_VERB_SET_PROC_COEF, 0x1C01}, /* A1 Enable, A Thresh = 300mV */
244 /* Errata: CS4207 rev C0/C1/C2 Silicon
246 * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf
248 * 6. At high temperature (TA > +85°C), the digital supply current (IVD)
249 * may be excessive (up to an additional 200 μA), which is most easily
250 * observed while the part is being held in reset (RESET# active low).
252 * Root Cause: At initial powerup of the device, the logic that drives
253 * the clock and write enable to the S/PDIF SRC RAMs is not properly
255 * Certain random patterns will cause a steady leakage current in those
256 * RAM cells. The issue will resolve once the SRCs are used (turned on).
258 * Workaround: The following verb sequence briefly turns on the S/PDIF SRC
259 * blocks, which will alleviate the issue.
262 static const struct hda_verb cs_errata_init_verbs[] = {
263 {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */
264 {0x11, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
266 {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
267 {0x11, AC_VERB_SET_PROC_COEF, 0x9999},
268 {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
269 {0x11, AC_VERB_SET_PROC_COEF, 0xa412},
270 {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
271 {0x11, AC_VERB_SET_PROC_COEF, 0x0009},
273 {0x07, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Rx: D0 */
274 {0x08, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Tx: D0 */
276 {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
277 {0x11, AC_VERB_SET_PROC_COEF, 0x2412},
278 {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
279 {0x11, AC_VERB_SET_PROC_COEF, 0x0000},
280 {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
281 {0x11, AC_VERB_SET_PROC_COEF, 0x0008},
282 {0x11, AC_VERB_SET_PROC_STATE, 0x00},
284 #if 0 /* Don't to set to D3 as we are in power-up sequence */
285 {0x07, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Rx: D3 */
286 {0x08, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Tx: D3 */
287 /*{0x01, AC_VERB_SET_POWER_STATE, 0x03},*/ /* AFG: D3 This is already handled */
294 static void init_digital_coef(struct hda_codec *codec)
298 coef = 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */
299 coef |= 0x0008; /* Replace with mute on error */
300 if (is_active_pin(codec, CS_DIG_OUT2_PIN_NID))
301 coef |= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2
302 * SPDIF_OUT2 is shared with GPIO1 and
305 cs_vendor_coef_set(codec, IDX_SPDIF_CTL, coef);
308 static int cs_init(struct hda_codec *codec)
310 struct cs_spec *spec = codec->spec;
312 if (spec->vendor_nid == CS420X_VENDOR_NID) {
313 /* init_verb sequence for C0/C1/C2 errata*/
314 snd_hda_sequence_write(codec, cs_errata_init_verbs);
315 snd_hda_sequence_write(codec, cs_coef_init_verbs);
316 } else if (spec->vendor_nid == CS4208_VENDOR_NID) {
317 snd_hda_sequence_write(codec, cs4208_coef_init_verbs);
320 snd_hda_gen_init(codec);
322 if (spec->gpio_mask) {
323 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
325 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
327 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
331 if (spec->vendor_nid == CS420X_VENDOR_NID) {
332 init_input_coef(codec);
333 init_digital_coef(codec);
339 static int cs_build_controls(struct hda_codec *codec)
343 err = snd_hda_gen_build_controls(codec);
346 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD);
350 #define cs_free snd_hda_gen_free
352 static const struct hda_codec_ops cs_patch_ops = {
353 .build_controls = cs_build_controls,
354 .build_pcms = snd_hda_gen_build_pcms,
357 .unsol_event = snd_hda_jack_unsol_event,
360 static int cs_parse_auto_config(struct hda_codec *codec)
362 struct cs_spec *spec = codec->spec;
366 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
370 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
374 /* keep the ADCs powered up when it's dynamically switchable */
375 if (spec->gen.dyn_adc_switch) {
376 unsigned int done = 0;
377 for (i = 0; i < spec->gen.input_mux.num_items; i++) {
378 int idx = spec->gen.dyn_adc_idx[i];
379 if (done & (1 << idx))
381 snd_hda_gen_fix_pin_power(codec,
382 spec->gen.adc_nids[idx]);
390 static const struct hda_model_fixup cs420x_models[] = {
391 { .id = CS420X_MBP53, .name = "mbp53" },
392 { .id = CS420X_MBP55, .name = "mbp55" },
393 { .id = CS420X_IMAC27, .name = "imac27" },
394 { .id = CS420X_IMAC27_122, .name = "imac27_122" },
395 { .id = CS420X_APPLE, .name = "apple" },
396 { .id = CS420X_MBP101, .name = "mbp101" },
397 { .id = CS420X_MBP81, .name = "mbp81" },
398 { .id = CS420X_MBA42, .name = "mba42" },
402 static const struct snd_pci_quirk cs420x_fixup_tbl[] = {
403 SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53),
404 SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55),
405 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
406 SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55),
407 /* this conflicts with too many other models */
408 /*SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),*/
411 SND_PCI_QUIRK(0x106b, 0x0600, "iMac 14,1", CS420X_IMAC27_122),
412 SND_PCI_QUIRK(0x106b, 0x0900, "iMac 12,1", CS420X_IMAC27_122),
413 SND_PCI_QUIRK(0x106b, 0x1c00, "MacBookPro 8,1", CS420X_MBP81),
414 SND_PCI_QUIRK(0x106b, 0x2000, "iMac 12,2", CS420X_IMAC27_122),
415 SND_PCI_QUIRK(0x106b, 0x2800, "MacBookPro 10,1", CS420X_MBP101),
416 SND_PCI_QUIRK(0x106b, 0x5600, "MacBookAir 5,2", CS420X_MBP81),
417 SND_PCI_QUIRK(0x106b, 0x5b00, "MacBookAir 4,2", CS420X_MBA42),
418 SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS420X_APPLE),
422 static const struct hda_pintbl mbp53_pincfgs[] = {
423 { 0x09, 0x012b4050 },
424 { 0x0a, 0x90100141 },
425 { 0x0b, 0x90100140 },
426 { 0x0c, 0x018b3020 },
427 { 0x0d, 0x90a00110 },
428 { 0x0e, 0x400000f0 },
429 { 0x0f, 0x01cbe030 },
430 { 0x10, 0x014be060 },
431 { 0x12, 0x400000f0 },
432 { 0x15, 0x400000f0 },
436 static const struct hda_pintbl mbp55_pincfgs[] = {
437 { 0x09, 0x012b4030 },
438 { 0x0a, 0x90100121 },
439 { 0x0b, 0x90100120 },
440 { 0x0c, 0x400000f0 },
441 { 0x0d, 0x90a00110 },
442 { 0x0e, 0x400000f0 },
443 { 0x0f, 0x400000f0 },
444 { 0x10, 0x014be040 },
445 { 0x12, 0x400000f0 },
446 { 0x15, 0x400000f0 },
450 static const struct hda_pintbl imac27_pincfgs[] = {
451 { 0x09, 0x012b4050 },
452 { 0x0a, 0x90100140 },
453 { 0x0b, 0x90100142 },
454 { 0x0c, 0x018b3020 },
455 { 0x0d, 0x90a00110 },
456 { 0x0e, 0x400000f0 },
457 { 0x0f, 0x01cbe030 },
458 { 0x10, 0x014be060 },
459 { 0x12, 0x01ab9070 },
460 { 0x15, 0x400000f0 },
464 static const struct hda_pintbl mbp101_pincfgs[] = {
465 { 0x0d, 0x40ab90f0 },
466 { 0x0e, 0x90a600f0 },
467 { 0x12, 0x50a600f0 },
471 static const struct hda_pintbl mba42_pincfgs[] = {
472 { 0x09, 0x012b4030 }, /* HP */
473 { 0x0a, 0x400000f0 },
474 { 0x0b, 0x90100120 }, /* speaker */
475 { 0x0c, 0x400000f0 },
476 { 0x0d, 0x90a00110 }, /* mic */
477 { 0x0e, 0x400000f0 },
478 { 0x0f, 0x400000f0 },
479 { 0x10, 0x400000f0 },
480 { 0x12, 0x400000f0 },
481 { 0x15, 0x400000f0 },
485 static const struct hda_pintbl mba6_pincfgs[] = {
486 { 0x10, 0x032120f0 }, /* HP */
487 { 0x11, 0x500000f0 },
488 { 0x12, 0x90100010 }, /* Speaker */
489 { 0x13, 0x500000f0 },
490 { 0x14, 0x500000f0 },
491 { 0x15, 0x770000f0 },
492 { 0x16, 0x770000f0 },
493 { 0x17, 0x430000f0 },
494 { 0x18, 0x43ab9030 }, /* Mic */
495 { 0x19, 0x770000f0 },
496 { 0x1a, 0x770000f0 },
497 { 0x1b, 0x770000f0 },
498 { 0x1c, 0x90a00090 },
499 { 0x1d, 0x500000f0 },
500 { 0x1e, 0x500000f0 },
501 { 0x1f, 0x500000f0 },
502 { 0x20, 0x500000f0 },
503 { 0x21, 0x430000f0 },
504 { 0x22, 0x430000f0 },
508 static void cs420x_fixup_gpio_13(struct hda_codec *codec,
509 const struct hda_fixup *fix, int action)
511 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
512 struct cs_spec *spec = codec->spec;
513 spec->gpio_eapd_hp = 2; /* GPIO1 = headphones */
514 spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */
515 spec->gpio_mask = spec->gpio_dir =
516 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
520 static void cs420x_fixup_gpio_23(struct hda_codec *codec,
521 const struct hda_fixup *fix, int action)
523 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
524 struct cs_spec *spec = codec->spec;
525 spec->gpio_eapd_hp = 4; /* GPIO2 = headphones */
526 spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */
527 spec->gpio_mask = spec->gpio_dir =
528 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
532 static const struct hda_fixup cs420x_fixups[] = {
534 .type = HDA_FIXUP_PINS,
535 .v.pins = mbp53_pincfgs,
537 .chain_id = CS420X_APPLE,
540 .type = HDA_FIXUP_PINS,
541 .v.pins = mbp55_pincfgs,
543 .chain_id = CS420X_GPIO_13,
546 .type = HDA_FIXUP_PINS,
547 .v.pins = imac27_pincfgs,
549 .chain_id = CS420X_GPIO_13,
552 .type = HDA_FIXUP_FUNC,
553 .v.func = cs420x_fixup_gpio_13,
556 .type = HDA_FIXUP_FUNC,
557 .v.func = cs420x_fixup_gpio_23,
560 .type = HDA_FIXUP_PINS,
561 .v.pins = mbp101_pincfgs,
563 .chain_id = CS420X_GPIO_13,
566 .type = HDA_FIXUP_VERBS,
567 .v.verbs = (const struct hda_verb[]) {
568 /* internal mic ADC2: right only, single ended */
569 {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG},
570 {0x11, AC_VERB_SET_PROC_COEF, 0x102a},
574 .chain_id = CS420X_GPIO_13,
577 .type = HDA_FIXUP_PINS,
578 .v.pins = mba42_pincfgs,
580 .chain_id = CS420X_GPIO_13,
584 static struct cs_spec *cs_alloc_spec(struct hda_codec *codec, int vendor_nid)
586 struct cs_spec *spec;
588 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
592 spec->vendor_nid = vendor_nid;
593 codec->power_save_node = 1;
594 snd_hda_gen_spec_init(&spec->gen);
599 static int patch_cs420x(struct hda_codec *codec)
601 struct cs_spec *spec;
604 spec = cs_alloc_spec(codec, CS420X_VENDOR_NID);
608 codec->patch_ops = cs_patch_ops;
609 spec->gen.automute_hook = cs_automute;
610 codec->single_adc_amp = 1;
612 snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl,
614 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
616 err = cs_parse_auto_config(codec);
620 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
631 * Its layout is no longer compatible with CS4206/CS4207
641 static const struct hda_model_fixup cs4208_models[] = {
642 { .id = CS4208_GPIO0, .name = "gpio0" },
643 { .id = CS4208_MBA6, .name = "mba6" },
644 { .id = CS4208_MBP11, .name = "mbp11" },
645 { .id = CS4208_MACMINI, .name = "macmini" },
649 static const struct snd_pci_quirk cs4208_fixup_tbl[] = {
650 SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS4208_MAC_AUTO),
654 /* codec SSID matching */
655 static const struct snd_pci_quirk cs4208_mac_fixup_tbl[] = {
656 SND_PCI_QUIRK(0x106b, 0x5e00, "MacBookPro 11,2", CS4208_MBP11),
657 SND_PCI_QUIRK(0x106b, 0x6c00, "MacMini 7,1", CS4208_MACMINI),
658 SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6),
659 SND_PCI_QUIRK(0x106b, 0x7200, "MacBookAir 6,2", CS4208_MBA6),
660 SND_PCI_QUIRK(0x106b, 0x7b00, "MacBookPro 12,1", CS4208_MBP11),
664 static void cs4208_fixup_gpio0(struct hda_codec *codec,
665 const struct hda_fixup *fix, int action)
667 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
668 struct cs_spec *spec = codec->spec;
669 spec->gpio_eapd_hp = 0;
670 spec->gpio_eapd_speaker = 1;
671 spec->gpio_mask = spec->gpio_dir =
672 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
676 static const struct hda_fixup cs4208_fixups[];
678 /* remap the fixup from codec SSID and apply it */
679 static void cs4208_fixup_mac(struct hda_codec *codec,
680 const struct hda_fixup *fix, int action)
682 if (action != HDA_FIXUP_ACT_PRE_PROBE)
685 codec->fixup_id = HDA_FIXUP_ID_NOT_SET;
686 snd_hda_pick_fixup(codec, NULL, cs4208_mac_fixup_tbl, cs4208_fixups);
687 if (codec->fixup_id == HDA_FIXUP_ID_NOT_SET)
688 codec->fixup_id = CS4208_GPIO0; /* default fixup */
689 snd_hda_apply_fixup(codec, action);
692 /* MacMini 7,1 has the inverted jack detection */
693 static void cs4208_fixup_macmini(struct hda_codec *codec,
694 const struct hda_fixup *fix, int action)
696 static const struct hda_pintbl pincfgs[] = {
697 { 0x18, 0x00ab9150 }, /* mic (audio-in) jack: disable detect */
698 { 0x21, 0x004be140 }, /* SPDIF: disable detect */
702 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
703 /* HP pin (0x10) has an inverted detection */
704 codec->inv_jack_detect = 1;
705 /* disable the bogus Mic and SPDIF jack detections */
706 snd_hda_apply_pincfgs(codec, pincfgs);
710 static int cs4208_spdif_sw_put(struct snd_kcontrol *kcontrol,
711 struct snd_ctl_elem_value *ucontrol)
713 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
714 struct cs_spec *spec = codec->spec;
715 hda_nid_t pin = spec->gen.autocfg.dig_out_pins[0];
716 int pinctl = ucontrol->value.integer.value[0] ? PIN_OUT : 0;
718 snd_hda_set_pin_ctl_cache(codec, pin, pinctl);
719 return spec->spdif_sw_put(kcontrol, ucontrol);
722 /* hook the SPDIF switch */
723 static void cs4208_fixup_spdif_switch(struct hda_codec *codec,
724 const struct hda_fixup *fix, int action)
726 if (action == HDA_FIXUP_ACT_BUILD) {
727 struct cs_spec *spec = codec->spec;
728 struct snd_kcontrol *kctl;
730 if (!spec->gen.autocfg.dig_out_pins[0])
732 kctl = snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch");
735 spec->spdif_sw_put = kctl->put;
736 kctl->put = cs4208_spdif_sw_put;
740 static const struct hda_fixup cs4208_fixups[] = {
742 .type = HDA_FIXUP_PINS,
743 .v.pins = mba6_pincfgs,
745 .chain_id = CS4208_GPIO0,
748 .type = HDA_FIXUP_FUNC,
749 .v.func = cs4208_fixup_spdif_switch,
751 .chain_id = CS4208_GPIO0,
754 .type = HDA_FIXUP_FUNC,
755 .v.func = cs4208_fixup_macmini,
757 .chain_id = CS4208_GPIO0,
760 .type = HDA_FIXUP_FUNC,
761 .v.func = cs4208_fixup_gpio0,
763 [CS4208_MAC_AUTO] = {
764 .type = HDA_FIXUP_FUNC,
765 .v.func = cs4208_fixup_mac,
769 /* correct the 0dB offset of input pins */
770 static void cs4208_fix_amp_caps(struct hda_codec *codec, hda_nid_t adc)
774 caps = query_amp_caps(codec, adc, HDA_INPUT);
775 caps &= ~(AC_AMPCAP_OFFSET);
777 snd_hda_override_amp_caps(codec, adc, HDA_INPUT, caps);
780 static int patch_cs4208(struct hda_codec *codec)
782 struct cs_spec *spec;
785 spec = cs_alloc_spec(codec, CS4208_VENDOR_NID);
789 codec->patch_ops = cs_patch_ops;
790 spec->gen.automute_hook = cs_automute;
791 /* exclude NID 0x10 (HP) from output volumes due to different steps */
792 spec->gen.out_vol_mask = 1ULL << 0x10;
794 snd_hda_pick_fixup(codec, cs4208_models, cs4208_fixup_tbl,
796 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
798 snd_hda_override_wcaps(codec, 0x18,
799 get_wcaps(codec, 0x18) | AC_WCAP_STEREO);
800 cs4208_fix_amp_caps(codec, 0x18);
801 cs4208_fix_amp_caps(codec, 0x1b);
802 cs4208_fix_amp_caps(codec, 0x1c);
804 err = cs_parse_auto_config(codec);
808 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
818 * Cirrus Logic CS4210
820 * 1 DAC => HP(sense) / Speakers,
821 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
822 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
825 /* CS4210 board names */
826 static const struct hda_model_fixup cs421x_models[] = {
827 { .id = CS421X_CDB4210, .name = "cdb4210" },
828 { .id = CS421X_STUMPY, .name = "stumpy" },
832 static const struct snd_pci_quirk cs421x_fixup_tbl[] = {
833 /* Test Intel board + CDB2410 */
834 SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210),
838 /* CS4210 board pinconfigs */
839 /* Default CS4210 (CDB4210)*/
840 static const struct hda_pintbl cdb4210_pincfgs[] = {
841 { 0x05, 0x0321401f },
842 { 0x06, 0x90170010 },
843 { 0x07, 0x03813031 },
844 { 0x08, 0xb7a70037 },
845 { 0x09, 0xb7a6003e },
846 { 0x0a, 0x034510f0 },
850 /* Stumpy ChromeBox */
851 static const struct hda_pintbl stumpy_pincfgs[] = {
852 { 0x05, 0x022120f0 },
853 { 0x06, 0x901700f0 },
854 { 0x07, 0x02a120f0 },
855 { 0x08, 0x77a70037 },
856 { 0x09, 0x77a6003e },
857 { 0x0a, 0x434510f0 },
861 /* Setup GPIO/SENSE for each board (if used) */
862 static void cs421x_fixup_sense_b(struct hda_codec *codec,
863 const struct hda_fixup *fix, int action)
865 struct cs_spec *spec = codec->spec;
866 if (action == HDA_FIXUP_ACT_PRE_PROBE)
870 static const struct hda_fixup cs421x_fixups[] = {
872 .type = HDA_FIXUP_PINS,
873 .v.pins = cdb4210_pincfgs,
875 .chain_id = CS421X_SENSE_B,
878 .type = HDA_FIXUP_FUNC,
879 .v.func = cs421x_fixup_sense_b,
882 .type = HDA_FIXUP_PINS,
883 .v.pins = stumpy_pincfgs,
887 static const struct hda_verb cs421x_coef_init_verbs[] = {
888 {0x0B, AC_VERB_SET_PROC_STATE, 1},
889 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DEV_CFG},
891 Disable Coefficient Index Auto-Increment(DAI)=1,
894 {0x0B, AC_VERB_SET_PROC_COEF, 0x0001 },
896 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_ADC_CFG},
897 /* ADC SZCMode = Digital Soft Ramp */
898 {0x0B, AC_VERB_SET_PROC_COEF, 0x0002 },
900 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DAC_CFG},
901 {0x0B, AC_VERB_SET_PROC_COEF,
902 (0x0002 /* DAC SZCMode = Digital Soft Ramp */
903 | 0x0004 /* Mute DAC on FIFO error */
904 | 0x0008 /* Enable DAC High Pass Filter */
909 /* Errata: CS4210 rev A1 Silicon
911 * http://www.cirrus.com/en/pubs/errata/
914 * 1. Performance degredation is present in the ADC.
915 * 2. Speaker output is not completely muted upon HP detect.
916 * 3. Noise is present when clipping occurs on the amplified
920 * The following verb sequence written to the registers during
921 * initialization will correct the issues listed above.
924 static const struct hda_verb cs421x_coef_init_verbs_A1_silicon_fixes[] = {
925 {0x0B, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
927 {0x0B, AC_VERB_SET_COEF_INDEX, 0x0006},
928 {0x0B, AC_VERB_SET_PROC_COEF, 0x9999}, /* Test mode: on */
930 {0x0B, AC_VERB_SET_COEF_INDEX, 0x000A},
931 {0x0B, AC_VERB_SET_PROC_COEF, 0x14CB}, /* Chop double */
933 {0x0B, AC_VERB_SET_COEF_INDEX, 0x0011},
934 {0x0B, AC_VERB_SET_PROC_COEF, 0xA2D0}, /* Increase ADC current */
936 {0x0B, AC_VERB_SET_COEF_INDEX, 0x001A},
937 {0x0B, AC_VERB_SET_PROC_COEF, 0x02A9}, /* Mute speaker */
939 {0x0B, AC_VERB_SET_COEF_INDEX, 0x001B},
940 {0x0B, AC_VERB_SET_PROC_COEF, 0X1006}, /* Remove noise */
945 /* Speaker Amp Gain is controlled by the vendor widget's coef 4 */
946 static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale, 900, 300, 0);
948 static int cs421x_boost_vol_info(struct snd_kcontrol *kcontrol,
949 struct snd_ctl_elem_info *uinfo)
951 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
953 uinfo->value.integer.min = 0;
954 uinfo->value.integer.max = 3;
958 static int cs421x_boost_vol_get(struct snd_kcontrol *kcontrol,
959 struct snd_ctl_elem_value *ucontrol)
961 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
963 ucontrol->value.integer.value[0] =
964 cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL) & 0x0003;
968 static int cs421x_boost_vol_put(struct snd_kcontrol *kcontrol,
969 struct snd_ctl_elem_value *ucontrol)
971 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
973 unsigned int vol = ucontrol->value.integer.value[0];
975 cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL);
976 unsigned int original_coef = coef;
979 coef |= (vol & 0x0003);
980 if (original_coef == coef)
983 cs_vendor_coef_set(codec, CS421X_IDX_SPK_CTL, coef);
988 static const struct snd_kcontrol_new cs421x_speaker_boost_ctl = {
990 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
991 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
992 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
993 .name = "Speaker Boost Playback Volume",
994 .info = cs421x_boost_vol_info,
995 .get = cs421x_boost_vol_get,
996 .put = cs421x_boost_vol_put,
997 .tlv = { .p = cs421x_speaker_boost_db_scale },
1000 static void cs4210_pinmux_init(struct hda_codec *codec)
1002 struct cs_spec *spec = codec->spec;
1003 unsigned int def_conf, coef;
1005 /* GPIO, DMIC_SCL, DMIC_SDA and SENSE_B are multiplexed */
1006 coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG);
1008 if (spec->gpio_mask)
1009 coef |= 0x0008; /* B1,B2 are GPIOs */
1014 coef |= 0x0010; /* B2 is SENSE_B, not inverted */
1018 cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef);
1020 if ((spec->gpio_mask || spec->sense_b) &&
1021 is_active_pin(codec, CS421X_DMIC_PIN_NID)) {
1024 GPIO or SENSE_B forced - disconnect the DMIC pin.
1026 def_conf = snd_hda_codec_get_pincfg(codec, CS421X_DMIC_PIN_NID);
1027 def_conf &= ~AC_DEFCFG_PORT_CONN;
1028 def_conf |= (AC_JACK_PORT_NONE << AC_DEFCFG_PORT_CONN_SHIFT);
1029 snd_hda_codec_set_pincfg(codec, CS421X_DMIC_PIN_NID, def_conf);
1033 static void cs4210_spdif_automute(struct hda_codec *codec,
1034 struct hda_jack_callback *tbl)
1036 struct cs_spec *spec = codec->spec;
1037 bool spdif_present = false;
1038 hda_nid_t spdif_pin = spec->gen.autocfg.dig_out_pins[0];
1040 /* detect on spdif is specific to CS4210 */
1041 if (!spec->spdif_detect ||
1042 spec->vendor_nid != CS4210_VENDOR_NID)
1045 spdif_present = snd_hda_jack_detect(codec, spdif_pin);
1046 if (spdif_present == spec->spdif_present)
1049 spec->spdif_present = spdif_present;
1050 /* SPDIF TX on/off */
1051 snd_hda_set_pin_ctl(codec, spdif_pin, spdif_present ? PIN_OUT : 0);
1056 static void parse_cs421x_digital(struct hda_codec *codec)
1058 struct cs_spec *spec = codec->spec;
1059 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
1062 for (i = 0; i < cfg->dig_outs; i++) {
1063 hda_nid_t nid = cfg->dig_out_pins[i];
1064 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
1065 spec->spdif_detect = 1;
1066 snd_hda_jack_detect_enable_callback(codec, nid,
1067 cs4210_spdif_automute);
1072 static int cs421x_init(struct hda_codec *codec)
1074 struct cs_spec *spec = codec->spec;
1076 if (spec->vendor_nid == CS4210_VENDOR_NID) {
1077 snd_hda_sequence_write(codec, cs421x_coef_init_verbs);
1078 snd_hda_sequence_write(codec, cs421x_coef_init_verbs_A1_silicon_fixes);
1079 cs4210_pinmux_init(codec);
1082 snd_hda_gen_init(codec);
1084 if (spec->gpio_mask) {
1085 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
1087 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
1089 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
1093 init_input_coef(codec);
1095 cs4210_spdif_automute(codec, NULL);
1100 static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
1104 /* set the upper-limit for mixer amp to 0dB */
1105 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
1106 caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT);
1107 caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f)
1108 << AC_AMPCAP_NUM_STEPS_SHIFT;
1109 snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps);
1112 static int cs421x_parse_auto_config(struct hda_codec *codec)
1114 struct cs_spec *spec = codec->spec;
1115 hda_nid_t dac = CS4210_DAC_NID;
1118 fix_volume_caps(codec, dac);
1120 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
1124 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
1128 parse_cs421x_digital(codec);
1130 if (spec->gen.autocfg.speaker_outs &&
1131 spec->vendor_nid == CS4210_VENDOR_NID) {
1132 if (!snd_hda_gen_add_kctl(&spec->gen, NULL,
1133 &cs421x_speaker_boost_ctl))
1142 Manage PDREF, when transitioning to D3hot
1143 (DAC,ADC) -> D3, PDREF=1, AFG->D3
1145 static int cs421x_suspend(struct hda_codec *codec)
1147 struct cs_spec *spec = codec->spec;
1150 snd_hda_shutup_pins(codec);
1152 snd_hda_codec_write(codec, CS4210_DAC_NID, 0,
1153 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1154 snd_hda_codec_write(codec, CS4210_ADC_NID, 0,
1155 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1157 if (spec->vendor_nid == CS4210_VENDOR_NID) {
1158 coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG);
1159 coef |= 0x0004; /* PDREF */
1160 cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef);
1167 static const struct hda_codec_ops cs421x_patch_ops = {
1168 .build_controls = snd_hda_gen_build_controls,
1169 .build_pcms = snd_hda_gen_build_pcms,
1170 .init = cs421x_init,
1172 .unsol_event = snd_hda_jack_unsol_event,
1174 .suspend = cs421x_suspend,
1178 static int patch_cs4210(struct hda_codec *codec)
1180 struct cs_spec *spec;
1183 spec = cs_alloc_spec(codec, CS4210_VENDOR_NID);
1187 codec->patch_ops = cs421x_patch_ops;
1188 spec->gen.automute_hook = cs_automute;
1190 snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl,
1192 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1195 Update the GPIO/DMIC/SENSE_B pinmux before the configuration
1196 is auto-parsed. If GPIO or SENSE_B is forced, DMIC input
1199 cs4210_pinmux_init(codec);
1201 err = cs421x_parse_auto_config(codec);
1205 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1214 static int patch_cs4213(struct hda_codec *codec)
1216 struct cs_spec *spec;
1219 spec = cs_alloc_spec(codec, CS4213_VENDOR_NID);
1223 codec->patch_ops = cs421x_patch_ops;
1225 err = cs421x_parse_auto_config(codec);
1240 static const struct hda_device_id snd_hda_id_cirrus[] = {
1241 HDA_CODEC_ENTRY(0x10134206, "CS4206", patch_cs420x),
1242 HDA_CODEC_ENTRY(0x10134207, "CS4207", patch_cs420x),
1243 HDA_CODEC_ENTRY(0x10134208, "CS4208", patch_cs4208),
1244 HDA_CODEC_ENTRY(0x10134210, "CS4210", patch_cs4210),
1245 HDA_CODEC_ENTRY(0x10134213, "CS4213", patch_cs4213),
1248 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_cirrus);
1250 MODULE_LICENSE("GPL");
1251 MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
1253 static struct hda_codec_driver cirrus_driver = {
1254 .id = snd_hda_id_cirrus,
1257 module_hda_codec_driver(cirrus_driver);