From ca3c771ddad0d254ff9cd20c2868a59186840372 Mon Sep 17 00:00:00 2001 From: Russell King Date: Fri, 22 Feb 2019 20:02:18 +0000 Subject: ASoC: hdmi-codec: add support for bclk_ratio 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 --- include/sound/hdmi-codec.h | 7 +++++++ sound/soc/codecs/hdmi-codec.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/sound/hdmi-codec.h b/include/sound/hdmi-codec.h index 83b17682e01c..5272aa17fe03 100644 --- a/include/sound/hdmi-codec.h +++ b/include/sound/hdmi-codec.h @@ -58,6 +58,13 @@ struct hdmi_codec_ops { */ int (*audio_startup)(struct device *dev, void *data); + /* + * Set the bit clock ratio, as needed for some HDMI bridges. + * Optional. + */ + int (*set_bclk_ratio)(struct device *dev, void *data, + unsigned int bclk_ratio); + /* * Configures HDMI-encoder for audio stream. * Mandatory diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index f005751da2cc..ec0468cae0f0 100644 --- a/sound/soc/codecs/hdmi-codec.c +++ b/sound/soc/codecs/hdmi-codec.c @@ -491,6 +491,19 @@ static int hdmi_codec_hw_params(struct snd_pcm_substream *substream, cf, &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); + int ret = -EOPNOTSUPP; + + if (hcp->hcd.ops->set_bclk_ratio) + ret = hcp->hcd.ops->set_bclk_ratio(dai->dev->parent, + hcp->hcd.data, ratio); + + return ret; +} + static int hdmi_codec_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) { @@ -573,6 +586,7 @@ static const struct snd_soc_dai_ops hdmi_codec_i2s_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_i2s_set_fmt, .digital_mute = hdmi_codec_digital_mute, }; -- cgit