[PATCH 00/11] ASoC: add and use asoc_dummy_dlc
Hi Mark
Many ASoC drivers are using dummy DAI. We can use common snd_soc_dai_link_component for it. This patch-set adds common asoc_dummy_dlc, and use it.
Kuninori Morimoto (11): ASoC: soc-utils.c: add asoc_dummy_dlc ASoC: simple_card_utils.c: use asoc_dummy_dlc ASoC: ti: use asoc_dummy_dlc ASoC: sof: use asoc_dummy_dlc ASoC: amd: use asoc_dummy_dlc ASoC: fsl: use asoc_dummy_dlc ASoC: qcom: use asoc_dummy_dlc ASoC: atmel: use asoc_dummy_dlc ASoC: intel: use asoc_dummy_dlc ASoC: meson: use asoc_dummy_dlc ASoC: soc-topology.c: use asoc_dummy_dlc
include/sound/simple_card_utils.h | 1 - include/sound/soc.h | 1 + sound/soc/amd/acp/acp-mach-common.c | 43 ++++++++------------ sound/soc/atmel/atmel-classd.c | 6 +-- sound/soc/atmel/atmel-pdmic.c | 6 +-- sound/soc/fsl/imx-audmix.c | 14 +++---- sound/soc/fsl/imx-card.c | 11 +---- sound/soc/fsl/imx-rpmsg.c | 3 +- sound/soc/fsl/imx-spdif.c | 6 +-- sound/soc/generic/simple-card-utils.c | 9 +--- sound/soc/intel/avs/boards/i2s_test.c | 6 +-- sound/soc/intel/boards/ehl_rt5660.c | 8 +--- sound/soc/intel/boards/skl_hda_dsp_generic.c | 8 +--- sound/soc/intel/boards/sof_cs42l42.c | 11 +---- sound/soc/intel/boards/sof_es8336.c | 11 +---- sound/soc/intel/boards/sof_nau8825.c | 11 +---- sound/soc/intel/boards/sof_pcm512x.c | 3 +- sound/soc/intel/boards/sof_rt5682.c | 14 ++----- sound/soc/intel/boards/sof_sdw.c | 13 +----- sound/soc/intel/boards/sof_ssp_amp.c | 18 +++----- sound/soc/meson/axg-card.c | 6 +-- sound/soc/meson/meson-card-utils.c | 10 +---- sound/soc/qcom/common.c | 11 +---- sound/soc/soc-topology.c | 12 +++--- sound/soc/soc-utils.c | 7 ++++ sound/soc/sof/nocodec.c | 8 ++-- sound/soc/ti/omap-hdmi.c | 6 +-- 27 files changed, 78 insertions(+), 185 deletions(-)
ASoC uses dummy Component, sharing snd_soc_dai_link_component for it is better idea. This patch adds it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- include/sound/soc.h | 1 + sound/soc/soc-utils.c | 7 +++++++ 2 files changed, 8 insertions(+)
diff --git a/include/sound/soc.h b/include/sound/soc.h index 05004c048dd5..533e553a343f 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -878,6 +878,7 @@ asoc_link_to_platform(struct snd_soc_dai_link *link, int n) { #define COMP_DUMMY() { .name = "snd-soc-dummy", .dai_name = "snd-soc-dummy-dai", }
extern struct snd_soc_dai_link_component null_dailink_component[0]; +extern struct snd_soc_dai_link_component asoc_dummy_dlc;
struct snd_soc_codec_conf { diff --git a/sound/soc/soc-utils.c b/sound/soc/soc-utils.c index a4dba0b751e7..11607c5f5d5a 100644 --- a/sound/soc/soc-utils.c +++ b/sound/soc/soc-utils.c @@ -224,6 +224,13 @@ int snd_soc_component_is_dummy(struct snd_soc_component *component) (component->driver == &dummy_codec)); }
+struct snd_soc_dai_link_component asoc_dummy_dlc = { + .of_node = NULL, + .dai_name = "snd-soc-dummy-dai", + .name = "snd-soc-dummy", +}; +EXPORT_SYMBOL_GPL(asoc_dummy_dlc); + static int snd_soc_dummy_probe(struct platform_device *pdev) { int ret;
Now we can share asoc_dummy_dlc. This patch use it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- include/sound/simple_card_utils.h | 1 - sound/soc/generic/simple-card-utils.c | 9 ++------- 2 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h index a3f3f3aa9e6e..0e46f985eeda 100644 --- a/include/sound/simple_card_utils.h +++ b/include/sound/simple_card_utils.h @@ -73,7 +73,6 @@ struct asoc_simple_priv { struct snd_soc_dai_link *dai_link; struct asoc_simple_dai *dais; struct snd_soc_dai_link_component *dlcs; - struct snd_soc_dai_link_component dummy; struct snd_soc_codec_conf *codec_conf; struct gpio_desc *pa_gpio; const struct snd_soc_ops *ops; diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c index 467edd96eae5..b5ac0f0d5e8e 100644 --- a/sound/soc/generic/simple-card-utils.c +++ b/sound/soc/generic/simple-card-utils.c @@ -889,11 +889,6 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv, dev_dbg(dev, "link %d, dais %d, ccnf %d\n", li->link, dai_num, cnf_num);
- /* dummy CPU/Codec */ - priv->dummy.of_node = NULL; - priv->dummy.dai_name = "snd-soc-dummy-dai"; - priv->dummy.name = "snd-soc-dummy"; - priv->dai_props = dai_props; priv->dai_link = dai_link; priv->dais = dais; @@ -919,7 +914,7 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv, } else { /* DPCM Be's CPU = dummy */ dai_props[i].cpus = - dai_link[i].cpus = &priv->dummy; + dai_link[i].cpus = &asoc_dummy_dlc; dai_props[i].num.cpus = dai_link[i].num_cpus = 1; } @@ -943,7 +938,7 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv, } else { /* DPCM Fe's Codec = dummy */ dai_props[i].codecs = - dai_link[i].codecs = &priv->dummy; + dai_link[i].codecs = &asoc_dummy_dlc; dai_props[i].num.codecs = dai_link[i].num_codecs = 1; }
Now we can share asoc_dummy_dlc. This patch use it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/ti/omap-hdmi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/sound/soc/ti/omap-hdmi.c b/sound/soc/ti/omap-hdmi.c index 96c3569d7643..fee7b82d7e52 100644 --- a/sound/soc/ti/omap-hdmi.c +++ b/sound/soc/ti/omap-hdmi.c @@ -365,19 +365,17 @@ static int omap_hdmi_audio_probe(struct platform_device *pdev) if (!card->dai_link) return -ENOMEM;
- compnent = devm_kzalloc(dev, 2 * sizeof(*compnent), GFP_KERNEL); + compnent = devm_kzalloc(dev, sizeof(*compnent), GFP_KERNEL); if (!compnent) return -ENOMEM; card->dai_link->cpus = &compnent[0]; card->dai_link->num_cpus = 1; - card->dai_link->codecs = &compnent[1]; + card->dai_link->codecs = &asoc_dummy_dlc; card->dai_link->num_codecs = 1;
card->dai_link->name = card->name; card->dai_link->stream_name = card->name; card->dai_link->cpus->dai_name = dev_name(ad->dssdev); - card->dai_link->codecs->name = "snd-soc-dummy"; - card->dai_link->codecs->dai_name = "snd-soc-dummy-dai"; card->num_links = 1; card->dev = dev;
Now we can share asoc_dummy_dlc. This patch use it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/fsl/imx-audmix.c | 14 +++++--------- sound/soc/fsl/imx-card.c | 11 +---------- sound/soc/fsl/imx-rpmsg.c | 3 +-- sound/soc/fsl/imx-spdif.c | 6 ++---- 4 files changed, 9 insertions(+), 25 deletions(-)
diff --git a/sound/soc/fsl/imx-audmix.c b/sound/soc/fsl/imx-audmix.c index 2c57fe9d2d08..8287b366eea1 100644 --- a/sound/soc/fsl/imx-audmix.c +++ b/sound/soc/fsl/imx-audmix.c @@ -207,8 +207,8 @@ static int imx_audmix_probe(struct platform_device *pdev) for (i = 0; i < num_dai; i++) { struct snd_soc_dai_link_component *dlc;
- /* for CPU/Codec x 2 */ - dlc = devm_kcalloc(&pdev->dev, 4, sizeof(*dlc), GFP_KERNEL); + /* for CPU x 2 */ + dlc = devm_kcalloc(&pdev->dev, 2, sizeof(*dlc), GFP_KERNEL); if (!dlc) return -ENOMEM;
@@ -239,15 +239,13 @@ static int imx_audmix_probe(struct platform_device *pdev) }
priv->dai[i].cpus = &dlc[0]; - priv->dai[i].codecs = &dlc[1]; + priv->dai[i].codecs = &asoc_dummy_dlc;
priv->dai[i].num_cpus = 1; priv->dai[i].num_codecs = 1;
priv->dai[i].name = dai_name; priv->dai[i].stream_name = "HiFi-AUDMIX-FE"; - priv->dai[i].codecs->dai_name = "snd-soc-dummy-dai"; - priv->dai[i].codecs->name = "snd-soc-dummy"; priv->dai[i].cpus->of_node = args.np; priv->dai[i].cpus->dai_name = dev_name(&cpu_pdev->dev); priv->dai[i].dynamic = 1; @@ -264,15 +262,13 @@ static int imx_audmix_probe(struct platform_device *pdev) be_cp = devm_kasprintf(&pdev->dev, GFP_KERNEL, "AUDMIX-Capture-%d", i);
- priv->dai[num_dai + i].cpus = &dlc[2]; - priv->dai[num_dai + i].codecs = &dlc[3]; + priv->dai[num_dai + i].cpus = &dlc[1]; + priv->dai[num_dai + i].codecs = &asoc_dummy_dlc;
priv->dai[num_dai + i].num_cpus = 1; priv->dai[num_dai + i].num_codecs = 1;
priv->dai[num_dai + i].name = be_name; - priv->dai[num_dai + i].codecs->dai_name = "snd-soc-dummy-dai"; - priv->dai[num_dai + i].codecs->name = "snd-soc-dummy"; priv->dai[num_dai + i].cpus->of_node = audmix_np; priv->dai[num_dai + i].cpus->dai_name = be_name; priv->dai[num_dai + i].no_pcm = 1; diff --git a/sound/soc/fsl/imx-card.c b/sound/soc/fsl/imx-card.c index 64a4d7e9db60..78e2e3932ba5 100644 --- a/sound/soc/fsl/imx-card.c +++ b/sound/soc/fsl/imx-card.c @@ -615,17 +615,8 @@ static int imx_card_parse_of(struct imx_card_data *data) plat_data->type = CODEC_AK5552;
} else { - dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL); - if (!dlc) { - ret = -ENOMEM; - goto err; - } - - link->codecs = dlc; + link->codecs = &asoc_dummy_dlc; link->num_codecs = 1; - - link->codecs->dai_name = "snd-soc-dummy-dai"; - link->codecs->name = "snd-soc-dummy"; }
if (!strncmp(link->name, "HiFi-ASRC-FE", 12)) { diff --git a/sound/soc/fsl/imx-rpmsg.c b/sound/soc/fsl/imx-rpmsg.c index 89178106fe2c..93fc976e98dc 100644 --- a/sound/soc/fsl/imx-rpmsg.c +++ b/sound/soc/fsl/imx-rpmsg.c @@ -92,8 +92,7 @@ static int imx_rpmsg_probe(struct platform_device *pdev) /* Optional codec node */ ret = of_parse_phandle_with_fixed_args(np, "audio-codec", 0, 0, &args); if (ret) { - data->dai.codecs->dai_name = "snd-soc-dummy-dai"; - data->dai.codecs->name = "snd-soc-dummy"; + *data->dai.codecs = asoc_dummy_dlc; } else { struct clk *clk;
diff --git a/sound/soc/fsl/imx-spdif.c b/sound/soc/fsl/imx-spdif.c index 114b49660193..547be9438333 100644 --- a/sound/soc/fsl/imx-spdif.c +++ b/sound/soc/fsl/imx-spdif.c @@ -26,22 +26,20 @@ static int imx_spdif_audio_probe(struct platform_device *pdev) }
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); - comp = devm_kzalloc(&pdev->dev, 2 * sizeof(*comp), GFP_KERNEL); + comp = devm_kzalloc(&pdev->dev, sizeof(*comp), GFP_KERNEL); if (!data || !comp) { ret = -ENOMEM; goto end; }
data->dai.cpus = &comp[0]; - data->dai.codecs = &comp[1]; + data->dai.codecs = &asoc_dummy_dlc;
data->dai.num_cpus = 1; data->dai.num_codecs = 1;
data->dai.name = "S/PDIF PCM"; data->dai.stream_name = "S/PDIF PCM"; - data->dai.codecs->dai_name = "snd-soc-dummy-dai"; - data->dai.codecs->name = "snd-soc-dummy"; data->dai.cpus->of_node = spdif_np; data->dai.playback_only = true; data->dai.capture_only = true;
Now we can share asoc_dummy_dlc. This patch use it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/qcom/common.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c index c1f24af17506..cab5a7937a57 100644 --- a/sound/soc/qcom/common.c +++ b/sound/soc/qcom/common.c @@ -140,17 +140,8 @@ int qcom_snd_parse_of(struct snd_soc_card *card) } } else { /* DPCM frontend */ - dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL); - if (!dlc) { - ret = -ENOMEM; - goto err; - } - - link->codecs = dlc; + link->codecs = &asoc_dummy_dlc; link->num_codecs = 1; - - link->codecs->dai_name = "snd-soc-dummy-dai"; - link->codecs->name = "snd-soc-dummy"; link->dynamic = 1; }
Now we can share asoc_dummy_dlc. This patch use it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/atmel/atmel-classd.c | 6 ++---- sound/soc/atmel/atmel-pdmic.c | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/sound/soc/atmel/atmel-classd.c b/sound/soc/atmel/atmel-classd.c index 007ab746973d..0fe42543a47a 100644 --- a/sound/soc/atmel/atmel-classd.c +++ b/sound/soc/atmel/atmel-classd.c @@ -473,21 +473,19 @@ static int atmel_classd_asoc_card_init(struct device *dev, if (!dai_link) return -ENOMEM;
- comp = devm_kzalloc(dev, 2 * sizeof(*comp), GFP_KERNEL); + comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL); if (!comp) return -ENOMEM;
dai_link->cpus = &comp[0]; - dai_link->codecs = &comp[1]; + dai_link->codecs = &asoc_dummy_dlc;
dai_link->num_cpus = 1; dai_link->num_codecs = 1;
dai_link->name = "CLASSD"; dai_link->stream_name = "CLASSD PCM"; - dai_link->codecs->dai_name = "snd-soc-dummy-dai"; dai_link->cpus->dai_name = dev_name(dev); - dai_link->codecs->name = "snd-soc-dummy";
card->dai_link = dai_link; card->num_links = 1; diff --git a/sound/soc/atmel/atmel-pdmic.c b/sound/soc/atmel/atmel-pdmic.c index 00c7b3a34ef5..133f17ae24a5 100644 --- a/sound/soc/atmel/atmel-pdmic.c +++ b/sound/soc/atmel/atmel-pdmic.c @@ -496,21 +496,19 @@ static int atmel_pdmic_asoc_card_init(struct device *dev, if (!dai_link) return -ENOMEM;
- comp = devm_kzalloc(dev, 2 * sizeof(*comp), GFP_KERNEL); + comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL); if (!comp) return -ENOMEM;
dai_link->cpus = &comp[0]; - dai_link->codecs = &comp[1]; + dai_link->codecs = &asoc_dummy_dlc;
dai_link->num_cpus = 1; dai_link->num_codecs = 1;
dai_link->name = "PDMIC"; dai_link->stream_name = "PDMIC PCM"; - dai_link->codecs->dai_name = "snd-soc-dummy-dai"; dai_link->cpus->dai_name = dev_name(dev); - dai_link->codecs->name = "snd-soc-dummy";
card->dai_link = dai_link; card->num_links = 1;
Now we can share asoc_dummy_dlc. This patch use it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/meson/axg-card.c | 6 ++---- sound/soc/meson/meson-card-utils.c | 10 +--------- 2 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/sound/soc/meson/axg-card.c b/sound/soc/meson/axg-card.c index a25c397c66c5..5c2fff1ff607 100644 --- a/sound/soc/meson/axg-card.c +++ b/sound/soc/meson/axg-card.c @@ -120,20 +120,18 @@ static int axg_card_add_tdm_loopback(struct snd_soc_card *card, if (!lb->name) return -ENOMEM;
- dlc = devm_kzalloc(card->dev, 2 * sizeof(*dlc), GFP_KERNEL); + dlc = devm_kzalloc(card->dev, sizeof(*dlc), GFP_KERNEL); if (!dlc) return -ENOMEM;
lb->cpus = &dlc[0]; - lb->codecs = &dlc[1]; + lb->codecs = &asoc_dummy_dlc; lb->num_cpus = 1; lb->num_codecs = 1;
lb->stream_name = lb->name; lb->cpus->of_node = pad->cpus->of_node; lb->cpus->dai_name = "TDM Loopback"; - lb->codecs->name = "snd-soc-dummy"; - lb->codecs->dai_name = "snd-soc-dummy-dai"; lb->dpcm_capture = 1; lb->no_pcm = 1; lb->ops = &axg_card_tdm_be_ops; diff --git a/sound/soc/meson/meson-card-utils.c b/sound/soc/meson/meson-card-utils.c index 2d8d5717fd8b..ffc5111f9e3c 100644 --- a/sound/soc/meson/meson-card-utils.c +++ b/sound/soc/meson/meson-card-utils.c @@ -183,21 +183,13 @@ int meson_card_set_fe_link(struct snd_soc_card *card, struct device_node *node, bool is_playback) { - struct snd_soc_dai_link_component *codec; - - codec = devm_kzalloc(card->dev, sizeof(*codec), GFP_KERNEL); - if (!codec) - return -ENOMEM; - - link->codecs = codec; + link->codecs = &asoc_dummy_dlc; link->num_codecs = 1;
link->dynamic = 1; link->dpcm_merged_format = 1; link->dpcm_merged_chan = 1; link->dpcm_merged_rate = 1; - link->codecs->dai_name = "snd-soc-dummy-dai"; - link->codecs->name = "snd-soc-dummy";
if (is_playback) link->dpcm_playback = 1;
Now we can share asoc_dummy_dlc. This patch use it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-topology.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index d0aca6b9058b..873448c4a895 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1685,15 +1685,15 @@ static int soc_tplg_fe_link_create(struct soc_tplg *tplg, struct snd_soc_dai_link_component *dlc; int ret;
- /* link + cpu + codec + platform */ - link = devm_kzalloc(tplg->dev, sizeof(*link) + (3 * sizeof(*dlc)), GFP_KERNEL); + /* link + cpu + platform */ + link = devm_kzalloc(tplg->dev, sizeof(*link) + (2 * sizeof(*dlc)), GFP_KERNEL); if (link == NULL) return -ENOMEM;
dlc = (struct snd_soc_dai_link_component *)(link + 1);
link->cpus = &dlc[0]; - link->codecs = &dlc[1]; + link->codecs = &asoc_dummy_dlc;
link->num_cpus = 1; link->num_codecs = 1; @@ -1721,14 +1721,12 @@ static int soc_tplg_fe_link_create(struct soc_tplg *tplg, } }
- link->codecs->name = "snd-soc-dummy"; - link->codecs->dai_name = "snd-soc-dummy-dai"; - /* * Many topology is assuming link has Platform. * This might be overwritten at soc_tplg_dai_link_load(). + * Don't use &asoc_dummy_dlc here. */ - link->platforms = &dlc[2]; + link->platforms = &dlc[1]; link->platforms->name = "snd-soc-dummy"; link->num_platforms = 1;
On 4/18/2023 2:28 AM, Kuninori Morimoto wrote:
Now we can share asoc_dummy_dlc. This patch use it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
sound/soc/soc-topology.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index d0aca6b9058b..873448c4a895 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1685,15 +1685,15 @@ static int soc_tplg_fe_link_create(struct soc_tplg *tplg, struct snd_soc_dai_link_component *dlc; int ret;
- /* link + cpu + codec + platform */
- link = devm_kzalloc(tplg->dev, sizeof(*link) + (3 * sizeof(*dlc)), GFP_KERNEL);
/* link + cpu + platform */
link = devm_kzalloc(tplg->dev, sizeof(*link) + (2 * sizeof(*dlc)), GFP_KERNEL); if (link == NULL) return -ENOMEM;
dlc = (struct snd_soc_dai_link_component *)(link + 1);
link->cpus = &dlc[0];
- link->codecs = &dlc[1];
link->codecs = &asoc_dummy_dlc;
link->num_cpus = 1; link->num_codecs = 1;
@@ -1721,14 +1721,12 @@ static int soc_tplg_fe_link_create(struct soc_tplg *tplg, } }
- link->codecs->name = "snd-soc-dummy";
- link->codecs->dai_name = "snd-soc-dummy-dai";
- /*
- Many topology is assuming link has Platform.
- This might be overwritten at soc_tplg_dai_link_load().
*/* Don't use &asoc_dummy_dlc here.
- link->platforms = &dlc[2];
- link->platforms = &dlc[1]; link->platforms->name = "snd-soc-dummy"; link->num_platforms = 1;
In case of topology I'm not convinced that it is a good idea. You set link->codecs to point at global object, but if any of link modifies its link->codecs, which for example can happen in soc_tplg_dai_link_load() then all other link objects will point at modified value.
Hi Amadeusz
In case of topology I'm not convinced that it is a good idea. You set link->codecs to point at global object, but if any of link modifies its link->codecs, which for example can happen in soc_tplg_dai_link_load() then all other link objects will point at modified value.
Thank you for pointing it. I see. Not only "platform" but "codecs" also might be modified on topology... I think we want to have such comment/note on the code. I will modify it on v2 patch.
Thank you for your help !!
Best regards --- Kuninori Morimoto
participants (2)
-
Amadeusz Sławiński
-
Kuninori Morimoto