All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
To: Mark Brown <broonie@kernel.org>
Cc: Linux-ALSA <alsa-devel@alsa-project.org>
Subject: [PATCH 3/6] ASoC: audio-graph-card: tidyup mclk-fs method
Date: Wed, 5 Dec 2018 01:31:54 +0000	[thread overview]
Message-ID: <87wooodayg.wl-kuninori.morimoto.gx@renesas.com> (raw)
In-Reply-To: <871s6wepmp.wl-kuninori.morimoto.gx@renesas.com>


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

Current audio-graph-card is handling "mclk-fs" by many way.
But, it is not useful and readable.
We want to do is that allow having mclk-fs everywere.
This patch support it.
It will be overwrote if lower node has it.

sound {
	mclk-fs = <xxx>; // initial
};

codec {
	ports {
		mclk-fs = <xxx>; // overwrite
		port {
			mclk-fs = <xxx>; // overwrite
			endpoint {
				mclk-fs = <xxx>; // overwrite
			};
		};
	};
};

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/generic/audio-graph-card.c | 52 ++++++++++++++++++++++++------------
 1 file changed, 35 insertions(+), 17 deletions(-)

diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c
index 5b8e7a1..efa6be6 100644
--- a/sound/soc/generic/audio-graph-card.c
+++ b/sound/soc/generic/audio-graph-card.c
@@ -31,7 +31,6 @@ struct graph_card_data {
 		struct snd_soc_codec_conf *codec_conf;
 		unsigned int mclk_fs;
 	} *dai_props;
-	unsigned int mclk_fs;
 	struct asoc_simple_jack hp_jack;
 	struct asoc_simple_jack mic_jack;
 	struct snd_soc_dai_link *dai_link;
@@ -115,9 +114,7 @@ static int asoc_graph_card_hw_params(struct snd_pcm_substream *substream,
 	unsigned int mclk, mclk_fs = 0;
 	int ret = 0;
 
-	if (priv->mclk_fs)
-		mclk_fs = priv->mclk_fs;
-	else if (dai_props->mclk_fs)
+	if (dai_props->mclk_fs)
 		mclk_fs = dai_props->mclk_fs;
 
 	if (mclk_fs) {
@@ -176,7 +173,8 @@ static int asoc_graph_card_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
 	return 0;
 }
 
-static int asoc_graph_card_dai_link_of_dpcm(struct device_node *cpu_ep,
+static int asoc_graph_card_dai_link_of_dpcm(struct device_node *top,
+					    struct device_node *cpu_ep,
 					    struct device_node *codec_ep,
 					    struct graph_card_data *priv,
 					    int *dai_idx, int link_idx,
@@ -187,12 +185,21 @@ static int asoc_graph_card_dai_link_of_dpcm(struct device_node *cpu_ep,
 	struct graph_dai_props *dai_props = graph_priv_to_props(priv, link_idx);
 	struct snd_soc_card *card = graph_priv_to_card(priv);
 	struct device_node *ep = is_cpu ? cpu_ep : codec_ep;
+	struct device_node *port = of_get_parent(ep);
+	struct device_node *ports = of_get_parent(port);
 	struct device_node *node = of_graph_get_port_parent(ep);
 	struct asoc_simple_dai *dai;
 	int ret;
 
 	dev_dbg(dev, "link_of DPCM (for %s)\n", is_cpu ? "CPU" : "Codec");
 
+	of_property_read_u32(top,   "mclk-fs", &dai_props->mclk_fs);
+	of_property_read_u32(ports, "mclk-fs", &dai_props->mclk_fs);
+	of_property_read_u32(port,  "mclk-fs", &dai_props->mclk_fs);
+	of_property_read_u32(ep,    "mclk-fs", &dai_props->mclk_fs);
+	of_node_put(ports);
+	of_node_put(port);
+
 	if (is_cpu) {
 		struct snd_soc_dai_link_component *codecs;
 
@@ -279,8 +286,6 @@ static int asoc_graph_card_dai_link_of_dpcm(struct device_node *cpu_ep,
 	if (ret < 0)
 		return ret;
 
-	of_property_read_u32(ep,   "mclk-fs", &dai_props->mclk_fs);
-
 	ret = asoc_simple_card_parse_daifmt(dev, cpu_ep, codec_ep,
 					    NULL, &dai_link->dai_fmt);
 	if (ret < 0)
@@ -294,7 +299,8 @@ static int asoc_graph_card_dai_link_of_dpcm(struct device_node *cpu_ep,
 	return 0;
 }
 
-static int asoc_graph_card_dai_link_of(struct device_node *cpu_ep,
+static int asoc_graph_card_dai_link_of(struct device_node *top,
+					struct device_node *cpu_ep,
 					struct device_node *codec_ep,
 					struct graph_card_data *priv,
 					int *dai_idx, int link_idx)
@@ -302,6 +308,10 @@ static int asoc_graph_card_dai_link_of(struct device_node *cpu_ep,
 	struct device *dev = graph_priv_to_dev(priv);
 	struct snd_soc_dai_link *dai_link = graph_priv_to_link(priv, link_idx);
 	struct graph_dai_props *dai_props = graph_priv_to_props(priv, link_idx);
+	struct device_node *cpu_port = of_get_parent(cpu_ep);
+	struct device_node *codec_port = of_get_parent(codec_ep);
+	struct device_node *cpu_ports = of_get_parent(cpu_port);
+	struct device_node *codec_ports = of_get_parent(codec_port);
 	struct asoc_simple_dai *cpu_dai;
 	struct asoc_simple_dai *codec_dai;
 	int ret;
@@ -313,14 +323,24 @@ static int asoc_graph_card_dai_link_of(struct device_node *cpu_ep,
 	codec_dai		=
 	dai_props->codec_dai	= &priv->dais[(*dai_idx)++];
 
+	/* Factor to mclk, used in hw_params() */
+	of_property_read_u32(top,         "mclk-fs", &dai_props->mclk_fs);
+	of_property_read_u32(cpu_ports,   "mclk-fs", &dai_props->mclk_fs);
+	of_property_read_u32(codec_ports, "mclk-fs", &dai_props->mclk_fs);
+	of_property_read_u32(cpu_port,    "mclk-fs", &dai_props->mclk_fs);
+	of_property_read_u32(codec_port,  "mclk-fs", &dai_props->mclk_fs);
+	of_property_read_u32(cpu_ep,      "mclk-fs", &dai_props->mclk_fs);
+	of_property_read_u32(codec_ep,    "mclk-fs", &dai_props->mclk_fs);
+	of_node_put(cpu_port);
+	of_node_put(cpu_ports);
+	of_node_put(codec_port);
+	of_node_put(codec_ports);
+
 	ret = asoc_simple_card_parse_daifmt(dev, cpu_ep, codec_ep,
 					    NULL, &dai_link->dai_fmt);
 	if (ret < 0)
 		return ret;
 
-	of_property_read_u32(cpu_ep,   "mclk-fs", &dai_props->mclk_fs);
-	of_property_read_u32(codec_ep, "mclk-fs", &dai_props->mclk_fs);
-
 	ret = asoc_simple_card_parse_graph_cpu(cpu_ep, dai_link);
 	if (ret < 0)
 		return ret;
@@ -370,7 +390,8 @@ static int asoc_graph_card_parse_of(struct graph_card_data *priv)
 	struct of_phandle_iterator it;
 	struct device *dev = graph_priv_to_dev(priv);
 	struct snd_soc_card *card = graph_priv_to_card(priv);
-	struct device_node *node = dev->of_node;
+	struct device_node *top = dev->of_node;
+	struct device_node *node = top;
 	struct device_node *cpu_port;
 	struct device_node *cpu_ep		= NULL;
 	struct device_node *codec_ep		= NULL;
@@ -390,9 +411,6 @@ static int asoc_graph_card_parse_of(struct graph_card_data *priv)
 
 	asoc_simple_card_parse_convert(dev, node, NULL, &priv->adata);
 
-	/* Factor to mclk, used in hw_params() */
-	of_property_read_u32(node, "mclk-fs", &priv->mclk_fs);
-
 	link_idx	= 0;
 	dai_idx		= 0;
 	conf_idx	= 0;
@@ -434,7 +452,7 @@ static int asoc_graph_card_parse_of(struct graph_card_data *priv)
 					codec_port_old = codec_port;
 				}
 				ret = asoc_graph_card_dai_link_of_dpcm(
-					cpu_ep, codec_ep, priv,
+					top, cpu_ep, codec_ep, priv,
 					&dai_idx, link_idx++,
 					&conf_idx, cpu);
 			} else if (cpu) {
@@ -442,7 +460,7 @@ static int asoc_graph_card_parse_of(struct graph_card_data *priv)
 				 * for Normal sound
 				 */
 				ret = asoc_graph_card_dai_link_of(
-					cpu_ep, codec_ep, priv,
+					top, cpu_ep, codec_ep, priv,
 					&dai_idx, link_idx++);
 			}
 			if (ret < 0)
-- 
2.7.4

  parent reply	other threads:[~2018-12-05  1:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-05  1:29 [PATCH 0/6] ASoC: merge audio-graph-scu into audio-graph - final step Kuninori Morimoto
2018-12-05  1:30 ` [PATCH 1/6] ASoC: audio-graph-card: merge audio-graph-scu-card on Doc Kuninori Morimoto
2018-12-05  1:31 ` [PATCH 2/6] ASoC: audio-graph-card: merge audio-graph-scu-card Kuninori Morimoto
2018-12-05  1:31 ` Kuninori Morimoto [this message]
2018-12-05  1:32 ` [PATCH 4/6] ASoC: audio-graph-card: tidyup convert_rate/channel method Kuninori Morimoto
2018-12-05  1:32 ` [PATCH 5/6] ASoC: audio-graph-scu-card: remove audio-graph-scu-card on Doc Kuninori Morimoto
2018-12-05  1:32 ` [PATCH 6/6] ASoC: audio-graph-scu-card: remove audio-graph-scu-card Kuninori Morimoto
2018-12-12  6:58 ` [PATCH 0/6] ASoC: merge audio-graph-scu into audio-graph - final step Kuninori Morimoto

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=87wooodayg.wl-kuninori.morimoto.gx@renesas.com \
    --to=kuninori.morimoto.gx@renesas.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@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.