Now platform can be replaced to component, let's do it.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: Garlic Tseng <garlic.tseng@mediatek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
 #include <linux/pm_runtime.h>
 #include <linux/regmap.h>
 #include <sound/soc.h>
+#include "mtk-afe-platform-driver.h"
 #include "mtk-afe-fe-dai.h"
 #include "mtk-base-afe.h"
 
                       struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct snd_pcm_runtime *runtime = substream->runtime;
        int memif_num = rtd->cpu_dai->id;
        struct mtk_base_afe_memif *memif = &afe->memif[memif_num];
                         struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mtk_base_afe_memif *memif = &afe->memif[rtd->cpu_dai->id];
        int irq_id;
 
                         struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mtk_base_afe_memif *memif = &afe->memif[rtd->cpu_dai->id];
        int msb_at_bit33 = 0;
        int ret, fs = 0;
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_pcm_runtime * const runtime = substream->runtime;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mtk_base_afe_memif *memif = &afe->memif[rtd->cpu_dai->id];
        struct mtk_base_afe_irq *irqs = &afe->irqs[memif->irq_usage];
        const struct mtk_base_irq_data *irq_data = irqs->irq_data;
                       struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd  = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mtk_base_afe_memif *memif = &afe->memif[rtd->cpu_dai->id];
        int hd_audio = 0;
 
 
                         (struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mtk_base_afe_memif *memif = &afe->memif[rtd->cpu_dai->id];
        const struct mtk_base_memif_data *memif_data = memif->data;
        struct regmap *regmap = afe->regmap;
        size_t size;
        struct snd_card *card = rtd->card->snd_card;
        struct snd_pcm *pcm = rtd->pcm;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
 
        size = afe->mtk_afe_hardware->buffer_bytes_max;
        return snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
        snd_pcm_lib_preallocate_free_for_all(pcm);
 }
 
-const struct snd_soc_platform_driver mtk_afe_pcm_platform = {
+const struct snd_soc_component_driver mtk_afe_pcm_platform = {
+       .name = AFE_PCM_NAME,
        .ops = &mtk_afe_pcm_ops,
        .pcm_new = mtk_afe_pcm_new,
        .pcm_free = mtk_afe_pcm_free,
 
 #ifndef _MTK_AFE_PLATFORM_DRIVER_H_
 #define _MTK_AFE_PLATFORM_DRIVER_H_
 
-extern const struct snd_soc_platform_driver mtk_afe_pcm_platform;
+#define AFE_PCM_NAME "mtk-afe-pcm"
+extern const struct snd_soc_component_driver mtk_afe_pcm_platform;
 
 #endif
 
 
                                  struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        int i2s_num = mt2701_dai_num_to_i2s(afe, dai->id);
 
        if (i2s_num < 0)
                                        int dir_invert)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mt2701_afe_private *afe_priv = afe->platform_priv;
        struct mt2701_i2s_path *i2s_path = &afe_priv->i2s_path[i2s_num];
        const struct mt2701_i2s_data *i2s_data;
                                    struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mt2701_afe_private *afe_priv = afe->platform_priv;
        int i2s_num = mt2701_dai_num_to_i2s(afe, dai->id);
        struct mt2701_i2s_path *i2s_path;
                                          int dir_invert)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mt2701_afe_private *afe_priv = afe->platform_priv;
        struct mt2701_i2s_path *i2s_path = &afe_priv->i2s_path[i2s_num];
        const struct mt2701_i2s_data *i2s_data;
 {
        int clk_domain;
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mt2701_afe_private *afe_priv = afe->platform_priv;
        int i2s_num = mt2701_dai_num_to_i2s(afe, dai->id);
        struct mt2701_i2s_path *i2s_path;
                                struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mt2701_afe_private *afe_priv = afe->platform_priv;
        int ret;
 
                                  struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        int stream_fs;
        u32 val, msk;
 
                                  struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mt2701_afe_private *afe_priv = afe->platform_priv;
 
        /* if the other direction stream is not occupied */
                                    struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        int stream_dir = substream->stream;
        int memif_num = rtd->cpu_dai->id;
        struct mtk_base_afe_memif *memif_tmp;
                                      struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        int stream_dir = substream->stream;
 
        /* single DL use PAIR_INTERLEAVE */
                                 struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mtk_base_afe_memif *memif_tmp;
        const struct mtk_base_memif_data *memif_data;
        int i;
                                   struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        const struct mtk_base_memif_data *memif_data;
        int i;
 
                                   struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        int channels = params_channels(params);
 
        regmap_update_bits(afe->regmap,
                                 int cmd, struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mtk_base_afe_memif *memif_tmp = &afe->memif[MT2701_MEMIF_DL1];
 
        switch (cmd) {
        }
        pm_runtime_get_sync(dev);
 
-       ret = snd_soc_register_platform(dev, &mtk_afe_pcm_platform);
+       ret = devm_snd_soc_register_component(&pdev->dev, &mtk_afe_pcm_platform,
+                                             NULL, 0);
        if (ret) {
                dev_warn(dev, "err_platform\n");
                goto err_platform;
        ret = mt2701_afe_add_component(afe);
        if (ret) {
                dev_warn(dev, "err_dai_component\n");
-               goto err_dai_component;
+               goto err_platform;
        }
 
        return 0;
 
-err_dai_component:
-       snd_soc_unregister_platform(dev);
 err_platform:
        pm_runtime_put_sync(dev);
 err_pm_disable:
                mt2701_afe_runtime_suspend(&pdev->dev);
 
        snd_soc_unregister_component(&pdev->dev);
-       snd_soc_unregister_platform(&pdev->dev);
 
        return 0;
 }
 
                                  struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
 
        if (dai->active)
                return 0;
                                    struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
 
        if (dai->active)
                return;
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_pcm_runtime * const runtime = substream->runtime;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mt8173_afe_private *afe_priv = afe->platform_priv;
        int ret;
 
                                   struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mt8173_afe_private *afe_priv = afe->platform_priv;
 
        if (dai->active)
                                     struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mt8173_afe_private *afe_priv = afe->platform_priv;
 
        if (dai->active)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_pcm_runtime * const runtime = substream->runtime;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mt8173_afe_private *afe_priv = afe->platform_priv;
 
        unsigned int val;
                                   struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
 
        dev_info(afe->dev, "%s cmd=%d %s\n", __func__, cmd, dai->name);
 
                           unsigned int rate)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
+       struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+       struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
        struct mtk_base_afe_memif *memif = &afe->memif[rtd->cpu_dai->id];
        int fs;
 
        afe->runtime_resume = mt8173_afe_runtime_resume;
        afe->runtime_suspend = mt8173_afe_runtime_suspend;
 
-       ret = snd_soc_register_platform(&pdev->dev, &mtk_afe_pcm_platform);
+       ret = devm_snd_soc_register_component(&pdev->dev,
+                                        &mtk_afe_pcm_platform,
+                                        NULL, 0);
        if (ret)
                goto err_pm_disable;
 
-       ret = snd_soc_register_component(&pdev->dev,
+       ret = devm_snd_soc_register_component(&pdev->dev,
                                         &mt8173_afe_pcm_dai_component,
                                         mt8173_afe_pcm_dais,
                                         ARRAY_SIZE(mt8173_afe_pcm_dais));
        if (ret)
-               goto err_platform;
+               goto err_pm_disable;
 
-       ret = snd_soc_register_component(&pdev->dev,
+       ret = devm_snd_soc_register_component(&pdev->dev,
                                         &mt8173_afe_hdmi_dai_component,
                                         mt8173_afe_hdmi_dais,
                                         ARRAY_SIZE(mt8173_afe_hdmi_dais));
        if (ret)
-               goto err_comp;
+               goto err_pm_disable;
 
        dev_info(&pdev->dev, "MT8173 AFE driver initialized.\n");
        return 0;
 
-err_comp:
-       snd_soc_unregister_component(&pdev->dev);
-err_platform:
-       snd_soc_unregister_platform(&pdev->dev);
 err_pm_disable:
        pm_runtime_disable(&pdev->dev);
        return ret;
        pm_runtime_disable(&pdev->dev);
        if (!pm_runtime_status_suspended(&pdev->dev))
                mt8173_afe_runtime_suspend(&pdev->dev);
-       snd_soc_unregister_component(&pdev->dev);
-       snd_soc_unregister_platform(&pdev->dev);
        return 0;
 }