linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: cros_ec_codec: Support setting bclk ratio
@ 2020-01-24 16:18 Yu-Hsuan Hsu
  2020-01-25 14:19 ` Tzung-Bi Shih
  0 siblings, 1 reply; 2+ messages in thread
From: Yu-Hsuan Hsu @ 2020-01-24 16:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Cheng-Yi Chiang, Tzung-Bi Shih, Enric Balletbo i Serra,
	Guenter Roeck, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Benson Leung, Yu-Hsuan Hsu

Support setting bclk ratio from machine drivers.

Signed-off-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>
---
 sound/soc/codecs/cros_ec_codec.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c
index 6a24f570c5e86f..818a405fbc44ff 100644
--- a/sound/soc/codecs/cros_ec_codec.c
+++ b/sound/soc/codecs/cros_ec_codec.c
@@ -42,6 +42,8 @@ struct cros_ec_codec_priv {
 	uint64_t ap_shm_addr;
 	uint64_t ap_shm_last_alloc;
 
+	uint32_t i2s_rx_bclk_ratio;
+
 	/* DMIC */
 	atomic_t dmic_probed;
 
@@ -259,6 +261,7 @@ static int i2s_rx_hw_params(struct snd_pcm_substream *substream,
 		snd_soc_component_get_drvdata(component);
 	struct ec_param_ec_codec_i2s_rx p;
 	enum ec_codec_i2s_rx_sample_depth depth;
+	uint32_t bclk;
 	int ret;
 
 	if (params_rate(params) != 48000)
@@ -284,15 +287,30 @@ static int i2s_rx_hw_params(struct snd_pcm_substream *substream,
 	if (ret < 0)
 		return ret;
 
-	dev_dbg(component->dev, "set bclk to %u\n",
-		snd_soc_params_to_bclk(params));
+	/* If the blck ratio is not set, get bclk from hw_params. */
+	if (priv->i2s_rx_bclk_ratio)
+		bclk = params_rate(params) * priv->i2s_rx_bclk_ratio;
+	else
+		bclk = snd_soc_params_to_bclk(params);
+
+	dev_dbg(component->dev, "set bclk to %u\n", bclk);
 
 	p.cmd = EC_CODEC_I2S_RX_SET_BCLK;
-	p.set_bclk_param.bclk = snd_soc_params_to_bclk(params);
+	p.set_bclk_param.bclk = bclk;
 	return send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_I2S_RX,
 				    (uint8_t *)&p, sizeof(p), NULL, 0);
 }
 
+static int i2s_rx_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
+{
+	struct snd_soc_component *component = dai->component;
+	struct cros_ec_codec_priv *priv =
+		snd_soc_component_get_drvdata(component);
+
+	priv->i2s_rx_bclk_ratio = ratio;
+	return 0;
+}
+
 static int i2s_rx_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 {
 	struct snd_soc_component *component = dai->component;
@@ -340,6 +358,7 @@ static int i2s_rx_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 static const struct snd_soc_dai_ops i2s_rx_dai_ops = {
 	.hw_params = i2s_rx_hw_params,
 	.set_fmt = i2s_rx_set_fmt,
+	.set_bclk_ratio = i2s_rx_set_bclk_ratio,
 };
 
 static int i2s_rx_event(struct snd_soc_dapm_widget *w,
-- 
2.25.0.341.g760bfbb309-goog


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

* Re: [PATCH] ASoC: cros_ec_codec: Support setting bclk ratio
  2020-01-24 16:18 [PATCH] ASoC: cros_ec_codec: Support setting bclk ratio Yu-Hsuan Hsu
@ 2020-01-25 14:19 ` Tzung-Bi Shih
  0 siblings, 0 replies; 2+ messages in thread
From: Tzung-Bi Shih @ 2020-01-25 14:19 UTC (permalink / raw)
  To: Yu-Hsuan Hsu
  Cc: Linux Kernel Mailing List, Cheng-Yi Chiang, Tzung-Bi Shih,
	Enric Balletbo i Serra, Guenter Roeck, Liam Girdwood, Mark Brown,
	Jaroslav Kysela, Takashi Iwai, Benson Leung

On Sat, Jan 25, 2020 at 12:18 AM Yu-Hsuan Hsu <yuhsuan@chromium.org> wrote:
>
> Support setting bclk ratio from machine drivers.
>
> Signed-off-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>

Please at least cc to <alsa-devel@alsa-project.org> for ASoC-related patches.

> @@ -42,6 +42,8 @@ struct cros_ec_codec_priv {
>         uint64_t ap_shm_addr;
>         uint64_t ap_shm_last_alloc;
>
> +       uint32_t i2s_rx_bclk_ratio;
> +

To be consistent, move the variable after the "DMIC" part and add a /*
I2S_RX */ comment.

>         /* DMIC */
>         atomic_t dmic_probed;

>         if (params_rate(params) != 48000)
> @@ -284,15 +287,30 @@ static int i2s_rx_hw_params(struct snd_pcm_substream *substream,
>         if (ret < 0)
>                 return ret;
>
> -       dev_dbg(component->dev, "set bclk to %u\n",
> -               snd_soc_params_to_bclk(params));
> +       /* If the blck ratio is not set, get bclk from hw_params. */

A typo, s/blck/bclk/.  I don't think the comment is very necessary.
The code block is obvious.

> +       if (priv->i2s_rx_bclk_ratio)
> +               bclk = params_rate(params) * priv->i2s_rx_bclk_ratio;
> +       else
> +               bclk = snd_soc_params_to_bclk(params);
> +
> +       dev_dbg(component->dev, "set bclk to %u\n", bclk);

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

end of thread, other threads:[~2020-01-25 14:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-24 16:18 [PATCH] ASoC: cros_ec_codec: Support setting bclk ratio Yu-Hsuan Hsu
2020-01-25 14:19 ` Tzung-Bi Shih

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).