linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/5] Support more sample rates, let the rates normal work
@ 2015-11-03  1:33 Caesar Wang
  2015-11-03  1:33 ` [PATCH v1 1/5] ASoC: rockchip: i2s: Support to set the divider clock API Caesar Wang
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Caesar Wang @ 2015-11-03  1:33 UTC (permalink / raw)
  To: Heiko Stuebner, Mark Brown
  Cc: Sonny Rao, Dylan Reid, Doug Anderson, Cheng-Yi Chiang,
	linux-rockchip, Caesar Wang, Jaroslav Kysela, alsa-devel,
	linux-kernel, Takashi Iwai, Liam Girdwood, linux-arm-kernel

That's seem the moment rockchip-codec driver other than 44100 and 48000 do not work.
Says the (max98090, rt5640).

----
As the chromeos reported issue:(https://chromium.googlesource.com/chromiumos/third_party/kernel/+/v3.14)

For detail:
In that bug we want to add 32000 to sound/soc/rockchip/rockchip_max98090.c rk_aif1_hw_params. However that does not work.

Previously, in https://chromium-review.googlesource.com/#/c/268398/ , rate 8000, 1600, 96000 were added.
However, those rates do not work. I got the same audio as 48000 when I run

aplay -D hw:0,0 /usr/local/autotest/cros/audio/fix_440_16_half.raw --rate 8000 -f S16_LE -c2
aplay -D hw:0,0 /usr/local/autotest/cros/audio/fix_440_16_half.raw --rate 16000 -f S16_LE -c2
aplay -D hw:0,0 /usr/local/autotest/cros/audio/fix_440_16_half.raw --rate 96000 -f S16_LE -c2

They all sound identical to
aplay -D hw:0,0 /usr/local/autotest/cros/audio/fix_440_16_half.raw --rate 48000 -f S16_LE -c2

Also, recording using
aplay -D hw:0,0 /usr/local/test.raw --rate 96000 -f S16_LE -c2  and examine the output we see it was recording using 48000.

Okay, let's add this series patchs to fix this issue.

arecord -D hw:0 -f S16_LE -c 2 --rate 96000 -d 5 foobar.wav
and
    aplay -D hw:0 foobar.wav
Tested on veyron devices.


Changes in v1:
- change the subject and commit.
- remove the print message dev_dbg().
- Fix a subject missspell.

Caesar Wang (5):
  ASoC: rockchip: i2s: Support to set the divider clock API
  ASoC: rockchip-max98090: Allow more sample rates
  ASoC: rockchip-rt5645: Allow more sample rates
  ASoC: rockchip-max98090: Add the divider clock for cpu
  ASoC: rockchip-rt5645: Add the divider clock for cpu

 sound/soc/rockchip/rockchip_i2s.c      | 27 +++++++++++++++++++++++++
 sound/soc/rockchip/rockchip_max98090.c | 37 ++++++++++++++++++++++++++++++++++
 sound/soc/rockchip/rockchip_rt5645.c   | 37 ++++++++++++++++++++++++++++++++++
 3 files changed, 101 insertions(+)

-- 
1.9.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v1 1/5] ASoC: rockchip: i2s: Support to set the divider clock API
  2015-11-03  1:33 [PATCH v1 0/5] Support more sample rates, let the rates normal work Caesar Wang
@ 2015-11-03  1:33 ` Caesar Wang
  2015-11-04 14:34   ` Mark Brown
  2015-11-03  1:33 ` [PATCH v1 2/5] ASoC: rockchip-max98090: Allow more sample rates Caesar Wang
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Caesar Wang @ 2015-11-03  1:33 UTC (permalink / raw)
  To: Heiko Stuebner, Mark Brown
  Cc: Sonny Rao, Dylan Reid, Doug Anderson, Cheng-Yi Chiang,
	linux-rockchip, Caesar Wang, Jaroslav Kysela, alsa-devel,
	linux-kernel, Takashi Iwai, Liam Girdwood, linux-arm-kernel

In order to support more sample rates, add the divider clock api.

As the input source clock to the module is MCLK_I2S,
and by the divider of the module, the clock generator generates
SCLK and LRCK to transmitter and receiver.

Signed-off-by: Caesar Wang <wxt@rock-chips.com>
---

Changes in v1:
- change the subject and commit.
- remove the print message dev_dbg().

 sound/soc/rockchip/rockchip_i2s.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c
index b936102..23c867f 100644
--- a/sound/soc/rockchip/rockchip_i2s.c
+++ b/sound/soc/rockchip/rockchip_i2s.c
@@ -286,6 +286,32 @@ static int rockchip_i2s_trigger(struct snd_pcm_substream *substream,
 	return ret;
 }
 
+static int rockchip_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
+				   int div_id, int div)
+{
+	struct rk_i2s_dev *i2s = to_info(cpu_dai);
+	unsigned int val = 0;
+
+	switch (div_id) {
+	case ROCKCHIP_DIV_BCLK:
+		val |= I2S_CKR_TSD(div);
+		val |= I2S_CKR_RSD(div);
+		regmap_update_bits(i2s->regmap, I2S_CKR,
+				   I2S_CKR_TSD_MASK | I2S_CKR_RSD_MASK,
+				   val);
+		break;
+	case ROCKCHIP_DIV_MCLK:
+		val |= I2S_CKR_MDIV(div);
+		regmap_update_bits(i2s->regmap, I2S_CKR,
+				   I2S_CKR_MDIV_MASK, val);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int rockchip_i2s_set_sysclk(struct snd_soc_dai *cpu_dai, int clk_id,
 				   unsigned int freq, int dir)
 {
@@ -311,6 +337,7 @@ static int rockchip_i2s_dai_probe(struct snd_soc_dai *dai)
 
 static const struct snd_soc_dai_ops rockchip_i2s_dai_ops = {
 	.hw_params = rockchip_i2s_hw_params,
+	.set_clkdiv = rockchip_i2s_set_clkdiv,
 	.set_sysclk = rockchip_i2s_set_sysclk,
 	.set_fmt = rockchip_i2s_set_fmt,
 	.trigger = rockchip_i2s_trigger,
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 2/5] ASoC: rockchip-max98090: Allow more sample rates
  2015-11-03  1:33 [PATCH v1 0/5] Support more sample rates, let the rates normal work Caesar Wang
  2015-11-03  1:33 ` [PATCH v1 1/5] ASoC: rockchip: i2s: Support to set the divider clock API Caesar Wang
@ 2015-11-03  1:33 ` Caesar Wang
  2015-11-03  1:33 ` [PATCH v1 3/5] ASoC: rockchip-rt5645: " Caesar Wang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Caesar Wang @ 2015-11-03  1:33 UTC (permalink / raw)
  To: Heiko Stuebner, Mark Brown
  Cc: Sonny Rao, Dylan Reid, Doug Anderson, Cheng-Yi Chiang,
	linux-rockchip, Caesar Wang, Jaroslav Kysela, alsa-devel,
	linux-kernel, Takashi Iwai, Liam Girdwood, linux-arm-kernel

The MAX98090 audio codec support sample rates from 8 to 96 kHz
as the dai claim.

Signed-off-by: Caesar Wang <wxt@rock-chips.com>
---

Changes in v1: None

 sound/soc/rockchip/rockchip_max98090.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sound/soc/rockchip/rockchip_max98090.c b/sound/soc/rockchip/rockchip_max98090.c
index 26567b1..a6ff221 100644
--- a/sound/soc/rockchip/rockchip_max98090.c
+++ b/sound/soc/rockchip/rockchip_max98090.c
@@ -80,11 +80,16 @@ static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
 	switch (params_rate(params)) {
 	case 8000:
 	case 16000:
+	case 24000:
+	case 32000:
 	case 48000:
 	case 96000:
 		mclk = 12288000;
 		break;
+	case 11025:
+	case 22050:
 	case 44100:
+	case 88200:
 		mclk = 11289600;
 		break;
 	default:
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 3/5] ASoC: rockchip-rt5645: Allow more sample rates
  2015-11-03  1:33 [PATCH v1 0/5] Support more sample rates, let the rates normal work Caesar Wang
  2015-11-03  1:33 ` [PATCH v1 1/5] ASoC: rockchip: i2s: Support to set the divider clock API Caesar Wang
  2015-11-03  1:33 ` [PATCH v1 2/5] ASoC: rockchip-max98090: Allow more sample rates Caesar Wang
@ 2015-11-03  1:33 ` Caesar Wang
  2015-11-03  1:33 ` [PATCH v1 4/5] ASoC: rockchip-max98090: Add the divider clock for cpu Caesar Wang
  2015-11-03  1:33 ` [PATCH v1 5/5] ASoC: rockchip-rt5645: " Caesar Wang
  4 siblings, 0 replies; 8+ messages in thread
From: Caesar Wang @ 2015-11-03  1:33 UTC (permalink / raw)
  To: Heiko Stuebner, Mark Brown
  Cc: Sonny Rao, Dylan Reid, Doug Anderson, Cheng-Yi Chiang,
	linux-rockchip, Caesar Wang, Jaroslav Kysela, alsa-devel,
	linux-kernel, Takashi Iwai, Liam Girdwood, linux-arm-kernel

The RT5645 audio codec support sample rates from 8 to 96 kHz
as the dai claim.

Signed-off-by: Caesar Wang <wxt@rock-chips.com>
---

Changes in v1: None

 sound/soc/rockchip/rockchip_rt5645.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sound/soc/rockchip/rockchip_rt5645.c b/sound/soc/rockchip/rockchip_rt5645.c
index 68c62e4..edff07f 100644
--- a/sound/soc/rockchip/rockchip_rt5645.c
+++ b/sound/soc/rockchip/rockchip_rt5645.c
@@ -79,11 +79,16 @@ static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
 	switch (params_rate(params)) {
 	case 8000:
 	case 16000:
+	case 24000:
+	case 32000:
 	case 48000:
 	case 96000:
 		mclk = 12288000;
 		break;
+	case 11025:
+	case 22050:
 	case 44100:
+	case 88200:
 		mclk = 11289600;
 		break;
 	default:
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 4/5] ASoC: rockchip-max98090: Add the divider clock for cpu
  2015-11-03  1:33 [PATCH v1 0/5] Support more sample rates, let the rates normal work Caesar Wang
                   ` (2 preceding siblings ...)
  2015-11-03  1:33 ` [PATCH v1 3/5] ASoC: rockchip-rt5645: " Caesar Wang
@ 2015-11-03  1:33 ` Caesar Wang
  2015-11-03  1:33 ` [PATCH v1 5/5] ASoC: rockchip-rt5645: " Caesar Wang
  4 siblings, 0 replies; 8+ messages in thread
From: Caesar Wang @ 2015-11-03  1:33 UTC (permalink / raw)
  To: Heiko Stuebner, Mark Brown
  Cc: Sonny Rao, Dylan Reid, Doug Anderson, Cheng-Yi Chiang,
	linux-rockchip, Caesar Wang, Jaroslav Kysela, alsa-devel,
	linux-kernel, Takashi Iwai, Liam Girdwood, linux-arm-kernel

Add to set the cpu/codec DAI configure, let's divider the
Transmit/Receive clocks for cpu.

In master mode, The SCLK and LRCK are configured as output,
this patch should can set each divider to arrange the clock distribution.

Signed-off-by: Caesar Wang <wxt@rock-chips.com>
---

Changes in v1: None

 sound/soc/rockchip/rockchip_max98090.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/sound/soc/rockchip/rockchip_max98090.c b/sound/soc/rockchip/rockchip_max98090.c
index a6ff221..e1cdd40 100644
--- a/sound/soc/rockchip/rockchip_max98090.c
+++ b/sound/soc/rockchip/rockchip_max98090.c
@@ -75,8 +75,25 @@ static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	int dai_fmt = rtd->card->dai_link->dai_fmt;
 	int mclk;
 
+	/* set codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
+	if (ret < 0) {
+		dev_err(codec_dai->dev,
+			"failed to set the format for codec side\n");
+		return ret;
+	}
+
+	/* set cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
+	if (ret < 0) {
+		dev_err(codec_dai->dev,
+			"failed to set the format for cpu side\n");
+		return ret;
+	}
+
 	switch (params_rate(params)) {
 	case 8000:
 	case 16000:
@@ -110,6 +127,21 @@ static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
 		return ret;
 	}
 
+	/* The codec is master mode, that's not needed set clkdiv for cpu */
+	if ((dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBM_CFM)
+		return ret;
+
+	/* the LRCK clock for cpu */
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_BCLK,
+				     (mclk / 4) / params_rate(params));
+	if (ret < 0)
+		return ret;
+
+	/* the SCLK clock for cpu */
+	snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 4);
+	if (ret < 0)
+		return ret;
+
 	return ret;
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 5/5] ASoC: rockchip-rt5645: Add the divider clock for cpu
  2015-11-03  1:33 [PATCH v1 0/5] Support more sample rates, let the rates normal work Caesar Wang
                   ` (3 preceding siblings ...)
  2015-11-03  1:33 ` [PATCH v1 4/5] ASoC: rockchip-max98090: Add the divider clock for cpu Caesar Wang
@ 2015-11-03  1:33 ` Caesar Wang
  4 siblings, 0 replies; 8+ messages in thread
From: Caesar Wang @ 2015-11-03  1:33 UTC (permalink / raw)
  To: Heiko Stuebner, Mark Brown
  Cc: Sonny Rao, Dylan Reid, Doug Anderson, Cheng-Yi Chiang,
	linux-rockchip, Caesar Wang, Jaroslav Kysela, alsa-devel,
	linux-kernel, Takashi Iwai, Liam Girdwood, linux-arm-kernel

Add to set the cpu/codec DAI configure, let's divider the
Transmit/Receive clock for cpu.

In master mode, The SCLK and LRCK are configured as output,
this patch should can set each divider to arrange the clock distribution.

Signed-off-by: Caesar Wang <wxt@rock-chips.com>

---

Changes in v1:
- Fix a subject missspell.

 sound/soc/rockchip/rockchip_rt5645.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/sound/soc/rockchip/rockchip_rt5645.c b/sound/soc/rockchip/rockchip_rt5645.c
index edff07f..4c1a693 100644
--- a/sound/soc/rockchip/rockchip_rt5645.c
+++ b/sound/soc/rockchip/rockchip_rt5645.c
@@ -74,8 +74,25 @@ static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	int dai_fmt = rtd->card->dai_link->dai_fmt;
 	int mclk;
 
+	/* set codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
+	if (ret < 0) {
+		dev_err(codec_dai->dev,
+			"failed to set the format for codec side\n");
+		return ret;
+	}
+
+	/* set cpu DAI configuration */
+	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
+	if (ret < 0) {
+		dev_err(codec_dai->dev,
+			"failed to set the format for cpu side\n");
+		return ret;
+	}
+
 	switch (params_rate(params)) {
 	case 8000:
 	case 16000:
@@ -109,6 +126,21 @@ static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
 		return ret;
 	}
 
+	/* The codec is master mode, that's not needed set clkdiv for cpu */
+	if ((dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBM_CFM)
+		return ret;
+
+	/* the LRCK clock for cpu */
+	ret = snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_BCLK,
+				     (mclk / 4) / params_rate(params));
+	if (ret < 0)
+		return ret;
+
+	/* the SCLK clock for cpu */
+	snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 4);
+	if (ret < 0)
+		return ret;
+
 	return ret;
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/5] ASoC: rockchip: i2s: Support to set the divider clock API
  2015-11-03  1:33 ` [PATCH v1 1/5] ASoC: rockchip: i2s: Support to set the divider clock API Caesar Wang
@ 2015-11-04 14:34   ` Mark Brown
       [not found]     ` <563AEF97.1080304@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Brown @ 2015-11-04 14:34 UTC (permalink / raw)
  To: Caesar Wang
  Cc: Heiko Stuebner, Sonny Rao, Dylan Reid, Doug Anderson,
	Cheng-Yi Chiang, linux-rockchip, Jaroslav Kysela, alsa-devel,
	linux-kernel, Takashi Iwai, Liam Girdwood, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 397 bytes --]

On Tue, Nov 03, 2015 at 09:33:54AM +0800, Caesar Wang wrote:
> In order to support more sample rates, add the divider clock api.
> 
> As the input source clock to the module is MCLK_I2S,
> and by the divider of the module, the clock generator generates
> SCLK and LRCK to transmitter and receiver.

Same thing as your other very similar patch: why does this feature
require set_clkdiv()?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/5] ASoC: rockchip: i2s: Support to set the divider clock API
       [not found]     ` <563AEF97.1080304@gmail.com>
@ 2015-11-05 16:16       ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2015-11-05 16:16 UTC (permalink / raw)
  To: Caesar Wang
  Cc: Caesar Wang, alsa-devel, Heiko Stuebner, Liam Girdwood,
	linux-kernel, Takashi Iwai, Doug Anderson, Jaroslav Kysela,
	linux-rockchip, Dylan Reid, Sonny Rao, linux-arm-kernel,
	Cheng-Yi Chiang

[-- Attachment #1: Type: text/plain, Size: 1125 bytes --]

On Thu, Nov 05, 2015 at 01:56:39PM +0800, Caesar Wang wrote:
> 在 2015年11月04日 22:34, Mark Brown 写道:

> >Same thing as your other very similar patch: why does this feature
> >require set_clkdiv()?

> Okay, you said "
> Why is this a requirement?  The clock to use as a source should normally
> be specified via set_sysclk() and any internal dividers calculated
> automatically by the driver.
> "

> I think we should divider settings for these different sample rates.

Sure, the question is how these things get set.

>  If the codec is master mode, we are *not* need this operate.
>  If the codec is slave mode, we are need to divider the MCLK to setting the different sample rates.
> (for example, the sample rates (8k, 48k) the clock is MCLK, the clock should be divider cpu ip )

> "dividers calculated automatically by the driver", that should be occured by codec(max98090
> ) driver, but the divider clocks (LRCK, SCLK) should need to set for cpu internal side.

So the CPU knows what rates it needs to set and what clocks it's getting
in, why can't it set the dividers autonomously.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-11-05 16:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-03  1:33 [PATCH v1 0/5] Support more sample rates, let the rates normal work Caesar Wang
2015-11-03  1:33 ` [PATCH v1 1/5] ASoC: rockchip: i2s: Support to set the divider clock API Caesar Wang
2015-11-04 14:34   ` Mark Brown
     [not found]     ` <563AEF97.1080304@gmail.com>
2015-11-05 16:16       ` Mark Brown
2015-11-03  1:33 ` [PATCH v1 2/5] ASoC: rockchip-max98090: Allow more sample rates Caesar Wang
2015-11-03  1:33 ` [PATCH v1 3/5] ASoC: rockchip-rt5645: " Caesar Wang
2015-11-03  1:33 ` [PATCH v1 4/5] ASoC: rockchip-max98090: Add the divider clock for cpu Caesar Wang
2015-11-03  1:33 ` [PATCH v1 5/5] ASoC: rockchip-rt5645: " Caesar Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).