alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Sven Van Asbroeck <thesven73@gmail.com>
To: Russell King - ARM Linux admin <linux@armlinux.org.uk>,
	Mark Brown <broonie@kernel.org>,
	Peter Ujfalusi <peter.ujfalusi@ti.com>,
	Jyri Sarha <jsarha@ti.com>
Cc: alsa-devel@alsa-project.org,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	David Airlie <airlied@linux.ie>, Takashi Iwai <tiwai@suse.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	dri-devel@lists.freedesktop.org, Daniel Vetter <daniel@ffwll.ch>
Subject: [RFC PATCH 1/2] ASoC: simple-card: add support for bclk_ratio
Date: Mon, 25 Feb 2019 11:42:17 -0500	[thread overview]
Message-ID: <20190225164218.19439-1-TheSven73@gmail.com> (raw)

In some situations, codec configuration will depend on the
bclk_ratio generated by the cpu dai. The tda998x hdmi transmitter
is an example of this.

Allow simple-card to set the bclk_ratio via the 'bclk-slot-ratio'
devicetree property, which describes the bclk to slot rate ratio.

This value is converted to the bclk to sample ratio before being
passed into set_bclk_ratio().

Signed-off-by: Sven Van Asbroeck <TheSven73@gmail.com>
---
 sound/soc/generic/simple-card.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 3fe34417ec89..61e9ba4e9b58 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -25,6 +25,7 @@ struct simple_card_data {
 		struct asoc_simple_card_data adata;
 		struct snd_soc_codec_conf *codec_conf;
 		unsigned int mclk_fs;
+		unsigned int bclk_slot_ratio;
 	} *dai_props;
 	struct asoc_simple_jack hp_jack;
 	struct asoc_simple_jack mic_jack;
@@ -97,7 +98,7 @@ static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
 	struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
 	struct simple_dai_props *dai_props =
 		simple_priv_to_props(priv, rtd->num);
-	unsigned int mclk, mclk_fs = 0;
+	unsigned int mclk, bclk_ratio, mclk_fs = 0, bclk_slot_ratio = 0;
 	int ret = 0;
 
 	if (dai_props->mclk_fs)
@@ -124,6 +125,23 @@ static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
 		if (ret && ret != -ENOTSUPP)
 			goto err;
 	}
+
+	if (dai_props->bclk_slot_ratio)
+		bclk_slot_ratio = dai_props->bclk_slot_ratio;
+
+	if (bclk_slot_ratio) {
+		/* FIXME do we need to care about TDM slots here ? */
+		bclk_ratio = snd_soc_calc_frame_size(bclk_slot_ratio,
+				params_channels(params), 1);
+
+		ret = snd_soc_dai_set_bclk_ratio(codec_dai, bclk_ratio);
+		if (ret && ret != -ENOTSUPP)
+			goto err;
+
+		ret = snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio);
+		if (ret && ret != -ENOTSUPP)
+			goto err;
+	}
 	return 0;
 err:
 	return ret;
@@ -277,6 +295,12 @@ static int asoc_simple_card_dai_link_of_dpcm(struct device_node *top,
 	of_property_read_u32(node, prop, &dai_props->mclk_fs);
 	of_property_read_u32(np,   prop, &dai_props->mclk_fs);
 
+	snprintf(prop, sizeof(prop), "%sbclk-slot-ratio", prefix);
+	of_property_read_u32(top,  PREFIX "bclk-slot-ratio",
+				&dai_props->bclk_slot_ratio);
+	of_property_read_u32(node, prop, &dai_props->bclk_slot_ratio);
+	of_property_read_u32(np,   prop, &dai_props->bclk_slot_ratio);
+
 	ret = asoc_simple_card_parse_daifmt(dev, node, codec,
 					    prefix, &dai_link->dai_fmt);
 	if (ret < 0)
@@ -349,6 +373,13 @@ static int asoc_simple_card_dai_link_of(struct device_node *top,
 	of_property_read_u32(cpu,   prop, &dai_props->mclk_fs);
 	of_property_read_u32(codec, prop, &dai_props->mclk_fs);
 
+	snprintf(prop, sizeof(prop), "%sbclk-slot-ratio", prefix);
+	of_property_read_u32(top,  PREFIX "bclk-slot-ratio",
+					&dai_props->bclk_slot_ratio);
+	of_property_read_u32(node,  prop, &dai_props->bclk_slot_ratio);
+	of_property_read_u32(cpu,   prop, &dai_props->bclk_slot_ratio);
+	of_property_read_u32(codec, prop, &dai_props->bclk_slot_ratio);
+
 	ret = asoc_simple_card_parse_cpu(cpu, dai_link,
 					 DAI, CELL, &single_cpu);
 	if (ret < 0)
-- 
2.17.1

             reply	other threads:[~2019-02-25 16:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-25 16:42 Sven Van Asbroeck [this message]
2019-02-25 16:42 ` [RFC PATCH 2/2] ASoC: core: standardize snd_soc_dai_set_bclk_ratio() behaviour Sven Van Asbroeck
2019-02-26  0:35 ` [RFC PATCH 1/2] ASoC: simple-card: add support for bclk_ratio Kuninori Morimoto
2019-02-26  9:11   ` Russell King - ARM Linux admin
2019-02-26 14:53     ` Sven Van Asbroeck
2019-02-26 15:23       ` Mark Brown
2019-02-26 15:45       ` Russell King - ARM Linux admin
2019-02-26 16:21         ` Mark Brown
2019-02-26 16:31         ` Sven Van Asbroeck
2019-02-26 16:41           ` Mark Brown
2019-02-26 17:03           ` Russell King - ARM Linux admin
2019-02-27 18:36             ` Mark Brown
2019-02-26 18:46     ` Sven Van Asbroeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190225164218.19439-1-TheSven73@gmail.com \
    --to=thesven73@gmail.com \
    --cc=airlied@linux.ie \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jsarha@ti.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux@armlinux.org.uk \
    --cc=peter.ujfalusi@ti.com \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).