forked from respeaker/seeed-voicecard
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathac101.c
1984 lines (1690 loc) · 61.3 KB
/
ac101.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* ac101.c
* (C) Copyright 2017-2018
* Seeed Technology Co., Ltd. <www.seeedstudio.com>
*
* PeterYang <linsheng.yang@seeed.cc>
*
* (C) Copyright 2014-2017
* Reuuimlla Technology Co., Ltd. <www.reuuimllatech.com>
*
* huangxin <huangxin@Reuuimllatech.com>
* liushaohua <liushaohua@allwinnertech.com>
*
* X-Powers AC101 codec driver
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include <sound/initval.h>
#include <sound/tlv.h>
#include <linux/io.h>
#include <linux/regulator/consumer.h>
#include <linux/i2c.h>
#include <linux/irq.h>
#include <linux/workqueue.h>
#include <linux/clk.h>
#include <linux/regmap.h>
#include "ac101.h"
/*Default initialize configuration*/
#define SPEAKER_DOUBLE_USED 1
#define D_SPEAKER_VOL 0x1b
#define S_SPEAKER_VOL 0x19
#define HEADPHONE_VOL 0x3b
#define EARPIECE_VOL 0x1e
#define MAINMIC_GAIN 0x4
#define HDSETMIC_GAIN 0x4
#define DMIC_USED 0
#define ADC_DIGITAL_GAIN 0xb0b0
#define AGC_USED 0
#define DRC_USED 1
#define _MORE_WIDGETS 0
static bool speaker_double_used = false;
static int double_speaker_val = 0;
static int single_speaker_val = 0;
static int headset_val = 0;
static int earpiece_val = 0;
static int mainmic_val = 0;
static int headsetmic_val = 0;
static bool dmic_used = false;
static int adc_digital_val = 0;
static bool agc_used = false;
static bool drc_used = false;
#define ac10x_RATES (SNDRV_PCM_RATE_8000_96000|SNDRV_PCM_RATE_KNOT)
#define ac10x_FORMATS ( /*SNDRV_PCM_FMTBIT_S8 | \
SNDRV_PCM_FMTBIT_S16_LE | \
SNDRV_PCM_FMTBIT_S18_3LE | \
SNDRV_PCM_FMTBIT_S20_3LE | \
SNDRV_PCM_FMTBIT_S24_LE |*/ \
SNDRV_PCM_FMTBIT_S32_LE | \
0)
/*supply voltage*/
static const char *ac10x_supplies[] = {
"vcc-avcc",
"vcc-io1",
"vcc-io2",
"vcc-ldoin",
"vcc-cpvdd",
};
/*struct for ac10x*/
struct ac10x_priv {
struct snd_soc_codec *codec;
struct regmap* regmap;
unsigned sysclk;
struct mutex dac_mutex;
struct mutex adc_mutex;
u8 dac_enable;
u8 adc_enable;
struct mutex aifclk_mutex;
u8 aif1_clken;
u8 aif2_clken;
/*voltage supply*/
int num_supplies;
struct regulator_bulk_data *supplies;
struct work_struct codec_resume;
struct delayed_work dlywork;
int trgr_cnt;
};
void get_configuration(void)
{
speaker_double_used = SPEAKER_DOUBLE_USED;
double_speaker_val = D_SPEAKER_VOL;
single_speaker_val = S_SPEAKER_VOL;
headset_val = HEADPHONE_VOL;
earpiece_val = EARPIECE_VOL;
mainmic_val = MAINMIC_GAIN;
headsetmic_val = HDSETMIC_GAIN;
dmic_used = DMIC_USED;
if (dmic_used) {
adc_digital_val = ADC_DIGITAL_GAIN;
}
agc_used = AGC_USED;
drc_used = DRC_USED;
}
void agc_config(struct snd_soc_codec *codec)
{
int reg_val;
reg_val = snd_soc_read(codec, 0xb4);
reg_val |= (0x3<<6);
snd_soc_write(codec, 0xb4, reg_val);
reg_val = snd_soc_read(codec, 0x84);
reg_val &= ~(0x3f<<8);
reg_val |= (0x31<<8);
snd_soc_write(codec, 0x84, reg_val);
reg_val = snd_soc_read(codec, 0x84);
reg_val &= ~(0xff<<0);
reg_val |= (0x28<<0);
snd_soc_write(codec, 0x84, reg_val);
reg_val = snd_soc_read(codec, 0x85);
reg_val &= ~(0x3f<<8);
reg_val |= (0x31<<8);
snd_soc_write(codec, 0x85, reg_val);
reg_val = snd_soc_read(codec, 0x85);
reg_val &= ~(0xff<<0);
reg_val |= (0x28<<0);
snd_soc_write(codec, 0x85, reg_val);
reg_val = snd_soc_read(codec, 0x8a);
reg_val &= ~(0x7fff<<0);
reg_val |= (0x24<<0);
snd_soc_write(codec, 0x8a, reg_val);
reg_val = snd_soc_read(codec, 0x8b);
reg_val &= ~(0x7fff<<0);
reg_val |= (0x2<<0);
snd_soc_write(codec, 0x8b, reg_val);
reg_val = snd_soc_read(codec, 0x8c);
reg_val &= ~(0x7fff<<0);
reg_val |= (0x24<<0);
snd_soc_write(codec, 0x8c, reg_val);
reg_val = snd_soc_read(codec, 0x8d);
reg_val &= ~(0x7fff<<0);
reg_val |= (0x2<<0);
snd_soc_write(codec, 0x8d, reg_val);
reg_val = snd_soc_read(codec, 0x8e);
reg_val &= ~(0x1f<<8);
reg_val |= (0xf<<8);
reg_val &= ~(0x1f<<0);
reg_val |= (0xf<<0);
snd_soc_write(codec, 0x8e, reg_val);
reg_val = snd_soc_read(codec, 0x93);
reg_val &= ~(0x7ff<<0);
reg_val |= (0xfc<<0);
snd_soc_write(codec, 0x93, reg_val);
snd_soc_write(codec, 0x94, 0xabb3);
}
void drc_config(struct snd_soc_codec *codec)
{
int reg_val;
reg_val = snd_soc_read(codec, 0xa3);
reg_val &= ~(0x7ff<<0);
reg_val |= 1<<0;
snd_soc_write(codec, 0xa3, reg_val);
snd_soc_write(codec, 0xa4, 0x2baf);
reg_val = snd_soc_read(codec, 0xa5);
reg_val &= ~(0x7ff<<0);
reg_val |= 1<<0;
snd_soc_write(codec, 0xa5, reg_val);
snd_soc_write(codec, 0xa6, 0x2baf);
reg_val = snd_soc_read(codec, 0xa7);
reg_val &= ~(0x7ff<<0);
snd_soc_write(codec, 0xa7, reg_val);
snd_soc_write(codec, 0xa8, 0x44a);
reg_val = snd_soc_read(codec, 0xa9);
reg_val &= ~(0x7ff<<0);
snd_soc_write(codec, 0xa9, reg_val);
snd_soc_write(codec, 0xaa, 0x1e06);
reg_val = snd_soc_read(codec, 0xab);
reg_val &= ~(0x7ff<<0);
reg_val |= (0x352<<0);
snd_soc_write(codec, 0xab, reg_val);
snd_soc_write(codec, 0xac, 0x6910);
reg_val = snd_soc_read(codec, 0xad);
reg_val &= ~(0x7ff<<0);
reg_val |= (0x77a<<0);
snd_soc_write(codec, 0xad, reg_val);
snd_soc_write(codec, 0xae, 0xaaaa);
reg_val = snd_soc_read(codec, 0xaf);
reg_val &= ~(0x7ff<<0);
reg_val |= (0x2de<<0);
snd_soc_write(codec, 0xaf, reg_val);
snd_soc_write(codec, 0xb0, 0xc982);
snd_soc_write(codec, 0x16, 0x9f9f);
}
void agc_enable(struct snd_soc_codec *codec,bool on)
{
int reg_val;
if (on) {
reg_val = snd_soc_read(codec, MOD_CLK_ENA);
reg_val |= (0x1<<7);
snd_soc_write(codec, MOD_CLK_ENA, reg_val);
reg_val = snd_soc_read(codec, MOD_RST_CTRL);
reg_val |= (0x1<<7);
snd_soc_write(codec, MOD_RST_CTRL, reg_val);
reg_val = snd_soc_read(codec, 0x82);
reg_val &= ~(0xf<<0);
reg_val |= (0x6<<0);
reg_val &= ~(0x7<<12);
reg_val |= (0x7<<12);
snd_soc_write(codec, 0x82, reg_val);
reg_val = snd_soc_read(codec, 0x83);
reg_val &= ~(0xf<<0);
reg_val |= (0x6<<0);
reg_val &= ~(0x7<<12);
reg_val |= (0x7<<12);
snd_soc_write(codec, 0x83, reg_val);
} else {
reg_val = snd_soc_read(codec, MOD_CLK_ENA);
reg_val &= ~(0x1<<7);
snd_soc_write(codec, MOD_CLK_ENA, reg_val);
reg_val = snd_soc_read(codec, MOD_RST_CTRL);
reg_val &= ~(0x1<<7);
snd_soc_write(codec, MOD_RST_CTRL, reg_val);
reg_val = snd_soc_read(codec, 0x82);
reg_val &= ~(0xf<<0);
reg_val &= ~(0x7<<12);
snd_soc_write(codec, 0x82, reg_val);
reg_val = snd_soc_read(codec, 0x83);
reg_val &= ~(0xf<<0);
reg_val &= ~(0x7<<12);
snd_soc_write(codec, 0x83, reg_val);
}
}
void drc_enable(struct snd_soc_codec *codec,bool on)
{
int reg_val;
if (on) {
snd_soc_write(codec, 0xb5, 0xA080);
reg_val = snd_soc_read(codec, MOD_CLK_ENA);
reg_val |= (0x1<<6);
snd_soc_write(codec, MOD_CLK_ENA, reg_val);
reg_val = snd_soc_read(codec, MOD_RST_CTRL);
reg_val |= (0x1<<6);
snd_soc_write(codec, MOD_RST_CTRL, reg_val);
reg_val = snd_soc_read(codec, 0xa0);
reg_val |= (0x7<<0);
snd_soc_write(codec, 0xa0, reg_val);
} else {
snd_soc_write(codec, 0xb5, 0x0);
reg_val = snd_soc_read(codec, MOD_CLK_ENA);
reg_val &= ~(0x1<<6);
snd_soc_write(codec, MOD_CLK_ENA, reg_val);
reg_val = snd_soc_read(codec, MOD_RST_CTRL);
reg_val &= ~(0x1<<6);
snd_soc_write(codec, MOD_RST_CTRL, reg_val);
reg_val = snd_soc_read(codec, 0xa0);
reg_val &= ~(0x7<<0);
snd_soc_write(codec, 0xa0, reg_val);
}
}
void set_configuration(struct snd_soc_codec *codec)
{
if (speaker_double_used) {
snd_soc_update_bits(codec, SPKOUT_CTRL, (0x1f<<SPK_VOL), (double_speaker_val<<SPK_VOL));
} else {
snd_soc_update_bits(codec, SPKOUT_CTRL, (0x1f<<SPK_VOL), (single_speaker_val<<SPK_VOL));
}
snd_soc_update_bits(codec, HPOUT_CTRL, (0x3f<<HP_VOL), (headset_val<<HP_VOL));
//snd_soc_update_bits(codec, ESPKOUT_CTRL, (0x1f<<ESP_VOL), (earpiece_val<<ESP_VOL));
snd_soc_update_bits(codec, ADC_SRCBST_CTRL, (0x7<<ADC_MIC1G), (mainmic_val<<ADC_MIC1G));
snd_soc_update_bits(codec, ADC_SRCBST_CTRL, (0x7<<ADC_MIC2G), (headsetmic_val<<ADC_MIC2G));
if (dmic_used) {
snd_soc_write(codec, ADC_VOL_CTRL, adc_digital_val);
}
if (agc_used) {
agc_config(codec);
}
if (drc_used) {
drc_config(codec);
}
/*headphone calibration clock frequency select*/
snd_soc_update_bits(codec, SPKOUT_CTRL, (0x7<<HPCALICKS), (0x7<<HPCALICKS));
#if ! _MORE_WIDGETS
/* I2S1 DAC Timeslot 0 data <- I2S1 DAC channel 0 */
// "AIF1IN0L Mux" <= "AIF1DACL"
// "AIF1IN0R Mux" <= "AIF1DACR"
snd_soc_update_bits(codec, AIF1_DACDAT_CTRL, 0x3 << AIF1_DA0L_SRC, 0x0 << AIF1_DA0L_SRC);
snd_soc_update_bits(codec, AIF1_DACDAT_CTRL, 0x3 << AIF1_DA0R_SRC, 0x0 << AIF1_DA0R_SRC);
/* Timeslot 0 Left & Right Channel enable */
snd_soc_update_bits(codec, AIF1_DACDAT_CTRL, 0x3 << AIF1_DA0R_ENA, 0x3 << AIF1_DA0R_ENA);
/* DAC Digital Mixer Source Select <- I2S1 DA0 */
// "DACL Mixer" += "AIF1IN0L Mux"
// "DACR Mixer" += "AIF1IN0R Mux"
snd_soc_update_bits(codec, DAC_MXR_SRC, 0xF << DACL_MXR_ADCL, 0x8 << DACL_MXR_ADCL);
snd_soc_update_bits(codec, DAC_MXR_SRC, 0xF << DACR_MXR_ADCR, 0x8 << DACR_MXR_ADCR);
/* Internal DAC Analog Left & Right Channel enable */
snd_soc_update_bits(codec, OMIXER_DACA_CTRL, 0x3 << DACALEN, 0x3 << DACALEN);
/* Output Mixer Source Select */
// "Left Output Mixer" += "DACL Mixer"
// "Right Output Mixer" += "DACR Mixer"
snd_soc_update_bits(codec, OMIXER_SR, 0x1 << LMIXMUTEDACL, 0x1 << LMIXMUTEDACL);
snd_soc_update_bits(codec, OMIXER_SR, 0x1 << RMIXMUTEDACR, 0x1 << RMIXMUTEDACR);
/* Left & Right Analog Output Mixer enable */
snd_soc_update_bits(codec, OMIXER_DACA_CTRL, 0x3 << LMIXEN, 0x3 << LMIXEN);
/* Headphone Ouput Control */
// "HP_R Mux" <= "DACR Mixer"
// "HP_L Mux" <= "DACL Mixer"
snd_soc_update_bits(codec, HPOUT_CTRL, 0x1 << LHPS, 0x0 << LHPS);
snd_soc_update_bits(codec, HPOUT_CTRL, 0x1 << RHPS, 0x0 << RHPS);
/* Speaker Output Control */
// "SPK_L Mux" <= "SPK_LR Adder"
// "SPK_R Mux" <= "SPK_LR Adder"
snd_soc_update_bits(codec, SPKOUT_CTRL, (0x1 << LSPKS) | (0x1 << RSPKS), (0x1 << LSPKS) | (0x1 << RSPKS));
/* Enable Left & Right Speaker */
snd_soc_update_bits(codec, SPKOUT_CTRL, (0x1 << LSPK_EN) | (0x1 << RSPK_EN), (0x1 << LSPK_EN) | (0x1 << RSPK_EN));
#endif
}
#if _MORE_WIDGETS
static int late_enable_dac(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
{
struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
#else
static int late_enable_dac(struct snd_soc_codec* codec, int event) {
#endif
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
mutex_lock(&ac10x->dac_mutex);
switch (event) {
case SND_SOC_DAPM_PRE_PMU:
AC10X_DBG("%s,line:%d\n",__func__,__LINE__);
if (ac10x->dac_enable == 0){
/*enable dac module clk*/
snd_soc_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_DAC_DIG), (0x1<<MOD_CLK_DAC_DIG));
snd_soc_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_DAC_DIG), (0x1<<MOD_RESET_DAC_DIG));
snd_soc_update_bits(codec, DAC_DIG_CTRL, (0x1<<ENDA), (0x1<<ENDA));
snd_soc_update_bits(codec, DAC_DIG_CTRL, (0x1<<ENHPF),(0x1<<ENHPF));
}
ac10x->dac_enable++;
break;
case SND_SOC_DAPM_POST_PMD:
if (ac10x->dac_enable > 0){
ac10x->dac_enable--;
if (ac10x->dac_enable == 0){
snd_soc_update_bits(codec, DAC_DIG_CTRL, (0x1<<ENHPF),(0x0<<ENHPF));
snd_soc_update_bits(codec, DAC_DIG_CTRL, (0x1<<ENDA), (0x0<<ENDA));
/*disable dac module clk*/
snd_soc_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_DAC_DIG), (0x0<<MOD_CLK_DAC_DIG));
snd_soc_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_DAC_DIG), (0x0<<MOD_RESET_DAC_DIG));
}
}
break;
}
mutex_unlock(&ac10x->dac_mutex);
return 0;
}
#if _MORE_WIDGETS
static int late_enable_adc(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
{
struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
mutex_lock(&ac10x->adc_mutex);
switch (event) {
case SND_SOC_DAPM_PRE_PMU:
if (ac10x->adc_enable == 0){
/*enable adc module clk*/
snd_soc_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_ADC_DIG), (0x1<<MOD_CLK_ADC_DIG));
snd_soc_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_ADC_DIG), (0x1<<MOD_RESET_ADC_DIG));
snd_soc_update_bits(codec, ADC_DIG_CTRL, (0x1<<ENAD), (0x1<<ENAD));
}
ac10x->adc_enable++;
break;
case SND_SOC_DAPM_POST_PMD:
if (ac10x->adc_enable > 0){
ac10x->adc_enable--;
if (ac10x->adc_enable == 0){
snd_soc_update_bits(codec, ADC_DIG_CTRL, (0x1<<ENAD), (0x0<<ENAD));
/*disable adc module clk*/
snd_soc_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_ADC_DIG), (0x0<<MOD_CLK_ADC_DIG));
snd_soc_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_ADC_DIG), (0x0<<MOD_RESET_ADC_DIG));
}
}
break;
}
mutex_unlock(&ac10x->adc_mutex);
return 0;
}
static int ac10x_speaker_event(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *k,
int event)
{
struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
switch (event) {
case SND_SOC_DAPM_POST_PMU:
AC10X_DBG("[speaker open ]%s,line:%d\n",__func__,__LINE__);
if (drc_used) {
drc_enable(codec,1);
}
break;
case SND_SOC_DAPM_PRE_PMD :
AC10X_DBG("[speaker close ]%s,line:%d\n",__func__,__LINE__);
if (drc_used) {
drc_enable(codec,0);
}
default:
break;
}
return 0;
}
static int ac10x_headphone_event(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *k, int event)
{
struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
#else
static int ac10x_headphone_event(struct snd_soc_codec* codec, int event) {
#endif
switch (event) {
case SND_SOC_DAPM_POST_PMU:
/*open*/
AC10X_DBG("post:open:%s,line:%d\n", __func__, __LINE__);
snd_soc_update_bits(codec, OMIXER_DACA_CTRL, (0xf<<HPOUTPUTENABLE), (0xf<<HPOUTPUTENABLE));
snd_soc_update_bits(codec, HPOUT_CTRL, (0x1<<HPPA_EN), (0x1<<HPPA_EN));
msleep(10);
snd_soc_update_bits(codec, HPOUT_CTRL, (0x3<<LHPPA_MUTE), (0x3<<LHPPA_MUTE));
break;
case SND_SOC_DAPM_PRE_PMD:
/*close*/
AC10X_DBG("pre:close:%s,line:%d\n", __func__, __LINE__);
snd_soc_update_bits(codec, HPOUT_CTRL, (0x1<<HPPA_EN), (0x0<<HPPA_EN));
snd_soc_update_bits(codec, OMIXER_DACA_CTRL, (0xf<<HPOUTPUTENABLE), (0x0<<HPOUTPUTENABLE));
snd_soc_update_bits(codec, HPOUT_CTRL, (0x3<<LHPPA_MUTE), (0x0<<LHPPA_MUTE));
break;
}
return 0;
}
#if _MORE_WIDGETS
int ac10x_aif1clk(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
{
struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
#else
static int ac10x_aif1clk(struct snd_soc_codec* codec, int event) {
#endif
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
AC10X_DBG("%s() L%d event=%d pre_up/%d post_down/%d\n", __func__, __LINE__,
event, SND_SOC_DAPM_PRE_PMU, SND_SOC_DAPM_POST_PMD);
mutex_lock(&ac10x->aifclk_mutex);
switch (event) {
case SND_SOC_DAPM_PRE_PMU:
if (ac10x->aif1_clken == 0){
/*enable AIF1CLK*/
snd_soc_update_bits(codec, SYSCLK_CTRL, (0x1<<AIF1CLK_ENA), (0x1<<AIF1CLK_ENA));
snd_soc_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_AIF1), (0x1<<MOD_CLK_AIF1));
snd_soc_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_AIF1), (0x1<<MOD_RESET_AIF1));
/*enable systemclk*/
if (ac10x->aif2_clken == 0)
snd_soc_update_bits(codec, SYSCLK_CTRL, (0x1<<SYSCLK_ENA), (0x1<<SYSCLK_ENA));
}
ac10x->aif1_clken++;
break;
case SND_SOC_DAPM_POST_PMD:
if (ac10x->aif1_clken > 0){
ac10x->aif1_clken--;
if (ac10x->aif1_clken == 0){
/*disable AIF1CLK*/
snd_soc_update_bits(codec, SYSCLK_CTRL, (0x1<<AIF1CLK_ENA), (0x0<<AIF1CLK_ENA));
snd_soc_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_AIF1), (0x0<<MOD_CLK_AIF1));
snd_soc_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_AIF1), (0x0<<MOD_RESET_AIF1));
/*DISABLE systemclk*/
if (ac10x->aif2_clken == 0)
snd_soc_update_bits(codec, SYSCLK_CTRL, (0x1<<SYSCLK_ENA), (0x0<<SYSCLK_ENA));
}
}
break;
}
mutex_unlock(&ac10x->aifclk_mutex);
return 0;
}
#if _MORE_WIDGETS
static int dmic_mux_ev(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
{
struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
switch (event){
case SND_SOC_DAPM_PRE_PMU:
snd_soc_update_bits(codec, ADC_DIG_CTRL, (0x1<<ENDM), (0x1<<ENDM));
break;
case SND_SOC_DAPM_POST_PMD:
snd_soc_update_bits(codec, ADC_DIG_CTRL, (0x1<<ENDM), (0x0<<ENDM));
break;
}
mutex_lock(&ac10x->adc_mutex);
switch (event) {
case SND_SOC_DAPM_PRE_PMU:
if (ac10x->adc_enable == 0){
/*enable adc module clk*/
snd_soc_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_ADC_DIG), (0x1<<MOD_CLK_ADC_DIG));
snd_soc_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_ADC_DIG), (0x1<<MOD_RESET_ADC_DIG));
snd_soc_update_bits(codec, ADC_DIG_CTRL, (0x1<<ENAD), (0x1<<ENAD));
}
ac10x->adc_enable++;
break;
case SND_SOC_DAPM_POST_PMD:
if (ac10x->adc_enable > 0){
ac10x->adc_enable--;
if (ac10x->adc_enable == 0){
snd_soc_update_bits(codec, ADC_DIG_CTRL, (0x1<<ENAD), (0x0<<ENAD));
/*disable adc module clk*/
snd_soc_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_ADC_DIG), (0x0<<MOD_CLK_ADC_DIG));
snd_soc_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_ADC_DIG), (0x0<<MOD_RESET_ADC_DIG));
}
}
break;
}
mutex_unlock(&ac10x->adc_mutex);
return 0;
}
static const DECLARE_TLV_DB_SCALE(headphone_vol_tlv, -6300, 100, 0);
static const DECLARE_TLV_DB_SCALE(speaker_vol_tlv, -4800, 150, 0);
static const DECLARE_TLV_DB_SCALE(aif1_ad_slot0_vol_tlv, -11925, 75, 0);
static const DECLARE_TLV_DB_SCALE(aif1_ad_slot1_vol_tlv, -11925, 75, 0);
static const DECLARE_TLV_DB_SCALE(aif1_da_slot0_vol_tlv, -11925, 75, 0);
static const DECLARE_TLV_DB_SCALE(aif1_da_slot1_vol_tlv, -11925, 75, 0);
static const DECLARE_TLV_DB_SCALE(aif1_ad_slot0_mix_vol_tlv, -600, 600, 0);
static const DECLARE_TLV_DB_SCALE(aif1_ad_slot1_mix_vol_tlv, -600, 600, 0);
static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -11925, 75, 0);
static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -11925, 75, 0);
static const DECLARE_TLV_DB_SCALE(dig_vol_tlv, -7308, 116, 0);
static const DECLARE_TLV_DB_SCALE(dac_mix_vol_tlv, -600, 600, 0);
static const DECLARE_TLV_DB_SCALE(adc_input_vol_tlv, -450, 150, 0);
/*mic1/mic2: 0db when 000, and from 30db to 48db when 001 to 111*/
static const DECLARE_TLV_DB_SCALE(mic1_boost_vol_tlv, 0, 200, 0);
static const DECLARE_TLV_DB_SCALE(mic2_boost_vol_tlv, 0, 200, 0);
static const DECLARE_TLV_DB_SCALE(linein_amp_vol_tlv, -1200, 300, 0);
static const DECLARE_TLV_DB_SCALE(axin_to_l_r_mix_vol_tlv, -450, 150, 0);
static const DECLARE_TLV_DB_SCALE(mic1_to_l_r_mix_vol_tlv, -450, 150, 0);
static const DECLARE_TLV_DB_SCALE(mic2_to_l_r_mix_vol_tlv, -450, 150, 0);
static const DECLARE_TLV_DB_SCALE(linein_to_l_r_mix_vol_tlv, -450, 150, 0);
static const struct snd_kcontrol_new ac10x_controls[] = {
/*AIF1*/
SOC_DOUBLE_TLV("AIF1 ADC timeslot 0 volume", AIF1_VOL_CTRL1, AIF1_AD0L_VOL, AIF1_AD0R_VOL, 0xff, 0, aif1_ad_slot0_vol_tlv),
SOC_DOUBLE_TLV("AIF1 ADC timeslot 1 volume", AIF1_VOL_CTRL2, AIF1_AD1L_VOL, AIF1_AD1R_VOL, 0xff, 0, aif1_ad_slot1_vol_tlv),
SOC_DOUBLE_TLV("AIF1 DAC timeslot 0 volume", AIF1_VOL_CTRL3, AIF1_DA0L_VOL, AIF1_DA0R_VOL, 0xff, 0, aif1_da_slot0_vol_tlv),
SOC_DOUBLE_TLV("AIF1 DAC timeslot 1 volume", AIF1_VOL_CTRL4, AIF1_DA1L_VOL, AIF1_DA1R_VOL, 0xff, 0, aif1_da_slot1_vol_tlv),
SOC_DOUBLE_TLV("AIF1 ADC timeslot 0 mixer gain", AIF1_MXR_GAIN, AIF1_AD0L_MXR_GAIN, AIF1_AD0R_MXR_GAIN, 0xf, 0, aif1_ad_slot0_mix_vol_tlv),
SOC_DOUBLE_TLV("AIF1 ADC timeslot 1 mixer gain", AIF1_MXR_GAIN, AIF1_AD1L_MXR_GAIN, AIF1_AD1R_MXR_GAIN, 0x3, 0, aif1_ad_slot1_mix_vol_tlv),
/*ADC*/
SOC_DOUBLE_TLV("ADC volume", ADC_VOL_CTRL, ADC_VOL_L, ADC_VOL_R, 0xff, 0, adc_vol_tlv),
/*DAC*/
SOC_DOUBLE_TLV("DAC volume", DAC_VOL_CTRL, DAC_VOL_L, DAC_VOL_R, 0xff, 0, dac_vol_tlv),
SOC_DOUBLE_TLV("DAC mixer gain", DAC_MXR_GAIN, DACL_MXR_GAIN, DACR_MXR_GAIN, 0xf, 0, dac_mix_vol_tlv),
SOC_SINGLE_TLV("digital volume", DAC_DBG_CTRL, DVC, 0x3f, 1, dig_vol_tlv),
/*ADC*/
SOC_DOUBLE_TLV("ADC input gain", ADC_APC_CTRL, ADCLG, ADCRG, 0x7, 0, adc_input_vol_tlv),
SOC_SINGLE_TLV("MIC1 boost amplifier gain", ADC_SRCBST_CTRL, ADC_MIC1G, 0x7, 0, mic1_boost_vol_tlv),
SOC_SINGLE_TLV("MIC2 boost amplifier gain", ADC_SRCBST_CTRL, ADC_MIC2G, 0x7, 0, mic2_boost_vol_tlv),
SOC_SINGLE_TLV("LINEINL-LINEINR pre-amplifier gain", ADC_SRCBST_CTRL, LINEIN_PREG, 0x7, 0, linein_amp_vol_tlv),
SOC_SINGLE_TLV("MIC1 BST stage to L_R outp mixer gain", OMIXER_BST1_CTRL, OMIXER_MIC1G, 0x7, 0, mic1_to_l_r_mix_vol_tlv),
SOC_SINGLE_TLV("MIC2 BST stage to L_R outp mixer gain", OMIXER_BST1_CTRL, OMIXER_MIC2G, 0x7, 0, mic2_to_l_r_mix_vol_tlv),
SOC_SINGLE_TLV("LINEINL/R to L_R output mixer gain", OMIXER_BST1_CTRL, LINEING, 0x7, 0, linein_to_l_r_mix_vol_tlv),
SOC_SINGLE_TLV("speaker volume", SPKOUT_CTRL, SPK_VOL, 0x1f, 0, speaker_vol_tlv),
SOC_SINGLE_TLV("headphone volume", HPOUT_CTRL, HP_VOL, 0x3f, 0, headphone_vol_tlv),
};
/*AIF1 AD0 OUT */
static const char *aif1out0l_text[] = {
"AIF1_AD0L", "AIF1_AD0R","SUM_AIF1AD0L_AIF1AD0R", "AVE_AIF1AD0L_AIF1AD0R"
};
static const char *aif1out0r_text[] = {
"AIF1_AD0R", "AIF1_AD0L","SUM_AIF1AD0L_AIF1AD0R", "AVE_AIF1AD0L_AIF1AD0R"
};
static const struct soc_enum aif1out0l_enum =
SOC_ENUM_SINGLE(AIF1_ADCDAT_CTRL, 10, 4, aif1out0l_text);
static const struct snd_kcontrol_new aif1out0l_mux =
SOC_DAPM_ENUM("AIF1OUT0L Mux", aif1out0l_enum);
static const struct soc_enum aif1out0r_enum =
SOC_ENUM_SINGLE(AIF1_ADCDAT_CTRL, 8, 4, aif1out0r_text);
static const struct snd_kcontrol_new aif1out0r_mux =
SOC_DAPM_ENUM("AIF1OUT0R Mux", aif1out0r_enum);
/*AIF1 AD1 OUT */
static const char *aif1out1l_text[] = {
"AIF1_AD1L", "AIF1_AD1R","SUM_AIF1ADC1L_AIF1ADC1R", "AVE_AIF1ADC1L_AIF1ADC1R"
};
static const char *aif1out1r_text[] = {
"AIF1_AD1R", "AIF1_AD1L","SUM_AIF1ADC1L_AIF1ADC1R", "AVE_AIF1ADC1L_AIF1ADC1R"
};
static const struct soc_enum aif1out1l_enum =
SOC_ENUM_SINGLE(AIF1_ADCDAT_CTRL, 6, 4, aif1out1l_text);
static const struct snd_kcontrol_new aif1out1l_mux =
SOC_DAPM_ENUM("AIF1OUT1L Mux", aif1out1l_enum);
static const struct soc_enum aif1out1r_enum =
SOC_ENUM_SINGLE(AIF1_ADCDAT_CTRL, 4, 4, aif1out1r_text);
static const struct snd_kcontrol_new aif1out1r_mux =
SOC_DAPM_ENUM("AIF1OUT1R Mux", aif1out1r_enum);
/*AIF1 DA0 IN*/
static const char *aif1in0l_text[] = {
"AIF1_DA0L", "AIF1_DA0R", "SUM_AIF1DA0L_AIF1DA0R", "AVE_AIF1DA0L_AIF1DA0R"
};
static const char *aif1in0r_text[] = {
"AIF1_DA0R", "AIF1_DA0L", "SUM_AIF1DA0L_AIF1DA0R", "AVE_AIF1DA0L_AIF1DA0R"
};
static const struct soc_enum aif1in0l_enum =
SOC_ENUM_SINGLE(AIF1_DACDAT_CTRL, 10, 4, aif1in0l_text);
static const struct snd_kcontrol_new aif1in0l_mux =
SOC_DAPM_ENUM("AIF1IN0L Mux", aif1in0l_enum);
static const struct soc_enum aif1in0r_enum =
SOC_ENUM_SINGLE(AIF1_DACDAT_CTRL, 8, 4, aif1in0r_text);
static const struct snd_kcontrol_new aif1in0r_mux =
SOC_DAPM_ENUM("AIF1IN0R Mux", aif1in0r_enum);
/*AIF1 DA1 IN*/
static const char *aif1in1l_text[] = {
"AIF1_DA1L", "AIF1_DA1R","SUM_AIF1DA1L_AIF1DA1R", "AVE_AIF1DA1L_AIF1DA1R"
};
static const char *aif1in1r_text[] = {
"AIF1_DA1R", "AIF1_DA1L","SUM_AIF1DA1L_AIF1DA1R", "AVE_AIF1DA1L_AIF1DA1R"
};
static const struct soc_enum aif1in1l_enum =
SOC_ENUM_SINGLE(AIF1_DACDAT_CTRL, 6, 4, aif1in1l_text);
static const struct snd_kcontrol_new aif1in1l_mux =
SOC_DAPM_ENUM("AIF1IN1L Mux", aif1in1l_enum);
static const struct soc_enum aif1in1r_enum =
SOC_ENUM_SINGLE(AIF1_DACDAT_CTRL, 4, 4, aif1in1r_text);
static const struct snd_kcontrol_new aif1in1r_mux =
SOC_DAPM_ENUM("AIF1IN1R Mux", aif1in1r_enum);
/*0x13register*/
/*AIF1 ADC0 MIXER SOURCE*/
static const struct snd_kcontrol_new aif1_ad0l_mxr_src_ctl[] = {
SOC_DAPM_SINGLE("AIF1 DA0L Switch", AIF1_MXR_SRC, AIF1_AD0L_AIF1_DA0L_MXR, 1, 0),
SOC_DAPM_SINGLE("ADCL Switch", AIF1_MXR_SRC, AIF1_AD0L_ADCL_MXR, 1, 0),
};
static const struct snd_kcontrol_new aif1_ad0r_mxr_src_ctl[] = {
SOC_DAPM_SINGLE("AIF1 DA0R Switch", AIF1_MXR_SRC, AIF1_AD0R_AIF1_DA0R_MXR, 1, 0),
SOC_DAPM_SINGLE("ADCR Switch", AIF1_MXR_SRC, AIF1_AD0R_ADCR_MXR, 1, 0),
};
/*AIF1 ADC1 MIXER SOURCE*/
static const struct snd_kcontrol_new aif1_ad1l_mxr_src_ctl[] = {
SOC_DAPM_SINGLE("ADCL Switch", AIF1_MXR_SRC, AIF1_AD1L_ADCL_MXR, 1, 0),
};
static const struct snd_kcontrol_new aif1_ad1r_mxr_src_ctl[] = {
SOC_DAPM_SINGLE("ADCR Switch", AIF1_MXR_SRC, AIF1_AD1R_ADCR_MXR, 1, 0),
};
/*4C register*/
static const struct snd_kcontrol_new dacl_mxr_src_controls[] = {
SOC_DAPM_SINGLE("ADCL Switch", DAC_MXR_SRC, DACL_MXR_ADCL, 1, 0),
SOC_DAPM_SINGLE("AIF1DA1L Switch", DAC_MXR_SRC, DACL_MXR_AIF1_DA1L, 1, 0),
SOC_DAPM_SINGLE("AIF1DA0L Switch", DAC_MXR_SRC, DACL_MXR_AIF1_DA0L, 1, 0),
};
static const struct snd_kcontrol_new dacr_mxr_src_controls[] = {
SOC_DAPM_SINGLE("ADCR Switch", DAC_MXR_SRC, DACR_MXR_ADCR, 1, 0),
SOC_DAPM_SINGLE("AIF1DA1R Switch", DAC_MXR_SRC, DACR_MXR_AIF1_DA1R, 1, 0),
SOC_DAPM_SINGLE("AIF1DA0R Switch", DAC_MXR_SRC, DACR_MXR_AIF1_DA0R, 1, 0),
};
/*** output mixer source select ***/
/*defined left output mixer*/
static const struct snd_kcontrol_new ac10x_loutmix_controls[] = {
SOC_DAPM_SINGLE("DACR Switch", OMIXER_SR, LMIXMUTEDACR, 1, 0),
SOC_DAPM_SINGLE("DACL Switch", OMIXER_SR, LMIXMUTEDACL, 1, 0),
SOC_DAPM_SINGLE("LINEINL Switch", OMIXER_SR, LMIXMUTELINEINL, 1, 0),
SOC_DAPM_SINGLE("LINEINL-LINEINR Switch", OMIXER_SR, LMIXMUTELINEINLR, 1, 0),
SOC_DAPM_SINGLE("MIC2Booststage Switch", OMIXER_SR, LMIXMUTEMIC2BOOST, 1, 0),
SOC_DAPM_SINGLE("MIC1Booststage Switch", OMIXER_SR, LMIXMUTEMIC1BOOST, 1, 0),
};
/*defined right output mixer*/
static const struct snd_kcontrol_new ac10x_routmix_controls[] = {
SOC_DAPM_SINGLE("DACL Switch", OMIXER_SR, RMIXMUTEDACL, 1, 0),
SOC_DAPM_SINGLE("DACR Switch", OMIXER_SR, RMIXMUTEDACR, 1, 0),
SOC_DAPM_SINGLE("LINEINR Switch", OMIXER_SR, RMIXMUTELINEINR, 1, 0),
SOC_DAPM_SINGLE("LINEINL-LINEINR Switch", OMIXER_SR, RMIXMUTELINEINLR, 1, 0),
SOC_DAPM_SINGLE("MIC2Booststage Switch", OMIXER_SR, RMIXMUTEMIC2BOOST, 1, 0),
SOC_DAPM_SINGLE("MIC1Booststage Switch", OMIXER_SR, RMIXMUTEMIC1BOOST, 1, 0),
};
/*** hp source select ***/
/*headphone input source*/
static const char *ac10x_hp_r_func_sel[] = {
"DACR HPR Switch", "Right Analog Mixer HPR Switch"};
static const struct soc_enum ac10x_hp_r_func_enum =
SOC_ENUM_SINGLE(HPOUT_CTRL, RHPS, 2, ac10x_hp_r_func_sel);
static const struct snd_kcontrol_new ac10x_hp_r_func_controls =
SOC_DAPM_ENUM("HP_R Mux", ac10x_hp_r_func_enum);
static const char *ac10x_hp_l_func_sel[] = {
"DACL HPL Switch", "Left Analog Mixer HPL Switch"};
static const struct soc_enum ac10x_hp_l_func_enum =
SOC_ENUM_SINGLE(HPOUT_CTRL, LHPS, 2, ac10x_hp_l_func_sel);
static const struct snd_kcontrol_new ac10x_hp_l_func_controls =
SOC_DAPM_ENUM("HP_L Mux", ac10x_hp_l_func_enum);
/*spk source select*/
static const char *ac10x_rspks_func_sel[] = {
"MIXER Switch", "MIXR MIXL Switch"};
static const struct soc_enum ac10x_rspks_func_enum =
SOC_ENUM_SINGLE(SPKOUT_CTRL, RSPKS, 2, ac10x_rspks_func_sel);
static const struct snd_kcontrol_new ac10x_rspks_func_controls =
SOC_DAPM_ENUM("SPK_R Mux", ac10x_rspks_func_enum);
static const char *ac10x_lspks_l_func_sel[] = {
"MIXEL Switch", "MIXL MIXR Switch"};
static const struct soc_enum ac10x_lspks_func_enum =
SOC_ENUM_SINGLE(SPKOUT_CTRL, LSPKS, 2, ac10x_lspks_l_func_sel);
static const struct snd_kcontrol_new ac10x_lspks_func_controls =
SOC_DAPM_ENUM("SPK_L Mux", ac10x_lspks_func_enum);
/*defined left input adc mixer*/
static const struct snd_kcontrol_new ac10x_ladcmix_controls[] = {
SOC_DAPM_SINGLE("MIC1 boost Switch", ADC_SRC, LADCMIXMUTEMIC1BOOST, 1, 0),
SOC_DAPM_SINGLE("MIC2 boost Switch", ADC_SRC, LADCMIXMUTEMIC2BOOST, 1, 0),
SOC_DAPM_SINGLE("LININL-R Switch", ADC_SRC, LADCMIXMUTELINEINLR, 1, 0),
SOC_DAPM_SINGLE("LINEINL Switch", ADC_SRC, LADCMIXMUTELINEINL, 1, 0),
SOC_DAPM_SINGLE("Lout_Mixer_Switch", ADC_SRC, LADCMIXMUTELOUTPUT, 1, 0),
SOC_DAPM_SINGLE("Rout_Mixer_Switch", ADC_SRC, LADCMIXMUTEROUTPUT, 1, 0),
};
/*defined right input adc mixer*/
static const struct snd_kcontrol_new ac10x_radcmix_controls[] = {
SOC_DAPM_SINGLE("MIC1 boost Switch", ADC_SRC, RADCMIXMUTEMIC1BOOST, 1, 0),
SOC_DAPM_SINGLE("MIC2 boost Switch", ADC_SRC, RADCMIXMUTEMIC2BOOST, 1, 0),
SOC_DAPM_SINGLE("LINEINL-R Switch", ADC_SRC, RADCMIXMUTELINEINLR, 1, 0),
SOC_DAPM_SINGLE("LINEINR Switch", ADC_SRC, RADCMIXMUTELINEINR, 1, 0),
SOC_DAPM_SINGLE("Rout_Mixer_Switch", ADC_SRC, RADCMIXMUTEROUTPUT, 1, 0),
SOC_DAPM_SINGLE("Lout_Mixer_Switch", ADC_SRC, RADCMIXMUTELOUTPUT, 1, 0),
};
/*mic2 source select*/
static const char *mic2src_text[] = {
"none","MIC2"};
static const struct soc_enum mic2src_enum =
SOC_ENUM_SINGLE(ADC_SRCBST_CTRL, 7, 2, mic2src_text);
static const struct snd_kcontrol_new mic2src_mux =
SOC_DAPM_ENUM("MIC2 SRC", mic2src_enum);
/*DMIC*/
static const char *adc_mux_text[] = {
"ADC",
"DMIC",
};
static SOC_ENUM_SINGLE_VIRT_DECL(adc_enum, adc_mux_text);
static const struct snd_kcontrol_new adcl_mux =
SOC_DAPM_ENUM("ADCL Mux", adc_enum);
static const struct snd_kcontrol_new adcr_mux =
SOC_DAPM_ENUM("ADCR Mux", adc_enum);
/*built widget*/
static const struct snd_soc_dapm_widget ac10x_dapm_widgets[] = {
SND_SOC_DAPM_MUX("AIF1OUT0L Mux", AIF1_ADCDAT_CTRL, 15, 0, &aif1out0l_mux),
SND_SOC_DAPM_MUX("AIF1OUT0R Mux", AIF1_ADCDAT_CTRL, 14, 0, &aif1out0r_mux),
SND_SOC_DAPM_MUX("AIF1OUT1L Mux", AIF1_ADCDAT_CTRL, 13, 0, &aif1out1l_mux),
SND_SOC_DAPM_MUX("AIF1OUT1R Mux", AIF1_ADCDAT_CTRL, 12, 0, &aif1out1r_mux),
SND_SOC_DAPM_MUX("AIF1IN0L Mux", AIF1_DACDAT_CTRL, 15, 0, &aif1in0l_mux),
SND_SOC_DAPM_MUX("AIF1IN0R Mux", AIF1_DACDAT_CTRL, 14, 0, &aif1in0r_mux),
SND_SOC_DAPM_MUX("AIF1IN1L Mux", AIF1_DACDAT_CTRL, 13, 0, &aif1in1l_mux),
SND_SOC_DAPM_MUX("AIF1IN1R Mux", AIF1_DACDAT_CTRL, 12, 0, &aif1in1r_mux),
SND_SOC_DAPM_MIXER("AIF1 AD0L Mixer", SND_SOC_NOPM, 0, 0, aif1_ad0l_mxr_src_ctl, ARRAY_SIZE(aif1_ad0l_mxr_src_ctl)),
SND_SOC_DAPM_MIXER("AIF1 AD0R Mixer", SND_SOC_NOPM, 0, 0, aif1_ad0r_mxr_src_ctl, ARRAY_SIZE(aif1_ad0r_mxr_src_ctl)),
SND_SOC_DAPM_MIXER("AIF1 AD1L Mixer", SND_SOC_NOPM, 0, 0, aif1_ad1l_mxr_src_ctl, ARRAY_SIZE(aif1_ad1l_mxr_src_ctl)),
SND_SOC_DAPM_MIXER("AIF1 AD1R Mixer", SND_SOC_NOPM, 0, 0, aif1_ad1r_mxr_src_ctl, ARRAY_SIZE(aif1_ad1r_mxr_src_ctl)),
SND_SOC_DAPM_MIXER_E("DACL Mixer", OMIXER_DACA_CTRL, DACALEN, 0, dacl_mxr_src_controls, ARRAY_SIZE(dacl_mxr_src_controls),
late_enable_dac, SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_MIXER_E("DACR Mixer", OMIXER_DACA_CTRL, DACAREN, 0, dacr_mxr_src_controls, ARRAY_SIZE(dacr_mxr_src_controls),
late_enable_dac, SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
/*dac digital enble*/
SND_SOC_DAPM_DAC("DAC En", NULL, DAC_DIG_CTRL, ENDA, 0),
/*ADC digital enble*/
SND_SOC_DAPM_ADC("ADC En", NULL, ADC_DIG_CTRL, ENAD, 0),
SND_SOC_DAPM_MIXER("Left Output Mixer", OMIXER_DACA_CTRL, LMIXEN, 0,
ac10x_loutmix_controls, ARRAY_SIZE(ac10x_loutmix_controls)),
SND_SOC_DAPM_MIXER("Right Output Mixer", OMIXER_DACA_CTRL, RMIXEN, 0,
ac10x_routmix_controls, ARRAY_SIZE(ac10x_routmix_controls)),
SND_SOC_DAPM_MUX("HP_R Mux", SND_SOC_NOPM, 0, 0, &ac10x_hp_r_func_controls),
SND_SOC_DAPM_MUX("HP_L Mux", SND_SOC_NOPM, 0, 0, &ac10x_hp_l_func_controls),
SND_SOC_DAPM_MUX("SPK_R Mux", SPKOUT_CTRL, RSPK_EN, 0, &ac10x_rspks_func_controls),
SND_SOC_DAPM_MUX("SPK_L Mux", SPKOUT_CTRL, LSPK_EN, 0, &ac10x_lspks_func_controls),
SND_SOC_DAPM_PGA("SPK_LR Adder", SND_SOC_NOPM, 0, 0, NULL, 0),
/*output widget*/
SND_SOC_DAPM_OUTPUT("HPOUTL"),
SND_SOC_DAPM_OUTPUT("HPOUTR"),
SND_SOC_DAPM_OUTPUT("SPK1P"),
SND_SOC_DAPM_OUTPUT("SPK2P"),
SND_SOC_DAPM_OUTPUT("SPK1N"),
SND_SOC_DAPM_OUTPUT("SPK2N"),
SND_SOC_DAPM_MIXER_E("LEFT ADC input Mixer", ADC_APC_CTRL, ADCLEN, 0,
ac10x_ladcmix_controls, ARRAY_SIZE(ac10x_ladcmix_controls),late_enable_adc, SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_MIXER_E("RIGHT ADC input Mixer", ADC_APC_CTRL, ADCREN, 0,
ac10x_radcmix_controls, ARRAY_SIZE(ac10x_radcmix_controls),late_enable_adc, SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
/*mic reference*/
SND_SOC_DAPM_PGA("MIC1 PGA", ADC_SRCBST_CTRL, MIC1AMPEN, 0, NULL, 0),
SND_SOC_DAPM_PGA("MIC2 PGA", ADC_SRCBST_CTRL, MIC2AMPEN, 0, NULL, 0),
SND_SOC_DAPM_PGA("LINEIN PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
SND_SOC_DAPM_MUX("MIC2 SRC", SND_SOC_NOPM, 0, 0, &mic2src_mux),
/*INPUT widget*/
SND_SOC_DAPM_INPUT("MIC1P"),
SND_SOC_DAPM_INPUT("MIC1N"),
SND_SOC_DAPM_MICBIAS("MainMic Bias", ADC_APC_CTRL, MBIASEN, 0),
SND_SOC_DAPM_MICBIAS("HMic Bias", SND_SOC_NOPM, 0, 0),
//SND_SOC_DAPM_MICBIAS("HMic Bias", ADC_APC_CTRL, HBIASEN, 0),
SND_SOC_DAPM_INPUT("MIC2"),
SND_SOC_DAPM_INPUT("LINEINP"),
SND_SOC_DAPM_INPUT("LINEINN"),
SND_SOC_DAPM_INPUT("D_MIC"),
/*aif1 interface*/
SND_SOC_DAPM_AIF_IN_E("AIF1DACL", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0,ac10x_aif1clk,
SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_AIF_IN_E("AIF1DACR", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0,ac10x_aif1clk,
SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_AIF_OUT_E("AIF1ADCL", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0,ac10x_aif1clk,
SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_AIF_OUT_E("AIF1ADCR", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0,ac10x_aif1clk,
SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
/*headphone*/
SND_SOC_DAPM_HP("Headphone", ac10x_headphone_event),
/*speaker*/
SND_SOC_DAPM_SPK("External Speaker", ac10x_speaker_event),
/*DMIC*/
SND_SOC_DAPM_MUX("ADCL Mux", SND_SOC_NOPM, 0, 0, &adcl_mux),
SND_SOC_DAPM_MUX("ADCR Mux", SND_SOC_NOPM, 0, 0, &adcr_mux),
SND_SOC_DAPM_PGA_E("DMICL VIR", SND_SOC_NOPM, 0, 0, NULL, 0,
dmic_mux_ev, SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_PGA_E("DMICR VIR", SND_SOC_NOPM, 0, 0, NULL, 0,
dmic_mux_ev, SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
};
static const struct snd_soc_dapm_route ac10x_dapm_routes[] = {
{"AIF1ADCL", NULL, "AIF1OUT0L Mux"},
{"AIF1ADCR", NULL, "AIF1OUT0R Mux"},
{"AIF1ADCL", NULL, "AIF1OUT1L Mux"},
{"AIF1ADCR", NULL, "AIF1OUT1R Mux"},
/* aif1out0 mux 11---13*/
{"AIF1OUT0L Mux", "AIF1_AD0L", "AIF1 AD0L Mixer"},
{"AIF1OUT0L Mux", "AIF1_AD0R", "AIF1 AD0R Mixer"},
{"AIF1OUT0R Mux", "AIF1_AD0R", "AIF1 AD0R Mixer"},
{"AIF1OUT0R Mux", "AIF1_AD0L", "AIF1 AD0L Mixer"},
/*AIF1OUT1 mux 11--13 */
{"AIF1OUT1L Mux", "AIF1_AD1L", "AIF1 AD1L Mixer"},
{"AIF1OUT1L Mux", "AIF1_AD1R", "AIF1 AD1R Mixer"},
{"AIF1OUT1R Mux", "AIF1_AD1R", "AIF1 AD1R Mixer"},
{"AIF1OUT1R Mux", "AIF1_AD1L", "AIF1 AD1L Mixer"},
/*AIF1 AD0L Mixer*/
{"AIF1 AD0L Mixer", "AIF1 DA0L Switch", "AIF1IN0L Mux"},
{"AIF1 AD0L Mixer", "ADCL Switch", "ADCL Mux"},
/*AIF1 AD0R Mixer*/
{"AIF1 AD0R Mixer", "AIF1 DA0R Switch", "AIF1IN0R Mux"},
{"AIF1 AD0R Mixer", "ADCR Switch", "ADCR Mux"},
/*AIF1 AD1L Mixer*/
{"AIF1 AD1L Mixer", "ADCL Switch", "ADCL Mux"},
/*AIF1 AD1R Mixer*/
{"AIF1 AD1R Mixer", "ADCR Switch", "ADCR Mux"},
/*AIF1 DA0 IN 12h*/
{"AIF1IN0L Mux", "AIF1_DA0L", "AIF1DACL"},
{"AIF1IN0L Mux", "AIF1_DA0R", "AIF1DACR"},
{"AIF1IN0R Mux", "AIF1_DA0R", "AIF1DACR"},
{"AIF1IN0R Mux", "AIF1_DA0L", "AIF1DACL"},
/*AIF1 DA1 IN 12h*/
{"AIF1IN1L Mux", "AIF1_DA1L", "AIF1DACL"},
{"AIF1IN1L Mux", "AIF1_DA1R", "AIF1DACR"},