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/pci.h>
24 #include <linux/module.h>
25 #include <sound/core.h>
26 #include <sound/tlv.h>
27 #include "hda_codec.h"
28 #include "hda_local.h"
29 #include "hda_auto_parser.h"
31 #include "hda_generic.h"
37 struct hda_gen_spec gen
;
39 unsigned int gpio_mask
;
40 unsigned int gpio_dir
;
41 unsigned int gpio_data
;
42 unsigned int gpio_eapd_hp
; /* EAPD GPIO bit for headphones */
43 unsigned int gpio_eapd_speaker
; /* EAPD GPIO bit for speakers */
46 unsigned int spdif_detect
:1;
47 unsigned int spdif_present
:1;
48 unsigned int sense_b
:1;
52 /* available models with CS420x */
64 CS420X_IMAC27_122
= CS420X_GPIO_23
,
65 CS420X_APPLE
= CS420X_GPIO_13
,
75 /* Vendor-specific processing widget */
76 #define CS420X_VENDOR_NID 0x11
77 #define CS_DIG_OUT1_PIN_NID 0x10
78 #define CS_DIG_OUT2_PIN_NID 0x15
79 #define CS_DMIC1_PIN_NID 0x0e
80 #define CS_DMIC2_PIN_NID 0x12
83 #define IDX_SPDIF_STAT 0x0000
84 #define IDX_SPDIF_CTL 0x0001
85 #define IDX_ADC_CFG 0x0002
86 /* SZC bitmask, 4 modes below:
88 * 1 = digital immediate, analog zero-cross
89 * 2 = digtail & analog soft-ramp
90 * 3 = digital soft-ramp, analog zero-cross
92 #define CS_COEF_ADC_SZC_MASK (3 << 0)
93 #define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */
94 #define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
95 /* PGA mode: 0 = differential, 1 = signle-ended */
96 #define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */
97 #define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
98 #define IDX_DAC_CFG 0x0003
99 /* SZC bitmask, 4 modes below:
103 * 3 = soft-ramp on zero-cross
105 #define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */
106 #define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */
107 #define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */
109 #define IDX_BEEP_CFG 0x0004
110 /* 0x0008 - test reg key */
111 /* 0x0009 - 0x0014 -> 12 test regs */
112 /* 0x0015 - visibility reg */
114 /* Cirrus Logic CS4208 */
115 #define CS4208_VENDOR_NID 0x24
118 * Cirrus Logic CS4210
120 * 1 DAC => HP(sense) / Speakers,
121 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
122 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
124 #define CS4210_DAC_NID 0x02
125 #define CS4210_ADC_NID 0x03
126 #define CS4210_VENDOR_NID 0x0B
127 #define CS421X_DMIC_PIN_NID 0x09 /* Port E */
128 #define CS421X_SPDIF_PIN_NID 0x0A /* Port H */
130 #define CS421X_IDX_DEV_CFG 0x01
131 #define CS421X_IDX_ADC_CFG 0x02
132 #define CS421X_IDX_DAC_CFG 0x03
133 #define CS421X_IDX_SPK_CTL 0x04
135 #define SPDIF_EVENT 0x04
137 /* Cirrus Logic CS4213 is like CS4210 but does not have SPDIF input/output */
138 #define CS4213_VENDOR_NID 0x09
141 static inline int cs_vendor_coef_get(struct hda_codec
*codec
, unsigned int idx
)
143 struct cs_spec
*spec
= codec
->spec
;
144 snd_hda_codec_write(codec
, spec
->vendor_nid
, 0,
145 AC_VERB_SET_COEF_INDEX
, idx
);
146 return snd_hda_codec_read(codec
, spec
->vendor_nid
, 0,
147 AC_VERB_GET_PROC_COEF
, 0);
150 static inline void cs_vendor_coef_set(struct hda_codec
*codec
, unsigned int idx
,
153 struct cs_spec
*spec
= codec
->spec
;
154 snd_hda_codec_write(codec
, spec
->vendor_nid
, 0,
155 AC_VERB_SET_COEF_INDEX
, idx
);
156 snd_hda_codec_write(codec
, spec
->vendor_nid
, 0,
157 AC_VERB_SET_PROC_COEF
, coef
);
161 * auto-mute and auto-mic switching
162 * CS421x auto-output redirecting
166 static void cs_automute(struct hda_codec
*codec
)
168 struct cs_spec
*spec
= codec
->spec
;
170 /* mute HPs if spdif jack (SENSE_B) is present */
171 spec
->gen
.master_mute
= !!(spec
->spdif_present
&& spec
->sense_b
);
173 snd_hda_gen_update_outputs(codec
);
175 if (spec
->gpio_eapd_hp
|| spec
->gpio_eapd_speaker
) {
176 spec
->gpio_data
= spec
->gen
.hp_jack_present
?
177 spec
->gpio_eapd_hp
: spec
->gpio_eapd_speaker
;
178 snd_hda_codec_write(codec
, 0x01, 0,
179 AC_VERB_SET_GPIO_DATA
, spec
->gpio_data
);
183 static bool is_active_pin(struct hda_codec
*codec
, hda_nid_t nid
)
186 val
= snd_hda_codec_get_pincfg(codec
, nid
);
187 return (get_defcfg_connect(val
) != AC_JACK_PORT_NONE
);
190 static void init_input_coef(struct hda_codec
*codec
)
192 struct cs_spec
*spec
= codec
->spec
;
195 /* CS420x has multiple ADC, CS421x has single ADC */
196 if (spec
->vendor_nid
== CS420X_VENDOR_NID
) {
197 coef
= cs_vendor_coef_get(codec
, IDX_BEEP_CFG
);
198 if (is_active_pin(codec
, CS_DMIC2_PIN_NID
))
199 coef
|= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */
200 if (is_active_pin(codec
, CS_DMIC1_PIN_NID
))
201 coef
|= 1 << 3; /* DMIC1 2 chan on, GPIO0 off
202 * No effect if SPDIF_OUT2 is
203 * selected in IDX_SPDIF_CTL.
206 cs_vendor_coef_set(codec
, IDX_BEEP_CFG
, coef
);
210 static const struct hda_verb cs_coef_init_verbs
[] = {
211 {0x11, AC_VERB_SET_PROC_STATE
, 1},
212 {0x11, AC_VERB_SET_COEF_INDEX
, IDX_DAC_CFG
},
213 {0x11, AC_VERB_SET_PROC_COEF
,
214 (0x002a /* DAC1/2/3 SZCMode Soft Ramp */
215 | 0x0040 /* Mute DACs on FIFO error */
216 | 0x1000 /* Enable DACs High Pass Filter */
217 | 0x0400 /* Disable Coefficient Auto increment */
219 /* ADC1/2 - Digital and Analog Soft Ramp */
220 {0x11, AC_VERB_SET_COEF_INDEX
, IDX_ADC_CFG
},
221 {0x11, AC_VERB_SET_PROC_COEF
, 0x000a},
223 {0x11, AC_VERB_SET_COEF_INDEX
, IDX_BEEP_CFG
},
224 {0x11, AC_VERB_SET_PROC_COEF
, 0x0007}, /* Enable Beep thru DAC1/2/3 */
229 static const struct hda_verb cs4208_coef_init_verbs
[] = {
230 {0x01, AC_VERB_SET_POWER_STATE
, 0x00}, /* AFG: D0 */
231 {0x24, AC_VERB_SET_PROC_STATE
, 0x01}, /* VPW: processing on */
232 {0x24, AC_VERB_SET_COEF_INDEX
, 0x0033},
233 {0x24, AC_VERB_SET_PROC_COEF
, 0x0001}, /* A1 ICS */
234 {0x24, AC_VERB_SET_COEF_INDEX
, 0x0034},
235 {0x24, AC_VERB_SET_PROC_COEF
, 0x1C01}, /* A1 Enable, A Thresh = 300mV */
239 /* Errata: CS4207 rev C0/C1/C2 Silicon
241 * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf
243 * 6. At high temperature (TA > +85°C), the digital supply current (IVD)
244 * may be excessive (up to an additional 200 μA), which is most easily
245 * observed while the part is being held in reset (RESET# active low).
247 * Root Cause: At initial powerup of the device, the logic that drives
248 * the clock and write enable to the S/PDIF SRC RAMs is not properly
250 * Certain random patterns will cause a steady leakage current in those
251 * RAM cells. The issue will resolve once the SRCs are used (turned on).
253 * Workaround: The following verb sequence briefly turns on the S/PDIF SRC
254 * blocks, which will alleviate the issue.
257 static const struct hda_verb cs_errata_init_verbs
[] = {
258 {0x01, AC_VERB_SET_POWER_STATE
, 0x00}, /* AFG: D0 */
259 {0x11, AC_VERB_SET_PROC_STATE
, 0x01}, /* VPW: processing on */
261 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0008},
262 {0x11, AC_VERB_SET_PROC_COEF
, 0x9999},
263 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0017},
264 {0x11, AC_VERB_SET_PROC_COEF
, 0xa412},
265 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0001},
266 {0x11, AC_VERB_SET_PROC_COEF
, 0x0009},
268 {0x07, AC_VERB_SET_POWER_STATE
, 0x00}, /* S/PDIF Rx: D0 */
269 {0x08, AC_VERB_SET_POWER_STATE
, 0x00}, /* S/PDIF Tx: D0 */
271 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0017},
272 {0x11, AC_VERB_SET_PROC_COEF
, 0x2412},
273 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0008},
274 {0x11, AC_VERB_SET_PROC_COEF
, 0x0000},
275 {0x11, AC_VERB_SET_COEF_INDEX
, 0x0001},
276 {0x11, AC_VERB_SET_PROC_COEF
, 0x0008},
277 {0x11, AC_VERB_SET_PROC_STATE
, 0x00},
279 #if 0 /* Don't to set to D3 as we are in power-up sequence */
280 {0x07, AC_VERB_SET_POWER_STATE
, 0x03}, /* S/PDIF Rx: D3 */
281 {0x08, AC_VERB_SET_POWER_STATE
, 0x03}, /* S/PDIF Tx: D3 */
282 /*{0x01, AC_VERB_SET_POWER_STATE, 0x03},*/ /* AFG: D3 This is already handled */
289 static void init_digital_coef(struct hda_codec
*codec
)
293 coef
= 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */
294 coef
|= 0x0008; /* Replace with mute on error */
295 if (is_active_pin(codec
, CS_DIG_OUT2_PIN_NID
))
296 coef
|= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2
297 * SPDIF_OUT2 is shared with GPIO1 and
300 cs_vendor_coef_set(codec
, IDX_SPDIF_CTL
, coef
);
303 static int cs_init(struct hda_codec
*codec
)
305 struct cs_spec
*spec
= codec
->spec
;
307 if (spec
->vendor_nid
== CS420X_VENDOR_NID
) {
308 /* init_verb sequence for C0/C1/C2 errata*/
309 snd_hda_sequence_write(codec
, cs_errata_init_verbs
);
310 snd_hda_sequence_write(codec
, cs_coef_init_verbs
);
311 } else if (spec
->vendor_nid
== CS4208_VENDOR_NID
) {
312 snd_hda_sequence_write(codec
, cs4208_coef_init_verbs
);
315 snd_hda_gen_init(codec
);
317 if (spec
->gpio_mask
) {
318 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_MASK
,
320 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION
,
322 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DATA
,
326 if (spec
->vendor_nid
== CS420X_VENDOR_NID
) {
327 init_input_coef(codec
);
328 init_digital_coef(codec
);
334 #define cs_free snd_hda_gen_free
336 static const struct hda_codec_ops cs_patch_ops
= {
337 .build_controls
= snd_hda_gen_build_controls
,
338 .build_pcms
= snd_hda_gen_build_pcms
,
341 .unsol_event
= snd_hda_jack_unsol_event
,
344 static int cs_parse_auto_config(struct hda_codec
*codec
)
346 struct cs_spec
*spec
= codec
->spec
;
349 err
= snd_hda_parse_pin_defcfg(codec
, &spec
->gen
.autocfg
, NULL
, 0);
353 err
= snd_hda_gen_parse_auto_config(codec
, &spec
->gen
.autocfg
);
360 static const struct hda_model_fixup cs420x_models
[] = {
361 { .id
= CS420X_MBP53
, .name
= "mbp53" },
362 { .id
= CS420X_MBP55
, .name
= "mbp55" },
363 { .id
= CS420X_IMAC27
, .name
= "imac27" },
364 { .id
= CS420X_IMAC27_122
, .name
= "imac27_122" },
365 { .id
= CS420X_APPLE
, .name
= "apple" },
366 { .id
= CS420X_MBP101
, .name
= "mbp101" },
367 { .id
= CS420X_MBP81
, .name
= "mbp81" },
368 { .id
= CS420X_MBA42
, .name
= "mba42" },
372 static const struct snd_pci_quirk cs420x_fixup_tbl
[] = {
373 SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53
),
374 SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55
),
375 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55
),
376 SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55
),
377 /* this conflicts with too many other models */
378 /*SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),*/
381 SND_PCI_QUIRK(0x106b, 0x1c00, "MacBookPro 8,1", CS420X_MBP81
),
382 SND_PCI_QUIRK(0x106b, 0x2000, "iMac 12,2", CS420X_IMAC27_122
),
383 SND_PCI_QUIRK(0x106b, 0x2800, "MacBookPro 10,1", CS420X_MBP101
),
384 SND_PCI_QUIRK(0x106b, 0x5b00, "MacBookAir 4,2", CS420X_MBA42
),
385 SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS420X_APPLE
),
389 static const struct hda_pintbl mbp53_pincfgs
[] = {
390 { 0x09, 0x012b4050 },
391 { 0x0a, 0x90100141 },
392 { 0x0b, 0x90100140 },
393 { 0x0c, 0x018b3020 },
394 { 0x0d, 0x90a00110 },
395 { 0x0e, 0x400000f0 },
396 { 0x0f, 0x01cbe030 },
397 { 0x10, 0x014be060 },
398 { 0x12, 0x400000f0 },
399 { 0x15, 0x400000f0 },
403 static const struct hda_pintbl mbp55_pincfgs
[] = {
404 { 0x09, 0x012b4030 },
405 { 0x0a, 0x90100121 },
406 { 0x0b, 0x90100120 },
407 { 0x0c, 0x400000f0 },
408 { 0x0d, 0x90a00110 },
409 { 0x0e, 0x400000f0 },
410 { 0x0f, 0x400000f0 },
411 { 0x10, 0x014be040 },
412 { 0x12, 0x400000f0 },
413 { 0x15, 0x400000f0 },
417 static const struct hda_pintbl imac27_pincfgs
[] = {
418 { 0x09, 0x012b4050 },
419 { 0x0a, 0x90100140 },
420 { 0x0b, 0x90100142 },
421 { 0x0c, 0x018b3020 },
422 { 0x0d, 0x90a00110 },
423 { 0x0e, 0x400000f0 },
424 { 0x0f, 0x01cbe030 },
425 { 0x10, 0x014be060 },
426 { 0x12, 0x01ab9070 },
427 { 0x15, 0x400000f0 },
431 static const struct hda_pintbl mbp101_pincfgs
[] = {
432 { 0x0d, 0x40ab90f0 },
433 { 0x0e, 0x90a600f0 },
434 { 0x12, 0x50a600f0 },
438 static const struct hda_pintbl mba42_pincfgs
[] = {
439 { 0x09, 0x012b4030 }, /* HP */
440 { 0x0a, 0x400000f0 },
441 { 0x0b, 0x90100120 }, /* speaker */
442 { 0x0c, 0x400000f0 },
443 { 0x0d, 0x90a00110 }, /* mic */
444 { 0x0e, 0x400000f0 },
445 { 0x0f, 0x400000f0 },
446 { 0x10, 0x400000f0 },
447 { 0x12, 0x400000f0 },
448 { 0x15, 0x400000f0 },
452 static const struct hda_pintbl mba6_pincfgs
[] = {
453 { 0x10, 0x032120f0 }, /* HP */
454 { 0x11, 0x500000f0 },
455 { 0x12, 0x90100010 }, /* Speaker */
456 { 0x13, 0x500000f0 },
457 { 0x14, 0x500000f0 },
458 { 0x15, 0x770000f0 },
459 { 0x16, 0x770000f0 },
460 { 0x17, 0x430000f0 },
461 { 0x18, 0x43ab9030 }, /* Mic */
462 { 0x19, 0x770000f0 },
463 { 0x1a, 0x770000f0 },
464 { 0x1b, 0x770000f0 },
465 { 0x1c, 0x90a00090 },
466 { 0x1d, 0x500000f0 },
467 { 0x1e, 0x500000f0 },
468 { 0x1f, 0x500000f0 },
469 { 0x20, 0x500000f0 },
470 { 0x21, 0x430000f0 },
471 { 0x22, 0x430000f0 },
475 static void cs420x_fixup_gpio_13(struct hda_codec
*codec
,
476 const struct hda_fixup
*fix
, int action
)
478 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
479 struct cs_spec
*spec
= codec
->spec
;
480 spec
->gpio_eapd_hp
= 2; /* GPIO1 = headphones */
481 spec
->gpio_eapd_speaker
= 8; /* GPIO3 = speakers */
482 spec
->gpio_mask
= spec
->gpio_dir
=
483 spec
->gpio_eapd_hp
| spec
->gpio_eapd_speaker
;
487 static void cs420x_fixup_gpio_23(struct hda_codec
*codec
,
488 const struct hda_fixup
*fix
, int action
)
490 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
491 struct cs_spec
*spec
= codec
->spec
;
492 spec
->gpio_eapd_hp
= 4; /* GPIO2 = headphones */
493 spec
->gpio_eapd_speaker
= 8; /* GPIO3 = speakers */
494 spec
->gpio_mask
= spec
->gpio_dir
=
495 spec
->gpio_eapd_hp
| spec
->gpio_eapd_speaker
;
499 static const struct hda_fixup cs420x_fixups
[] = {
501 .type
= HDA_FIXUP_PINS
,
502 .v
.pins
= mbp53_pincfgs
,
504 .chain_id
= CS420X_APPLE
,
507 .type
= HDA_FIXUP_PINS
,
508 .v
.pins
= mbp55_pincfgs
,
510 .chain_id
= CS420X_GPIO_13
,
513 .type
= HDA_FIXUP_PINS
,
514 .v
.pins
= imac27_pincfgs
,
516 .chain_id
= CS420X_GPIO_13
,
519 .type
= HDA_FIXUP_FUNC
,
520 .v
.func
= cs420x_fixup_gpio_13
,
523 .type
= HDA_FIXUP_FUNC
,
524 .v
.func
= cs420x_fixup_gpio_23
,
527 .type
= HDA_FIXUP_PINS
,
528 .v
.pins
= mbp101_pincfgs
,
530 .chain_id
= CS420X_GPIO_13
,
533 .type
= HDA_FIXUP_VERBS
,
534 .v
.verbs
= (const struct hda_verb
[]) {
535 /* internal mic ADC2: right only, single ended */
536 {0x11, AC_VERB_SET_COEF_INDEX
, IDX_ADC_CFG
},
537 {0x11, AC_VERB_SET_PROC_COEF
, 0x102a},
541 .chain_id
= CS420X_GPIO_13
,
544 .type
= HDA_FIXUP_PINS
,
545 .v
.pins
= mba42_pincfgs
,
547 .chain_id
= CS420X_GPIO_13
,
551 static struct cs_spec
*cs_alloc_spec(struct hda_codec
*codec
, int vendor_nid
)
553 struct cs_spec
*spec
;
555 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
559 spec
->vendor_nid
= vendor_nid
;
560 snd_hda_gen_spec_init(&spec
->gen
);
565 static int patch_cs420x(struct hda_codec
*codec
)
567 struct cs_spec
*spec
;
570 spec
= cs_alloc_spec(codec
, CS420X_VENDOR_NID
);
574 spec
->gen
.automute_hook
= cs_automute
;
576 snd_hda_pick_fixup(codec
, cs420x_models
, cs420x_fixup_tbl
,
578 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
580 err
= cs_parse_auto_config(codec
);
584 codec
->patch_ops
= cs_patch_ops
;
586 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
597 * Its layout is no longer compatible with CS4206/CS4207
604 static const struct hda_model_fixup cs4208_models
[] = {
605 { .id
= CS4208_GPIO0
, .name
= "gpio0" },
606 { .id
= CS4208_MBA6
, .name
= "mba6" },
610 static const struct snd_pci_quirk cs4208_fixup_tbl
[] = {
612 SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6
),
613 SND_PCI_QUIRK(0x106b, 0x7200, "MacBookAir 6,2", CS4208_MBA6
),
617 static void cs4208_fixup_gpio0(struct hda_codec
*codec
,
618 const struct hda_fixup
*fix
, int action
)
620 if (action
== HDA_FIXUP_ACT_PRE_PROBE
) {
621 struct cs_spec
*spec
= codec
->spec
;
622 spec
->gpio_eapd_hp
= 0;
623 spec
->gpio_eapd_speaker
= 1;
624 spec
->gpio_mask
= spec
->gpio_dir
=
625 spec
->gpio_eapd_hp
| spec
->gpio_eapd_speaker
;
629 static const struct hda_fixup cs4208_fixups
[] = {
631 .type
= HDA_FIXUP_PINS
,
632 .v
.pins
= mba6_pincfgs
,
634 .chain_id
= CS4208_GPIO0
,
637 .type
= HDA_FIXUP_FUNC
,
638 .v
.func
= cs4208_fixup_gpio0
,
642 /* correct the 0dB offset of input pins */
643 static void cs4208_fix_amp_caps(struct hda_codec
*codec
, hda_nid_t adc
)
647 caps
= query_amp_caps(codec
, adc
, HDA_INPUT
);
648 caps
&= ~(AC_AMPCAP_OFFSET
);
650 snd_hda_override_amp_caps(codec
, adc
, HDA_INPUT
, caps
);
653 static int patch_cs4208(struct hda_codec
*codec
)
655 struct cs_spec
*spec
;
658 spec
= cs_alloc_spec(codec
, CS4208_VENDOR_NID
);
662 spec
->gen
.automute_hook
= cs_automute
;
664 snd_hda_pick_fixup(codec
, cs4208_models
, cs4208_fixup_tbl
,
666 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
668 snd_hda_override_wcaps(codec
, 0x18,
669 get_wcaps(codec
, 0x18) | AC_WCAP_STEREO
);
670 cs4208_fix_amp_caps(codec
, 0x18);
671 cs4208_fix_amp_caps(codec
, 0x1b);
672 cs4208_fix_amp_caps(codec
, 0x1c);
674 err
= cs_parse_auto_config(codec
);
678 codec
->patch_ops
= cs_patch_ops
;
680 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
690 * Cirrus Logic CS4210
692 * 1 DAC => HP(sense) / Speakers,
693 * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
694 * 1 SPDIF OUT => SPDIF Trasmitter(sense)
697 /* CS4210 board names */
698 static const struct hda_model_fixup cs421x_models
[] = {
699 { .id
= CS421X_CDB4210
, .name
= "cdb4210" },
700 { .id
= CS421X_STUMPY
, .name
= "stumpy" },
704 static const struct snd_pci_quirk cs421x_fixup_tbl
[] = {
705 /* Test Intel board + CDB2410 */
706 SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210
),
710 /* CS4210 board pinconfigs */
711 /* Default CS4210 (CDB4210)*/
712 static const struct hda_pintbl cdb4210_pincfgs
[] = {
713 { 0x05, 0x0321401f },
714 { 0x06, 0x90170010 },
715 { 0x07, 0x03813031 },
716 { 0x08, 0xb7a70037 },
717 { 0x09, 0xb7a6003e },
718 { 0x0a, 0x034510f0 },
722 /* Stumpy ChromeBox */
723 static const struct hda_pintbl stumpy_pincfgs
[] = {
724 { 0x05, 0x022120f0 },
725 { 0x06, 0x901700f0 },
726 { 0x07, 0x02a120f0 },
727 { 0x08, 0x77a70037 },
728 { 0x09, 0x77a6003e },
729 { 0x0a, 0x434510f0 },
733 /* Setup GPIO/SENSE for each board (if used) */
734 static void cs421x_fixup_sense_b(struct hda_codec
*codec
,
735 const struct hda_fixup
*fix
, int action
)
737 struct cs_spec
*spec
= codec
->spec
;
738 if (action
== HDA_FIXUP_ACT_PRE_PROBE
)
742 static const struct hda_fixup cs421x_fixups
[] = {
744 .type
= HDA_FIXUP_PINS
,
745 .v
.pins
= cdb4210_pincfgs
,
747 .chain_id
= CS421X_SENSE_B
,
750 .type
= HDA_FIXUP_FUNC
,
751 .v
.func
= cs421x_fixup_sense_b
,
754 .type
= HDA_FIXUP_PINS
,
755 .v
.pins
= stumpy_pincfgs
,
759 static const struct hda_verb cs421x_coef_init_verbs
[] = {
760 {0x0B, AC_VERB_SET_PROC_STATE
, 1},
761 {0x0B, AC_VERB_SET_COEF_INDEX
, CS421X_IDX_DEV_CFG
},
763 Disable Coefficient Index Auto-Increment(DAI)=1,
766 {0x0B, AC_VERB_SET_PROC_COEF
, 0x0001 },
768 {0x0B, AC_VERB_SET_COEF_INDEX
, CS421X_IDX_ADC_CFG
},
769 /* ADC SZCMode = Digital Soft Ramp */
770 {0x0B, AC_VERB_SET_PROC_COEF
, 0x0002 },
772 {0x0B, AC_VERB_SET_COEF_INDEX
, CS421X_IDX_DAC_CFG
},
773 {0x0B, AC_VERB_SET_PROC_COEF
,
774 (0x0002 /* DAC SZCMode = Digital Soft Ramp */
775 | 0x0004 /* Mute DAC on FIFO error */
776 | 0x0008 /* Enable DAC High Pass Filter */
781 /* Errata: CS4210 rev A1 Silicon
783 * http://www.cirrus.com/en/pubs/errata/
786 * 1. Performance degredation is present in the ADC.
787 * 2. Speaker output is not completely muted upon HP detect.
788 * 3. Noise is present when clipping occurs on the amplified
792 * The following verb sequence written to the registers during
793 * initialization will correct the issues listed above.
796 static const struct hda_verb cs421x_coef_init_verbs_A1_silicon_fixes
[] = {
797 {0x0B, AC_VERB_SET_PROC_STATE
, 0x01}, /* VPW: processing on */
799 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x0006},
800 {0x0B, AC_VERB_SET_PROC_COEF
, 0x9999}, /* Test mode: on */
802 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x000A},
803 {0x0B, AC_VERB_SET_PROC_COEF
, 0x14CB}, /* Chop double */
805 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x0011},
806 {0x0B, AC_VERB_SET_PROC_COEF
, 0xA2D0}, /* Increase ADC current */
808 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x001A},
809 {0x0B, AC_VERB_SET_PROC_COEF
, 0x02A9}, /* Mute speaker */
811 {0x0B, AC_VERB_SET_COEF_INDEX
, 0x001B},
812 {0x0B, AC_VERB_SET_PROC_COEF
, 0X1006}, /* Remove noise */
817 /* Speaker Amp Gain is controlled by the vendor widget's coef 4 */
818 static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale
, 900, 300, 0);
820 static int cs421x_boost_vol_info(struct snd_kcontrol
*kcontrol
,
821 struct snd_ctl_elem_info
*uinfo
)
823 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
825 uinfo
->value
.integer
.min
= 0;
826 uinfo
->value
.integer
.max
= 3;
830 static int cs421x_boost_vol_get(struct snd_kcontrol
*kcontrol
,
831 struct snd_ctl_elem_value
*ucontrol
)
833 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
835 ucontrol
->value
.integer
.value
[0] =
836 cs_vendor_coef_get(codec
, CS421X_IDX_SPK_CTL
) & 0x0003;
840 static int cs421x_boost_vol_put(struct snd_kcontrol
*kcontrol
,
841 struct snd_ctl_elem_value
*ucontrol
)
843 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
845 unsigned int vol
= ucontrol
->value
.integer
.value
[0];
847 cs_vendor_coef_get(codec
, CS421X_IDX_SPK_CTL
);
848 unsigned int original_coef
= coef
;
851 coef
|= (vol
& 0x0003);
852 if (original_coef
== coef
)
855 cs_vendor_coef_set(codec
, CS421X_IDX_SPK_CTL
, coef
);
860 static const struct snd_kcontrol_new cs421x_speaker_boost_ctl
= {
862 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
863 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
864 SNDRV_CTL_ELEM_ACCESS_TLV_READ
),
865 .name
= "Speaker Boost Playback Volume",
866 .info
= cs421x_boost_vol_info
,
867 .get
= cs421x_boost_vol_get
,
868 .put
= cs421x_boost_vol_put
,
869 .tlv
= { .p
= cs421x_speaker_boost_db_scale
},
872 static void cs4210_pinmux_init(struct hda_codec
*codec
)
874 struct cs_spec
*spec
= codec
->spec
;
875 unsigned int def_conf
, coef
;
877 /* GPIO, DMIC_SCL, DMIC_SDA and SENSE_B are multiplexed */
878 coef
= cs_vendor_coef_get(codec
, CS421X_IDX_DEV_CFG
);
881 coef
|= 0x0008; /* B1,B2 are GPIOs */
886 coef
|= 0x0010; /* B2 is SENSE_B, not inverted */
890 cs_vendor_coef_set(codec
, CS421X_IDX_DEV_CFG
, coef
);
892 if ((spec
->gpio_mask
|| spec
->sense_b
) &&
893 is_active_pin(codec
, CS421X_DMIC_PIN_NID
)) {
896 GPIO or SENSE_B forced - disconnect the DMIC pin.
898 def_conf
= snd_hda_codec_get_pincfg(codec
, CS421X_DMIC_PIN_NID
);
899 def_conf
&= ~AC_DEFCFG_PORT_CONN
;
900 def_conf
|= (AC_JACK_PORT_NONE
<< AC_DEFCFG_PORT_CONN_SHIFT
);
901 snd_hda_codec_set_pincfg(codec
, CS421X_DMIC_PIN_NID
, def_conf
);
905 static void cs4210_spdif_automute(struct hda_codec
*codec
,
906 struct hda_jack_tbl
*tbl
)
908 struct cs_spec
*spec
= codec
->spec
;
909 bool spdif_present
= false;
910 hda_nid_t spdif_pin
= spec
->gen
.autocfg
.dig_out_pins
[0];
912 /* detect on spdif is specific to CS4210 */
913 if (!spec
->spdif_detect
||
914 spec
->vendor_nid
!= CS4210_VENDOR_NID
)
917 spdif_present
= snd_hda_jack_detect(codec
, spdif_pin
);
918 if (spdif_present
== spec
->spdif_present
)
921 spec
->spdif_present
= spdif_present
;
922 /* SPDIF TX on/off */
924 snd_hda_set_pin_ctl(codec
, spdif_pin
,
925 spdif_present
? PIN_OUT
: 0);
930 static void parse_cs421x_digital(struct hda_codec
*codec
)
932 struct cs_spec
*spec
= codec
->spec
;
933 struct auto_pin_cfg
*cfg
= &spec
->gen
.autocfg
;
936 for (i
= 0; i
< cfg
->dig_outs
; i
++) {
937 hda_nid_t nid
= cfg
->dig_out_pins
[i
];
938 if (get_wcaps(codec
, nid
) & AC_WCAP_UNSOL_CAP
) {
939 spec
->spdif_detect
= 1;
940 snd_hda_jack_detect_enable_callback(codec
, nid
,
942 cs4210_spdif_automute
);
947 static int cs421x_init(struct hda_codec
*codec
)
949 struct cs_spec
*spec
= codec
->spec
;
951 if (spec
->vendor_nid
== CS4210_VENDOR_NID
) {
952 snd_hda_sequence_write(codec
, cs421x_coef_init_verbs
);
953 snd_hda_sequence_write(codec
, cs421x_coef_init_verbs_A1_silicon_fixes
);
954 cs4210_pinmux_init(codec
);
957 snd_hda_gen_init(codec
);
959 if (spec
->gpio_mask
) {
960 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_MASK
,
962 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION
,
964 snd_hda_codec_write(codec
, 0x01, 0, AC_VERB_SET_GPIO_DATA
,
968 init_input_coef(codec
);
970 cs4210_spdif_automute(codec
, NULL
);
975 static int cs421x_build_controls(struct hda_codec
*codec
)
977 struct cs_spec
*spec
= codec
->spec
;
980 err
= snd_hda_gen_build_controls(codec
);
984 if (spec
->gen
.autocfg
.speaker_outs
&&
985 spec
->vendor_nid
== CS4210_VENDOR_NID
) {
986 err
= snd_hda_ctl_add(codec
, 0,
987 snd_ctl_new1(&cs421x_speaker_boost_ctl
, codec
));
994 static void fix_volume_caps(struct hda_codec
*codec
, hda_nid_t dac
)
998 /* set the upper-limit for mixer amp to 0dB */
999 caps
= query_amp_caps(codec
, dac
, HDA_OUTPUT
);
1000 caps
&= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT
);
1001 caps
|= ((caps
>> AC_AMPCAP_OFFSET_SHIFT
) & 0x7f)
1002 << AC_AMPCAP_NUM_STEPS_SHIFT
;
1003 snd_hda_override_amp_caps(codec
, dac
, HDA_OUTPUT
, caps
);
1006 static int cs421x_parse_auto_config(struct hda_codec
*codec
)
1008 struct cs_spec
*spec
= codec
->spec
;
1009 hda_nid_t dac
= CS4210_DAC_NID
;
1012 fix_volume_caps(codec
, dac
);
1014 err
= snd_hda_parse_pin_defcfg(codec
, &spec
->gen
.autocfg
, NULL
, 0);
1018 err
= snd_hda_gen_parse_auto_config(codec
, &spec
->gen
.autocfg
);
1022 parse_cs421x_digital(codec
);
1028 Manage PDREF, when transitioning to D3hot
1029 (DAC,ADC) -> D3, PDREF=1, AFG->D3
1031 static int cs421x_suspend(struct hda_codec
*codec
)
1033 struct cs_spec
*spec
= codec
->spec
;
1036 snd_hda_shutup_pins(codec
);
1038 snd_hda_codec_write(codec
, CS4210_DAC_NID
, 0,
1039 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
1040 snd_hda_codec_write(codec
, CS4210_ADC_NID
, 0,
1041 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
1043 if (spec
->vendor_nid
== CS4210_VENDOR_NID
) {
1044 coef
= cs_vendor_coef_get(codec
, CS421X_IDX_DEV_CFG
);
1045 coef
|= 0x0004; /* PDREF */
1046 cs_vendor_coef_set(codec
, CS421X_IDX_DEV_CFG
, coef
);
1053 static const struct hda_codec_ops cs421x_patch_ops
= {
1054 .build_controls
= cs421x_build_controls
,
1055 .build_pcms
= snd_hda_gen_build_pcms
,
1056 .init
= cs421x_init
,
1058 .unsol_event
= snd_hda_jack_unsol_event
,
1060 .suspend
= cs421x_suspend
,
1064 static int patch_cs4210(struct hda_codec
*codec
)
1066 struct cs_spec
*spec
;
1069 spec
= cs_alloc_spec(codec
, CS4210_VENDOR_NID
);
1073 spec
->gen
.automute_hook
= cs_automute
;
1075 snd_hda_pick_fixup(codec
, cs421x_models
, cs421x_fixup_tbl
,
1077 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
1080 Update the GPIO/DMIC/SENSE_B pinmux before the configuration
1081 is auto-parsed. If GPIO or SENSE_B is forced, DMIC input
1084 cs4210_pinmux_init(codec
);
1086 err
= cs421x_parse_auto_config(codec
);
1090 codec
->patch_ops
= cs421x_patch_ops
;
1092 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PROBE
);
1101 static int patch_cs4213(struct hda_codec
*codec
)
1103 struct cs_spec
*spec
;
1106 spec
= cs_alloc_spec(codec
, CS4213_VENDOR_NID
);
1110 err
= cs421x_parse_auto_config(codec
);
1114 codec
->patch_ops
= cs421x_patch_ops
;
1126 static const struct hda_codec_preset snd_hda_preset_cirrus
[] = {
1127 { .id
= 0x10134206, .name
= "CS4206", .patch
= patch_cs420x
},
1128 { .id
= 0x10134207, .name
= "CS4207", .patch
= patch_cs420x
},
1129 { .id
= 0x10134208, .name
= "CS4208", .patch
= patch_cs4208
},
1130 { .id
= 0x10134210, .name
= "CS4210", .patch
= patch_cs4210
},
1131 { .id
= 0x10134213, .name
= "CS4213", .patch
= patch_cs4213
},
1135 MODULE_ALIAS("snd-hda-codec-id:10134206");
1136 MODULE_ALIAS("snd-hda-codec-id:10134207");
1137 MODULE_ALIAS("snd-hda-codec-id:10134208");
1138 MODULE_ALIAS("snd-hda-codec-id:10134210");
1139 MODULE_ALIAS("snd-hda-codec-id:10134213");
1141 MODULE_LICENSE("GPL");
1142 MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
1144 static struct hda_codec_preset_list cirrus_list
= {
1145 .preset
= snd_hda_preset_cirrus
,
1146 .owner
= THIS_MODULE
,
1149 static int __init
patch_cirrus_init(void)
1151 return snd_hda_add_codec_preset(&cirrus_list
);
1154 static void __exit
patch_cirrus_exit(void)
1156 snd_hda_delete_codec_preset(&cirrus_list
);
1159 module_init(patch_cirrus_init
)
1160 module_exit(patch_cirrus_exit
)