-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0001-I2S-module-rework.patch
1143 lines (1041 loc) · 35.7 KB
/
0001-I2S-module-rework.patch
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
From 9aec2b8e002ec3fd7664ec0c6b9ec608067bdde8 Mon Sep 17 00:00:00 2001
From: nikkov <[email protected]>
Date: Wed, 19 Mar 2014 17:17:53 +0700
Subject: [PATCH] I2S module rework
---
sound/soc/Kconfig | 2 +-
sound/soc/sunxi/i2s/Kconfig | 2 +-
sound/soc/sunxi/i2s/sndi2s.c | 68 ++++++++--
sound/soc/sunxi/i2s/sndi2s.h | 3 +
sound/soc/sunxi/i2s/sunxi-i2s.c | 279 ++++++++++++++++++++++++++++--------
sound/soc/sunxi/i2s/sunxi-i2s.h | 9 +-
sound/soc/sunxi/i2s/sunxi-i2sdma.c | 36 +++++-
sound/soc/sunxi/i2s/sunxi-i2sdma.h | 4 +-
sound/soc/sunxi/i2s/sunxi-sndi2s.c | 135 ++++++++++++++++--
sound/soc/sunxi/i2s/sunxi-sndi2s.h | 3 +-
10 files changed, 446 insertions(+), 95 deletions(-)
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
index adafead..2334cab 100644
--- a/sound/soc/Kconfig
+++ b/sound/soc/Kconfig
@@ -60,7 +60,7 @@ source "sound/soc/sunxi/Kconfig"
source "sound/soc/sunxi/hdmiaudio/Kconfig"
source "sound/soc/sunxi/spdif/Kconfig"
# i2s needs various adjustments for sun7i
-if ARCH_SUN4I || ARCH_SUN5I
+if ARCH_SUN4I || ARCH_SUN5I || ARCH_SUN7I
source "sound/soc/sunxi/i2s/Kconfig"
endif
endif
diff --git a/sound/soc/sunxi/i2s/Kconfig b/sound/soc/sunxi/i2s/Kconfig
index a6dff42..f244faa 100644
--- a/sound/soc/sunxi/i2s/Kconfig
+++ b/sound/soc/sunxi/i2s/Kconfig
@@ -1,5 +1,5 @@
config SND_SUNXI_SOC_I2S_INTERFACE
- tristate "SoC i2s interface for the AllWinner sun4i and sun5i chips"
+ tristate "SoC i2s interface for the AllWinner sun4i, sun5i and sun7i chips"
default m
help
Say Y or M if you want to add support for codecs attached to
diff --git a/sound/soc/sunxi/i2s/sndi2s.c b/sound/soc/sunxi/i2s/sndi2s.c
index 68bad02..f07129e 100644
--- a/sound/soc/sunxi/i2s/sndi2s.c
+++ b/sound/soc/sunxi/i2s/sndi2s.c
@@ -35,11 +35,23 @@ struct sndi2s_priv {
};
static int i2s_used = 0;
-#define sndi2s_RATES (SNDRV_PCM_RATE_8000_192000|SNDRV_PCM_RATE_KNOT)
+static int sunxi_i2s_slave = 0;
+
+#define sndi2s_RATES_MASTER (SNDRV_PCM_RATE_8000_192000|SNDRV_PCM_RATE_KNOT)
+#define sndi2s_RATES_SLAVE (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
+ SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |\
+ SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000)
+
+#if defined CONFIG_ARCH_SUN7I
+#define sndi2s_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
+#else
#define sndi2s_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE | \
- SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S20_3LE)
+ SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S20_LE)
+#endif
+/* cleaning code
hdmi_audio_t hdmi_parameter;
+*/
static int sndi2s_mute(struct snd_soc_dai *dai, int mute)
{
@@ -62,8 +74,26 @@ static int sndi2s_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
{
+/*
+ switch (params_format(params))
+ {
+ case SNDRV_PCM_FORMAT_S16_LE:
+ printk("[IIS-0] sndi2s_hw_params: format 16 bit\n");
+ break;
+ case SNDRV_PCM_FORMAT_S20_3LE:
+ printk("[IIS-0] sndi2s_hw_params: format 20 bit in 3 bytes\n");
+ break;
+ case SNDRV_PCM_FORMAT_S24_LE:
+ printk("[IIS-0] sndi2s_hw_params: format 24 bit in 4 bytes\n");
+ break;
+ default:
+ printk("[IIS-0] sndi2s_hw_params: Unsupported format (%d)\n", (int)params_format(params));
+ //return -EINVAL;
+ }
+*/
+/* cleaning code
hdmi_parameter.sample_rate = params_rate(params);
-
+*/
return 0;
}
@@ -75,15 +105,18 @@ static int sndi2s_set_dai_sysclk(struct snd_soc_dai *codec_dai,
static int sndi2s_set_dai_clkdiv(struct snd_soc_dai *codec_dai, int div_id, int div)
{
-
+/* cleaning code
hdmi_parameter.fs_between = div;
-
+*/
return 0;
}
static int sndi2s_set_dai_fmt(struct snd_soc_dai *codec_dai,
unsigned int fmt)
{
+/*
+ printk("[IIS-0] sndi2s_set_dai_fmt: format (%u)\n", fmt);
+*/
return 0;
}
@@ -104,7 +137,7 @@ struct snd_soc_dai_driver sndi2s_dai = {
.stream_name = "Playback",
.channels_min = 1,
.channels_max = 2,
- .rates = sndi2s_RATES,
+ .rates = sndi2s_RATES_MASTER,
.formats = sndi2s_FORMATS,
},
/* pcm operations */
@@ -129,10 +162,8 @@ static int sndi2s_soc_probe(struct snd_soc_codec *codec)
/* power down chip */
static int sndi2s_soc_remove(struct snd_soc_codec *codec)
{
- struct sndhdmi_priv *sndi2s = snd_soc_codec_get_drvdata(codec);
-
+ struct sndi2s_priv *sndi2s = snd_soc_codec_get_drvdata(codec);
kfree(sndi2s);
-
return 0;
}
@@ -143,6 +174,12 @@ static struct snd_soc_codec_driver soc_codec_dev_sndi2s = {
static int __devinit sndi2s_codec_probe(struct platform_device *pdev)
{
+ if(sunxi_i2s_slave) {
+ sndi2s_dai.playback.rates = sndi2s_RATES_SLAVE;
+ printk("[I2S-0] sndi2s_codec_probe I2S used in slave mode\n");
+ }
+ else
+ printk("[I2S-0] sndi2s_codec_probe I2S used in master mode\n");
return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_sndi2s, &sndi2s_dai, 1);
}
@@ -169,7 +206,7 @@ static struct platform_driver sndi2s_codec_driver = {
static int __init sndi2s_codec_init(void)
{
int err = 0;
- int ret = 0;
+ int ret = 0, i2s_slave = 0;
ret = script_parser_fetch("i2s_para","i2s_used", &i2s_used, sizeof(int));
if (ret) {
@@ -177,6 +214,16 @@ static int __init sndi2s_codec_init(void)
}
if (i2s_used) {
+ ret = script_parser_fetch("i2s_para","i2s_slave", &i2s_slave, sizeof(int));
+ if(ret == 0 && i2s_slave == 1) {
+ sunxi_i2s_slave = 1;
+ printk("[I2S-0] sndi2s_codec_init I2S used in slave mode\n");
+ }
+ else {
+ sunxi_i2s_slave = 0;
+ printk("[I2S-0] sndi2s_codec_init I2S used in master mode\n");
+ }
+
if((err = platform_device_register(&sndi2s_codec_device)) < 0)
return err;
@@ -204,3 +251,4 @@ MODULE_DESCRIPTION("SNDI2S ALSA soc codec driver");
MODULE_AUTHOR("Zoltan Devai, Christian Pellegrin <[email protected]>");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:sunxi-i2s-codec");
+
diff --git a/sound/soc/sunxi/i2s/sndi2s.h b/sound/soc/sunxi/i2s/sndi2s.h
index e5b95c8..57e2aa5 100644
--- a/sound/soc/sunxi/i2s/sndi2s.h
+++ b/sound/soc/sunxi/i2s/sndi2s.h
@@ -16,6 +16,8 @@
#ifndef SNDI2S_H_
#define SNDI2S_H_
+#if 0
+cleaning code
typedef struct hdmi_audio
{
__u8 hw_intf; /* 0:iis 1:spdif 2:pcm */
@@ -54,5 +56,6 @@ typedef enum tag_HDMI_CMD
HDMI_CMD_AUDIO_ENABLE,
HDMI_CMD_GET_HPD_STATUS,
}__hdmi_cmd_t;
+#endif
#endif
diff --git a/sound/soc/sunxi/i2s/sunxi-i2s.c b/sound/soc/sunxi/i2s/sunxi-i2s.c
index b4dd3ad..9f19991 100644
--- a/sound/soc/sunxi/i2s/sunxi-i2s.c
+++ b/sound/soc/sunxi/i2s/sunxi-i2s.c
@@ -58,13 +58,15 @@ static struct sunxi_dma_params sunxi_i2s_pcm_stereo_in = {
};
- struct sunxi_i2s_info sunxi_iis;
+/* most of fields of this structure is never initialized and useless !!!*/
+struct sunxi_i2s_info sunxi_iis;
static u32 i2s_handle = 0;
- static struct clk *i2s_apbclk, *i2s_pll2clk, *i2s_pllx8, *i2s_moduleclk;
+static struct clk *i2s_apbclk, *i2s_pll2clk, *i2s_pllx8, *i2s_moduleclk;
void sunxi_snd_txctrl_i2s(struct snd_pcm_substream *substream, int on)
{
u32 reg_val;
+ /*printk("[I2S-0] sunxi_snd_txctrl_i2s\n");*/
reg_val = readl(sunxi_iis.regs + SUNXI_TXCHSEL);
reg_val &= ~0x7;
@@ -73,7 +75,7 @@ void sunxi_snd_txctrl_i2s(struct snd_pcm_substream *substream, int on)
reg_val = readl(sunxi_iis.regs + SUNXI_TXCHMAP);
reg_val = 0;
- if (sunxi_is_sun4i()) {
+ if (sunxi_is_sun4i() || sunxi_is_sun7i()) {
if(substream->runtime->channels == 1) {
reg_val = 0x76543200;
} else {
@@ -89,7 +91,7 @@ void sunxi_snd_txctrl_i2s(struct snd_pcm_substream *substream, int on)
writel(reg_val, sunxi_iis.regs + SUNXI_TXCHMAP);
reg_val = readl(sunxi_iis.regs + SUNXI_IISCTL);
- if (sunxi_is_sun4i()) {
+ if (sunxi_is_sun4i() || sunxi_is_sun7i()) {
reg_val &= ~SUNXI_IISCTL_SDO3EN;
reg_val &= ~SUNXI_IISCTL_SDO2EN;
reg_val &= ~SUNXI_IISCTL_SDO1EN;
@@ -146,6 +148,8 @@ void sunxi_snd_txctrl_i2s(struct snd_pcm_substream *substream, int on)
//Global Enable Digital Audio Interface
reg_val = readl(sunxi_iis.regs + SUNXI_IISCTL);
+ if(sunxi_iis.slave)
+ reg_val |= SUNXI_IISCTL_MS; // 1: Slave!
reg_val |= SUNXI_IISCTL_GEN;
writel(reg_val, sunxi_iis.regs + SUNXI_IISCTL);
@@ -170,7 +174,7 @@ void sunxi_snd_txctrl_i2s(struct snd_pcm_substream *substream, int on)
void sunxi_snd_rxctrl_i2s(int on)
{
u32 reg_val;
-
+ /*printk("[I2S-0] sunxi_snd_rxctrl_i2s\n");*/
//flush RX FIFO
reg_val = readl(sunxi_iis.regs + SUNXI_IISFCTL);
reg_val |= SUNXI_IISFCTL_FRX;
@@ -192,6 +196,8 @@ void sunxi_snd_rxctrl_i2s(int on)
//Global Enable Digital Audio Interface
reg_val = readl(sunxi_iis.regs + SUNXI_IISCTL);
+ if(sunxi_iis.slave)
+ reg_val |= SUNXI_IISCTL_MS; // 1: Slave!
reg_val |= SUNXI_IISCTL_GEN;
writel(reg_val, sunxi_iis.regs + SUNXI_IISCTL);
@@ -201,7 +207,7 @@ void sunxi_snd_rxctrl_i2s(int on)
reg_val &= ~SUNXI_IISCTL_RXEN;
writel(reg_val, sunxi_iis.regs + SUNXI_IISCTL);
- /* DISBALE dma DRQ mode */
+ /* DISABLE dma DRQ mode */
reg_val = readl(sunxi_iis.regs + SUNXI_IISINT);
reg_val &= ~SUNXI_IISINT_RXDRQEN;
writel(reg_val, sunxi_iis.regs + SUNXI_IISINT);
@@ -213,11 +219,13 @@ void sunxi_snd_rxctrl_i2s(int on)
}
}
+//not used
+/*
static inline int sunxi_snd_is_clkmaster(void)
{
return ((readl(sunxi_iis.regs + SUNXI_IISCTL) & SUNXI_IISCTL_MS) ? 0 : 1);
}
-
+*/
static int sunxi_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
{
u32 reg_val;
@@ -225,7 +233,7 @@ static int sunxi_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
//SDO ON
reg_val = readl(sunxi_iis.regs + SUNXI_IISCTL);
- if (sunxi_is_sun4i()) {
+ if (sunxi_is_sun4i() || sunxi_is_sun7i()) {
reg_val |= (SUNXI_IISCTL_SDO0EN | SUNXI_IISCTL_SDO1EN |
SUNXI_IISCTL_SDO2EN | SUNXI_IISCTL_SDO3EN);
} else {
@@ -235,16 +243,31 @@ static int sunxi_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
/* master or slave selection */
reg_val = readl(sunxi_iis.regs + SUNXI_IISCTL);
+ if(sunxi_iis.slave)
+ {
+ reg_val |= SUNXI_IISCTL_MS; // 1: Slave!
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: set slave mode for I2S interface\n");*/
+ }
+ else
+ {
+ reg_val &= ~SUNXI_IISCTL_MS; // 0: Master!
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: set master mode for I2S interface\n");*/
+ }
+/*
switch(fmt & SND_SOC_DAIFMT_MASTER_MASK){
- case SND_SOC_DAIFMT_CBM_CFM: /* codec clk & frm master */
- reg_val |= SUNXI_IISCTL_MS;
+ case SND_SOC_DAIFMT_CBS_CFS: // codec clk & frm slave
+ reg_val |= SUNXI_IISCTL_MS; // 1: Slave!
+ printk("[IIS-0] sunxi_i2s_set_fmt: set slave mode for I2S interface\n");
break;
- case SND_SOC_DAIFMT_CBS_CFS: /* codec clk & frm slave */
- reg_val &= ~SUNXI_IISCTL_MS;
+ case SND_SOC_DAIFMT_CBM_CFM: // codec clk & frm master
+ reg_val &= ~SUNXI_IISCTL_MS; // 0: Master!
+ printk("[IIS-0] sunxi_i2s_set_fmt: set master mode for I2S interface\n");
break;
default:
+ printk("[IIS-0] sunxi_i2s_set_fmt: not master or slave mode\n");
return -EINVAL;
}
+*/
writel(reg_val, sunxi_iis.regs + SUNXI_IISCTL);
/* pcm or i2s mode selection */
@@ -255,24 +278,30 @@ static int sunxi_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
case SND_SOC_DAIFMT_I2S: /* I2S mode */
reg_val &= ~SUNXI_IISCTL_PCM;
reg_val1 |= SUNXI_IISFAT0_FMT_I2S;
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: set I2S mode\n");*/
break;
case SND_SOC_DAIFMT_RIGHT_J: /* Right Justified mode */
reg_val &= ~SUNXI_IISCTL_PCM;
reg_val1 |= SUNXI_IISFAT0_FMT_RGT;
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: set Right Justified mode\n");*/
break;
case SND_SOC_DAIFMT_LEFT_J: /* Left Justified mode */
reg_val &= ~SUNXI_IISCTL_PCM;
reg_val1 |= SUNXI_IISFAT0_FMT_LFT;
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: set Left Justified mode\n");*/
break;
case SND_SOC_DAIFMT_DSP_A: /* L data msb after FRM LRC */
reg_val |= SUNXI_IISCTL_PCM;
reg_val1 &= ~SUNXI_IISFAT0_LRCP;
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: set L data msb after FRM LRC mode\n");*/
break;
case SND_SOC_DAIFMT_DSP_B: /* L data msb during FRM LRC */
reg_val |= SUNXI_IISCTL_PCM;
reg_val1 |= SUNXI_IISFAT0_LRCP;
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: set L data msb during FRM LRC mode\n");*/
break;
default:
+ printk("[IIS-0] sunxi_i2s_set_fmt: unknown mode\n");
return -EINVAL;
}
writel(reg_val, sunxi_iis.regs + SUNXI_IISCTL);
@@ -284,25 +313,30 @@ static int sunxi_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
case SND_SOC_DAIFMT_NB_NF: /* normal bit clock + frame */
reg_val1 &= ~SUNXI_IISFAT0_LRCP;
reg_val1 &= ~SUNXI_IISFAT0_BCP;
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: normal bit clock + frame\n");*/
break;
case SND_SOC_DAIFMT_NB_IF: /* normal bclk + inv frm */
reg_val1 |= SUNXI_IISFAT0_LRCP;
reg_val1 &= ~SUNXI_IISFAT0_BCP;
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: normal bclk + inv frm\n");*/
break;
case SND_SOC_DAIFMT_IB_NF: /* invert bclk + nor frm */
reg_val1 &= ~SUNXI_IISFAT0_LRCP;
reg_val1 |= SUNXI_IISFAT0_BCP;
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: invert bclk + nor frm\n");*/
break;
case SND_SOC_DAIFMT_IB_IF: /* invert bclk + frm */
reg_val1 |= SUNXI_IISFAT0_LRCP;
reg_val1 |= SUNXI_IISFAT0_BCP;
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: invert bclk + frm\n");*/
break;
}
writel(reg_val1, sunxi_iis.regs + SUNXI_IISFAT0);
- /* word select size */
+ /* clear word select size */
reg_val = readl(sunxi_iis.regs + SUNXI_IISFAT0);
reg_val &= ~SUNXI_IISFAT0_WSS_32BCLK;
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: word size = %d\n", sunxi_iis.ws_size);*/
if(sunxi_iis.ws_size == 16)
reg_val |= SUNXI_IISFAT0_WSS_16BCLK;
else if(sunxi_iis.ws_size == 20)
@@ -318,9 +352,15 @@ static int sunxi_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
reg_val |= sunxi_iis.pcm_rxtype<<2;
if(!sunxi_iis.pcm_sync_type)
+ {
reg_val |= SUNXI_IISFAT1_SSYNC; //short sync
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: set pcm_sync_type = short sync\n");*/
+ }
if(sunxi_iis.pcm_sw == 16)
+ {
reg_val |= SUNXI_IISFAT1_SW;
+ /*printk("[IIS-0] sunxi_i2s_set_fmt: pcm_sw == 16\n");*/
+ }
reg_val |=((sunxi_iis.pcm_start_slot - 1)&0x3)<<6; //start slot index
@@ -349,6 +389,7 @@ static int sunxi_i2s_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
{
+ u32 reg_val;
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct sunxi_dma_params *dma_data;
@@ -358,6 +399,31 @@ static int sunxi_i2s_hw_params(struct snd_pcm_substream *substream,
else
dma_data = &sunxi_i2s_pcm_stereo_in;
+ /* set format info */
+ reg_val = readl(sunxi_iis.regs + SUNXI_IISFAT0);
+ /* clear sample resolution select size */
+ reg_val &= ~SUNXI_IISFAT0_SR_RVD;
+
+ switch (params_format(params))
+ {
+ case SNDRV_PCM_FORMAT_S16_LE:
+ reg_val |= SUNXI_IISFAT0_SR_16BIT;
+ /*printk("[IIS-0] sunxi_i2s_hw_params: format 16 bit\n");*/
+ break;
+ case SNDRV_PCM_FORMAT_S20_3LE:
+ reg_val |= SUNXI_IISFAT0_SR_20BIT;
+ /*printk("[IIS-0] sunxi_i2s_hw_params: format 20 bit\n");*/
+ break;
+ case SNDRV_PCM_FORMAT_S24_LE:
+ reg_val |= SUNXI_IISFAT0_SR_24BIT;
+ /*printk("[IIS-0] sunxi_i2s_hw_params: format 24 bit\n");*/
+ break;
+ default:
+ printk("[IIS-0] sunxi_i2s_hw_params: Unsupported format (%d)\n", (int)params_format(params));
+ //return -EINVAL;
+ }
+ writel(reg_val, sunxi_iis.regs + SUNXI_IISFAT0);
+
snd_soc_dai_set_dma_data(rtd->cpu_dai, substream, dma_data);
return 0;
}
@@ -403,9 +469,17 @@ static int sunxi_i2s_set_sysclk(struct snd_soc_dai *cpu_dai, int clk_id,
unsigned int freq, int dir)
{
if (!freq) {
- clk_set_rate(i2s_pll2clk, 24576000);
+ /*printk("[IIS-0] sunxi_i2s_set_sysclk: set sysclk=24576000\n");*/
+ if(sunxi_iis.slave)
+ gpio_write_one_pin_value(i2s_handle, 0, "i2s_clk_sel");
+ else
+ clk_set_rate(i2s_pll2clk, 24576000);
} else {
- clk_set_rate(i2s_pll2clk, 22579200);
+ /*printk("[IIS-0] sunxi_i2s_set_sysclk: set sysclk=22579200\n");*/
+ if(sunxi_iis.slave)
+ gpio_write_one_pin_value(i2s_handle, 1, "i2s_clk_sel");
+ else
+ clk_set_rate(i2s_pll2clk, 22579200);
}
return 0;
@@ -414,6 +488,27 @@ static int sunxi_i2s_set_sysclk(struct snd_soc_dai *cpu_dai, int clk_id,
static int sunxi_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai, int div_id, int div)
{
u32 reg;
+ /*printk("[IIS-0] sunxi_i2s_set_clkdiv: PLL clock div_id=(%s), div=(%d)\n",
+ div_id == SUNXI_DIV_MCLK ? "SUNXI_DIV_MCLK" :
+ (div_id == SUNXI_DIV_BCLK ? "SUNXI_DIV_BCLK" : "SUNXI_DIV_EXTCLK"), div);*/
+
+
+ if(sunxi_iis.slave) {
+ if(div_id != SUNXI_DIV_EXTCLK) {
+ pr_err("[I2S-0] try to set external clock divider failed\n");
+ return -EINVAL;
+ }
+ /*printk("[IIS-0] sunxi_i2s_set_clkdiv: external clock, div=(%d)\n", div);*/
+ }
+ else {
+ if(div_id != SUNXI_DIV_MCLK && div_id != SUNXI_DIV_BCLK) {
+ pr_err("[I2S-0] try to set PLL clock divider failed\n");
+ return -EINVAL;
+ }
+ /*printk("[IIS-0] sunxi_i2s_set_clkdiv: PLL clock div_id=(%s), div=(%d)\n",
+ div_id == SUNXI_DIV_MCLK ? "SUNXI_DIV_MCLK" : "SUNXI_DIV_BCLK", div);*/
+ }
+
switch (div_id) {
case SUNXI_DIV_MCLK:
if(div <= 8)
@@ -447,18 +542,39 @@ static int sunxi_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai, int div_id, int div
reg = (readl(sunxi_iis.regs + SUNXI_IISCLKD) & ~SUNXI_IISCLKD_BCLK_MASK) | (div <<SUNXI_IISCLKD_BCLK_OFFS);
writel(reg, sunxi_iis.regs + SUNXI_IISCLKD);
break;
+ case SUNXI_DIV_EXTCLK:
+ /*printk("[IIS-0] sunxi_i2s_set_clkdiv set divider=(%d)\n", div);*/
+ if(div == 512) {
+ gpio_write_one_pin_value(i2s_handle, 1, "i2s_clk_div1");
+ gpio_write_one_pin_value(i2s_handle, 1, "i2s_clk_div0");
+ }
+ else if(div == 256) {
+ gpio_write_one_pin_value(i2s_handle, 0, "i2s_clk_div1");
+ gpio_write_one_pin_value(i2s_handle, 1, "i2s_clk_div0");
+ }
+ else if(div == 128) {
+ gpio_write_one_pin_value(i2s_handle, 0, "i2s_clk_div1");
+ gpio_write_one_pin_value(i2s_handle, 0, "i2s_clk_div0");
+ }
+ else {
+ pr_err("[I2S-0] try to set unsupported external clock divider div=(%d)\n", div);
+ return -EINVAL;
+ }
+ break;
default:
return -EINVAL;
}
- //diable MCLK output when high samplerate
+ //disable MCLK output when high samplerate or slave mode
reg = readl(sunxi_iis.regs + SUNXI_IISCLKD);
- if (!(reg & 0xF)) {
+ if (!(reg & 0xF) || sunxi_iis.slave) {
reg &= ~SUNXI_IISCLKD_MCLKOEN;
writel(reg, sunxi_iis.regs + SUNXI_IISCLKD);
+ /*printk("[IIS-0] sunxi_i2s_set_clkdiv: disable MCLK\n");*/
} else {
reg |= SUNXI_IISCLKD_MCLKOEN;
writel(reg, sunxi_iis.regs + SUNXI_IISCLKD);
+ /*printk("[IIS-0] sunxi_i2s_set_clkdiv: enable MCLK\n");*/
}
return 0;
@@ -502,16 +618,17 @@ static int sunxi_i2s_suspend(struct snd_soc_dai *cpu_dai)
u32 reg_val;
printk("[IIS]Entered %s\n", __func__);
- //Global Enable Digital Audio Interface
+ //Global Disable Digital Audio Interface
reg_val = readl(sunxi_iis.regs + SUNXI_IISCTL);
reg_val &= ~SUNXI_IISCTL_GEN;
writel(reg_val, sunxi_iis.regs + SUNXI_IISCTL);
iisregsave();
- //release the module clock
- clk_disable(i2s_moduleclk);
-
+ if(!sunxi_iis.slave) {
+ //release the module clock, only for master mode
+ clk_disable(i2s_moduleclk);
+ }
clk_disable(i2s_apbclk);
//printk("[IIS]PLL2 0x01c20008 = %#x\n", *(volatile int*)0xF1C20008);
@@ -525,16 +642,21 @@ static int sunxi_i2s_resume(struct snd_soc_dai *cpu_dai)
u32 reg_val;
printk("[IIS]Entered %s\n", __func__);
- //release the module clock
+ //enable the module clock
clk_enable(i2s_apbclk);
- //release the module clock
- clk_enable(i2s_moduleclk);
+ if(!sunxi_iis.slave) {
+
+ //enable the module clock
+ clk_enable(i2s_moduleclk);
+ }
iisregrestore();
//Global Enable Digital Audio Interface
reg_val = readl(sunxi_iis.regs + SUNXI_IISCTL);
+ if(sunxi_iis.slave)
+ reg_val |= SUNXI_IISCTL_MS; // 1: Slave!
reg_val |= SUNXI_IISCTL_GEN;
writel(reg_val, sunxi_iis.regs + SUNXI_IISCTL);
@@ -545,7 +667,10 @@ static int sunxi_i2s_resume(struct snd_soc_dai *cpu_dai)
return 0;
}
-#define SUNXI_I2S_RATES (SNDRV_PCM_RATE_8000_192000 | SNDRV_PCM_RATE_KNOT)
+#define SUNXI_I2S_RATES_MASTER (SNDRV_PCM_RATE_8000_192000 | SNDRV_PCM_RATE_KNOT)
+#define SUNXI_I2S_RATES_SLAVE (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
+ SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |\
+ SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000)
static struct snd_soc_dai_ops sunxi_iis_dai_ops = {
.trigger = sunxi_i2s_trigger,
.hw_params = sunxi_i2s_hw_params,
@@ -562,14 +687,14 @@ static struct snd_soc_dai_driver sunxi_iis_dai = {
.playback = {
.channels_min = 1,
.channels_max = 2,
- .rates = SUNXI_I2S_RATES,
- .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
+ .rates = SUNXI_I2S_RATES_MASTER,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
},
.capture = {
.channels_min = 1,
.channels_max = 2,
- .rates = SUNXI_I2S_RATES,
- .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
+ .rates = SUNXI_I2S_RATES_MASTER,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
},
.symmetric_rates = 1,
.ops = &sunxi_iis_dai_ops,
@@ -579,42 +704,60 @@ static int __devinit sunxi_i2s_dev_probe(struct platform_device *pdev)
{
int reg_val = 0;
int ret;
+ printk("[IIS]Entered %s\n", __func__);
sunxi_iis.regs = ioremap(SUNXI_IISBASE, 0x100);
if (sunxi_iis.regs == NULL)
return -ENXIO;
//i2s apbclk
- i2s_apbclk = clk_get(NULL, "apb_i2s");
+ i2s_apbclk = clk_get(NULL,
+#if defined CONFIG_ARCH_SUN7I
+ "apb_i2s0"
+#else
+ "apb_i2s"
+#endif
+ );
+
if(-1 == clk_enable(i2s_apbclk)){
printk("i2s_apbclk failed! line = %d\n", __LINE__);
goto out;
}
- i2s_pllx8 = clk_get(NULL, "audio_pllx8");
-
- //i2s pll2clk
- i2s_pll2clk = clk_get(NULL, "audio_pll");
-
- //i2s module clk
- i2s_moduleclk = clk_get(NULL, "i2s");
+ if(!sunxi_iis.slave) {
+
+ i2s_pllx8 = clk_get(NULL, "audio_pllx8");
+ //i2s pll2clk
+ i2s_pll2clk = clk_get(NULL, "audio_pll");
+ //i2s module clk
+ i2s_moduleclk = clk_get(NULL,
+#if defined CONFIG_ARCH_SUN7I
+ "i2s0"
+#else
+ "i2s"
+#endif
+ );
- if(clk_set_parent(i2s_moduleclk, i2s_pll2clk)){
- printk("try to set parent of i2s_moduleclk to i2s_pll2ck failed! line = %d\n",__LINE__);
- goto out1;
- }
+ if(clk_set_parent(i2s_moduleclk, i2s_pll2clk)){
+ printk("try to set parent of i2s_moduleclk to i2s_pll2ck failed! line = %d\n",__LINE__);
+ goto out1;
+ }
- if(clk_set_rate(i2s_moduleclk, 24576000/8)){
- printk("set i2s_moduleclk clock freq to 24576000 failed! line = %d\n", __LINE__);
- goto out1;
- }
+ if(clk_set_rate(i2s_moduleclk, 24576000/8)){
+ printk("set i2s_moduleclk clock freq to 24576000 failed! line = %d\n", __LINE__);
+ goto out1;
+ }
- if(-1 == clk_enable(i2s_moduleclk)){
- printk("open i2s_moduleclk failed! line = %d\n", __LINE__);
- goto out1;
- }
+ if(-1 == clk_enable(i2s_moduleclk)){
+ printk("open i2s_moduleclk failed! line = %d\n", __LINE__);
+ goto out1;
+ }
+ } else
+ sunxi_iis_dai.playback.rates = SUNXI_I2S_RATES_SLAVE;
reg_val = readl(sunxi_iis.regs + SUNXI_IISCTL);
+ if(sunxi_iis.slave)
+ reg_val |= SUNXI_IISCTL_MS; // 1: Slave!
reg_val |= SUNXI_IISCTL_GEN;
writel(reg_val, sunxi_iis.regs + SUNXI_IISCTL);
@@ -627,7 +770,8 @@ static int __devinit sunxi_i2s_dev_probe(struct platform_device *pdev)
goto out;
out2:
- clk_disable(i2s_moduleclk);
+ if(!sunxi_iis.slave)
+ clk_disable(i2s_moduleclk);
out1:
clk_disable(i2s_apbclk);
out:
@@ -636,17 +780,20 @@ static int __devinit sunxi_i2s_dev_probe(struct platform_device *pdev)
static int __devexit sunxi_i2s_dev_remove(struct platform_device *pdev)
{
+ printk("[IIS]Entered %s\n", __func__);
+
if(i2s_used) {
i2s_used = 0;
- //release the module clock
- clk_disable(i2s_moduleclk);
-
- //release pllx8clk
- clk_put(i2s_pllx8);
+ if(!sunxi_iis.slave) {
+ //release the module clock
+ clk_disable(i2s_moduleclk);
- //release pll2clk
- clk_put(i2s_pll2clk);
+ //release pllx8clk
+ clk_put(i2s_pllx8);
+ //release pll2clk
+ clk_put(i2s_pll2clk);
+ }
//release apbclk
clk_put(i2s_apbclk);
@@ -674,15 +821,26 @@ static struct platform_driver sunxi_i2s_driver = {
static int __init sunxi_i2s_init(void)
{
- int err = 0;
+ int err = 0, i2s_slave = 0;
int ret;
+ printk("[IIS]Entered %s\n", __func__);
+
ret = script_parser_fetch("i2s_para","i2s_used", &i2s_used, sizeof(int));
if (ret) {
- printk("[I2S]sunxi_i2s_init fetch i2s using configuration failed\n");
- }
+ printk("[I2S]sunxi_i2s_init fetch i2s using configuration failed\n");
+ }
if (i2s_used) {
+ ret = script_parser_fetch("i2s_para","i2s_slave", &i2s_slave, sizeof(int));
+ if (ret == 0 && i2s_slave) {
+ sunxi_iis.slave = 1;
+ printk("[I2S-0] sunxi_i2s_init I2S used in slave mode\n");
+ } else {
+ sunxi_iis.slave = 0;
+ printk("[I2S-0] sunxi_i2s_init I2S used in master mode\n");
+ }
+
i2s_handle = gpio_request_ex("i2s_para", NULL);
if((err = platform_device_register(&sunxi_i2s_device)) < 0)
@@ -700,6 +858,7 @@ module_init(sunxi_i2s_init);
static void __exit sunxi_i2s_exit(void)
{
+ printk("[IIS]Entered %s\n", __func__);
platform_driver_unregister(&sunxi_i2s_driver);
}
module_exit(sunxi_i2s_exit);
diff --git a/sound/soc/sunxi/i2s/sunxi-i2s.h b/sound/soc/sunxi/i2s/sunxi-i2s.h
index f12d6d5..484c9c9 100644
--- a/sound/soc/sunxi/i2s/sunxi-i2s.h
+++ b/sound/soc/sunxi/i2s/sunxi-i2s.h
@@ -259,8 +259,9 @@
/*------------------------------------------------------------*/
/* Clock dividers */
-#define SUNXI_DIV_MCLK 0
-#define SUNXI_DIV_BCLK 1
+#define SUNXI_DIV_MCLK 0
+#define SUNXI_DIV_BCLK 1
+#define SUNXI_DIV_EXTCLK 2
#define SUNXI_IISCLKD_MCLK_MASK 0x0f
#define SUNXI_IISCLKD_MCLK_OFFS 0
@@ -269,7 +270,7 @@
#define SUNXI_IISCLKD_MCLKEN_OFFS 7
unsigned int sunxi_i2s_get_clockrate(void);
-extern struct sunxi_i2s_info sunxi_i2s;
+//extern struct sunxi_i2s_info sunxi_iis;
//extern struct snd_soc_dai sunxi_iis_dai;
extern void sunxi_snd_txctrl_i2s(struct snd_pcm_substream *substream, int on);
@@ -300,5 +301,5 @@ struct sunxi_i2s_info {
};
-extern struct sunxi_i2s_info sunxi_i2s;
+//extern struct sunxi_i2s_info sunxi_iis;
#endif
diff --git a/sound/soc/sunxi/i2s/sunxi-i2sdma.c b/sound/soc/sunxi/i2s/sunxi-i2sdma.c
index 488ef4d..d103098 100644
--- a/sound/soc/sunxi/i2s/sunxi-i2sdma.c
+++ b/sound/soc/sunxi/i2s/sunxi-i2sdma.c
@@ -35,11 +35,15 @@
static volatile unsigned int dmasrc = 0;
static volatile unsigned int dmadst = 0;
+//DMA data width
+static unsigned int dma_width = 16;
+
+
static const struct snd_pcm_hardware sunxi_pcm_hardware = {
.info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME,
- .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
.rates = SNDRV_PCM_RATE_8000_192000 | SNDRV_PCM_RATE_KNOT,
.rate_min = 8000,
.rate_max = 192000,
@@ -125,6 +129,20 @@ static int sunxi_pcm_hw_params(struct snd_pcm_substream *substream,
if (!dma)
return 0;
+ /* set DMA width for using in sunxi_pcm_prepare*/
+ switch(params_format(params)) {
+ case SNDRV_PCM_FORMAT_S16_LE:
+ dma_width = 16;
+ break;
+ case SNDRV_PCM_FORMAT_S20_3LE:
+ dma_width = 32;
+ break;
+ case SNDRV_PCM_FORMAT_S24_LE:
+ dma_width = 32;
+ break;
+ }
+ /*printk("[IIS-0] sunxi_pcm_hw_params: dma width %d bit\n", dma_width);*/
+
if (prtd->params == NULL) {
prtd->params = dma;
ret = sunxi_dma_request(prtd->params, 0);
@@ -196,10 +214,22 @@ static int sunxi_pcm_prepare(struct snd_pcm_substream *substream)
#else
dma_config_t codec_dma_conf;
memset(&codec_dma_conf, 0, sizeof(codec_dma_conf));
- codec_dma_conf.xfer_type.src_data_width = DATA_WIDTH_16BIT;
+
+ /*printk("[IIS-0] sunxi_pcm_prepare: DMA data width=(%d)\n", dma_width);*/
+ if(dma_width > 16)
+ {
+ codec_dma_conf.xfer_type.src_data_width = DATA_WIDTH_32BIT;
+ codec_dma_conf.xfer_type.dst_data_width = DATA_WIDTH_32BIT;
+ }
+ else
+ {
+ codec_dma_conf.xfer_type.src_data_width = DATA_WIDTH_16BIT;
+ codec_dma_conf.xfer_type.dst_data_width = DATA_WIDTH_16BIT;
+ }
codec_dma_conf.xfer_type.src_bst_len = DATA_BRST_1;
- codec_dma_conf.xfer_type.dst_data_width = DATA_WIDTH_16BIT;
+// codec_dma_conf.xfer_type.src_bst_len = DATA_BRST_4; /*like SPDIF module?*/
codec_dma_conf.xfer_type.dst_bst_len = DATA_BRST_1;
+// codec_dma_conf.xfer_type.src_bst_len = DATA_BRST_4; /*like SPDIF module?*/
codec_dma_conf.address_type.src_addr_mode = NDMA_ADDR_INCREMENT;
codec_dma_conf.address_type.dst_addr_mode = NDMA_ADDR_NOCHANGE;
codec_dma_conf.src_drq_type = N_SRC_SDRAM;
diff --git a/sound/soc/sunxi/i2s/sunxi-i2sdma.h b/sound/soc/sunxi/i2s/sunxi-i2sdma.h
index 50418a58..8f0b029 100644
--- a/sound/soc/sunxi/i2s/sunxi-i2sdma.h
+++ b/sound/soc/sunxi/i2s/sunxi-i2sdma.h
@@ -29,7 +29,7 @@ enum sunxi_dma_buffresult {
};
/* platform data */
-extern struct snd_soc_platform sunxi_soc_platform_i2s;
-extern struct sunxi_i2s_info sunxi_iis;
+//extern struct snd_soc_platform sunxi_soc_platform_i2s;
+//extern struct sunxi_i2s_info sunxi_iis;
#endif //SUNXI_PCM_H_
diff --git a/sound/soc/sunxi/i2s/sunxi-sndi2s.c b/sound/soc/sunxi/i2s/sunxi-sndi2s.c
index 7c1a3d4..682c553 100644
--- a/sound/soc/sunxi/i2s/sunxi-sndi2s.c
+++ b/sound/soc/sunxi/i2s/sunxi-sndi2s.c
@@ -29,9 +29,14 @@
#include "sndi2s.h"
+/* cleaning code
static struct clk *xtal;
static int clk_users;
static DEFINE_MUTEX(clk_lock);
+*/
+
+/* slave mode flag*/
+static int sunxi_i2s_slave = 0;
#ifdef ENFORCE_RATES
static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
@@ -62,6 +67,7 @@ static int sunxi_sndi2s_startup(struct snd_pcm_substream *substream)
static void sunxi_sndi2s_shutdown(struct snd_pcm_substream *substream)
{
+/* cleaning code
mutex_lock(&clk_lock);
clk_users -= 1;
if (clk_users == 0) {
@@ -70,6 +76,7 @@ static void sunxi_sndi2s_shutdown(struct snd_pcm_substream *substream)
}
mutex_unlock(&clk_lock);
+*/
}
typedef struct __MCLK_SET_INF
@@ -91,6 +98,14 @@ typedef struct __BCLK_SET_INF
} __bclk_set_inf;
+typedef struct __EXTCLK_SET_INF
+{
+ __u32 samp_rate; // sample rate
+ __u16 clk_div; // masterclock division
+ __u16 mpll; // select mpll, 0 - 24.576 Mhz, 1 - 22.5792 Mhz
+
+} __extclk_set_inf;
+
static __bclk_set_inf BCLK_INF[] =
{
@@ -164,7 +179,45 @@ static __mclk_set_inf MCLK_INF[] =
{0xffffffff, 0, 0, 0},
};
-static s32 get_clock_divder(u32 sample_rate, u32 sample_width, u32 * mclk_div, u32* mpll, u32* bclk_div, u32* mult_fs)
+static __extclk_set_inf EXTCLK_INF[] =
+{
+ //44.1k bitrate
+ { 44100, 512, 1},
+ //48k bitrate
+ { 48000, 512, 0},
+ //88.2k bitrate
+ { 88200, 256, 1},
+ //96k bitrate
+ { 96000, 256, 0},
+ //176.4k bitrate
+ { 176400, 128, 1},
+ //192k bitrate
+ { 192000, 128, 0},
+
+ //end flag 0xffffffff
+ {0xffffffff, 0, 0}
+};
+
+
+static s32 get_clock_divder_slave(u32 sample_rate, u32 sample_width, u32* bclk_div, u32* mpll, u32* mult_fs)
+{
+ u32 i, ret = -EINVAL;
+
+ for(i=0; i< 100; i++) {
+ if(EXTCLK_INF[i].samp_rate == sample_rate) {
+ //set mpll and bclk division
+ *mpll = EXTCLK_INF[i].mpll;
+ *bclk_div = EXTCLK_INF[i].clk_div;
+ ret = 0;
+ break;
+ }
+ else if(EXTCLK_INF[i].samp_rate == 0xffffffff)
+ break;
+ }
+ return ret;
+}
+
+static s32 get_clock_divder_master(u32 sample_rate, u32 sample_width, u32 * mclk_div, u32* mpll, u32* bclk_div, u32* mult_fs)
{
u32 i, j, ret = -EINVAL;
@@ -200,35 +253,77 @@ static int sunxi_sndi2s_hw_params(struct snd_pcm_substream *substream,
int ret = 0;
unsigned long rate = params_rate(params);
u32 mclk_div=0, mpll=0, bclk_div=0, mult_fs=0;