From fda2f6024ced25b03bca7ed5655b8f2dc2c36ab2 Mon Sep 17 00:00:00 2001 From: Xing Wang Date: Thu, 13 Apr 2017 20:07:33 +0800 Subject: [PATCH] audio: adjust pcm bclk for 24/32bit PD#141217: fix pcm 24/32bit support Change-Id: I3aae169645ec237079a17c89ce4f5361962a3e62 Signed-off-by: Xing Wang --- sound/soc/amlogic/aml_audio_hw_pcm.c | 8 +++----- sound/soc/amlogic/aml_pcm_dai.c | 26 +++++++++++++++----------- sound/soc/amlogic/aml_pcm_dai.h | 1 - 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/sound/soc/amlogic/aml_audio_hw_pcm.c b/sound/soc/amlogic/aml_audio_hw_pcm.c index c3b1b99e0d84..4844359f832e 100644 --- a/sound/soc/amlogic/aml_audio_hw_pcm.c +++ b/sound/soc/amlogic/aml_audio_hw_pcm.c @@ -132,9 +132,6 @@ RESET_FIFO: pcm_mode = 2; max_bits = 0x17; valid_bits = 0x17; - - //pcm_mode = 3; - max_bits = 0x1f; break; case SNDRV_PCM_FORMAT_S16_LE: pcm_mode = 1; @@ -549,10 +546,10 @@ void pcm_master_out_enable(struct snd_pcm_substream *substream, int flag) break; case SNDRV_PCM_FORMAT_S24_LE: pcm_mode = 2; - valid_bits = 0x1f; + valid_bits = 0x17; if (dsp_mode == SND_SOC_DAIFMT_DSP_A) { bit_offset_s = 0xF; - slot_offset_s = 0x1F; + slot_offset_s = 0x17; bit_offset_e = 0; slot_offset_e = 0; } @@ -634,6 +631,7 @@ void pcm_master_out_enable(struct snd_pcm_substream *substream, int flag) /* pcmout control2 */ /* FS * 16 * 16 = BCLK */ + /* FS * 32 * 16 = BCLK */ aml_write_cbus(PCMOUT_CTRL2, /* underrun use mute constant */ (0 << 29) | diff --git a/sound/soc/amlogic/aml_pcm_dai.c b/sound/soc/amlogic/aml_pcm_dai.c index d9328f256922..f89e3c8f74b9 100644 --- a/sound/soc/amlogic/aml_pcm_dai.c +++ b/sound/soc/amlogic/aml_pcm_dai.c @@ -46,6 +46,8 @@ #define PCM_DEFAULT_SAMPLERATE 8000 #define PCM_DEFAULT_MCLK_RATIO_SR 256 +#define PCM_24BIT_MCLK_RATIO_SR 384 +#define PCM_32BIT_MCLK_RATIO_SR 512 static int aml_pcm_set_clk(struct aml_pcm *pcm, unsigned long rate) { @@ -89,9 +91,21 @@ static int aml_pcm_dai_prepare(struct snd_pcm_substream *substream, { struct snd_pcm_runtime *runtime = substream->runtime; struct aml_pcm_runtime_data *prtd = runtime->private_data; + struct aml_pcm *pcm = snd_soc_dai_get_drvdata(dai); + int mclk_rate; pr_debug("***Entered %s\n", __func__); + /* set bclk */ + if (runtime->format == SNDRV_PCM_FORMAT_S32_LE) + mclk_rate = runtime->rate * PCM_32BIT_MCLK_RATIO_SR; + else if (runtime->format == SNDRV_PCM_FORMAT_S24_LE) + mclk_rate = runtime->rate * PCM_24BIT_MCLK_RATIO_SR; + else + mclk_rate = runtime->rate * PCM_DEFAULT_MCLK_RATIO_SR; + + aml_pcm_set_clk(pcm, mclk_rate); + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { pr_info( "%s playback stream buffer start: %ld size: 0x%x\n", @@ -168,16 +182,6 @@ static int aml_pcm_dai_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { - struct aml_pcm *pcm = snd_soc_dai_get_drvdata(dai); - int srate, mclk_rate; - - srate = params_rate(params); - if (pcm->old_samplerate != srate) { - pcm->old_samplerate = srate; - mclk_rate = srate * PCM_DEFAULT_MCLK_RATIO_SR; - aml_pcm_set_clk(pcm, mclk_rate); - } - pr_debug("***Entered %s:%s\n", __FILE__, __func__); return 0; } @@ -301,7 +305,7 @@ static int aml_pcm_dai_probe(struct platform_device *pdev) goto err; } - /* now only 256fs is supported */ + /* Default 256fs */ ret = aml_pcm_set_clk(pcm_p, PCM_DEFAULT_SAMPLERATE * PCM_DEFAULT_MCLK_RATIO_SR); if (ret < 0) { diff --git a/sound/soc/amlogic/aml_pcm_dai.h b/sound/soc/amlogic/aml_pcm_dai.h index 0a64f3bdc2fa..4f6b0474c48c 100644 --- a/sound/soc/amlogic/aml_pcm_dai.h +++ b/sound/soc/amlogic/aml_pcm_dai.h @@ -22,7 +22,6 @@ struct aml_pcm { struct clk *clk_mpll; struct clk *clk_pcm_mclk; struct clk *clk_pcm_sync; - int old_samplerate; int pcm_mode; };