summaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorViorel Suman <viorel.suman@nxp.com>2018-06-27 10:31:02 +0300
committerJason Liu <jason.hui.liu@nxp.com>2019-02-12 10:32:33 +0800
commitfa34c5b967f26a04c0be948a31a122f5752d71a6 (patch)
treeff8951c7279489bf4269efe486e4570d5ea567e0 /sound
parent0197d0801b181a89b665fc7b90669eba05e45590 (diff)
MLK-18682-1: ASoC: fsl: sai: use set_bclk_ratio to calculate BCLK freq
ALSA API has a standard way to configure DAI BCLK by calling "snd_soc_dai_set_bclk_ratio" function. So use it to set BCLK ratio and calculate SAI BCLK frequency. Signed-off-by: Viorel Suman <viorel.suman@nxp.com>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/fsl/fsl_sai.c21
-rw-r--r--sound/soc/fsl/fsl_sai.h3
-rw-r--r--sound/soc/fsl/imx-pdm.c4
3 files changed, 15 insertions, 13 deletions
diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index 6273bfca897a..c004c916c1fa 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -240,6 +240,14 @@ static int fsl_sai_set_dai_sysclk_tr(struct snd_soc_dai *cpu_dai,
return 0;
}
+static int fsl_sai_set_dai_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
+{
+ struct fsl_sai *sai = snd_soc_dai_get_drvdata(dai);
+
+ sai->bitclk_ratio = ratio;
+ return 0;
+}
+
static int fsl_sai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
int clk_id, unsigned int freq, int dir)
{
@@ -249,11 +257,6 @@ static int fsl_sai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
if (dir == SND_SOC_CLOCK_IN)
return 0;
- if (clk_id == FSL_SAI_CLK_BIT) {
- sai->bitclk_freq = freq;
- return 0;
- }
-
if (freq > 0) {
if (clk_id < 0 || clk_id >= FSL_SAI_MCLK_MAX) {
dev_err(cpu_dai->dev, "Unknown clock id: %d\n", clk_id);
@@ -575,6 +578,7 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
unsigned int channels = params_channels(params);
u32 word_width = params_width(params);
+ u32 rate = params_rate(params);
u32 val_cr4 = 0, val_cr5 = 0;
u32 slots = (channels == 1) ? 2 : channels;
u32 slot_width = word_width;
@@ -609,12 +613,12 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
slot_width = sai->slot_width;
if (!sai->slave_mode[tx]) {
- if (sai->bitclk_freq)
+ if (sai->bitclk_ratio)
ret = fsl_sai_set_bclk(cpu_dai, tx,
- sai->bitclk_freq);
+ rate * sai->bitclk_ratio);
else
ret = fsl_sai_set_bclk(cpu_dai, tx,
- slots * slot_width * params_rate(params));
+ rate * slots * slot_width);
if (ret)
return ret;
@@ -930,6 +934,7 @@ static void fsl_sai_shutdown(struct snd_pcm_substream *substream,
}
static const struct snd_soc_dai_ops fsl_sai_pcm_dai_ops = {
+ .set_bclk_ratio = fsl_sai_set_dai_bclk_ratio,
.set_sysclk = fsl_sai_set_dai_sysclk,
.set_fmt = fsl_sai_set_dai_fmt,
.set_tdm_slot = fsl_sai_set_dai_tdm_slot,
diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h
index abed3d6d48f0..1389a2394678 100644
--- a/sound/soc/fsl/fsl_sai.h
+++ b/sound/soc/fsl/fsl_sai.h
@@ -208,7 +208,6 @@
#define FSL_SAI_CLK_MAST3 3
#define FSL_SAI_MCLK_MAX 4
-#define FSL_SAI_CLK_BIT 5
/* SAI data transfer numbers per DMA request */
#define FSL_SAI_MAXBURST_TX 6
@@ -263,7 +262,7 @@ struct fsl_sai {
unsigned int mclk_streams;
unsigned int slots;
unsigned int slot_width;
- unsigned int bitclk_freq;
+ unsigned int bitclk_ratio;
struct snd_dmaengine_dai_dma_data dma_params_rx;
struct snd_dmaengine_dai_dma_data dma_params_tx;
diff --git a/sound/soc/fsl/imx-pdm.c b/sound/soc/fsl/imx-pdm.c
index e8cea5255209..d69e27ec50c8 100644
--- a/sound/soc/fsl/imx-pdm.c
+++ b/sound/soc/fsl/imx-pdm.c
@@ -67,7 +67,6 @@ static int imx_pdm_mic_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_card *card = rtd->card;
struct imx_pdm_data *data = snd_soc_card_get_drvdata(card);
- unsigned int bitclk = params_rate(params) * data->decimation;
int ret;
/* set cpu dai format configuration */
@@ -80,8 +79,7 @@ static int imx_pdm_mic_hw_params(struct snd_pcm_substream *substream,
/* set tdm slots only one for now */
snd_soc_dai_set_tdm_slot(cpu_dai, 0, 0, 1, 32);
/* Set clock out */
- ret = snd_soc_dai_set_sysclk(cpu_dai, FSL_SAI_CLK_BIT,
- bitclk, SND_SOC_CLOCK_OUT);
+ ret = snd_soc_dai_set_bclk_ratio(cpu_dai, data->decimation);
if (ret) {
dev_err(card->dev, "fail to set cpu sysclk: %d\n", ret);
return ret;