1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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"
30#include "hda_jack.h"
31#include "hda_generic.h"
32
33
34
35
36struct cs_spec {
37 struct hda_gen_spec gen;
38
39 unsigned int gpio_mask;
40 unsigned int gpio_dir;
41 unsigned int gpio_data;
42 unsigned int gpio_eapd_hp;
43 unsigned int gpio_eapd_speaker;
44
45
46 unsigned int spdif_detect:1;
47 unsigned int spdif_present:1;
48 unsigned int sense_b:1;
49 hda_nid_t vendor_nid;
50};
51
52
53enum {
54 CS420X_MBP53,
55 CS420X_MBP55,
56 CS420X_IMAC27,
57 CS420X_GPIO_13,
58 CS420X_GPIO_23,
59 CS420X_MBP101,
60 CS420X_MBP81,
61 CS420X_MBA42,
62 CS420X_AUTO,
63
64 CS420X_IMAC27_122 = CS420X_GPIO_23,
65 CS420X_APPLE = CS420X_GPIO_13,
66};
67
68
69enum {
70 CS421X_CDB4210,
71 CS421X_SENSE_B,
72 CS421X_STUMPY,
73};
74
75
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
81
82
83#define IDX_SPDIF_STAT 0x0000
84#define IDX_SPDIF_CTL 0x0001
85#define IDX_ADC_CFG 0x0002
86
87
88
89
90
91
92#define CS_COEF_ADC_SZC_MASK (3 << 0)
93#define CS_COEF_ADC_MIC_SZC_MODE (3 << 0)
94#define CS_COEF_ADC_LI_SZC_MODE (3 << 0)
95
96#define CS_COEF_ADC_MIC_PGA_MODE (1 << 5)
97#define CS_COEF_ADC_LI_PGA_MODE (1 << 6)
98#define IDX_DAC_CFG 0x0003
99
100
101
102
103
104
105#define CS_COEF_DAC_HP_SZC_MODE (3 << 0)
106#define CS_COEF_DAC_LO_SZC_MODE (3 << 2)
107#define CS_COEF_DAC_SPK_SZC_MODE (3 << 4)
108
109#define IDX_BEEP_CFG 0x0004
110
111
112
113
114
115
116
117
118
119
120
121#define CS4210_DAC_NID 0x02
122#define CS4210_ADC_NID 0x03
123#define CS4210_VENDOR_NID 0x0B
124#define CS421X_DMIC_PIN_NID 0x09
125#define CS421X_SPDIF_PIN_NID 0x0A
126
127#define CS421X_IDX_DEV_CFG 0x01
128#define CS421X_IDX_ADC_CFG 0x02
129#define CS421X_IDX_DAC_CFG 0x03
130#define CS421X_IDX_SPK_CTL 0x04
131
132#define SPDIF_EVENT 0x04
133
134
135#define CS4213_VENDOR_NID 0x09
136
137
138static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx)
139{
140 struct cs_spec *spec = codec->spec;
141 snd_hda_codec_write(codec, spec->vendor_nid, 0,
142 AC_VERB_SET_COEF_INDEX, idx);
143 return snd_hda_codec_read(codec, spec->vendor_nid, 0,
144 AC_VERB_GET_PROC_COEF, 0);
145}
146
147static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx,
148 unsigned int coef)
149{
150 struct cs_spec *spec = codec->spec;
151 snd_hda_codec_write(codec, spec->vendor_nid, 0,
152 AC_VERB_SET_COEF_INDEX, idx);
153 snd_hda_codec_write(codec, spec->vendor_nid, 0,
154 AC_VERB_SET_PROC_COEF, coef);
155}
156
157
158
159
160
161
162
163static void cs_automute(struct hda_codec *codec)
164{
165 struct cs_spec *spec = codec->spec;
166
167
168 spec->gen.master_mute = !!(spec->spdif_present && spec->sense_b);
169
170 snd_hda_gen_update_outputs(codec);
171
172 if (spec->gpio_eapd_hp) {
173 spec->gpio_data = spec->gen.hp_jack_present ?
174 spec->gpio_eapd_hp : spec->gpio_eapd_speaker;
175 snd_hda_codec_write(codec, 0x01, 0,
176 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
177 }
178}
179
180static bool is_active_pin(struct hda_codec *codec, hda_nid_t nid)
181{
182 unsigned int val;
183 val = snd_hda_codec_get_pincfg(codec, nid);
184 return (get_defcfg_connect(val) != AC_JACK_PORT_NONE);
185}
186
187static void init_input_coef(struct hda_codec *codec)
188{
189 struct cs_spec *spec = codec->spec;
190 unsigned int coef;
191
192
193 if (spec->vendor_nid == CS420X_VENDOR_NID) {
194 coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG);
195 if (is_active_pin(codec, CS_DMIC2_PIN_NID))
196 coef |= 1 << 4;
197 if (is_active_pin(codec, CS_DMIC1_PIN_NID))
198 coef |= 1 << 3;
199
200
201
202
203 cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef);
204 }
205}
206
207static const struct hda_verb cs_coef_init_verbs[] = {
208 {0x11, AC_VERB_SET_PROC_STATE, 1},
209 {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
210 {0x11, AC_VERB_SET_PROC_COEF,
211 (0x002a
212 | 0x0040
213 | 0x1000
214 | 0x0400
215 )},
216
217 {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG},
218 {0x11, AC_VERB_SET_PROC_COEF, 0x000a},
219
220 {0x11, AC_VERB_SET_COEF_INDEX, IDX_BEEP_CFG},
221 {0x11, AC_VERB_SET_PROC_COEF, 0x0007},
222
223 {}
224};
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244static const struct hda_verb cs_errata_init_verbs[] = {
245 {0x01, AC_VERB_SET_POWER_STATE, 0x00},
246 {0x11, AC_VERB_SET_PROC_STATE, 0x01},
247
248 {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
249 {0x11, AC_VERB_SET_PROC_COEF, 0x9999},
250 {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
251 {0x11, AC_VERB_SET_PROC_COEF, 0xa412},
252 {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
253 {0x11, AC_VERB_SET_PROC_COEF, 0x0009},
254
255 {0x07, AC_VERB_SET_POWER_STATE, 0x00},
256 {0x08, AC_VERB_SET_POWER_STATE, 0x00},
257
258 {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
259 {0x11, AC_VERB_SET_PROC_COEF, 0x2412},
260 {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
261 {0x11, AC_VERB_SET_PROC_COEF, 0x0000},
262 {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
263 {0x11, AC_VERB_SET_PROC_COEF, 0x0008},
264 {0x11, AC_VERB_SET_PROC_STATE, 0x00},
265
266#if 0
267 {0x07, AC_VERB_SET_POWER_STATE, 0x03},
268 {0x08, AC_VERB_SET_POWER_STATE, 0x03},
269
270#endif
271
272 {}
273};
274
275
276static void init_digital_coef(struct hda_codec *codec)
277{
278 unsigned int coef;
279
280 coef = 0x0002;
281 coef |= 0x0008;
282 if (is_active_pin(codec, CS_DIG_OUT2_PIN_NID))
283 coef |= 0x4000;
284
285
286
287 cs_vendor_coef_set(codec, IDX_SPDIF_CTL, coef);
288}
289
290static int cs_init(struct hda_codec *codec)
291{
292 struct cs_spec *spec = codec->spec;
293
294
295 snd_hda_sequence_write(codec, cs_errata_init_verbs);
296
297 snd_hda_sequence_write(codec, cs_coef_init_verbs);
298
299 snd_hda_gen_init(codec);
300
301 if (spec->gpio_mask) {
302 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
303 spec->gpio_mask);
304 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
305 spec->gpio_dir);
306 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
307 spec->gpio_data);
308 }
309
310 init_input_coef(codec);
311 init_digital_coef(codec);
312
313 return 0;
314}
315
316#define cs_free snd_hda_gen_free
317
318static const struct hda_codec_ops cs_patch_ops = {
319 .build_controls = snd_hda_gen_build_controls,
320 .build_pcms = snd_hda_gen_build_pcms,
321 .init = cs_init,
322 .free = cs_free,
323 .unsol_event = snd_hda_jack_unsol_event,
324};
325
326static int cs_parse_auto_config(struct hda_codec *codec)
327{
328 struct cs_spec *spec = codec->spec;
329 int err;
330
331 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
332 if (err < 0)
333 return err;
334
335 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
336 if (err < 0)
337 return err;
338
339 return 0;
340}
341
342static const struct hda_model_fixup cs420x_models[] = {
343 { .id = CS420X_MBP53, .name = "mbp53" },
344 { .id = CS420X_MBP55, .name = "mbp55" },
345 { .id = CS420X_IMAC27, .name = "imac27" },
346 { .id = CS420X_IMAC27_122, .name = "imac27_122" },
347 { .id = CS420X_APPLE, .name = "apple" },
348 { .id = CS420X_MBP101, .name = "mbp101" },
349 { .id = CS420X_MBP81, .name = "mbp81" },
350 { .id = CS420X_MBA42, .name = "mba42" },
351 {}
352};
353
354static const struct snd_pci_quirk cs420x_fixup_tbl[] = {
355 SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53),
356 SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55),
357 SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
358 SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55),
359
360
361
362
363 SND_PCI_QUIRK(0x106b, 0x1c00, "MacBookPro 8,1", CS420X_MBP81),
364 SND_PCI_QUIRK(0x106b, 0x2000, "iMac 12,2", CS420X_IMAC27_122),
365 SND_PCI_QUIRK(0x106b, 0x2800, "MacBookPro 10,1", CS420X_MBP101),
366 SND_PCI_QUIRK(0x106b, 0x5b00, "MacBookAir 4,2", CS420X_MBA42),
367 SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS420X_APPLE),
368 {}
369};
370
371static const struct hda_pintbl mbp53_pincfgs[] = {
372 { 0x09, 0x012b4050 },
373 { 0x0a, 0x90100141 },
374 { 0x0b, 0x90100140 },
375 { 0x0c, 0x018b3020 },
376 { 0x0d, 0x90a00110 },
377 { 0x0e, 0x400000f0 },
378 { 0x0f, 0x01cbe030 },
379 { 0x10, 0x014be060 },
380 { 0x12, 0x400000f0 },
381 { 0x15, 0x400000f0 },
382 {}
383};
384
385static const struct hda_pintbl mbp55_pincfgs[] = {
386 { 0x09, 0x012b4030 },
387 { 0x0a, 0x90100121 },
388 { 0x0b, 0x90100120 },
389 { 0x0c, 0x400000f0 },
390 { 0x0d, 0x90a00110 },
391 { 0x0e, 0x400000f0 },
392 { 0x0f, 0x400000f0 },
393 { 0x10, 0x014be040 },
394 { 0x12, 0x400000f0 },
395 { 0x15, 0x400000f0 },
396 {}
397};
398
399static const struct hda_pintbl imac27_pincfgs[] = {
400 { 0x09, 0x012b4050 },
401 { 0x0a, 0x90100140 },
402 { 0x0b, 0x90100142 },
403 { 0x0c, 0x018b3020 },
404 { 0x0d, 0x90a00110 },
405 { 0x0e, 0x400000f0 },
406 { 0x0f, 0x01cbe030 },
407 { 0x10, 0x014be060 },
408 { 0x12, 0x01ab9070 },
409 { 0x15, 0x400000f0 },
410 {}
411};
412
413static const struct hda_pintbl mbp101_pincfgs[] = {
414 { 0x0d, 0x40ab90f0 },
415 { 0x0e, 0x90a600f0 },
416 { 0x12, 0x50a600f0 },
417 {}
418};
419
420static const struct hda_pintbl mba42_pincfgs[] = {
421 { 0x09, 0x012b4030 },
422 { 0x0a, 0x400000f0 },
423 { 0x0b, 0x90100120 },
424 { 0x0c, 0x400000f0 },
425 { 0x0d, 0x90a00110 },
426 { 0x0e, 0x400000f0 },
427 { 0x0f, 0x400000f0 },
428 { 0x10, 0x400000f0 },
429 { 0x12, 0x400000f0 },
430 { 0x15, 0x400000f0 },
431 {}
432};
433
434static void cs420x_fixup_gpio_13(struct hda_codec *codec,
435 const struct hda_fixup *fix, int action)
436{
437 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
438 struct cs_spec *spec = codec->spec;
439 spec->gpio_eapd_hp = 2;
440 spec->gpio_eapd_speaker = 8;
441 spec->gpio_mask = spec->gpio_dir =
442 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
443 }
444}
445
446static void cs420x_fixup_gpio_23(struct hda_codec *codec,
447 const struct hda_fixup *fix, int action)
448{
449 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
450 struct cs_spec *spec = codec->spec;
451 spec->gpio_eapd_hp = 4;
452 spec->gpio_eapd_speaker = 8;
453 spec->gpio_mask = spec->gpio_dir =
454 spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
455 }
456}
457
458static const struct hda_fixup cs420x_fixups[] = {
459 [CS420X_MBP53] = {
460 .type = HDA_FIXUP_PINS,
461 .v.pins = mbp53_pincfgs,
462 .chained = true,
463 .chain_id = CS420X_APPLE,
464 },
465 [CS420X_MBP55] = {
466 .type = HDA_FIXUP_PINS,
467 .v.pins = mbp55_pincfgs,
468 .chained = true,
469 .chain_id = CS420X_GPIO_13,
470 },
471 [CS420X_IMAC27] = {
472 .type = HDA_FIXUP_PINS,
473 .v.pins = imac27_pincfgs,
474 .chained = true,
475 .chain_id = CS420X_GPIO_13,
476 },
477 [CS420X_GPIO_13] = {
478 .type = HDA_FIXUP_FUNC,
479 .v.func = cs420x_fixup_gpio_13,
480 },
481 [CS420X_GPIO_23] = {
482 .type = HDA_FIXUP_FUNC,
483 .v.func = cs420x_fixup_gpio_23,
484 },
485 [CS420X_MBP101] = {
486 .type = HDA_FIXUP_PINS,
487 .v.pins = mbp101_pincfgs,
488 .chained = true,
489 .chain_id = CS420X_GPIO_13,
490 },
491 [CS420X_MBP81] = {
492 .type = HDA_FIXUP_VERBS,
493 .v.verbs = (const struct hda_verb[]) {
494
495 {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG},
496 {0x11, AC_VERB_SET_PROC_COEF, 0x102a},
497 {}
498 },
499 .chained = true,
500 .chain_id = CS420X_GPIO_13,
501 },
502 [CS420X_MBA42] = {
503 .type = HDA_FIXUP_PINS,
504 .v.pins = mba42_pincfgs,
505 .chained = true,
506 .chain_id = CS420X_GPIO_13,
507 },
508};
509
510static struct cs_spec *cs_alloc_spec(struct hda_codec *codec, int vendor_nid)
511{
512 struct cs_spec *spec;
513
514 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
515 if (!spec)
516 return NULL;
517 codec->spec = spec;
518 spec->vendor_nid = vendor_nid;
519 snd_hda_gen_spec_init(&spec->gen);
520
521 return spec;
522}
523
524static int patch_cs420x(struct hda_codec *codec)
525{
526 struct cs_spec *spec;
527 int err;
528
529 spec = cs_alloc_spec(codec, CS420X_VENDOR_NID);
530 if (!spec)
531 return -ENOMEM;
532
533 spec->gen.automute_hook = cs_automute;
534
535 snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl,
536 cs420x_fixups);
537 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
538
539 err = cs_parse_auto_config(codec);
540 if (err < 0)
541 goto error;
542
543 codec->patch_ops = cs_patch_ops;
544
545 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
546
547 return 0;
548
549 error:
550 cs_free(codec);
551 return err;
552}
553
554
555
556
557
558
559
560
561
562
563static const struct hda_model_fixup cs421x_models[] = {
564 { .id = CS421X_CDB4210, .name = "cdb4210" },
565 { .id = CS421X_STUMPY, .name = "stumpy" },
566 {}
567};
568
569static const struct snd_pci_quirk cs421x_fixup_tbl[] = {
570
571 SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210),
572 {}
573};
574
575
576
577static const struct hda_pintbl cdb4210_pincfgs[] = {
578 { 0x05, 0x0321401f },
579 { 0x06, 0x90170010 },
580 { 0x07, 0x03813031 },
581 { 0x08, 0xb7a70037 },
582 { 0x09, 0xb7a6003e },
583 { 0x0a, 0x034510f0 },
584 {}
585};
586
587
588static const struct hda_pintbl stumpy_pincfgs[] = {
589 { 0x05, 0x022120f0 },
590 { 0x06, 0x901700f0 },
591 { 0x07, 0x02a120f0 },
592 { 0x08, 0x77a70037 },
593 { 0x09, 0x77a6003e },
594 { 0x0a, 0x434510f0 },
595 {}
596};
597
598
599static void cs421x_fixup_sense_b(struct hda_codec *codec,
600 const struct hda_fixup *fix, int action)
601{
602 struct cs_spec *spec = codec->spec;
603 if (action == HDA_FIXUP_ACT_PRE_PROBE)
604 spec->sense_b = 1;
605}
606
607static const struct hda_fixup cs421x_fixups[] = {
608 [CS421X_CDB4210] = {
609 .type = HDA_FIXUP_PINS,
610 .v.pins = cdb4210_pincfgs,
611 .chained = true,
612 .chain_id = CS421X_SENSE_B,
613 },
614 [CS421X_SENSE_B] = {
615 .type = HDA_FIXUP_FUNC,
616 .v.func = cs421x_fixup_sense_b,
617 },
618 [CS421X_STUMPY] = {
619 .type = HDA_FIXUP_PINS,
620 .v.pins = stumpy_pincfgs,
621 },
622};
623
624static const struct hda_verb cs421x_coef_init_verbs[] = {
625 {0x0B, AC_VERB_SET_PROC_STATE, 1},
626 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DEV_CFG},
627
628
629
630
631 {0x0B, AC_VERB_SET_PROC_COEF, 0x0001 },
632
633 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_ADC_CFG},
634
635 {0x0B, AC_VERB_SET_PROC_COEF, 0x0002 },
636
637 {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DAC_CFG},
638 {0x0B, AC_VERB_SET_PROC_COEF,
639 (0x0002
640 | 0x0004
641 | 0x0008
642 )},
643 {}
644};
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661static const struct hda_verb cs421x_coef_init_verbs_A1_silicon_fixes[] = {
662 {0x0B, AC_VERB_SET_PROC_STATE, 0x01},
663
664 {0x0B, AC_VERB_SET_COEF_INDEX, 0x0006},
665 {0x0B, AC_VERB_SET_PROC_COEF, 0x9999},
666
667 {0x0B, AC_VERB_SET_COEF_INDEX, 0x000A},
668 {0x0B, AC_VERB_SET_PROC_COEF, 0x14CB},
669
670 {0x0B, AC_VERB_SET_COEF_INDEX, 0x0011},
671 {0x0B, AC_VERB_SET_PROC_COEF, 0xA2D0},
672
673 {0x0B, AC_VERB_SET_COEF_INDEX, 0x001A},
674 {0x0B, AC_VERB_SET_PROC_COEF, 0x02A9},
675
676 {0x0B, AC_VERB_SET_COEF_INDEX, 0x001B},
677 {0x0B, AC_VERB_SET_PROC_COEF, 0X1006},
678
679 {}
680};
681
682
683static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale, 900, 300, 0);
684
685static int cs421x_boost_vol_info(struct snd_kcontrol *kcontrol,
686 struct snd_ctl_elem_info *uinfo)
687{
688 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
689 uinfo->count = 1;
690 uinfo->value.integer.min = 0;
691 uinfo->value.integer.max = 3;
692 return 0;
693}
694
695static int cs421x_boost_vol_get(struct snd_kcontrol *kcontrol,
696 struct snd_ctl_elem_value *ucontrol)
697{
698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
699
700 ucontrol->value.integer.value[0] =
701 cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL) & 0x0003;
702 return 0;
703}
704
705static int cs421x_boost_vol_put(struct snd_kcontrol *kcontrol,
706 struct snd_ctl_elem_value *ucontrol)
707{
708 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
709
710 unsigned int vol = ucontrol->value.integer.value[0];
711 unsigned int coef =
712 cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL);
713 unsigned int original_coef = coef;
714
715 coef &= ~0x0003;
716 coef |= (vol & 0x0003);
717 if (original_coef == coef)
718 return 0;
719 else {
720 cs_vendor_coef_set(codec, CS421X_IDX_SPK_CTL, coef);
721 return 1;
722 }
723}
724
725static const struct snd_kcontrol_new cs421x_speaker_boost_ctl = {
726
727 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
728 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
729 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
730 .name = "Speaker Boost Playback Volume",
731 .info = cs421x_boost_vol_info,
732 .get = cs421x_boost_vol_get,
733 .put = cs421x_boost_vol_put,
734 .tlv = { .p = cs421x_speaker_boost_db_scale },
735};
736
737static void cs4210_pinmux_init(struct hda_codec *codec)
738{
739 struct cs_spec *spec = codec->spec;
740 unsigned int def_conf, coef;
741
742
743 coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG);
744
745 if (spec->gpio_mask)
746 coef |= 0x0008;
747 else
748 coef &= ~0x0008;
749
750 if (spec->sense_b)
751 coef |= 0x0010;
752 else
753 coef &= ~0x0010;
754
755 cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef);
756
757 if ((spec->gpio_mask || spec->sense_b) &&
758 is_active_pin(codec, CS421X_DMIC_PIN_NID)) {
759
760
761
762
763 def_conf = snd_hda_codec_get_pincfg(codec, CS421X_DMIC_PIN_NID);
764 def_conf &= ~AC_DEFCFG_PORT_CONN;
765 def_conf |= (AC_JACK_PORT_NONE << AC_DEFCFG_PORT_CONN_SHIFT);
766 snd_hda_codec_set_pincfg(codec, CS421X_DMIC_PIN_NID, def_conf);
767 }
768}
769
770static void cs4210_spdif_automute(struct hda_codec *codec,
771 struct hda_jack_tbl *tbl)
772{
773 struct cs_spec *spec = codec->spec;
774 bool spdif_present = false;
775 hda_nid_t spdif_pin = spec->gen.autocfg.dig_out_pins[0];
776
777
778 if (!spec->spdif_detect ||
779 spec->vendor_nid != CS4210_VENDOR_NID)
780 return;
781
782 spdif_present = snd_hda_jack_detect(codec, spdif_pin);
783 if (spdif_present == spec->spdif_present)
784 return;
785
786 spec->spdif_present = spdif_present;
787
788 if (spdif_present)
789 snd_hda_set_pin_ctl(codec, spdif_pin,
790 spdif_present ? PIN_OUT : 0);
791
792 cs_automute(codec);
793}
794
795static void parse_cs421x_digital(struct hda_codec *codec)
796{
797 struct cs_spec *spec = codec->spec;
798 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
799 int i;
800
801 for (i = 0; i < cfg->dig_outs; i++) {
802 hda_nid_t nid = cfg->dig_out_pins[i];
803 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
804 spec->spdif_detect = 1;
805 snd_hda_jack_detect_enable_callback(codec, nid,
806 SPDIF_EVENT,
807 cs4210_spdif_automute);
808 }
809 }
810}
811
812static int cs421x_init(struct hda_codec *codec)
813{
814 struct cs_spec *spec = codec->spec;
815
816 if (spec->vendor_nid == CS4210_VENDOR_NID) {
817 snd_hda_sequence_write(codec, cs421x_coef_init_verbs);
818 snd_hda_sequence_write(codec, cs421x_coef_init_verbs_A1_silicon_fixes);
819 cs4210_pinmux_init(codec);
820 }
821
822 snd_hda_gen_init(codec);
823
824 if (spec->gpio_mask) {
825 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
826 spec->gpio_mask);
827 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
828 spec->gpio_dir);
829 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
830 spec->gpio_data);
831 }
832
833 init_input_coef(codec);
834
835 cs4210_spdif_automute(codec, NULL);
836
837 return 0;
838}
839
840static int cs421x_build_controls(struct hda_codec *codec)
841{
842 struct cs_spec *spec = codec->spec;
843 int err;
844
845 err = snd_hda_gen_build_controls(codec);
846 if (err < 0)
847 return err;
848
849 if (spec->gen.autocfg.speaker_outs &&
850 spec->vendor_nid == CS4210_VENDOR_NID) {
851 err = snd_hda_ctl_add(codec, 0,
852 snd_ctl_new1(&cs421x_speaker_boost_ctl, codec));
853 if (err < 0)
854 return err;
855 }
856 return 0;
857}
858
859static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
860{
861 unsigned int caps;
862
863
864 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
865 caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT);
866 caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f)
867 << AC_AMPCAP_NUM_STEPS_SHIFT;
868 snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps);
869}
870
871static int cs421x_parse_auto_config(struct hda_codec *codec)
872{
873 struct cs_spec *spec = codec->spec;
874 hda_nid_t dac = CS4210_DAC_NID;
875 int err;
876
877 fix_volume_caps(codec, dac);
878
879 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
880 if (err < 0)
881 return err;
882
883 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
884 if (err < 0)
885 return err;
886
887 parse_cs421x_digital(codec);
888 return 0;
889}
890
891#ifdef CONFIG_PM
892
893
894
895
896static int cs421x_suspend(struct hda_codec *codec)
897{
898 struct cs_spec *spec = codec->spec;
899 unsigned int coef;
900
901 snd_hda_shutup_pins(codec);
902
903 snd_hda_codec_write(codec, CS4210_DAC_NID, 0,
904 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
905 snd_hda_codec_write(codec, CS4210_ADC_NID, 0,
906 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
907
908 if (spec->vendor_nid == CS4210_VENDOR_NID) {
909 coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG);
910 coef |= 0x0004;
911 cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef);
912 }
913
914 return 0;
915}
916#endif
917
918static const struct hda_codec_ops cs421x_patch_ops = {
919 .build_controls = cs421x_build_controls,
920 .build_pcms = snd_hda_gen_build_pcms,
921 .init = cs421x_init,
922 .free = cs_free,
923 .unsol_event = snd_hda_jack_unsol_event,
924#ifdef CONFIG_PM
925 .suspend = cs421x_suspend,
926#endif
927};
928
929static int patch_cs4210(struct hda_codec *codec)
930{
931 struct cs_spec *spec;
932 int err;
933
934 spec = cs_alloc_spec(codec, CS4210_VENDOR_NID);
935 if (!spec)
936 return -ENOMEM;
937
938 spec->gen.automute_hook = cs_automute;
939
940 snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl,
941 cs421x_fixups);
942 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
943
944
945
946
947
948
949 cs4210_pinmux_init(codec);
950
951 err = cs421x_parse_auto_config(codec);
952 if (err < 0)
953 goto error;
954
955 codec->patch_ops = cs421x_patch_ops;
956
957 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
958
959 return 0;
960
961 error:
962 cs_free(codec);
963 return err;
964}
965
966static int patch_cs4213(struct hda_codec *codec)
967{
968 struct cs_spec *spec;
969 int err;
970
971 spec = cs_alloc_spec(codec, CS4213_VENDOR_NID);
972 if (!spec)
973 return -ENOMEM;
974
975 err = cs421x_parse_auto_config(codec);
976 if (err < 0)
977 goto error;
978
979 codec->patch_ops = cs421x_patch_ops;
980 return 0;
981
982 error:
983 cs_free(codec);
984 return err;
985}
986
987
988
989
990
991static const struct hda_codec_preset snd_hda_preset_cirrus[] = {
992 { .id = 0x10134206, .name = "CS4206", .patch = patch_cs420x },
993 { .id = 0x10134207, .name = "CS4207", .patch = patch_cs420x },
994 { .id = 0x10134210, .name = "CS4210", .patch = patch_cs4210 },
995 { .id = 0x10134213, .name = "CS4213", .patch = patch_cs4213 },
996 {}
997};
998
999MODULE_ALIAS("snd-hda-codec-id:10134206");
1000MODULE_ALIAS("snd-hda-codec-id:10134207");
1001MODULE_ALIAS("snd-hda-codec-id:10134210");
1002MODULE_ALIAS("snd-hda-codec-id:10134213");
1003
1004MODULE_LICENSE("GPL");
1005MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
1006
1007static struct hda_codec_preset_list cirrus_list = {
1008 .preset = snd_hda_preset_cirrus,
1009 .owner = THIS_MODULE,
1010};
1011
1012static int __init patch_cirrus_init(void)
1013{
1014 return snd_hda_add_codec_preset(&cirrus_list);
1015}
1016
1017static void __exit patch_cirrus_exit(void)
1018{
1019 snd_hda_delete_codec_preset(&cirrus_list);
1020}
1021
1022module_init(patch_cirrus_init)
1023module_exit(patch_cirrus_exit)
1024