All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
To: Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Timur Tabi <timur@kernel.org>, Xiubo Li <Xiubo.Lee@gmail.com>,
	Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
	Shengjiu Wang <shengjiu.wang@gmail.com>,
	Sameer Pujar <spujar@nvidia.com>,
	Neil Armstrong <narmstrong@baylibre.com>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Nicolin Chen <nicoleotsuka@gmail.com>,
	Ludovic Desroches <ludovic.desroches@microchip.com>,
	Kevin Hilman <khilman@baylibre.com>,
	Codrin Ciubotariu <codrin.ciubotariu@microchip.com>,
	alsa-devel@alsa-project.org, Fabio Estevam <festevam@gmail.com>,
	Jerome Brunet <jbrunet@baylibre.com>
Subject: [PATCH 4/9] ASoC: soc-core: add snd_soc_daifmt_parse_format/clock_provider()
Date: 08 Jun 2021 09:12:24 +0900	[thread overview]
Message-ID: <87zgw1cizb.wl-kuninori.morimoto.gx@renesas.com> (raw)
In-Reply-To: <875yypdxlm.wl-kuninori.morimoto.gx@renesas.com>

From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

snd_soc_of_parse_daifmt() parses daifmt, but bitclock/frame provider
parsing part is one of headache, because we are assuming below both cases.

A)	node {
		bitclock-master;
		frame-master;
		...
	};

B)	link {
		bitclock-master = <&xxx>;
		frame-master = <&xxx>;
		...
	};

The original was style A), and style B) was added later
by commit b3ca11ff59bc ("ASoC: simple-card: Move dai-link level
properties away from dai subnodes").

snd_soc_of_parse_daifmt() parses A) style as original style,
and user need to update to B) style for clock_provider part if needed.
In such case, user need to re-parse it, like below.

	daifmt = snd_soc_of_parse_daifmt(..., &bitclkmaster, &framemaster);
	daifmt &= ~SND_SOC_DAIFMT_MASTER_MASK;

	if (codec == bitclkmaster)
		daifmt |= (codec == framemaster) ?
			SND_SOC_DAIFMT_CBM_CFM : SND_SOC_DAIFMT_CBM_CFS;
	else
		daifmt |= (codec == framemaster) ?
			SND_SOC_DAIFMT_CBS_CFM : SND_SOC_DAIFMT_CBS_CFS;

This patch adds new functions which separetes
snd_soc_of_parse_daifmt() helper function into
parsing format         part (= snd_soc_daifmt_parse_format()), and
parsing clock_provider part (= snd_soc_daifmt_parse_clock_provider()).
User can use snd_soc_daifmt_clock_provider_pickup/fliped() helper
function with it.

style A)
	bit_frame = snd_soc_daifmt_parse_clock_provider();
	daifmt = snd_soc_daifmt_parse_format(...) |               /* format part */
		 snd_soc_daifmt_clock_provider_pickup(bit_frame); /* clock  part */

style B)
	snd_soc_daifmt_parse_clock_provider(..., &bit, &frame);
	daifmt = snd_soc_daifmt_parse_format(...) |     /* format part */
		 snd_soc_daifmt_clock_provider_pickup(  /* clock  part */
			((codec == bit) << 4) + (codec == frame));

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 include/sound/soc.h  |   6 +++
 sound/soc/soc-core.c | 114 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 0f25d4be92ae..f402b259a255 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1235,6 +1235,12 @@ int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname);
 
 unsigned int snd_soc_daifmt_clock_provider_fliped(unsigned int dai_fmt);
 unsigned int snd_soc_daifmt_clock_provider_pickup(unsigned int bit_frame);
+unsigned int snd_soc_daifmt_parse_format(struct device_node *np,
+					 const char *prefix);
+unsigned int snd_soc_daifmt_parse_clock_provider(struct device_node *np,
+						 const char *prefix,
+						 struct device_node **bitclkmaster,
+						 struct device_node **framemaster);
 unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
 				     const char *prefix,
 				     struct device_node **bitclkmaster,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index fd5a3b60aeb3..a9cb39c3d8c5 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3045,6 +3045,120 @@ unsigned int snd_soc_daifmt_clock_provider_pickup(unsigned int bit_frame)
 }
 EXPORT_SYMBOL_GPL(snd_soc_daifmt_clock_provider_pickup);
 
+unsigned int snd_soc_daifmt_parse_format(struct device_node *np,
+					 const char *prefix)
+{
+	int ret, i;
+	char prop[128];
+	unsigned int format = 0;
+	int bit, frame;
+	const char *str;
+	struct {
+		char *name;
+		unsigned int val;
+	} of_fmt_table[] = {
+		{ "i2s",	SND_SOC_DAIFMT_I2S },
+		{ "right_j",	SND_SOC_DAIFMT_RIGHT_J },
+		{ "left_j",	SND_SOC_DAIFMT_LEFT_J },
+		{ "dsp_a",	SND_SOC_DAIFMT_DSP_A },
+		{ "dsp_b",	SND_SOC_DAIFMT_DSP_B },
+		{ "ac97",	SND_SOC_DAIFMT_AC97 },
+		{ "pdm",	SND_SOC_DAIFMT_PDM},
+		{ "msb",	SND_SOC_DAIFMT_MSB },
+		{ "lsb",	SND_SOC_DAIFMT_LSB },
+	};
+
+	if (!prefix)
+		prefix = "";
+
+	/*
+	 * check "dai-format = xxx"
+	 * or    "[prefix]format = xxx"
+	 * SND_SOC_DAIFMT_FORMAT_MASK area
+	 */
+	ret = of_property_read_string(np, "dai-format", &str);
+	if (ret < 0) {
+		snprintf(prop, sizeof(prop), "%sformat", prefix);
+		ret = of_property_read_string(np, prop, &str);
+	}
+	if (ret == 0) {
+		for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) {
+			if (strcmp(str, of_fmt_table[i].name) == 0) {
+				format |= of_fmt_table[i].val;
+				break;
+			}
+		}
+	}
+
+	/*
+	 * check "[prefix]continuous-clock"
+	 * SND_SOC_DAIFMT_CLOCK_MASK area
+	 */
+	snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix);
+	if (of_property_read_bool(np, prop))
+		format |= SND_SOC_DAIFMT_CONT;
+	else
+		format |= SND_SOC_DAIFMT_GATED;
+
+	/*
+	 * check "[prefix]bitclock-inversion"
+	 * check "[prefix]frame-inversion"
+	 * SND_SOC_DAIFMT_INV_MASK area
+	 */
+	snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix);
+	bit = !!of_get_property(np, prop, NULL);
+
+	snprintf(prop, sizeof(prop), "%sframe-inversion", prefix);
+	frame = !!of_get_property(np, prop, NULL);
+
+	switch ((bit << 4) + frame) {
+	case 0x11:
+		format |= SND_SOC_DAIFMT_IB_IF;
+		break;
+	case 0x10:
+		format |= SND_SOC_DAIFMT_IB_NF;
+		break;
+	case 0x01:
+		format |= SND_SOC_DAIFMT_NB_IF;
+		break;
+	default:
+		/* SND_SOC_DAIFMT_NB_NF is default */
+		break;
+	}
+
+	return format;
+}
+EXPORT_SYMBOL_GPL(snd_soc_daifmt_parse_format);
+
+unsigned int snd_soc_daifmt_parse_clock_provider(struct device_node *np,
+						 const char *prefix,
+						 struct device_node **bitclkmaster,
+						 struct device_node **framemaster)
+{
+	char prop[128];
+	unsigned int bit, frame;
+
+	if (!prefix)
+		prefix = "";
+
+	/*
+	 * check "[prefix]bitclock-master"
+	 * check "[prefix]frame-master"
+	 */
+	snprintf(prop, sizeof(prop), "%sbitclock-master", prefix);
+	bit = !!of_get_property(np, prop, NULL);
+	if (bit && bitclkmaster)
+		*bitclkmaster = of_parse_phandle(np, prop, 0);
+
+	snprintf(prop, sizeof(prop), "%sframe-master", prefix);
+	frame = !!of_get_property(np, prop, NULL);
+	if (frame && framemaster)
+		*framemaster = of_parse_phandle(np, prop, 0);
+
+	return (bit << 4) + frame;
+}
+EXPORT_SYMBOL_GPL(snd_soc_daifmt_parse_clock_provider);
+
 unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
 				     const char *prefix,
 				     struct device_node **bitclkmaster,
-- 
2.25.1


  parent reply	other threads:[~2021-06-08  0:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08  0:11 [PATCH 0/9] ASoC: tidyup snd_soc_of_parse_daifmt() Kuninori Morimoto
2021-06-08  0:11 ` [PATCH 1/9] ASoC: soc-core: don't use discriminatory terms on snd_soc_runtime_get_dai_fmt() Kuninori Morimoto
2021-06-08  0:11 ` [PATCH 2/9] ASoC: soc-core: add snd_soc_daifmt_clock_provider_pickup() Kuninori Morimoto
2021-06-08  0:12 ` [PATCH 3/9] ASoC: soc-core: add snd_soc_daifmt_clock_provider_fliped() Kuninori Morimoto
2021-06-08  0:12 ` Kuninori Morimoto [this message]
2021-06-08  0:12 ` [PATCH 5/9] ASoC: atmel: switch to use snd_soc_daifmt_parse_format/clock_provider() Kuninori Morimoto
2021-06-08  0:12 ` [PATCH 6/9] ASoC: fsl: " Kuninori Morimoto
2021-06-08  7:50   ` Jerome Brunet
2021-06-08 12:34     ` Mark Brown
2021-06-08 23:50       ` Kuninori Morimoto
2021-06-08  0:12 ` [PATCH 7/9] ASoC: meson: " Kuninori Morimoto
2021-06-08  0:12 ` [PATCH 8/9] ASoC: simple-card-utils: " Kuninori Morimoto
2021-06-08  0:12 ` [PATCH 9/9] ASoC: soc-core: remove snd_soc_of_parse_daifmt() Kuninori Morimoto
2021-06-08 16:06 ` (subset) [PATCH 0/9] ASoC: tidyup snd_soc_of_parse_daifmt() Mark Brown

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=87zgw1cizb.wl-kuninori.morimoto.gx@renesas.com \
    --to=kuninori.morimoto.gx@renesas.com \
    --cc=Xiubo.Lee@gmail.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=codrin.ciubotariu@microchip.com \
    --cc=festevam@gmail.com \
    --cc=jbrunet@baylibre.com \
    --cc=khilman@baylibre.com \
    --cc=lgirdwood@gmail.com \
    --cc=ludovic.desroches@microchip.com \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=narmstrong@baylibre.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=nicoleotsuka@gmail.com \
    --cc=shengjiu.wang@gmail.com \
    --cc=spujar@nvidia.com \
    --cc=timur@kernel.org \
    /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.