[PATCH v3 07/13] ASoC: audio-graph: Update driver as per new exposed members

From: Sameer Pujar
Date: Thu Oct 01 2020 - 13:34:39 EST


As per the members exposed earlier in the series, audio graph driver
is updated to make use of these. Functionally there is no change
in behavior if these are not populated. So following changes are made
as part of this.

- Update 'dai_link->ops' for DPCM links if a custom 'snd_soc_ops'
is defined by the vendor driver.

- Consider 'force_dpcm' flag status when deciding if a DAI link
needs to be treated as DPCM or not. In doing so the logic is
moved to a separate inline function for a better readability.

- Populate 'dpcm_selectable' flag which is then used to detect
DPCM DAI links.

Signed-off-by: Sameer Pujar <spujar@xxxxxxxxxx>
Cc: Kuninori Morimoto <kuninori.morimoto.gx@xxxxxxxxxxx>
---
sound/soc/generic/audio-graph-card.c | 40 ++++++++++++++++++++++++++++--------
1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c
index 0ba50be9..fb34e34 100644
--- a/sound/soc/generic/audio-graph-card.c
+++ b/sound/soc/generic/audio-graph-card.c
@@ -355,6 +355,11 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
snd_soc_dai_link_set_capabilities(dai_link);

dai_link->ops = &graph_ops;
+
+ /* Use custom snd_soc_ops callbacks if available */
+ if (priv->ops)
+ dai_link->ops = priv->ops;
+
dai_link->init = asoc_simple_dai_init;

out_put_node:
@@ -439,6 +444,28 @@ static int graph_dai_link_of(struct asoc_simple_priv *priv,
return 0;
}

+static inline bool parse_as_dpcm_link(struct asoc_simple_priv *priv,
+ struct device_node *codec_port,
+ struct asoc_simple_data *adata)
+{
+ if (priv->force_dpcm)
+ return true;
+
+ if (!priv->dpcm_selectable)
+ return false;
+
+ /*
+ * It is DPCM
+ * if Codec port has many endpoints,
+ * or has convert-xxx property
+ */
+ if ((of_get_child_count(codec_port) > 1) ||
+ (adata->convert_rate || adata->convert_channels))
+ return true;
+
+ return false;
+}
+
static int graph_for_each_link(struct asoc_simple_priv *priv,
struct link_info *li,
int (*func_noml)(struct asoc_simple_priv *priv,
@@ -459,7 +486,6 @@ static int graph_for_each_link(struct asoc_simple_priv *priv,
struct device_node *codec_port;
struct device_node *codec_port_old = NULL;
struct asoc_simple_data adata;
- uintptr_t dpcm_selectable = (uintptr_t)of_device_get_match_data(dev);
int rc, ret;

/* loop for all listed CPU port */
@@ -482,14 +508,8 @@ static int graph_for_each_link(struct asoc_simple_priv *priv,
graph_parse_convert(dev, codec_ep, &adata);
graph_parse_convert(dev, cpu_ep, &adata);

- /*
- * It is DPCM
- * if Codec port has many endpoints,
- * or has convert-xxx property
- */
- if (dpcm_selectable &&
- ((of_get_child_count(codec_port) > 1) ||
- adata.convert_rate || adata.convert_channels))
+ /* check if link requires DPCM parsing */
+ if (parse_as_dpcm_link(priv, codec_port, &adata))
ret = func_dpcm(priv, cpu_ep, codec_ep, li,
(codec_port_old == codec_port));
/* else normal sound */
@@ -678,6 +698,8 @@ static int graph_probe(struct platform_device *pdev)
card->num_dapm_widgets = ARRAY_SIZE(graph_dapm_widgets);
card->probe = graph_card_probe;

+ priv->dpcm_selectable = (uintptr_t)of_device_get_match_data(dev);
+
memset(&li, 0, sizeof(li));
graph_get_dais_count(priv, &li);
if (!li.link || !li.dais)
--
2.7.4