ASoC: mt6797: sub dai use list_head
authorKaiChieh Chuang <kaichieh.chuang@mediatek.com>
Fri, 29 Jun 2018 12:29:45 +0000 (20:29 +0800)
committerMark Brown <broonie@kernel.org>
Fri, 29 Jun 2018 12:31:53 +0000 (13:31 +0100)
Signed-off-by: KaiChieh Chuang <kaichieh.chuang@mediatek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/mediatek/mt6797/mt6797-afe-common.h
sound/soc/mediatek/mt6797/mt6797-afe-pcm.c
sound/soc/mediatek/mt6797/mt6797-dai-adda.c
sound/soc/mediatek/mt6797/mt6797-dai-hostless.c
sound/soc/mediatek/mt6797/mt6797-dai-pcm.c

index 22eb7b455cf1eac81bcbff8c9a89807cc3821355..4eac9977b2b0d88b826f0484a095bf43634947fb 100644 (file)
@@ -10,6 +10,7 @@
 #define _MT_6797_AFE_COMMON_H_
 
 #include <sound/soc.h>
+#include <linux/list.h>
 #include <linux/regmap.h>
 #include "../common/mtk-base-afe.h"
 
index 6c5dd9fc99766e6109d21a957b5b74d839692f26..192f4d7b37b6ad003d558dcc9b6b74f125225792 100644 (file)
@@ -733,6 +733,34 @@ static const struct snd_soc_component_driver mt6797_afe_component = {
        .probe = mt6797_afe_component_probe,
 };
 
+static int mt6797_dai_memif_register(struct mtk_base_afe *afe)
+{
+       struct mtk_base_afe_dai *dai;
+
+       dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL);
+       if (!dai)
+               return -ENOMEM;
+
+       list_add(&dai->list, &afe->sub_dais);
+
+       dai->dai_drivers = mt6797_memif_dai_driver;
+       dai->num_dai_drivers = ARRAY_SIZE(mt6797_memif_dai_driver);
+
+       dai->dapm_widgets = mt6797_memif_widgets;
+       dai->num_dapm_widgets = ARRAY_SIZE(mt6797_memif_widgets);
+       dai->dapm_routes = mt6797_memif_routes;
+       dai->num_dapm_routes = ARRAY_SIZE(mt6797_memif_routes);
+       return 0;
+}
+
+typedef int (*dai_register_cb)(struct mtk_base_afe *);
+static const dai_register_cb dai_register_cbs[] = {
+       mt6797_dai_adda_register,
+       mt6797_dai_pcm_register,
+       mt6797_dai_hostless_register,
+       mt6797_dai_memif_register,
+};
+
 static int mt6797_afe_pcm_dev_probe(struct platform_device *pdev)
 {
        struct mtk_base_afe *afe;
@@ -811,29 +839,24 @@ static int mt6797_afe_pcm_dev_probe(struct platform_device *pdev)
        }
 
        /* init sub_dais */
-       afe->num_sub_dais = MT6797_DAI_NUM;
-       afe->sub_dais = devm_kcalloc(dev, afe->num_sub_dais,
-                                    sizeof(*afe->sub_dais),
-                                    GFP_KERNEL);
-       if (!afe->sub_dais)
-               return -ENOMEM;
-
-       mt6797_dai_adda_register(afe);
-       mt6797_dai_pcm_register(afe);
-       mt6797_dai_hostless_register(afe);
-
-       afe->sub_dais[MT6797_MEMIF_DL1].dai_drivers = mt6797_memif_dai_driver;
-       afe->sub_dais[MT6797_MEMIF_DL1].num_dai_drivers =
-               ARRAY_SIZE(mt6797_memif_dai_driver);
-       afe->sub_dais[MT6797_MEMIF_DL1].dapm_widgets = mt6797_memif_widgets;
-       afe->sub_dais[MT6797_MEMIF_DL1].num_dapm_widgets =
-               ARRAY_SIZE(mt6797_memif_widgets);
-       afe->sub_dais[MT6797_MEMIF_DL1].dapm_routes = mt6797_memif_routes;
-       afe->sub_dais[MT6797_MEMIF_DL1].num_dapm_routes =
-               ARRAY_SIZE(mt6797_memif_routes);
+       INIT_LIST_HEAD(&afe->sub_dais);
+
+       for (i = 0; i < ARRAY_SIZE(dai_register_cbs); i++) {
+               ret = dai_register_cbs[i](afe);
+               if (ret) {
+                       dev_warn(afe->dev, "dai register i %d fail, ret %d\n",
+                                i, ret);
+                       return ret;
+               }
+       }
 
        /* init dai_driver and component_driver */
-       mtk_afe_combine_sub_dai(afe);
+       ret = mtk_afe_combine_sub_dai(afe);
+       if (ret) {
+               dev_warn(afe->dev, "mtk_afe_combine_sub_dai fail, ret %d\n",
+                        ret);
+               return ret;
+       }
 
        afe->mtk_afe_hardware = &mt6797_afe_hardware;
        afe->memif_fs = mt6797_memif_fs;
index ad083265ce944bf01e82a8a84e464add6c458151..0ac6409c6d61f273003bd27ad1776596f7b529fa 100644 (file)
@@ -383,14 +383,20 @@ static struct snd_soc_dai_driver mtk_dai_adda_driver[] = {
 
 int mt6797_dai_adda_register(struct mtk_base_afe *afe)
 {
-       int id = MT6797_DAI_ADDA;
+       struct mtk_base_afe_dai *dai;
 
-       afe->sub_dais[id].dai_drivers = mtk_dai_adda_driver;
-       afe->sub_dais[id].num_dai_drivers = ARRAY_SIZE(mtk_dai_adda_driver);
+       dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL);
+       if (!dai)
+               return -ENOMEM;
 
-       afe->sub_dais[id].dapm_widgets = mtk_dai_adda_widgets;
-       afe->sub_dais[id].num_dapm_widgets = ARRAY_SIZE(mtk_dai_adda_widgets);
-       afe->sub_dais[id].dapm_routes = mtk_dai_adda_routes;
-       afe->sub_dais[id].num_dapm_routes = ARRAY_SIZE(mtk_dai_adda_routes);
+       list_add(&dai->list, &afe->sub_dais);
+
+       dai->dai_drivers = mtk_dai_adda_driver;
+       dai->num_dai_drivers = ARRAY_SIZE(mtk_dai_adda_driver);
+
+       dai->dapm_widgets = mtk_dai_adda_widgets;
+       dai->num_dapm_widgets = ARRAY_SIZE(mtk_dai_adda_widgets);
+       dai->dapm_routes = mtk_dai_adda_routes;
+       dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_adda_routes);
        return 0;
 }
index 4cf985b15a11e9b9c136280f64f9c81451b62dda..ed23e6a53b086f63e42ab539916d94e889a521c8 100644 (file)
@@ -100,13 +100,19 @@ static struct snd_soc_dai_driver mtk_dai_hostless_driver[] = {
 
 int mt6797_dai_hostless_register(struct mtk_base_afe *afe)
 {
-       int id = MT6797_DAI_HOSTLESS_LPBK;
+       struct mtk_base_afe_dai *dai;
 
-       afe->sub_dais[id].dai_drivers = mtk_dai_hostless_driver;
-       afe->sub_dais[id].num_dai_drivers = ARRAY_SIZE(mtk_dai_hostless_driver);
+       dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL);
+       if (!dai)
+               return -ENOMEM;
 
-       afe->sub_dais[id].dapm_routes = mtk_dai_hostless_routes;
-       afe->sub_dais[id].num_dapm_routes = ARRAY_SIZE(mtk_dai_hostless_routes);
+       list_add(&dai->list, &afe->sub_dais);
+
+       dai->dai_drivers = mtk_dai_hostless_driver;
+       dai->num_dai_drivers = ARRAY_SIZE(mtk_dai_hostless_driver);
+
+       dai->dapm_routes = mtk_dai_hostless_routes;
+       dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_hostless_routes);
 
        return 0;
 }
index 16d5b5067204ad9f25654744c755e5e4f641ddb4..3136f0bc7827d789703d798957a711a7d9abb411 100644 (file)
@@ -298,15 +298,20 @@ static struct snd_soc_dai_driver mtk_dai_pcm_driver[] = {
 
 int mt6797_dai_pcm_register(struct mtk_base_afe *afe)
 {
-       int id = MT6797_DAI_PCM_1;
+       struct mtk_base_afe_dai *dai;
 
-       afe->sub_dais[id].dai_drivers = mtk_dai_pcm_driver;
-       afe->sub_dais[id].num_dai_drivers = ARRAY_SIZE(mtk_dai_pcm_driver);
+       dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL);
+       if (!dai)
+               return -ENOMEM;
 
-       afe->sub_dais[id].dapm_widgets = mtk_dai_pcm_widgets;
-       afe->sub_dais[id].num_dapm_widgets = ARRAY_SIZE(mtk_dai_pcm_widgets);
-       afe->sub_dais[id].dapm_routes = mtk_dai_pcm_routes;
-       afe->sub_dais[id].num_dapm_routes = ARRAY_SIZE(mtk_dai_pcm_routes);
+       list_add(&dai->list, &afe->sub_dais);
 
+       dai->dai_drivers = mtk_dai_pcm_driver;
+       dai->num_dai_drivers = ARRAY_SIZE(mtk_dai_pcm_driver);
+
+       dai->dapm_widgets = mtk_dai_pcm_widgets;
+       dai->num_dapm_widgets = ARRAY_SIZE(mtk_dai_pcm_widgets);
+       dai->dapm_routes = mtk_dai_pcm_routes;
+       dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_pcm_routes);
        return 0;
 }