[PATCH 8/13] ASoC: qcom: Add generic of_xlate_dai_name helper to common
From: Harendra Gautam
Date: Fri Jun 05 2026 - 06:40:36 EST
Multiple Qualcomm ASoC CPU DAI drivers need to resolve a sound-dai
phandle argument to a DAI name by searching the component's DAI driver
array by ID. Each driver currently implements this identically.
Extract the common logic into asoc_qcom_of_xlate_dai_name() in
common.c so it can be shared across drivers without duplication.
Signed-off-by: Harendra Gautam <harendra.gautam@xxxxxxxxxxxxxxxx>
---
sound/soc/qcom/common.c | 34 ++++++++++++++++++++++++++++++++++
sound/soc/qcom/common.h | 5 +++++
2 files changed, 39 insertions(+)
diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c
index cf1f3a767cee..46569290d44c 100644
--- a/sound/soc/qcom/common.c
+++ b/sound/soc/qcom/common.c
@@ -23,6 +23,40 @@ static const struct snd_soc_dapm_widget qcom_jack_snd_widgets[] = {
SND_SOC_DAPM_SPK("DP7 Jack", NULL),
};
+/**
+ * asoc_qcom_of_xlate_dai_name - Resolve a sound-dai phandle argument to a
+ * DAI name by searching the DAI driver array.
+ * @dai_drv: Array of DAI drivers registered by the component.
+ * @num_dai: Number of entries in @dai_drv.
+ * @args: Phandle arguments from the sound-dai property; args[0] is the
+ * DAI ID.
+ * @dai_name: Output pointer set to the matched DAI name on success.
+ *
+ * Returns 0 on success, -EINVAL if args_count != 1 or no match is found.
+ */
+int asoc_qcom_of_xlate_dai_name(const struct snd_soc_dai_driver *dai_drv,
+ int num_dai,
+ const struct of_phandle_args *args,
+ const char **dai_name)
+{
+ int id, i;
+
+ if (args->args_count != 1)
+ return -EINVAL;
+
+ id = args->args[0];
+
+ for (i = 0; i < num_dai; i++) {
+ if (dai_drv[i].id == id) {
+ *dai_name = dai_drv[i].name;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(asoc_qcom_of_xlate_dai_name);
+
int qcom_snd_parse_of(struct snd_soc_card *card)
{
struct device_node *np;
diff --git a/sound/soc/qcom/common.h b/sound/soc/qcom/common.h
index ee6662885593..5baf51a39c97 100644
--- a/sound/soc/qcom/common.h
+++ b/sound/soc/qcom/common.h
@@ -6,6 +6,7 @@
#include <dt-bindings/sound/qcom,q6afe.h>
#include <sound/soc.h>
+#include <sound/soc-dai.h>
#define LPASS_MAX_PORT (SENARY_MI2S_TX + 1)
@@ -15,5 +16,9 @@ int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd,
int qcom_snd_dp_jack_setup(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_jack *dp_jack, int id);
+int asoc_qcom_of_xlate_dai_name(const struct snd_soc_dai_driver *dai_drv,
+ int num_dai,
+ const struct of_phandle_args *args,
+ const char **dai_name);
#endif
--
2.34.1