From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sven Van Asbroeck Subject: [RFC PATCH 1/2] ASoC: simple-card: add support for bclk_ratio Date: Mon, 25 Feb 2019 11:42:17 -0500 Message-ID: <20190225164218.19439-1-TheSven73@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-it1-x142.google.com (mail-it1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 17BC0F89650 for ; Mon, 25 Feb 2019 17:42:27 +0100 (CET) Received: by mail-it1-x142.google.com with SMTP id r11so13705101itc.2 for ; Mon, 25 Feb 2019 08:42:27 -0800 (PST) List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" To: Russell King - ARM Linux admin , Mark Brown , Peter Ujfalusi , Jyri Sarha Cc: alsa-devel@alsa-project.org, Kuninori Morimoto , David Airlie , Takashi Iwai , Liam Girdwood , dri-devel@lists.freedesktop.org, Daniel Vetter List-Id: alsa-devel@alsa-project.org 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 --- 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