1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * HD audio interface patch for Cirrus Logic CS420x chip
5 * Copyright (c) 2009 Takashi Iwai <tiwai@suse.de>
8 #include <linux/init.h>
9 #include <linux/slab.h>
10 #include <linux/module.h>
11 #include <sound/core.h>
12 #include <linux/mutex.h>
13 #include <linux/pci.h>
14 #include <sound/tlv.h>
15 #include <sound/hda_codec.h>
16 #include "hda_local.h"
17 #include "hda_auto_parser.h"
19 #include "hda_generic.h"
24 #define CS42L42_HP_CH (2U)
25 #define CS42L42_HS_MIC_CH (1U)
28 struct hda_gen_spec gen;
30 unsigned int gpio_mask;
31 unsigned int gpio_dir;
32 unsigned int gpio_data;
33 unsigned int gpio_eapd_hp; /* EAPD GPIO bit for headphones */
34 unsigned int gpio_eapd_speaker; /* EAPD GPIO bit for speakers */
37 unsigned int spdif_detect:1;
38 unsigned int spdif_present:1;
39 unsigned int sense_b:1;
42 /* for MBP SPDIF control */
43 int (*spdif_sw_put)(struct snd_kcontrol *kcontrol,
44 struct snd_ctl_elem_value *ucontrol);
46 unsigned int cs42l42_hp_jack_in:1;
47 unsigned int cs42l42_mic_jack_in:1;
48 unsigned int cs42l42_volume_init:1;
49 char cs42l42_hp_volume[CS42L42_HP_CH];
50 char cs42l42_hs_mic_volume[CS42L42_HS_MIC_CH];
52 struct mutex cs8409_i2c_mux;
54 /* verb exec op override */
55 int (*exec_verb)(struct hdac_device *dev, unsigned int cmd,
56 unsigned int flags, unsigned int *res);
59 /* available models with CS420x */
71 CS420X_IMAC27_122 = CS420X_GPIO_23,
72 CS420X_APPLE = CS420X_GPIO_13,
82 /* Vendor-specific processing widget */
83 #define CS420X_VENDOR_NID 0x11
84 #define CS_DIG_OUT1_PIN_NID 0x10
85 #define CS_DIG_OUT2_PIN_NID 0x15
86 #define CS_DMIC1_PIN_NID 0x0e
87 #define CS_DMIC2_PIN_NID 0x12
90 #define IDX_SPDIF_STAT 0x0000
91 #define IDX_SPDIF_CTL 0x0001
92 #define IDX_ADC_CFG 0x0002
93 /* SZC bitmask, 4 modes below:
95 * 1 = digital immediate, analog zero-cross
96 * 2 = digtail & analog soft-ramp
97 * 3 = digital soft-ramp, analog zero-cross
99 #define CS_COEF_ADC_SZC_MASK (3 << 0)
100 #define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */
101 #define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
102 /* PGA mode: 0 = differential, 1 = signle-ended */
103 #define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */
104 #define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
105 #define IDX_DAC_CFG 0x0003
106 /* SZC bitmask, 4 modes below:
110 * 3 = soft-ramp on zero-cross
112 #define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */
113 #define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */
114 #define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */
116 #define IDX_BEEP_CFG 0x0004
117 /* 0x0008 - test reg key */
118 /* 0x0009 - 0x0014 -> 12 test regs */
119 /* 0x0015 - visibility reg */
121 /* Cirrus Logic CS4208 */
122 #define CS4208_VENDOR_NID 0x24
125 * Cirrus Logic CS4210
127 * 1 DAC => HP(sense) / Speakers,
128 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
129 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
131 #define CS4210_DAC_NID 0x02
132 #define CS4210_ADC_NID 0x03
133 #define CS4210_VENDOR_NID 0x0B
134 #define CS421X_DMIC_PIN_NID 0x09 /* Port E */
135 #define CS421X_SPDIF_PIN_NID 0x0A /* Port H */
137 #define CS421X_IDX_DEV_CFG 0x01
138 #define CS421X_IDX_ADC_CFG 0x02
139 #define CS421X_IDX_DAC_CFG 0x03
140 #define CS421X_IDX_SPK_CTL 0x04
142 /* Cirrus Logic CS4213 is like CS4210 but does not have SPDIF input/output */
143 #define CS4213_VENDOR_NID 0x09
146 static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx)
148 struct cs_spec *spec = codec->spec;
150 snd_hda_codec_write(codec, spec->vendor_nid, 0,
151 AC_VERB_SET_COEF_INDEX, idx);
152 return snd_hda_codec_read(codec, spec->vendor_nid, 0,
153 AC_VERB_GET_PROC_COEF, 0);
156 static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx,
159 struct cs_spec *spec = codec->spec;
161 snd_hda_codec_write(codec, spec->vendor_nid, 0,
162 AC_VERB_SET_COEF_INDEX, idx);
163 snd_hda_codec_write(codec, spec->vendor_nid, 0,
164 AC_VERB_SET_PROC_COEF, coef);
168 * auto-mute and auto-mic switching
169 * CS421x auto-output redirecting
173 static void cs_automute(struct hda_codec *codec)
175 struct cs_spec *spec = codec->spec;
177 /* mute HPs if spdif jack (SENSE_B) is present */
178 spec->gen.master_mute = !!(spec->spdif_present && spec->sense_b);
180 snd_hda_gen_update_outputs(codec);
182 if (spec->gpio_eapd_hp || spec->gpio_eapd_speaker) {
183 if (spec->gen.automute_speaker)
184 spec->gpio_data = spec->gen.hp_jack_present ?
185 spec->gpio_eapd_hp : spec->gpio_eapd_speaker;
188 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
189 snd_hda_codec_write(codec, 0x01, 0,
190 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
194 static bool is_active_pin(struct hda_codec *codec, hda_nid_t nid)
198 val = snd_hda_codec_get_pincfg(codec, nid);
199 return (get_defcfg_connect(val) != AC_JACK_PORT_NONE);
202 static void init_input_coef(struct hda_codec *codec)
204 struct cs_spec *spec = codec->spec;
207 /* CS420x has multiple ADC, CS421x has single ADC */
208 if (spec->vendor_nid == CS420X_VENDOR_NID) {
209 coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG);
210 if (is_active_pin(codec, CS_DMIC2_PIN_NID))
211 coef |= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */
212 if (is_active_pin(codec, CS_DMIC1_PIN_NID))
213 coef |= 1 << 3; /* DMIC1 2 chan on, GPIO0 off
214 * No effect if SPDIF_OUT2 is
215 * selected in IDX_SPDIF_CTL.
218 cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef);
222 static const struct hda_verb cs_coef_init_verbs[] = {
223 {0x11, AC_VERB_SET_PROC_STATE, 1},
224 {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
225 {0x11, AC_VERB_SET_PROC_COEF,
226 (0x002a /* DAC1/2/3 SZCMode Soft Ramp */
227 | 0x0040 /* Mute DACs on FIFO error */
228 | 0x1000 /* Enable DACs High Pass Filter */
229 | 0x0400 /* Disable Coefficient Auto increment */
231 /* ADC1/2 - Digital and Analog Soft Ramp */
232 {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG},
233 {0x11, AC_VERB_SET_PROC_COEF, 0x000a},
235 {0x11, AC_VERB_SET_COEF_INDEX, IDX_BEEP_CFG},
236 {0x11, AC_VERB_SET_PROC_COEF, 0x0007}, /* Enable Beep thru DAC1/2/3 */
241 static const struct hda_verb cs4208_coef_init_verbs[] = {
242 {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */
243 {0x24, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
244 {0x24, AC_VERB_SET_COEF_INDEX, 0x0033},
245 {0x24, AC_VERB_SET_PROC_COEF, 0x0001}, /* A1 ICS */
246 {0x24, AC_VERB_SET_COEF_INDEX, 0x0034},
247 {0x24, AC_VERB_SET_PROC_COEF, 0x1C01}, /* A1 Enable, A Thresh = 300mV */
251 /* Errata: CS4207 rev C0/C1/C2 Silicon
253 * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf
255 * 6. At high temperature (TA > +85°C), the digital supply current (IVD)
256 * may be excessive (up to an additional 200 μA), which is most easily
257 * observed while the part is being held in reset (RESET# active low).
259 * Root Cause: At initial powerup of the device, the logic that drives
260 * the clock and write enable to the S/PDIF SRC RAMs is not properly
262 * Certain random patterns will cause a steady leakage current in those
263 * RAM cells. The issue will resolve once the SRCs are used (turned on).
265 * Workaround: The following verb sequence briefly turns on the S/PDIF SRC
266 * blocks, which will alleviate the issue.
269 static const struct hda_verb cs_errata_init_verbs[] = {
270 {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */
271 {0x11, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
273 {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
274 {0x11, AC_VERB_SET_PROC_COEF, 0x9999},
275 {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
276 {0x11, AC_VERB_SET_PROC_COEF, 0xa412},
277 {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
278 {0x11, AC_VERB_SET_PROC_COEF, 0x0009},
280 {0x07, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Rx: D0 */
281 {0x08, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Tx: D0 */
283 {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
284 {0x11, AC_VERB_SET_PROC_COEF, 0x2412},
285 {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
286 {0x11, AC_VERB_SET_PROC_COEF, 0x0000},
287 {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
288 {0x11, AC_VERB_SET_PROC_COEF, 0x0008},
289 {0x11, AC_VERB_SET_PROC_STATE, 0x00},
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;
378 for (i = 0; i < spec->gen.input_mux.num_items; i++) {
379 int idx = spec->gen.dyn_adc_idx[i];
381 if (done & (1 << idx))
383 snd_hda_gen_fix_pin_power(codec,
384 spec->gen.adc_nids[idx]);
392 static const struct hda_model_fixup cs420x_models[] = {
393 { .id = CS420X_MBP53, .name = "mbp53" },
394 { .id = CS420X_MBP55, .name = "mbp55" },
395 { .id = CS420X_IMAC27, .name = "imac27" },
396 { .id = CS420X_IMAC27_122, .name = "imac27_122" },
397 { .id = CS420X_APPLE, .name = "apple" },
398 { .id = CS420X_MBP101, .name = "mbp101" },
399 { .id = CS420X_MBP81, .name = "mbp81" },
400 { .id = CS420X_MBA42, .name = "mba42" },
404 static const struct snd_pci_quirk cs420x_fixup_tbl[] = {
405 SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53),
406 SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55),
407 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
408 SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55),
409 /* this conflicts with too many other models */
410 /*SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),*/
413 SND_PCI_QUIRK(0x106b, 0x0600, "iMac 14,1", CS420X_IMAC27_122),
414 SND_PCI_QUIRK(0x106b, 0x1c00, "MacBookPro 8,1", CS420X_MBP81),
415 SND_PCI_QUIRK(0x106b, 0x2000, "iMac 12,2", CS420X_IMAC27_122),
416 SND_PCI_QUIRK(0x106b, 0x2800, "MacBookPro 10,1", CS420X_MBP101),
417 SND_PCI_QUIRK(0x106b, 0x5600, "MacBookAir 5,2", CS420X_MBP81),
418 SND_PCI_QUIRK(0x106b, 0x5b00, "MacBookAir 4,2", CS420X_MBA42),
419 SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS420X_APPLE),
423 static const struct hda_pintbl mbp53_pincfgs[] = {
424 { 0x09, 0x012b4050 },
425 { 0x0a, 0x90100141 },
426 { 0x0b, 0x90100140 },
427 { 0x0c, 0x018b3020 },
428 { 0x0d, 0x90a00110 },
429 { 0x0e, 0x400000f0 },
430 { 0x0f, 0x01cbe030 },
431 { 0x10, 0x014be060 },
432 { 0x12, 0x400000f0 },
433 { 0x15, 0x400000f0 },
437 static const struct hda_pintbl mbp55_pincfgs[] = {
438 { 0x09, 0x012b4030 },
439 { 0x0a, 0x90100121 },
440 { 0x0b, 0x90100120 },
441 { 0x0c, 0x400000f0 },
442 { 0x0d, 0x90a00110 },
443 { 0x0e, 0x400000f0 },
444 { 0x0f, 0x400000f0 },
445 { 0x10, 0x014be040 },
446 { 0x12, 0x400000f0 },
447 { 0x15, 0x400000f0 },
451 static const struct hda_pintbl imac27_pincfgs[] = {
452 { 0x09, 0x012b4050 },
453 { 0x0a, 0x90100140 },
454 { 0x0b, 0x90100142 },
455 { 0x0c, 0x018b3020 },
456 { 0x0d, 0x90a00110 },
457 { 0x0e, 0x400000f0 },
458 { 0x0f, 0x01cbe030 },
459 { 0x10, 0x014be060 },
460 { 0x12, 0x01ab9070 },
461 { 0x15, 0x400000f0 },
465 static const struct hda_pintbl mbp101_pincfgs[] = {
466 { 0x0d, 0x40ab90f0 },
467 { 0x0e, 0x90a600f0 },
468 { 0x12, 0x50a600f0 },
472 static const struct hda_pintbl mba42_pincfgs[] = {
473 { 0x09, 0x012b4030 }, /* HP */
474 { 0x0a, 0x400000f0 },
475 { 0x0b, 0x90100120 }, /* speaker */
476 { 0x0c, 0x400000f0 },
477 { 0x0d, 0x90a00110 }, /* mic */
478 { 0x0e, 0x400000f0 },
479 { 0x0f, 0x400000f0 },
480 { 0x10, 0x400000f0 },
481 { 0x12, 0x400000f0 },
482 { 0x15, 0x400000f0 },
486 static const struct hda_pintbl mba6_pincfgs[] = {
487 { 0x10, 0x032120f0 }, /* HP */
488 { 0x11, 0x500000f0 },
489 { 0x12, 0x90100010 }, /* Speaker */
490 { 0x13, 0x500000f0 },
491 { 0x14, 0x500000f0 },
492 { 0x15, 0x770000f0 },
493 { 0x16, 0x770000f0 },
494 { 0x17, 0x430000f0 },
495 { 0x18, 0x43ab9030 }, /* Mic */
496 { 0x19, 0x770000f0 },
497 { 0x1a, 0x770000f0 },
498 { 0x1b, 0x770000f0 },
499 { 0x1c, 0x90a00090 },
500 { 0x1d, 0x500000f0 },
501 { 0x1e, 0x500000f0 },
502 { 0x1f, 0x500000f0 },
503 { 0x20, 0x500000f0 },
504 { 0x21, 0x430000f0 },
505 { 0x22, 0x430000f0 },
509 static void cs420x_fixup_gpio_13(struct hda_codec *codec,
510 const struct hda_fixup *fix, int action)
512 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
513 struct cs_spec *spec = codec->spec;
515 spec->gpio_eapd_hp = 2; /* GPIO1 = headphones */
516 spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */
517 spec->gpio_mask = spec->gpio_dir =
518 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
522 static void cs420x_fixup_gpio_23(struct hda_codec *codec,
523 const struct hda_fixup *fix, int action)
525 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
526 struct cs_spec *spec = codec->spec;
528 spec->gpio_eapd_hp = 4; /* GPIO2 = headphones */
529 spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */
530 spec->gpio_mask = spec->gpio_dir =
531 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
535 static const struct hda_fixup cs420x_fixups[] = {
537 .type = HDA_FIXUP_PINS,
538 .v.pins = mbp53_pincfgs,
540 .chain_id = CS420X_APPLE,
543 .type = HDA_FIXUP_PINS,
544 .v.pins = mbp55_pincfgs,
546 .chain_id = CS420X_GPIO_13,
549 .type = HDA_FIXUP_PINS,
550 .v.pins = imac27_pincfgs,
552 .chain_id = CS420X_GPIO_13,
555 .type = HDA_FIXUP_FUNC,
556 .v.func = cs420x_fixup_gpio_13,
559 .type = HDA_FIXUP_FUNC,
560 .v.func = cs420x_fixup_gpio_23,
563 .type = HDA_FIXUP_PINS,
564 .v.pins = mbp101_pincfgs,
566 .chain_id = CS420X_GPIO_13,
569 .type = HDA_FIXUP_VERBS,
570 .v.verbs = (const struct hda_verb[]) {
571 /* internal mic ADC2: right only, single ended */
572 {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG},
573 {0x11, AC_VERB_SET_PROC_COEF, 0x102a},
577 .chain_id = CS420X_GPIO_13,
580 .type = HDA_FIXUP_PINS,
581 .v.pins = mba42_pincfgs,
583 .chain_id = CS420X_GPIO_13,
587 static struct cs_spec *cs_alloc_spec(struct hda_codec *codec, int vendor_nid)
589 struct cs_spec *spec;
591 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
595 spec->vendor_nid = vendor_nid;
596 codec->power_save_node = 1;
597 snd_hda_gen_spec_init(&spec->gen);
602 static int patch_cs420x(struct hda_codec *codec)
604 struct cs_spec *spec;
607 spec = cs_alloc_spec(codec, CS420X_VENDOR_NID);
611 codec->patch_ops = cs_patch_ops;
612 spec->gen.automute_hook = cs_automute;
613 codec->single_adc_amp = 1;
615 snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl,
617 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
619 err = cs_parse_auto_config(codec);
623 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
634 * Its layout is no longer compatible with CS4206/CS4207
644 static const struct hda_model_fixup cs4208_models[] = {
645 { .id = CS4208_GPIO0, .name = "gpio0" },
646 { .id = CS4208_MBA6, .name = "mba6" },
647 { .id = CS4208_MBP11, .name = "mbp11" },
648 { .id = CS4208_MACMINI, .name = "macmini" },
652 static const struct snd_pci_quirk cs4208_fixup_tbl[] = {
653 SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS4208_MAC_AUTO),
657 /* codec SSID matching */
658 static const struct snd_pci_quirk cs4208_mac_fixup_tbl[] = {
659 SND_PCI_QUIRK(0x106b, 0x5e00, "MacBookPro 11,2", CS4208_MBP11),
660 SND_PCI_QUIRK(0x106b, 0x6c00, "MacMini 7,1", CS4208_MACMINI),
661 SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6),
662 SND_PCI_QUIRK(0x106b, 0x7200, "MacBookAir 6,2", CS4208_MBA6),
663 SND_PCI_QUIRK(0x106b, 0x7b00, "MacBookPro 12,1", CS4208_MBP11),
667 static void cs4208_fixup_gpio0(struct hda_codec *codec,
668 const struct hda_fixup *fix, int action)
670 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
671 struct cs_spec *spec = codec->spec;
673 spec->gpio_eapd_hp = 0;
674 spec->gpio_eapd_speaker = 1;
675 spec->gpio_mask = spec->gpio_dir =
676 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
680 static const struct hda_fixup cs4208_fixups[];
682 /* remap the fixup from codec SSID and apply it */
683 static void cs4208_fixup_mac(struct hda_codec *codec,
684 const struct hda_fixup *fix, int action)
686 if (action != HDA_FIXUP_ACT_PRE_PROBE)
689 codec->fixup_id = HDA_FIXUP_ID_NOT_SET;
690 snd_hda_pick_fixup(codec, NULL, cs4208_mac_fixup_tbl, cs4208_fixups);
691 if (codec->fixup_id == HDA_FIXUP_ID_NOT_SET)
692 codec->fixup_id = CS4208_GPIO0; /* default fixup */
693 snd_hda_apply_fixup(codec, action);
696 /* MacMini 7,1 has the inverted jack detection */
697 static void cs4208_fixup_macmini(struct hda_codec *codec,
698 const struct hda_fixup *fix, int action)
700 static const struct hda_pintbl pincfgs[] = {
701 { 0x18, 0x00ab9150 }, /* mic (audio-in) jack: disable detect */
702 { 0x21, 0x004be140 }, /* SPDIF: disable detect */
706 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
707 /* HP pin (0x10) has an inverted detection */
708 codec->inv_jack_detect = 1;
709 /* disable the bogus Mic and SPDIF jack detections */
710 snd_hda_apply_pincfgs(codec, pincfgs);
714 static int cs4208_spdif_sw_put(struct snd_kcontrol *kcontrol,
715 struct snd_ctl_elem_value *ucontrol)
717 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718 struct cs_spec *spec = codec->spec;
719 hda_nid_t pin = spec->gen.autocfg.dig_out_pins[0];
720 int pinctl = ucontrol->value.integer.value[0] ? PIN_OUT : 0;
722 snd_hda_set_pin_ctl_cache(codec, pin, pinctl);
723 return spec->spdif_sw_put(kcontrol, ucontrol);
726 /* hook the SPDIF switch */
727 static void cs4208_fixup_spdif_switch(struct hda_codec *codec,
728 const struct hda_fixup *fix, int action)
730 if (action == HDA_FIXUP_ACT_BUILD) {
731 struct cs_spec *spec = codec->spec;
732 struct snd_kcontrol *kctl;
734 if (!spec->gen.autocfg.dig_out_pins[0])
736 kctl = snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch");
739 spec->spdif_sw_put = kctl->put;
740 kctl->put = cs4208_spdif_sw_put;
744 static const struct hda_fixup cs4208_fixups[] = {
746 .type = HDA_FIXUP_PINS,
747 .v.pins = mba6_pincfgs,
749 .chain_id = CS4208_GPIO0,
752 .type = HDA_FIXUP_FUNC,
753 .v.func = cs4208_fixup_spdif_switch,
755 .chain_id = CS4208_GPIO0,
758 .type = HDA_FIXUP_FUNC,
759 .v.func = cs4208_fixup_macmini,
761 .chain_id = CS4208_GPIO0,
764 .type = HDA_FIXUP_FUNC,
765 .v.func = cs4208_fixup_gpio0,
767 [CS4208_MAC_AUTO] = {
768 .type = HDA_FIXUP_FUNC,
769 .v.func = cs4208_fixup_mac,
773 /* correct the 0dB offset of input pins */
774 static void cs4208_fix_amp_caps(struct hda_codec *codec, hda_nid_t adc)
778 caps = query_amp_caps(codec, adc, HDA_INPUT);
779 caps &= ~(AC_AMPCAP_OFFSET);
781 snd_hda_override_amp_caps(codec, adc, HDA_INPUT, caps);
784 static int patch_cs4208(struct hda_codec *codec)
786 struct cs_spec *spec;
789 spec = cs_alloc_spec(codec, CS4208_VENDOR_NID);
793 codec->patch_ops = cs_patch_ops;
794 spec->gen.automute_hook = cs_automute;
795 /* exclude NID 0x10 (HP) from output volumes due to different steps */
796 spec->gen.out_vol_mask = 1ULL << 0x10;
798 snd_hda_pick_fixup(codec, cs4208_models, cs4208_fixup_tbl,
800 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
802 snd_hda_override_wcaps(codec, 0x18,
803 get_wcaps(codec, 0x18) | AC_WCAP_STEREO);
804 cs4208_fix_amp_caps(codec, 0x18);
805 cs4208_fix_amp_caps(codec, 0x1b);
806 cs4208_fix_amp_caps(codec, 0x1c);
808 err = cs_parse_auto_config(codec);
812 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
822 * Cirrus Logic CS4210
824 * 1 DAC => HP(sense) / Speakers,
825 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
826 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
829 /* CS4210 board names */
830 static const struct hda_model_fixup cs421x_models[] = {
831 { .id = CS421X_CDB4210, .name = "cdb4210" },
832 { .id = CS421X_STUMPY, .name = "stumpy" },
836 static const struct snd_pci_quirk cs421x_fixup_tbl[] = {
837 /* Test Intel board + CDB2410 */
838 SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210),
842 /* CS4210 board pinconfigs */
843 /* Default CS4210 (CDB4210)*/
844 static const struct hda_pintbl cdb4210_pincfgs[] = {
845 { 0x05, 0x0321401f },
846 { 0x06, 0x90170010 },
847 { 0x07, 0x03813031 },
848 { 0x08, 0xb7a70037 },
849 { 0x09, 0xb7a6003e },
850 { 0x0a, 0x034510f0 },
854 /* Stumpy ChromeBox */
855 static const struct hda_pintbl stumpy_pincfgs[] = {
856 { 0x05, 0x022120f0 },
857 { 0x06, 0x901700f0 },
858 { 0x07, 0x02a120f0 },
859 { 0x08, 0x77a70037 },
860 { 0x09, 0x77a6003e },
861 { 0x0a, 0x434510f0 },
865 /* Setup GPIO/SENSE for each board (if used) */
866 static void cs421x_fixup_sense_b(struct hda_codec *codec,
867 const struct hda_fixup *fix, int action)
869 struct cs_spec *spec = codec->spec;
871 if (action == HDA_FIXUP_ACT_PRE_PROBE)
875 static const struct hda_fixup cs421x_fixups[] = {
877 .type = HDA_FIXUP_PINS,
878 .v.pins = cdb4210_pincfgs,
880 .chain_id = CS421X_SENSE_B,
883 .type = HDA_FIXUP_FUNC,
884 .v.func = cs421x_fixup_sense_b,
887 .type = HDA_FIXUP_PINS,
888 .v.pins = stumpy_pincfgs,
892 static const struct hda_verb cs421x_coef_init_verbs[] = {
893 {0x0B, AC_VERB_SET_PROC_STATE, 1},
894 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DEV_CFG},
896 * Disable Coefficient Index Auto-Increment(DAI)=1,
899 {0x0B, AC_VERB_SET_PROC_COEF, 0x0001 },
901 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_ADC_CFG},
902 /* ADC SZCMode = Digital Soft Ramp */
903 {0x0B, AC_VERB_SET_PROC_COEF, 0x0002 },
905 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DAC_CFG},
906 {0x0B, AC_VERB_SET_PROC_COEF,
907 (0x0002 /* DAC SZCMode = Digital Soft Ramp */
908 | 0x0004 /* Mute DAC on FIFO error */
909 | 0x0008 /* Enable DAC High Pass Filter */
914 /* Errata: CS4210 rev A1 Silicon
916 * http://www.cirrus.com/en/pubs/errata/
919 * 1. Performance degredation is present in the ADC.
920 * 2. Speaker output is not completely muted upon HP detect.
921 * 3. Noise is present when clipping occurs on the amplified
925 * The following verb sequence written to the registers during
926 * initialization will correct the issues listed above.
929 static const struct hda_verb cs421x_coef_init_verbs_A1_silicon_fixes[] = {
930 {0x0B, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
932 {0x0B, AC_VERB_SET_COEF_INDEX, 0x0006},
933 {0x0B, AC_VERB_SET_PROC_COEF, 0x9999}, /* Test mode: on */
935 {0x0B, AC_VERB_SET_COEF_INDEX, 0x000A},
936 {0x0B, AC_VERB_SET_PROC_COEF, 0x14CB}, /* Chop double */
938 {0x0B, AC_VERB_SET_COEF_INDEX, 0x0011},
939 {0x0B, AC_VERB_SET_PROC_COEF, 0xA2D0}, /* Increase ADC current */
941 {0x0B, AC_VERB_SET_COEF_INDEX, 0x001A},
942 {0x0B, AC_VERB_SET_PROC_COEF, 0x02A9}, /* Mute speaker */
944 {0x0B, AC_VERB_SET_COEF_INDEX, 0x001B},
945 {0x0B, AC_VERB_SET_PROC_COEF, 0X1006}, /* Remove noise */
950 /* Speaker Amp Gain is controlled by the vendor widget's coef 4 */
951 static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale, 900, 300, 0);
953 static int cs421x_boost_vol_info(struct snd_kcontrol *kcontrol,
954 struct snd_ctl_elem_info *uinfo)
956 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
958 uinfo->value.integer.min = 0;
959 uinfo->value.integer.max = 3;
963 static int cs421x_boost_vol_get(struct snd_kcontrol *kcontrol,
964 struct snd_ctl_elem_value *ucontrol)
966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
968 ucontrol->value.integer.value[0] =
969 cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL) & 0x0003;
973 static int cs421x_boost_vol_put(struct snd_kcontrol *kcontrol,
974 struct snd_ctl_elem_value *ucontrol)
976 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
978 unsigned int vol = ucontrol->value.integer.value[0];
980 cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL);
981 unsigned int original_coef = coef;
984 coef |= (vol & 0x0003);
985 if (original_coef != coef) {
986 cs_vendor_coef_set(codec, CS421X_IDX_SPK_CTL, coef);
993 static const struct snd_kcontrol_new cs421x_speaker_boost_ctl = {
995 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
996 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
997 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
998 .name = "Speaker Boost Playback Volume",
999 .info = cs421x_boost_vol_info,
1000 .get = cs421x_boost_vol_get,
1001 .put = cs421x_boost_vol_put,
1002 .tlv = { .p = cs421x_speaker_boost_db_scale },
1005 static void cs4210_pinmux_init(struct hda_codec *codec)
1007 struct cs_spec *spec = codec->spec;
1008 unsigned int def_conf, coef;
1010 /* GPIO, DMIC_SCL, DMIC_SDA and SENSE_B are multiplexed */
1011 coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG);
1013 if (spec->gpio_mask)
1014 coef |= 0x0008; /* B1,B2 are GPIOs */
1019 coef |= 0x0010; /* B2 is SENSE_B, not inverted */
1023 cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef);
1025 if ((spec->gpio_mask || spec->sense_b) &&
1026 is_active_pin(codec, CS421X_DMIC_PIN_NID)) {
1029 * GPIO or SENSE_B forced - disconnect the DMIC pin.
1031 def_conf = snd_hda_codec_get_pincfg(codec, CS421X_DMIC_PIN_NID);
1032 def_conf &= ~AC_DEFCFG_PORT_CONN;
1033 def_conf |= (AC_JACK_PORT_NONE << AC_DEFCFG_PORT_CONN_SHIFT);
1034 snd_hda_codec_set_pincfg(codec, CS421X_DMIC_PIN_NID, def_conf);
1038 static void cs4210_spdif_automute(struct hda_codec *codec,
1039 struct hda_jack_callback *tbl)
1041 struct cs_spec *spec = codec->spec;
1042 bool spdif_present = false;
1043 hda_nid_t spdif_pin = spec->gen.autocfg.dig_out_pins[0];
1045 /* detect on spdif is specific to CS4210 */
1046 if (!spec->spdif_detect ||
1047 spec->vendor_nid != CS4210_VENDOR_NID)
1050 spdif_present = snd_hda_jack_detect(codec, spdif_pin);
1051 if (spdif_present == spec->spdif_present)
1054 spec->spdif_present = spdif_present;
1055 /* SPDIF TX on/off */
1056 snd_hda_set_pin_ctl(codec, spdif_pin, spdif_present ? PIN_OUT : 0);
1061 static void parse_cs421x_digital(struct hda_codec *codec)
1063 struct cs_spec *spec = codec->spec;
1064 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
1067 for (i = 0; i < cfg->dig_outs; i++) {
1068 hda_nid_t nid = cfg->dig_out_pins[i];
1070 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
1071 spec->spdif_detect = 1;
1072 snd_hda_jack_detect_enable_callback(codec, nid,
1073 cs4210_spdif_automute);
1078 static int cs421x_init(struct hda_codec *codec)
1080 struct cs_spec *spec = codec->spec;
1082 if (spec->vendor_nid == CS4210_VENDOR_NID) {
1083 snd_hda_sequence_write(codec, cs421x_coef_init_verbs);
1084 snd_hda_sequence_write(codec, cs421x_coef_init_verbs_A1_silicon_fixes);
1085 cs4210_pinmux_init(codec);
1088 snd_hda_gen_init(codec);
1090 if (spec->gpio_mask) {
1091 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
1093 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
1095 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
1099 init_input_coef(codec);
1101 cs4210_spdif_automute(codec, NULL);
1106 static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
1110 /* set the upper-limit for mixer amp to 0dB */
1111 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
1112 caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT);
1113 caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f)
1114 << AC_AMPCAP_NUM_STEPS_SHIFT;
1115 snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps);
1118 static int cs421x_parse_auto_config(struct hda_codec *codec)
1120 struct cs_spec *spec = codec->spec;
1121 hda_nid_t dac = CS4210_DAC_NID;
1124 fix_volume_caps(codec, dac);
1126 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
1130 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
1134 parse_cs421x_digital(codec);
1136 if (spec->gen.autocfg.speaker_outs &&
1137 spec->vendor_nid == CS4210_VENDOR_NID) {
1138 if (!snd_hda_gen_add_kctl(&spec->gen, NULL,
1139 &cs421x_speaker_boost_ctl))
1148 * Manage PDREF, when transitioning to D3hot
1149 * (DAC,ADC) -> D3, PDREF=1, AFG->D3
1151 static int cs421x_suspend(struct hda_codec *codec)
1153 struct cs_spec *spec = codec->spec;
1156 snd_hda_shutup_pins(codec);
1158 snd_hda_codec_write(codec, CS4210_DAC_NID, 0,
1159 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1160 snd_hda_codec_write(codec, CS4210_ADC_NID, 0,
1161 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1163 if (spec->vendor_nid == CS4210_VENDOR_NID) {
1164 coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG);
1165 coef |= 0x0004; /* PDREF */
1166 cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef);
1173 static const struct hda_codec_ops cs421x_patch_ops = {
1174 .build_controls = snd_hda_gen_build_controls,
1175 .build_pcms = snd_hda_gen_build_pcms,
1176 .init = cs421x_init,
1178 .unsol_event = snd_hda_jack_unsol_event,
1180 .suspend = cs421x_suspend,
1184 static int patch_cs4210(struct hda_codec *codec)
1186 struct cs_spec *spec;
1189 spec = cs_alloc_spec(codec, CS4210_VENDOR_NID);
1193 codec->patch_ops = cs421x_patch_ops;
1194 spec->gen.automute_hook = cs_automute;
1196 snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl,
1198 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1201 * Update the GPIO/DMIC/SENSE_B pinmux before the configuration
1202 * is auto-parsed. If GPIO or SENSE_B is forced, DMIC input
1205 cs4210_pinmux_init(codec);
1207 err = cs421x_parse_auto_config(codec);
1211 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1220 static int patch_cs4213(struct hda_codec *codec)
1222 struct cs_spec *spec;
1225 spec = cs_alloc_spec(codec, CS4213_VENDOR_NID);
1229 codec->patch_ops = cs421x_patch_ops;
1231 err = cs421x_parse_auto_config(codec);
1242 /* Cirrus Logic CS8409 HDA bridge with
1243 * companion codec CS42L42
1245 #define CS8409_VENDOR_NID 0x47
1247 #define CS8409_CS42L42_HP_PIN_NID 0x24
1248 #define CS8409_CS42L42_SPK_PIN_NID 0x2c
1249 #define CS8409_CS42L42_AMIC_PIN_NID 0x34
1250 #define CS8409_CS42L42_DMIC_PIN_NID 0x44
1251 #define CS8409_CS42L42_DMIC_ADC_PIN_NID 0x22
1253 #define CS42L42_HSDET_AUTO_DONE 0x02
1254 #define CS42L42_HSTYPE_MASK 0x03
1256 #define CS42L42_JACK_INSERTED 0x0C
1257 #define CS42L42_JACK_REMOVED 0x00
1259 #define GPIO3_INT (1 << 3)
1260 #define GPIO4_INT (1 << 4)
1261 #define GPIO5_INT (1 << 5)
1263 #define CS42L42_I2C_ADDR (0x48 << 1)
1265 #define CIR_I2C_ADDR 0x0059
1266 #define CIR_I2C_DATA 0x005A
1267 #define CIR_I2C_CTRL 0x005B
1268 #define CIR_I2C_STATUS 0x005C
1269 #define CIR_I2C_QWRITE 0x005D
1270 #define CIR_I2C_QREAD 0x005E
1272 #define CS8409_CS42L42_HP_VOL_REAL_MIN (-63)
1273 #define CS8409_CS42L42_HP_VOL_REAL_MAX (0)
1274 #define CS8409_CS42L42_AMIC_VOL_REAL_MIN (-97)
1275 #define CS8409_CS42L42_AMIC_VOL_REAL_MAX (12)
1276 #define CS8409_CS42L42_REG_HS_VOLUME_CHA (0x2301)
1277 #define CS8409_CS42L42_REG_HS_VOLUME_CHB (0x2303)
1278 #define CS8409_CS42L42_REG_AMIC_VOLUME (0x1D03)
1280 struct cs8409_i2c_param {
1285 struct cs8409_cir_param {
1298 static void cs8409_cs42l42_fixups(struct hda_codec *codec,
1299 const struct hda_fixup *fix, int action);
1300 static int cs8409_cs42l42_exec_verb(struct hdac_device *dev,
1301 unsigned int cmd, unsigned int flags, unsigned int *res);
1303 /* Dell Inspiron models with cs8409/cs42l42 */
1304 static const struct hda_model_fixup cs8409_models[] = {
1305 { .id = CS8409_BULLSEYE, .name = "bullseye" },
1306 { .id = CS8409_WARLOCK, .name = "warlock" },
1307 { .id = CS8409_CYBORG, .name = "cyborg" },
1311 /* Dell Inspiron platforms
1312 * with cs8409 bridge and cs42l42 codec
1314 static const struct snd_pci_quirk cs8409_fixup_tbl[] = {
1315 SND_PCI_QUIRK(0x1028, 0x0A11, "Bullseye", CS8409_BULLSEYE),
1316 SND_PCI_QUIRK(0x1028, 0x0A12, "Bullseye", CS8409_BULLSEYE),
1317 SND_PCI_QUIRK(0x1028, 0x0A23, "Bullseye", CS8409_BULLSEYE),
1318 SND_PCI_QUIRK(0x1028, 0x0A24, "Bullseye", CS8409_BULLSEYE),
1319 SND_PCI_QUIRK(0x1028, 0x0A25, "Bullseye", CS8409_BULLSEYE),
1320 SND_PCI_QUIRK(0x1028, 0x0A29, "Bullseye", CS8409_BULLSEYE),
1321 SND_PCI_QUIRK(0x1028, 0x0A2A, "Bullseye", CS8409_BULLSEYE),
1322 SND_PCI_QUIRK(0x1028, 0x0A2B, "Bullseye", CS8409_BULLSEYE),
1323 SND_PCI_QUIRK(0x1028, 0x0AB0, "Warlock", CS8409_WARLOCK),
1324 SND_PCI_QUIRK(0x1028, 0x0AB2, "Warlock", CS8409_WARLOCK),
1325 SND_PCI_QUIRK(0x1028, 0x0AB1, "Warlock", CS8409_WARLOCK),
1326 SND_PCI_QUIRK(0x1028, 0x0AB3, "Warlock", CS8409_WARLOCK),
1327 SND_PCI_QUIRK(0x1028, 0x0AB4, "Warlock", CS8409_WARLOCK),
1328 SND_PCI_QUIRK(0x1028, 0x0AB5, "Warlock", CS8409_WARLOCK),
1329 SND_PCI_QUIRK(0x1028, 0x0AD9, "Warlock", CS8409_WARLOCK),
1330 SND_PCI_QUIRK(0x1028, 0x0ADA, "Warlock", CS8409_WARLOCK),
1331 SND_PCI_QUIRK(0x1028, 0x0ADB, "Warlock", CS8409_WARLOCK),
1332 SND_PCI_QUIRK(0x1028, 0x0ADC, "Warlock", CS8409_WARLOCK),
1333 SND_PCI_QUIRK(0x1028, 0x0AF4, "Warlock", CS8409_WARLOCK),
1334 SND_PCI_QUIRK(0x1028, 0x0AF5, "Warlock", CS8409_WARLOCK),
1335 SND_PCI_QUIRK(0x1028, 0x0A77, "Cyborg", CS8409_CYBORG),
1336 SND_PCI_QUIRK(0x1028, 0x0A78, "Cyborg", CS8409_CYBORG),
1337 SND_PCI_QUIRK(0x1028, 0x0A79, "Cyborg", CS8409_CYBORG),
1338 SND_PCI_QUIRK(0x1028, 0x0A7A, "Cyborg", CS8409_CYBORG),
1339 SND_PCI_QUIRK(0x1028, 0x0A7D, "Cyborg", CS8409_CYBORG),
1340 SND_PCI_QUIRK(0x1028, 0x0A7E, "Cyborg", CS8409_CYBORG),
1341 SND_PCI_QUIRK(0x1028, 0x0A7F, "Cyborg", CS8409_CYBORG),
1342 SND_PCI_QUIRK(0x1028, 0x0A80, "Cyborg", CS8409_CYBORG),
1343 SND_PCI_QUIRK(0x1028, 0x0ADF, "Cyborg", CS8409_CYBORG),
1344 SND_PCI_QUIRK(0x1028, 0x0AE0, "Cyborg", CS8409_CYBORG),
1345 SND_PCI_QUIRK(0x1028, 0x0AE1, "Cyborg", CS8409_CYBORG),
1346 SND_PCI_QUIRK(0x1028, 0x0AE2, "Cyborg", CS8409_CYBORG),
1347 SND_PCI_QUIRK(0x1028, 0x0AE9, "Cyborg", CS8409_CYBORG),
1348 SND_PCI_QUIRK(0x1028, 0x0AEA, "Cyborg", CS8409_CYBORG),
1349 SND_PCI_QUIRK(0x1028, 0x0AEB, "Cyborg", CS8409_CYBORG),
1350 SND_PCI_QUIRK(0x1028, 0x0AEC, "Cyborg", CS8409_CYBORG),
1351 SND_PCI_QUIRK(0x1028, 0x0AED, "Cyborg", CS8409_CYBORG),
1352 SND_PCI_QUIRK(0x1028, 0x0AEE, "Cyborg", CS8409_CYBORG),
1353 SND_PCI_QUIRK(0x1028, 0x0AEF, "Cyborg", CS8409_CYBORG),
1354 SND_PCI_QUIRK(0x1028, 0x0AF0, "Cyborg", CS8409_CYBORG),
1358 static const struct hda_verb cs8409_cs42l42_init_verbs[] = {
1359 { 0x01, AC_VERB_SET_GPIO_WAKE_MASK, 0x0018 }, /* WAKE from GPIO 3,4 */
1360 { 0x47, AC_VERB_SET_PROC_STATE, 0x0001 }, /* Enable VPW processing */
1361 { 0x47, AC_VERB_SET_COEF_INDEX, 0x0002 }, /* Configure GPIO 6,7 */
1362 { 0x47, AC_VERB_SET_PROC_COEF, 0x0080 }, /* I2C mode */
1363 { 0x47, AC_VERB_SET_COEF_INDEX, 0x005b }, /* Set I2C bus speed */
1364 { 0x47, AC_VERB_SET_PROC_COEF, 0x0200 }, /* 100kHz I2C_STO = 2 */
1368 static const struct hda_pintbl cs8409_cs42l42_pincfgs[] = {
1369 { 0x24, 0x042120f0 }, /* ASP-1-TX */
1370 { 0x34, 0x04a12050 }, /* ASP-1-RX */
1371 { 0x2c, 0x901000f0 }, /* ASP-2-TX */
1372 { 0x44, 0x90a00090 }, /* DMIC-1 */
1376 static const struct hda_fixup cs8409_fixups[] = {
1377 [CS8409_BULLSEYE] = {
1378 .type = HDA_FIXUP_PINS,
1379 .v.pins = cs8409_cs42l42_pincfgs,
1381 .chain_id = CS8409_FIXUPS,
1383 [CS8409_WARLOCK] = {
1384 .type = HDA_FIXUP_PINS,
1385 .v.pins = cs8409_cs42l42_pincfgs,
1387 .chain_id = CS8409_FIXUPS,
1390 .type = HDA_FIXUP_PINS,
1391 .v.pins = cs8409_cs42l42_pincfgs,
1393 .chain_id = CS8409_FIXUPS,
1396 .type = HDA_FIXUP_FUNC,
1397 .v.func = cs8409_cs42l42_fixups,
1401 /* Vendor specific HW configuration for CS42L42 */
1402 static const struct cs8409_i2c_param cs42l42_init_reg_seq[] = {
1455 /* Vendor specific hw configuration for CS8409 */
1456 static const struct cs8409_cir_param cs8409_cs42l42_hw_cfg[] = {
1457 { 0x47, 0x00, 0xb008 }, /* +PLL1/2_EN, +I2C_EN */
1458 { 0x47, 0x01, 0x0002 }, /* ASP1/2_EN=0, ASP1_STP=1 */
1459 { 0x47, 0x02, 0x0a80 }, /* ASP1/2_BUS_IDLE=10, +GPIO_I2C */
1460 { 0x47, 0x19, 0x0800 }, /* ASP1.A: TX.LAP=0, TX.LSZ=24 bits, TX.LCS=0 */
1461 { 0x47, 0x1a, 0x0820 }, /* ASP1.A: TX.RAP=0, TX.RSZ=24 bits, TX.RCS=32 */
1462 { 0x47, 0x29, 0x0800 }, /* ASP2.A: TX.LAP=0, TX.LSZ=24 bits, TX.LCS=0 */
1463 { 0x47, 0x2a, 0x2800 }, /* ASP2.A: TX.RAP=1, TX.RSZ=24 bits, TX.RCS=0 */
1464 { 0x47, 0x39, 0x0800 }, /* ASP1.A: RX.LAP=0, RX.LSZ=24 bits, RX.LCS=0 */
1465 { 0x47, 0x3a, 0x0800 }, /* ASP1.A: RX.RAP=0, RX.RSZ=24 bits, RX.RCS=0 */
1466 { 0x47, 0x03, 0x8000 }, /* ASP1: LCHI = 00h */
1467 { 0x47, 0x04, 0x28ff }, /* ASP1: MC/SC_SRCSEL=PLL1, LCPR=FFh */
1468 { 0x47, 0x05, 0x0062 }, /* ASP1: MCEN=0, FSD=011, SCPOL_IN/OUT=0, SCDIV=1:4 */
1469 { 0x47, 0x06, 0x801f }, /* ASP2: LCHI=1Fh */
1470 { 0x47, 0x07, 0x283f }, /* ASP2: MC/SC_SRCSEL=PLL1, LCPR=3Fh */
1471 { 0x47, 0x08, 0x805c }, /* ASP2: 5050=1, MCEN=0, FSD=010, SCPOL_IN/OUT=1, SCDIV=1:16 */
1472 { 0x47, 0x09, 0x0023 }, /* DMIC1_MO=10b, DMIC1/2_SR=1 */
1473 { 0x47, 0x0a, 0x0000 }, /* ASP1/2_BEEP=0 */
1474 { 0x47, 0x01, 0x0062 }, /* ASP1/2_EN=1, ASP1_STP=1 */
1475 { 0x47, 0x00, 0x9008 }, /* -PLL2_EN */
1476 { 0x47, 0x68, 0x0000 }, /* TX2.A: pre-scale att.=0 dB */
1477 { 0x47, 0x82, 0xfc03 }, /* ASP1/2_xxx_EN=1, ASP1/2_MCLK_EN=0, DMIC1_SCL_EN=1 */
1478 { 0x47, 0xc0, 0x9999 }, /* test mode on */
1479 { 0x47, 0xc5, 0x0000 }, /* GPIO hysteresis = 30 us */
1480 { 0x47, 0xc0, 0x0000 }, /* test mode off */
1484 static const struct cs8409_cir_param cs8409_cs42l42_bullseye_atn[] = {
1485 { 0x47, 0x65, 0x4000 }, /* EQ_SEL=1, EQ1/2_EN=0 */
1486 { 0x47, 0x64, 0x4000 }, /* +EQ_ACC */
1487 { 0x47, 0x65, 0x4010 }, /* +EQ2_EN */
1488 { 0x47, 0x63, 0x0647 }, /* EQ_DATA_HI=0x0647 */
1489 { 0x47, 0x64, 0xc0c7 }, /* +EQ_WRT, +EQ_ACC, EQ_ADR=0, EQ_DATA_LO=0x67 */
1490 { 0x47, 0x63, 0x0647 }, /* EQ_DATA_HI=0x0647 */
1491 { 0x47, 0x64, 0xc1c7 }, /* +EQ_WRT, +EQ_ACC, EQ_ADR=1, EQ_DATA_LO=0x67 */
1492 { 0x47, 0x63, 0xf370 }, /* EQ_DATA_HI=0xf370 */
1493 { 0x47, 0x64, 0xc271 }, /* +EQ_WRT, +EQ_ACC, EQ_ADR=2, EQ_DATA_LO=0x71 */
1494 { 0x47, 0x63, 0x1ef8 }, /* EQ_DATA_HI=0x1ef8 */
1495 { 0x47, 0x64, 0xc348 }, /* +EQ_WRT, +EQ_ACC, EQ_ADR=3, EQ_DATA_LO=0x48 */
1496 { 0x47, 0x63, 0xc110 }, /* EQ_DATA_HI=0xc110 */
1497 { 0x47, 0x64, 0xc45a }, /* +EQ_WRT, +EQ_ACC, EQ_ADR=4, EQ_DATA_LO=0x5a */
1498 { 0x47, 0x63, 0x1f29 }, /* EQ_DATA_HI=0x1f29 */
1499 { 0x47, 0x64, 0xc574 }, /* +EQ_WRT, +EQ_ACC, EQ_ADR=5, EQ_DATA_LO=0x74 */
1500 { 0x47, 0x63, 0x1d7a }, /* EQ_DATA_HI=0x1d7a */
1501 { 0x47, 0x64, 0xc653 }, /* +EQ_WRT, +EQ_ACC, EQ_ADR=6, EQ_DATA_LO=0x53 */
1502 { 0x47, 0x63, 0xc38c }, /* EQ_DATA_HI=0xc38c */
1503 { 0x47, 0x64, 0xc714 }, /* +EQ_WRT, +EQ_ACC, EQ_ADR=7, EQ_DATA_LO=0x14 */
1504 { 0x47, 0x63, 0x1ca3 }, /* EQ_DATA_HI=0x1ca3 */
1505 { 0x47, 0x64, 0xc8c7 }, /* +EQ_WRT, +EQ_ACC, EQ_ADR=8, EQ_DATA_LO=0xc7 */
1506 { 0x47, 0x63, 0xc38c }, /* EQ_DATA_HI=0xc38c */
1507 { 0x47, 0x64, 0xc914 }, /* +EQ_WRT, +EQ_ACC, EQ_ADR=9, EQ_DATA_LO=0x14 */
1508 { 0x47, 0x64, 0x0000 }, /* -EQ_ACC, -EQ_WRT */
1513 * cs8409_enable_i2c_clock - Enable I2C clocks
1514 * @codec: the codec instance
1515 * @enable: Enable or disable I2C clocks
1517 * Enable or Disable I2C clocks.
1519 static void cs8409_enable_i2c_clock(struct hda_codec *codec, unsigned int enable)
1521 unsigned int retval;
1522 unsigned int newval;
1524 retval = cs_vendor_coef_get(codec, 0x0);
1525 newval = (enable) ? (retval | 0x8) : (retval & 0xfffffff7);
1526 cs_vendor_coef_set(codec, 0x0, newval);
1530 * cs8409_i2c_wait_complete - Wait for I2C transaction
1531 * @codec: the codec instance
1533 * Wait for I2C transaction to complete.
1534 * Return -1 if transaction wait times out.
1536 static int cs8409_i2c_wait_complete(struct hda_codec *codec)
1539 unsigned int retval;
1542 retval = cs_vendor_coef_get(codec, CIR_I2C_STATUS);
1543 if ((retval & 0x18) != 0x18) {
1544 usleep_range(2000, 4000);
1555 * cs8409_i2c_read - CS8409 I2C Read.
1556 * @codec: the codec instance
1557 * @i2c_address: I2C Address
1558 * @i2c_reg: Register to read
1559 * @paged: Is a paged transaction
1562 * Returns negative on error, otherwise returns read value in bits 0-7.
1564 static int cs8409_i2c_read(struct hda_codec *codec,
1565 unsigned int i2c_address,
1566 unsigned int i2c_reg,
1569 unsigned int i2c_reg_data;
1570 unsigned int read_data;
1572 cs8409_enable_i2c_clock(codec, 1);
1573 cs_vendor_coef_set(codec, CIR_I2C_ADDR, i2c_address);
1576 cs_vendor_coef_set(codec, CIR_I2C_QWRITE, i2c_reg >> 8);
1577 if (cs8409_i2c_wait_complete(codec) < 0) {
1579 "%s() Paged Transaction Failed 0x%02x : 0x%04x\n",
1580 __func__, i2c_address, i2c_reg);
1585 i2c_reg_data = (i2c_reg << 8) & 0x0ffff;
1586 cs_vendor_coef_set(codec, CIR_I2C_QREAD, i2c_reg_data);
1587 if (cs8409_i2c_wait_complete(codec) < 0) {
1588 codec_err(codec, "%s() Transaction Failed 0x%02x : 0x%04x\n",
1589 __func__, i2c_address, i2c_reg);
1593 /* Register in bits 15-8 and the data in 7-0 */
1594 read_data = cs_vendor_coef_get(codec, CIR_I2C_QREAD);
1596 cs8409_enable_i2c_clock(codec, 0);
1598 return read_data & 0x0ff;
1602 * cs8409_i2c_write - CS8409 I2C Write.
1603 * @codec: the codec instance
1604 * @i2c_address: I2C Address
1605 * @i2c_reg: Register to write to
1606 * @i2c_data: Data to write
1607 * @paged: Is a paged transaction
1610 * Returns negative on error, otherwise returns 0.
1612 static int cs8409_i2c_write(struct hda_codec *codec,
1613 unsigned int i2c_address, unsigned int i2c_reg,
1614 unsigned int i2c_data,
1617 unsigned int i2c_reg_data;
1619 cs8409_enable_i2c_clock(codec, 1);
1620 cs_vendor_coef_set(codec, CIR_I2C_ADDR, i2c_address);
1623 cs_vendor_coef_set(codec, CIR_I2C_QWRITE, i2c_reg >> 8);
1624 if (cs8409_i2c_wait_complete(codec) < 0) {
1626 "%s() Paged Transaction Failed 0x%02x : 0x%04x\n",
1627 __func__, i2c_address, i2c_reg);
1632 i2c_reg_data = ((i2c_reg << 8) & 0x0ff00) | (i2c_data & 0x0ff);
1633 cs_vendor_coef_set(codec, CIR_I2C_QWRITE, i2c_reg_data);
1635 if (cs8409_i2c_wait_complete(codec) < 0) {
1636 codec_err(codec, "%s() Transaction Failed 0x%02x : 0x%04x\n",
1637 __func__, i2c_address, i2c_reg);
1641 cs8409_enable_i2c_clock(codec, 0);
1646 static int cs8409_cs42l42_volume_info(struct snd_kcontrol *kcontrol,
1647 struct snd_ctl_elem_info *uinfo)
1649 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1650 u16 nid = get_amp_nid(kcontrol);
1651 u8 chs = get_amp_channels(kcontrol);
1653 codec_dbg(codec, "%s() nid: %d\n", __func__, nid);
1655 case CS8409_CS42L42_HP_PIN_NID:
1656 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1657 uinfo->count = chs == 3 ? 2 : 1;
1658 uinfo->value.integer.min = CS8409_CS42L42_HP_VOL_REAL_MIN;
1659 uinfo->value.integer.max = CS8409_CS42L42_HP_VOL_REAL_MAX;
1661 case CS8409_CS42L42_AMIC_PIN_NID:
1662 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1663 uinfo->count = chs == 3 ? 2 : 1;
1664 uinfo->value.integer.min = CS8409_CS42L42_AMIC_VOL_REAL_MIN;
1665 uinfo->value.integer.max = CS8409_CS42L42_AMIC_VOL_REAL_MAX;
1673 static void cs8409_cs42l42_update_volume(struct hda_codec *codec)
1675 struct cs_spec *spec = codec->spec;
1678 mutex_lock(&spec->cs8409_i2c_mux);
1679 data = cs8409_i2c_read(codec, CS42L42_I2C_ADDR,
1680 CS8409_CS42L42_REG_HS_VOLUME_CHA, 1);
1682 spec->cs42l42_hp_volume[0] = -data;
1684 spec->cs42l42_hp_volume[0] = CS8409_CS42L42_HP_VOL_REAL_MIN;
1685 data = cs8409_i2c_read(codec, CS42L42_I2C_ADDR,
1686 CS8409_CS42L42_REG_HS_VOLUME_CHB, 1);
1688 spec->cs42l42_hp_volume[1] = -data;
1690 spec->cs42l42_hp_volume[1] = CS8409_CS42L42_HP_VOL_REAL_MIN;
1691 data = cs8409_i2c_read(codec, CS42L42_I2C_ADDR,
1692 CS8409_CS42L42_REG_AMIC_VOLUME, 1);
1694 spec->cs42l42_hs_mic_volume[0] = -data;
1696 spec->cs42l42_hs_mic_volume[0] = CS8409_CS42L42_AMIC_VOL_REAL_MIN;
1697 mutex_unlock(&spec->cs8409_i2c_mux);
1698 spec->cs42l42_volume_init = 1;
1701 static int cs8409_cs42l42_volume_get(struct snd_kcontrol *kcontrol,
1702 struct snd_ctl_elem_value *ucontrol)
1704 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1705 struct cs_spec *spec = codec->spec;
1706 hda_nid_t nid = get_amp_nid(kcontrol);
1707 int chs = get_amp_channels(kcontrol);
1708 long *valp = ucontrol->value.integer.value;
1710 if (!spec->cs42l42_volume_init) {
1711 snd_hda_power_up(codec);
1712 cs8409_cs42l42_update_volume(codec);
1713 snd_hda_power_down(codec);
1716 case CS8409_CS42L42_HP_PIN_NID:
1718 *valp++ = spec->cs42l42_hp_volume[0];
1720 *valp++ = spec->cs42l42_hp_volume[1];
1722 case CS8409_CS42L42_AMIC_PIN_NID:
1724 *valp++ = spec->cs42l42_hs_mic_volume[0];
1732 static int cs8409_cs42l42_volume_put(struct snd_kcontrol *kcontrol,
1733 struct snd_ctl_elem_value *ucontrol)
1735 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1736 struct cs_spec *spec = codec->spec;
1737 hda_nid_t nid = get_amp_nid(kcontrol);
1738 int chs = get_amp_channels(kcontrol);
1739 long *valp = ucontrol->value.integer.value;
1743 snd_hda_power_up(codec);
1745 case CS8409_CS42L42_HP_PIN_NID:
1746 mutex_lock(&spec->cs8409_i2c_mux);
1749 change = cs8409_i2c_write(codec, CS42L42_I2C_ADDR,
1750 CS8409_CS42L42_REG_HS_VOLUME_CHA, vol, 1);
1755 change |= cs8409_i2c_write(codec, CS42L42_I2C_ADDR,
1756 CS8409_CS42L42_REG_HS_VOLUME_CHB, vol, 1);
1758 mutex_unlock(&spec->cs8409_i2c_mux);
1760 case CS8409_CS42L42_AMIC_PIN_NID:
1761 mutex_lock(&spec->cs8409_i2c_mux);
1763 change = cs8409_i2c_write(
1764 codec, CS42L42_I2C_ADDR,
1765 CS8409_CS42L42_REG_AMIC_VOLUME, (char)*valp, 1);
1768 mutex_unlock(&spec->cs8409_i2c_mux);
1773 cs8409_cs42l42_update_volume(codec);
1774 snd_hda_power_down(codec);
1778 static const DECLARE_TLV_DB_SCALE(
1779 cs8409_cs42l42_hp_db_scale,
1780 CS8409_CS42L42_HP_VOL_REAL_MIN * 100, 100, 1);
1782 static const DECLARE_TLV_DB_SCALE(
1783 cs8409_cs42l42_amic_db_scale,
1784 CS8409_CS42L42_AMIC_VOL_REAL_MIN * 100, 100, 1);
1786 static const struct snd_kcontrol_new cs8409_cs42l42_hp_volume_mixer = {
1787 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1789 .name = "Headphone Playback Volume",
1790 .subdevice = (HDA_SUBDEV_AMP_FLAG | HDA_SUBDEV_NID_FLAG),
1791 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE
1792 | SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1793 .info = cs8409_cs42l42_volume_info,
1794 .get = cs8409_cs42l42_volume_get,
1795 .put = cs8409_cs42l42_volume_put,
1796 .tlv = { .p = cs8409_cs42l42_hp_db_scale },
1797 .private_value = HDA_COMPOSE_AMP_VAL(
1798 CS8409_CS42L42_HP_PIN_NID, 3, 0, HDA_OUTPUT)
1799 | HDA_AMP_VAL_MIN_MUTE
1802 static const struct snd_kcontrol_new cs8409_cs42l42_amic_volume_mixer = {
1803 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1805 .name = "Mic Capture Volume",
1806 .subdevice = (HDA_SUBDEV_AMP_FLAG | HDA_SUBDEV_NID_FLAG),
1807 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE
1808 | SNDRV_CTL_ELEM_ACCESS_TLV_READ),
1809 .info = cs8409_cs42l42_volume_info,
1810 .get = cs8409_cs42l42_volume_get,
1811 .put = cs8409_cs42l42_volume_put,
1812 .tlv = { .p = cs8409_cs42l42_amic_db_scale },
1813 .private_value = HDA_COMPOSE_AMP_VAL(
1814 CS8409_CS42L42_AMIC_PIN_NID, 1, 0, HDA_INPUT)
1815 | HDA_AMP_VAL_MIN_MUTE
1818 /* Assert/release RTS# line to CS42L42 */
1819 static void cs8409_cs42l42_reset(struct hda_codec *codec)
1821 struct cs_spec *spec = codec->spec;
1823 /* Assert RTS# line */
1824 snd_hda_codec_write(codec,
1825 codec->core.afg, 0, AC_VERB_SET_GPIO_DATA, 0);
1827 usleep_range(10000, 15000);
1828 /* Release RTS# line */
1829 snd_hda_codec_write(codec,
1830 codec->core.afg, 0, AC_VERB_SET_GPIO_DATA, GPIO5_INT);
1832 usleep_range(10000, 15000);
1834 mutex_lock(&spec->cs8409_i2c_mux);
1836 /* Clear interrupts, by reading interrupt status registers */
1837 cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x1308, 1);
1838 cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x1309, 1);
1839 cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x130A, 1);
1840 cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x130F, 1);
1842 mutex_unlock(&spec->cs8409_i2c_mux);
1846 /* Configure CS42L42 slave codec for jack autodetect */
1847 static void cs8409_cs42l42_enable_jack_detect(struct hda_codec *codec)
1849 struct cs_spec *spec = codec->spec;
1851 mutex_lock(&spec->cs8409_i2c_mux);
1853 /* Set TIP_SENSE_EN for analog front-end of tip sense. */
1854 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1b70, 0x0020, 1);
1856 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1b71, 0x0001, 1);
1858 usleep_range(2500, 3000);
1859 /* Set mode WAKE# output follows the combination logic directly */
1860 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1b71, 0x0020, 1);
1861 /* Clear interrupts status */
1862 cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x130f, 1);
1863 cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x1b7b, 1);
1864 /* Enable interrupt */
1865 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1320, 0x03, 1);
1866 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1b79, 0x00, 1);
1868 mutex_unlock(&spec->cs8409_i2c_mux);
1871 /* Enable and run CS42L42 slave codec jack auto detect */
1872 static void cs8409_cs42l42_run_jack_detect(struct hda_codec *codec)
1874 struct cs_spec *spec = codec->spec;
1876 mutex_lock(&spec->cs8409_i2c_mux);
1878 /* Clear interrupts */
1879 cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x1308, 1);
1880 cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x1b77, 1);
1882 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1102, 0x87, 1);
1883 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1f06, 0x86, 1);
1884 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1b74, 0x07, 1);
1885 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x131b, 0x01, 1);
1886 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1120, 0x80, 1);
1888 usleep_range(110000, 200000);
1889 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x111f, 0x77, 1);
1890 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1120, 0xc0, 1);
1892 usleep_range(10000, 25000);
1894 mutex_unlock(&spec->cs8409_i2c_mux);
1898 static void cs8409_cs42l42_reg_setup(struct hda_codec *codec)
1900 const struct cs8409_i2c_param *seq = cs42l42_init_reg_seq;
1901 struct cs_spec *spec = codec->spec;
1903 mutex_lock(&spec->cs8409_i2c_mux);
1905 for (; seq->addr; seq++)
1906 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, seq->addr, seq->reg, 1);
1908 mutex_unlock(&spec->cs8409_i2c_mux);
1913 * In the case of CS8409 we do not have unsolicited events from NID's 0x24
1914 * and 0x34 where hs mic and hp are connected. Companion codec CS42L42 will
1915 * generate interrupt via gpio 4 to notify jack events. We have to overwrite
1916 * generic snd_hda_jack_unsol_event(), read CS42L42 jack detect status registers
1917 * and then notify status via generic snd_hda_jack_unsol_event() call.
1919 static void cs8409_jack_unsol_event(struct hda_codec *codec, unsigned int res)
1921 struct cs_spec *spec = codec->spec;
1922 int status_changed = 0;
1927 struct hda_jack_tbl *jk;
1929 /* jack_unsol_event() will be called every time gpio line changing state.
1930 * In this case gpio4 line goes up as a result of reading interrupt status
1931 * registers in previous cs8409_jack_unsol_event() call.
1932 * We don't need to handle this event, ignoring...
1934 if ((res & (1 << 4)))
1937 mutex_lock(&spec->cs8409_i2c_mux);
1939 /* Read jack detect status registers */
1940 reg_cdc_status = cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x1308, 1);
1941 reg_hs_status = cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x1124, 1);
1942 reg_ts_status = cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x130f, 1);
1944 /* Clear interrupts, by reading interrupt status registers */
1945 cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x1b7b, 1);
1947 mutex_unlock(&spec->cs8409_i2c_mux);
1949 /* If status values are < 0, read error has occurred. */
1950 if (reg_cdc_status < 0 || reg_hs_status < 0 || reg_ts_status < 0)
1953 /* HSDET_AUTO_DONE */
1954 if (reg_cdc_status & CS42L42_HSDET_AUTO_DONE) {
1956 type = ((reg_hs_status & CS42L42_HSTYPE_MASK) + 1);
1957 /* CS42L42 reports optical jack as type 4
1958 * We don't handle optical jack
1961 if (!spec->cs42l42_hp_jack_in) {
1963 spec->cs42l42_hp_jack_in = 1;
1965 /* type = 3 has no mic */
1966 if ((!spec->cs42l42_mic_jack_in) && (type != 3)) {
1968 spec->cs42l42_mic_jack_in = 1;
1971 if (spec->cs42l42_hp_jack_in || spec->cs42l42_mic_jack_in) {
1973 spec->cs42l42_hp_jack_in = 0;
1974 spec->cs42l42_mic_jack_in = 0;
1979 /* TIP_SENSE INSERT/REMOVE */
1980 switch (reg_ts_status) {
1981 case CS42L42_JACK_INSERTED:
1982 cs8409_cs42l42_run_jack_detect(codec);
1985 case CS42L42_JACK_REMOVED:
1986 if (spec->cs42l42_hp_jack_in || spec->cs42l42_mic_jack_in) {
1988 spec->cs42l42_hp_jack_in = 0;
1989 spec->cs42l42_mic_jack_in = 0;
1994 /* jack in transition */
2000 if (status_changed) {
2002 snd_hda_set_pin_ctl(codec, CS8409_CS42L42_SPK_PIN_NID,
2003 spec->cs42l42_hp_jack_in ? 0 : PIN_OUT);
2006 jk = snd_hda_jack_tbl_get_mst(codec, CS8409_CS42L42_HP_PIN_NID, 0);
2008 snd_hda_jack_unsol_event(codec,
2009 (jk->tag << AC_UNSOL_RES_TAG_SHIFT) & AC_UNSOL_RES_TAG);
2012 jk = snd_hda_jack_tbl_get_mst(codec, CS8409_CS42L42_AMIC_PIN_NID, 0);
2014 snd_hda_jack_unsol_event(codec,
2015 (jk->tag << AC_UNSOL_RES_TAG_SHIFT) & AC_UNSOL_RES_TAG);
2021 /* Manage PDREF, when transition to D3hot */
2022 static int cs8409_suspend(struct hda_codec *codec)
2024 struct cs_spec *spec = codec->spec;
2026 mutex_lock(&spec->cs8409_i2c_mux);
2027 /* Power down CS42L42 ASP/EQ/MIX/HP */
2028 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1101, 0xfe, 1);
2029 mutex_unlock(&spec->cs8409_i2c_mux);
2030 /* Assert CS42L42 RTS# line */
2031 snd_hda_codec_write(codec,
2032 codec->core.afg, 0, AC_VERB_SET_GPIO_DATA, 0);
2034 snd_hda_shutup_pins(codec);
2040 /* Enable/Disable Unsolicited Response for gpio(s) 3,4 */
2041 static void cs8409_enable_ur(struct hda_codec *codec, int flag)
2043 /* GPIO4 INT# and GPIO3 WAKE# */
2044 snd_hda_codec_write(codec, codec->core.afg,
2045 0, AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK,
2046 flag ? (GPIO3_INT | GPIO4_INT) : 0);
2048 snd_hda_codec_write(codec, codec->core.afg,
2049 0, AC_VERB_SET_UNSOLICITED_ENABLE,
2050 flag ? AC_UNSOL_ENABLED : 0);
2054 /* Vendor specific HW configuration
2055 * PLL, ASP, I2C, SPI, GPIOs, DMIC etc...
2057 static void cs8409_cs42l42_hw_init(struct hda_codec *codec)
2059 const struct cs8409_cir_param *seq = cs8409_cs42l42_hw_cfg;
2060 const struct cs8409_cir_param *seq_bullseye = cs8409_cs42l42_bullseye_atn;
2061 struct cs_spec *spec = codec->spec;
2063 if (spec->gpio_mask) {
2064 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
2066 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
2068 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
2072 for (; seq->nid; seq++)
2073 cs_vendor_coef_set(codec, seq->cir, seq->coeff);
2075 if (codec->fixup_id == CS8409_BULLSEYE)
2076 for (; seq_bullseye->nid; seq_bullseye++)
2077 cs_vendor_coef_set(codec, seq_bullseye->cir, seq_bullseye->coeff);
2079 /* Disable Unsolicited Response during boot */
2080 cs8409_enable_ur(codec, 0);
2083 cs8409_cs42l42_reset(codec);
2085 /* Initialise CS42L42 companion codec */
2086 cs8409_cs42l42_reg_setup(codec);
2088 if (codec->fixup_id == CS8409_WARLOCK ||
2089 codec->fixup_id == CS8409_CYBORG) {
2090 /* FULL_SCALE_VOL = 0 for Warlock / Cyborg */
2091 mutex_lock(&spec->cs8409_i2c_mux);
2092 cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x2001, 0x01, 1);
2093 mutex_unlock(&spec->cs8409_i2c_mux);
2094 /* DMIC1_MO=00b, DMIC1/2_SR=1 */
2095 cs_vendor_coef_set(codec, 0x09, 0x0003);
2098 /* Restore Volumes after Resume */
2099 if (spec->cs42l42_volume_init) {
2100 mutex_lock(&spec->cs8409_i2c_mux);
2101 cs8409_i2c_write(codec, CS42L42_I2C_ADDR,
2102 CS8409_CS42L42_REG_HS_VOLUME_CHA,
2103 -spec->cs42l42_hp_volume[0],
2105 cs8409_i2c_write(codec, CS42L42_I2C_ADDR,
2106 CS8409_CS42L42_REG_HS_VOLUME_CHB,
2107 -spec->cs42l42_hp_volume[1],
2109 cs8409_i2c_write(codec, CS42L42_I2C_ADDR,
2110 CS8409_CS42L42_REG_AMIC_VOLUME,
2111 spec->cs42l42_hs_mic_volume[0],
2113 mutex_unlock(&spec->cs8409_i2c_mux);
2116 cs8409_cs42l42_update_volume(codec);
2118 cs8409_cs42l42_enable_jack_detect(codec);
2120 /* Enable Unsolicited Response */
2121 cs8409_enable_ur(codec, 1);
2124 static int cs8409_cs42l42_init(struct hda_codec *codec)
2126 int ret = snd_hda_gen_init(codec);
2129 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
2134 static const struct hda_codec_ops cs8409_cs42l42_patch_ops = {
2135 .build_controls = cs_build_controls,
2136 .build_pcms = snd_hda_gen_build_pcms,
2137 .init = cs8409_cs42l42_init,
2139 .unsol_event = cs8409_jack_unsol_event,
2141 .suspend = cs8409_suspend,
2145 static void cs8409_cs42l42_fixups(struct hda_codec *codec,
2146 const struct hda_fixup *fix, int action)
2148 struct cs_spec *spec = codec->spec;
2152 case HDA_FIXUP_ACT_PRE_PROBE:
2153 snd_hda_add_verbs(codec, cs8409_cs42l42_init_verbs);
2154 /* verb exec op override */
2155 spec->exec_verb = codec->core.exec_verb;
2156 codec->core.exec_verb = cs8409_cs42l42_exec_verb;
2158 mutex_init(&spec->cs8409_i2c_mux);
2160 codec->patch_ops = cs8409_cs42l42_patch_ops;
2162 spec->gen.suppress_auto_mute = 1;
2163 spec->gen.no_primary_hp = 1;
2164 spec->gen.suppress_vmaster = 1;
2166 /* GPIO 5 out, 3,4 in */
2167 spec->gpio_dir = GPIO5_INT;
2168 spec->gpio_data = 0;
2169 spec->gpio_mask = 0x03f;
2171 spec->cs42l42_hp_jack_in = 0;
2172 spec->cs42l42_mic_jack_in = 0;
2174 /* Basic initial sequence for specific hw configuration */
2175 snd_hda_sequence_write(codec, cs8409_cs42l42_init_verbs);
2177 /* CS8409 is simple HDA bridge and intended to be used with a remote
2178 * companion codec. Most of input/output PIN(s) have only basic
2179 * capabilities. NID(s) 0x24 and 0x34 have only OUTC and INC
2180 * capabilities and no presence detect capable (PDC) and call to
2181 * snd_hda_gen_build_controls() will mark them as non detectable
2182 * phantom jacks. However, in this configuration companion codec
2183 * CS42L42 is connected to these pins and it has jack detect
2184 * capabilities. We have to override pin capabilities,
2185 * otherwise they will not be created as input devices.
2187 caps = snd_hdac_read_parm(&codec->core, CS8409_CS42L42_HP_PIN_NID,
2190 snd_hdac_override_parm(&codec->core,
2191 CS8409_CS42L42_HP_PIN_NID, AC_PAR_PIN_CAP,
2192 (caps | (AC_PINCAP_IMP_SENSE | AC_PINCAP_PRES_DETECT)));
2194 caps = snd_hdac_read_parm(&codec->core, CS8409_CS42L42_AMIC_PIN_NID,
2197 snd_hdac_override_parm(&codec->core,
2198 CS8409_CS42L42_AMIC_PIN_NID, AC_PAR_PIN_CAP,
2199 (caps | (AC_PINCAP_IMP_SENSE | AC_PINCAP_PRES_DETECT)));
2201 snd_hda_override_wcaps(codec, CS8409_CS42L42_HP_PIN_NID,
2202 (get_wcaps(codec, CS8409_CS42L42_HP_PIN_NID) | AC_WCAP_UNSOL_CAP));
2204 snd_hda_override_wcaps(codec, CS8409_CS42L42_AMIC_PIN_NID,
2205 (get_wcaps(codec, CS8409_CS42L42_AMIC_PIN_NID) | AC_WCAP_UNSOL_CAP));
2207 case HDA_FIXUP_ACT_PROBE:
2209 /* Set initial DMIC volume to -26 dB */
2210 snd_hda_codec_amp_init_stereo(codec, CS8409_CS42L42_DMIC_ADC_PIN_NID,
2211 HDA_INPUT, 0, 0xff, 0x19);
2212 snd_hda_gen_add_kctl(&spec->gen,
2213 NULL, &cs8409_cs42l42_hp_volume_mixer);
2214 snd_hda_gen_add_kctl(&spec->gen,
2215 NULL, &cs8409_cs42l42_amic_volume_mixer);
2216 cs8409_cs42l42_hw_init(codec);
2217 snd_hda_codec_set_name(codec, "CS8409/CS42L42");
2219 case HDA_FIXUP_ACT_INIT:
2220 cs8409_cs42l42_hw_init(codec);
2222 case HDA_FIXUP_ACT_BUILD:
2223 /* Run jack auto detect first time on boot
2224 * after controls have been added, to check if jack has
2225 * been already plugged in.
2226 * Run immediately after init.
2228 cs8409_cs42l42_run_jack_detect(codec);
2229 usleep_range(100000, 150000);
2236 static int cs8409_cs42l42_exec_verb(struct hdac_device *dev,
2237 unsigned int cmd, unsigned int flags, unsigned int *res)
2239 struct hda_codec *codec = container_of(dev, struct hda_codec, core);
2240 struct cs_spec *spec = codec->spec;
2242 unsigned int nid = ((cmd >> 20) & 0x07f);
2243 unsigned int verb = ((cmd >> 8) & 0x0fff);
2245 /* CS8409 pins have no AC_PINSENSE_PRESENCE
2246 * capabilities. We have to intercept 2 calls for pins 0x24 and 0x34
2247 * and return correct pin sense values for read_pin_sense() call from
2248 * hda_jack based on CS42L42 jack detect status.
2251 case CS8409_CS42L42_HP_PIN_NID:
2252 if (verb == AC_VERB_GET_PIN_SENSE) {
2253 *res = (spec->cs42l42_hp_jack_in) ? AC_PINSENSE_PRESENCE : 0;
2258 case CS8409_CS42L42_AMIC_PIN_NID:
2259 if (verb == AC_VERB_GET_PIN_SENSE) {
2260 *res = (spec->cs42l42_mic_jack_in) ? AC_PINSENSE_PRESENCE : 0;
2269 return spec->exec_verb(dev, cmd, flags, res);
2272 static int patch_cs8409(struct hda_codec *codec)
2276 if (!cs_alloc_spec(codec, CS8409_VENDOR_NID))
2279 snd_hda_pick_fixup(codec,
2280 cs8409_models, cs8409_fixup_tbl, cs8409_fixups);
2282 codec_dbg(codec, "Picked ID=%d, VID=%08x, DEV=%08x\n",
2284 codec->bus->pci->subsystem_vendor,
2285 codec->bus->pci->subsystem_device);
2287 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2289 err = cs_parse_auto_config(codec);
2295 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2302 static const struct hda_device_id snd_hda_id_cirrus[] = {
2303 HDA_CODEC_ENTRY(0x10134206, "CS4206", patch_cs420x),
2304 HDA_CODEC_ENTRY(0x10134207, "CS4207", patch_cs420x),
2305 HDA_CODEC_ENTRY(0x10134208, "CS4208", patch_cs4208),
2306 HDA_CODEC_ENTRY(0x10134210, "CS4210", patch_cs4210),
2307 HDA_CODEC_ENTRY(0x10134213, "CS4213", patch_cs4213),
2308 HDA_CODEC_ENTRY(0x10138409, "CS8409", patch_cs8409),
2311 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_cirrus);
2313 MODULE_LICENSE("GPL");
2314 MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
2316 static struct hda_codec_driver cirrus_driver = {
2317 .id = snd_hda_id_cirrus,
2320 module_hda_codec_driver(cirrus_driver);