summaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2024-05-28 07:05:36 +0200
committerMark Brown <broonie@kernel.org>2024-06-03 16:59:38 +0200
commitdf23fcd56bb75ab522350bd8cb52bde9067aea45 (patch)
tree9fabd064c1db8833b182e441664e192d97ac3b05 /sound
parentASoC: audio-graph-card2: merge graph_parse_mclk_fs() into graph_link_init() (diff)
downloadlinux-df23fcd56bb75ab522350bd8cb52bde9067aea45.tar.xz
linux-df23fcd56bb75ab522350bd8cb52bde9067aea45.zip
ASoC: audio-graph-card: add ep_to_port() / port_to_ports()
Current audio-graph-card is using of_get_parent() to get "port" from "ep", or get "ports" from "port". But it is difficlut to understand, and "ports" might not exist. This patch adds ep_to_port() to get "port" from "ep", and port_to_ports() to get "ports" from "port". "ports" will be NULL if not exist. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Link: https://msgid.link/r/8734q2h6fz.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/generic/audio-graph-card.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c
index 83e3ba773fbd..552b94908cf7 100644
--- a/sound/soc/generic/audio-graph-card.c
+++ b/sound/soc/generic/audio-graph-card.c
@@ -19,6 +19,18 @@
#define DPCM_SELECTABLE 1
+#define ep_to_port(ep) of_get_parent(ep)
+static struct device_node *port_to_ports(struct device_node *port)
+{
+ struct device_node *ports = of_get_parent(port);
+
+ if (!of_node_name_eq(ports, "ports")) {
+ of_node_put(ports);
+ return NULL;
+ }
+ return ports;
+}
+
static int graph_outdrv_event(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol,
int event)
@@ -68,8 +80,8 @@ static void graph_parse_convert(struct device *dev,
struct simple_util_data *adata)
{
struct device_node *top = dev->of_node;
- struct device_node *port = of_get_parent(ep);
- struct device_node *ports = of_get_parent(port);
+ struct device_node *port = ep_to_port(ep);
+ struct device_node *ports = port_to_ports(port);
struct device_node *node = of_graph_get_port_parent(ep);
simple_util_parse_convert(top, NULL, adata);
@@ -87,8 +99,8 @@ static void graph_parse_mclk_fs(struct device_node *top,
struct device_node *ep,
struct simple_dai_props *props)
{
- struct device_node *port = of_get_parent(ep);
- struct device_node *ports = of_get_parent(port);
+ struct device_node *port = ep_to_port(ep);
+ struct device_node *ports = port_to_ports(port);
of_property_read_u32(top, "mclk-fs", &props->mclk_fs);
if (of_node_name_eq(ports, "ports"))
@@ -231,8 +243,8 @@ static int graph_dai_link_of_dpcm(struct simple_util_priv *priv,
"be.%pOFP.%s", codecs->of_node, codecs->dai_name);
/* check "prefix" from top node */
- port = of_get_parent(ep);
- ports = of_get_parent(port);
+ port = ep_to_port(ep);
+ ports = port_to_ports(port);
snd_soc_of_parse_node_prefix(top, cconf, codecs->of_node,
"prefix");
if (of_node_name_eq(ports, "ports"))
@@ -350,7 +362,7 @@ static int __graph_for_each_link(struct simple_util_priv *priv,
/* get codec */
codec_ep = of_graph_get_remote_endpoint(cpu_ep);
- codec_port = of_get_parent(codec_ep);
+ codec_port = ep_to_port(codec_ep);
/* get convert-xxx property */
memset(&adata, 0, sizeof(adata));