ASoC: qcom: Refactor of_xlate_dai_name into common helper
Subsystems (4)
cover ASoC: qcom: Refactor of_xlate_dai_name into common helper
Multiple Qualcomm ASoC CPU DAI drivers implement the same logic to resolve a sound-dai phandle argument to a DAI name: iterate the component's DAI driver array and match by ID. This is currently duplicated between lpass-cpu.c and qaif-cpu.c.
This series extracts the common logic into a shared helper asoc_qcom_of_xlate_dai_name() in common.c and refactors lpass-cpu.c to use it. The QAIF driver (in a separate series) will also use this helper instead of its own private implementation.
Patch 1: Add asoc_qcom_of_xlate_dai_name() to common.c/h Patch 2: Refactor lpass-cpu.c to use the new helper
Harendra Gautam (2):
ASoC: qcom: Add generic of_xlate_dai_name helper to common
ASoC: qcom: lpass-cpu: Use asoc_qcom_of_xlate_dai_name helper
sound/soc/qcom/common.c | 34 ++++++++++++++++++++++++++++++++++ sound/soc/qcom/common.h | 5 +++++ sound/soc/qcom/lpass-cpu.c | 19 +++++-------------- 3 files changed, 44 insertions(+), 14 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 ASoC: qcom: Add generic of_xlate_dai_name helper to common
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.
--- sound/soc/qcom/common.c | 34 ++++++++++++++++++++++++++++++++++ sound/soc/qcom/common.h | 5 +++++ 2 files changed, 39 insertions(+)
sound/soc/qcom/common.c +34 -0
@@ -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;
sound/soc/qcom/common.h +5 -0
@@ -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
Signature · 1 line
2.34.1
PATCH 2/2 ASoC: qcom: lpass-cpu: Use asoc_qcom_of_xlate_dai_name helper
In reply to Harendra GautamReplace the private static asoc_qcom_of_xlate_dai_name() implementation in lpass-cpu.c with a thin wrapper that calls the new shared helper from common.c. This removes the duplicate implementation.
--- sound/soc/qcom/lpass-cpu.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)
sound/soc/qcom/lpass-cpu.c +5 -14
@@ -18,6 +18,7 @@#include <sound/soc-dai.h> #include "lpass-lpaif-reg.h" #include "lpass.h" +#include "common.h" #define LPASS_CPU_MAX_MI2S_LINES 4#define LPASS_CPU_I2S_SD0_MASK BIT(0)
@@ -458,30 +459,20 @@ const struct snd_soc_dai_ops asoc_qcom_lpass_cpu_dai_ops2 = { };EXPORT_SYMBOL_GPL (asoc_qcom_lpass_cpu_dai_ops2); -static int asoc_qcom_of_xlate_dai_name (struct snd_soc_component *component, +static int lpass_cpu_of_xlate_dai_name (struct snd_soc_component *component,const struct of_phandle_args *args,const char **dai_name) {struct lpass_data *drvdata =snd_soc_component_get_drvdata (component);const struct lpass_variant *variant = drvdata->variant; -int id = args->args[0 ]; -int ret = -EINVAL ; -int i; -for (i =0 ; i < variant->num_dai; i++) { -if (variant->dai_driver[i].id == id) { - *dai_name = variant->dai_driver[i].name; - ret =0 ; -break ; - } - } - -return ret; +return asoc_qcom_of_xlate_dai_name (variant->dai_driver, + variant->num_dai, args, dai_name); }static const struct snd_soc_component_driver lpass_cpu_comp_driver = { .name ="lpass-cpu" , - .of_xlate_dai_name = asoc_qcom_of_xlate_dai_name, + .of_xlate_dai_name = lpass_cpu_of_xlate_dai_name, .legacy_dai_naming =1 , };
Signature · 1 line
2.34.1
Mark Brown
maintainerRe: [PATCH 2/2] ASoC: qcom: lpass-cpu: Use asoc_qcom_of_xlate_dai_name helper
Quoted 14 lines · Harendra Gautam
Replace the private static
asoc_qcom_of_xlate_dai_name()implementation inlpass-cpu.cwith a thin wrapper that calls the new shared helper fromcommon.c. This removes the duplicate implementation.Signed-off-by Harendra Gautam <[email protected]>--- sound/soc/qcom/lpass-cpu.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)sound/soc/qcom/lpass-cpu.c +0
-0
sound/soc/qcom/lpass-cpu.c line 21
Quoted 4 lines
sound/soc/qcom/lpass-cpu.c +1
-0@@ -18,6 +18,7 @@#include <sound/soc-dai.h> #include "lpass-lpaif-reg.h" #include "lpass.h" +#include "common.h"
Did you double check that all users of LPASS select SND_SOC_QCOM_COMMON?
Srinivas Kandagatla
maintainerQuoted 5 lines · Harendra Gautam
Multiple Qualcomm ASoC CPU DAI drivers implement the same logic to resolve a sound-dai phandle argument to a DAI name: iterate the component's DAI driver array and match by ID. This is currently duplicated between
lpass-cpu.candqaif-cpu.c.
Quoted 7 lines
This series extracts the common logic into a shared helper
asoc_qcom_of_xlate_dai_name()incommon.cand refactorslpass-cpu.cto use it. The QAIF driver (in a separate series) will also use this helper instead of its own private implementation.Patch 1: Add
asoc_qcom_of_xlate_dai_name()to common.c/h Patch 2: Refactorlpass-cpu.cto use the new helper
series itself does not make sense, as you only have one user for this at the moment.
Please consider making it part of the series that actually has more than one user for this.
--srini
Quoted 10 lines
Harendra Gautam (2):
ASoC: qcom: Add genericof_xlate_dai_namehelper to common
ASoC: qcom: lpass-cpu: Useasoc_qcom_of_xlate_dai_namehelpersound/soc/qcom/common.c | 34 ++++++++++++++++++++++++++++++++++ sound/soc/qcom/common.h | 5 +++++ sound/soc/qcom/lpass-cpu.c | 19 +++++-------------- 3 files changed, 44 insertions(+), 14 deletions(-)
Mark Brown
maintainerQuoted 2 lines · Srinivas Kandagatla
Please consider making it part of the series that actually has more than one user for this.
Or at least identify additional users that will be added soon, it might make sense to cut down the size of a larger series by splitting out the API addition. That's especially true if there's multiple new users that each need their own series.