All of lore.kernel.org
 help / color / mirror / Atom feed
From: Russell King <rmk+kernel@armlinux.org.uk>
To: Sven Van Asbroeck <thesven73@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Peter Ujfalusi <peter.ujfalusi@ti.com>,
	Jyri Sarha <jsarha@ti.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	alsa-devel@alsa-project.org, Takashi Iwai <tiwai@suse.com>
Subject: [PATCH RFC 2/3] ASoC: hdmi-codec: add support for bclk_ratio
Date: Fri, 22 Feb 2019 21:27:18 +0000	[thread overview]
Message-ID: <E1gxILm-0004MX-Kb@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <20190222212619.ghxly3eb6dx7p2ut@shell.armlinux.org.uk>

Some HDMI codecs need to know the relationship between the I2S bit clock
and the I2S word clock in order to correctly generate the CTS value for
audio clock recovery on the sink.

Add support for this, but there are currently no callers of
snd_soc_dai_set_bclk_ratio(), we provide a default implementation that
uses the sample width to derive the ratio from the 8-bit aligned
sample size.  This reflects the derivation that is in TDA998x, which
we are going to convert to use this new support.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
 include/sound/hdmi-codec.h    |  1 +
 sound/soc/codecs/hdmi-codec.c | 45 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/include/sound/hdmi-codec.h b/include/sound/hdmi-codec.h
index 9483c55f871b..0fca69880dc3 100644
--- a/include/sound/hdmi-codec.h
+++ b/include/sound/hdmi-codec.h
@@ -42,6 +42,7 @@ struct hdmi_codec_daifmt {
 	unsigned int frame_clk_inv:1;
 	unsigned int bit_clk_master:1;
 	unsigned int frame_clk_master:1;
+	unsigned int bclk_ratio;
 };
 
 /*
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index e5b6769b9797..d71a7e5a2231 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -470,6 +470,7 @@ static int hdmi_codec_hw_params(struct snd_pcm_substream *substream,
 				struct snd_soc_dai *dai)
 {
 	struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai);
+	struct hdmi_codec_daifmt fmt;
 	struct hdmi_codec_params hp = {
 		.iec = {
 			.status = { 0 },
@@ -520,8 +521,43 @@ static int hdmi_codec_hw_params(struct snd_pcm_substream *substream,
 	hp.sample_rate = params_rate(params);
 	hp.channels = params_channels(params);
 
+	fmt = hcp->daifmt[dai->id];
+
+	/*
+	 * If the .set_bclk_ratio() has not been called, default it
+	 * using the sample width for compatibility for TDA998x.
+	 * Rather than changing this, drivers should arrange to make
+	 * an appropriate call to snd_soc_dai_set_bclk_ratio().
+	 */
+	if (fmt.bclk_ratio == 0) {
+		switch (hp.sample_width) {
+		case 16:
+			fmt.bclk_ratio = 32;
+			break;
+		case 18:
+		case 20:
+		case 24:
+			fmt.bclk_ratio = 48;
+			break;
+		default:
+			fmt.bclk_ratio = 64;
+			break;
+		}
+	}
+
 	return hcp->hcd.ops->hw_params(dai->dev->parent, hcp->hcd.data,
-				       &hcp->daifmt[dai->id], &hp);
+				       &fmt, &hp);
+}
+
+static int hdmi_codec_set_bclk_ratio(struct snd_soc_dai *dai,
+				     unsigned int ratio)
+{
+	struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai);
+
+	/* FIXME: some validation here would be good? */
+	hcp->daifmt[dai->id].bclk_ratio = ratio;
+
+	return 0;
 }
 
 static int hdmi_codec_set_fmt(struct snd_soc_dai *dai,
@@ -593,7 +629,11 @@ static int hdmi_codec_set_fmt(struct snd_soc_dai *dai,
 		}
 	}
 
-	hcp->daifmt[dai->id] = cf;
+	hcp->daifmt[dai->id].fmt = cf.fmt;
+	hcp->daifmt[dai->id].bit_clk_inv = cf.bit_clk_inv;
+	hcp->daifmt[dai->id].frame_clk_inv = cf.frame_clk_inv;
+	hcp->daifmt[dai->id].bit_clk_master = cf.bit_clk_master;
+	hcp->daifmt[dai->id].frame_clk_master = cf.frame_clk_master;
 
 	return ret;
 }
@@ -615,6 +655,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {
 	.startup	= hdmi_codec_startup,
 	.shutdown	= hdmi_codec_shutdown,
 	.hw_params	= hdmi_codec_hw_params,
+	.set_bclk_ratio	= hdmi_codec_set_bclk_ratio,
 	.set_fmt	= hdmi_codec_set_fmt,
 	.digital_mute	= hdmi_codec_digital_mute,
 };
-- 
2.7.4

  parent reply	other threads:[~2019-02-22 21:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22 21:26 [PATCH RFC 0/3] tda998x updates for DAI formats and bclk_ratio Russell King - ARM Linux admin
2019-02-22 21:27 ` [PATCH RFC 1/3] drm/i2c: tda998x: implement different I2S flavours Russell King
2019-02-25 13:26   ` Jyri Sarha
2019-02-25 13:28   ` Peter Ujfalusi
2019-02-25 13:40     ` Russell King - ARM Linux admin
2019-02-25 16:23   ` Sven Van Asbroeck
2019-02-22 21:27 ` Russell King [this message]
2019-02-25 13:45   ` [PATCH RFC 2/3] ASoC: hdmi-codec: add support for bclk_ratio Jyri Sarha
2019-02-25 14:03     ` Russell King - ARM Linux admin
2019-02-25 20:58       ` Jyri Sarha
2019-02-25 23:01         ` Russell King - ARM Linux admin
2019-02-27 11:47         ` Russell King - ARM Linux admin
2019-02-27 17:48           ` Jyri Sarha
2019-02-27 18:00             ` Russell King - ARM Linux admin
2019-02-27 20:24               ` Jyri Sarha
2019-02-27 18:01       ` Sven Van Asbroeck
2019-02-27 19:56         ` Russell King - ARM Linux admin
2019-02-27 20:22           ` Sven Van Asbroeck
2019-02-27 20:24           ` Russell King - ARM Linux admin
2019-03-01 12:36     ` Mark Brown
2019-03-01 14:05       ` Jyri Sarha
2019-03-01 14:59         ` Russell King - ARM Linux admin
2019-03-01 16:35           ` Jyri Sarha
2019-03-04 16:59       ` Sven Van Asbroeck
2019-03-04 17:32         ` Jyri Sarha
2019-02-22 21:27 ` [PATCH RFC 3/3] drm/i2c: tda998x: " Russell King
2019-02-25 13:47   ` Jyri Sarha
2019-02-25 16:26   ` 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=E1gxILm-0004MX-Kb@rmk-PC.armlinux.org.uk \
    --to=rmk+kernel@armlinux.org.uk \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=jsarha@ti.com \
    --cc=lgirdwood@gmail.com \
    --cc=peter.ujfalusi@ti.com \
    --cc=thesven73@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.