7c3685f6541e0021c4910dcde2fec69b68b4ba4c
[openwrt/staging/aparcar.git] /
1 From fc4146698489c4725c9ac86ea3e0484914d5285b Mon Sep 17 00:00:00 2001
2 From: Viorel Suman <viorel.suman@nxp.com>
3 Date: Wed, 27 Jun 2018 10:31:02 +0300
4 Subject: [PATCH] MLK-18682-1: ASoC: fsl: sai: use set_bclk_ratio to calculate
5 BCLK freq (part 1)
6
7 ALSA API has a standard way to configure DAI BCLK by calling
8 "snd_soc_dai_set_bclk_ratio" function. So use it to set BCLK ratio
9 and calculate SAI BCLK frequency.
10
11 Signed-off-by: Viorel Suman <viorel.suman@nxp.com>
12 [ Aisheng: split machine imx-pdm changes ]
13 Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
14 ---
15 sound/soc/fsl/fsl_sai.c | 21 +++++++++++++--------
16 sound/soc/fsl/fsl_sai.h | 3 +--
17 2 files changed, 14 insertions(+), 10 deletions(-)
18
19 --- a/sound/soc/fsl/fsl_sai.c
20 +++ b/sound/soc/fsl/fsl_sai.c
21 @@ -234,6 +234,14 @@ static int fsl_sai_set_dai_sysclk_tr(str
22 return 0;
23 }
24
25 +static int fsl_sai_set_dai_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
26 +{
27 + struct fsl_sai *sai = snd_soc_dai_get_drvdata(dai);
28 +
29 + sai->bitclk_ratio = ratio;
30 + return 0;
31 +}
32 +
33 static int fsl_sai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
34 int clk_id, unsigned int freq, int dir)
35 {
36 @@ -243,11 +251,6 @@ static int fsl_sai_set_dai_sysclk(struct
37 if (dir == SND_SOC_CLOCK_IN)
38 return 0;
39
40 - if (clk_id == FSL_SAI_CLK_BIT) {
41 - sai->bitclk_freq = freq;
42 - return 0;
43 - }
44 -
45 if (freq > 0) {
46 if (clk_id < 0 || clk_id >= FSL_SAI_MCLK_MAX) {
47 dev_err(cpu_dai->dev, "Unknown clock id: %d\n", clk_id);
48 @@ -571,6 +574,7 @@ static int fsl_sai_hw_params(struct snd_
49 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
50 unsigned int channels = params_channels(params);
51 u32 word_width = params_width(params);
52 + u32 rate = params_rate(params);
53 u32 val_cr4 = 0, val_cr5 = 0;
54 u32 slots = (channels == 1) ? 2 : channels;
55 u32 slot_width = word_width;
56 @@ -605,12 +609,12 @@ static int fsl_sai_hw_params(struct snd_
57 slot_width = sai->slot_width;
58
59 if (!sai->slave_mode[tx]) {
60 - if (sai->bitclk_freq)
61 + if (sai->bitclk_ratio)
62 ret = fsl_sai_set_bclk(cpu_dai, tx,
63 - sai->bitclk_freq);
64 + rate * sai->bitclk_ratio);
65 else
66 ret = fsl_sai_set_bclk(cpu_dai, tx,
67 - slots * slot_width * params_rate(params));
68 + rate * slots * slot_width);
69 if (ret)
70 return ret;
71
72 @@ -935,6 +939,7 @@ static void fsl_sai_shutdown(struct snd_
73 }
74
75 static const struct snd_soc_dai_ops fsl_sai_pcm_dai_ops = {
76 + .set_bclk_ratio = fsl_sai_set_dai_bclk_ratio,
77 .set_sysclk = fsl_sai_set_dai_sysclk,
78 .set_fmt = fsl_sai_set_dai_fmt,
79 .set_tdm_slot = fsl_sai_set_dai_tdm_slot,
80 --- a/sound/soc/fsl/fsl_sai.h
81 +++ b/sound/soc/fsl/fsl_sai.h
82 @@ -203,7 +203,6 @@
83 #define FSL_SAI_CLK_MAST3 3
84
85 #define FSL_SAI_MCLK_MAX 4
86 -#define FSL_SAI_CLK_BIT 5
87
88 /* SAI data transfer numbers per DMA request */
89 #define FSL_SAI_MAXBURST_TX 6
90 @@ -258,7 +257,7 @@ struct fsl_sai {
91 unsigned int mclk_streams;
92 unsigned int slots;
93 unsigned int slot_width;
94 - unsigned int bitclk_freq;
95 + unsigned int bitclk_ratio;
96
97 struct snd_dmaengine_dai_dma_data dma_params_rx;
98 struct snd_dmaengine_dai_dma_data dma_params_tx;