ASoC: seeed-voicecard: Fix init and parse func
authorHoegeun Kwon <hoegeun.kwon@samsung.com>
Mon, 18 May 2020 07:59:35 +0000 (16:59 +0900)
committerHoegeun Kwon <hoegeun.kwon@samsung.com>
Mon, 7 Feb 2022 07:09:31 +0000 (16:09 +0900)
When we rebase the kernel version to v5.x, the interface changed and
a build error occurred. Modify the interface for card init and parse.

This patch is already been reviewd from [1].

[1]
  "Commit: ASoC: ac108: Adds ac108 codec and machine code"
  "Change-Id: Idd1fd85a461c3f2ac03192ec49bf527601d797b7"

Change-Id: If6e460240cd750b8d56e9b7ec22be6e46162699a
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
Signed-off-by: Hoegeun Kwon <hoegeun.kwon@samsung.com>
sound/soc/seeed/seeed-voicecard.c

index 8c4ee3856fe136838c488b34dcbed91c33bb632d..5de1b4058f236fbbd37ad0e31c3dd797e6bba219 100644 (file)
@@ -232,6 +232,64 @@ static struct snd_soc_ops seeed_voice_card_ops = {
        .prepare = seeed_voice_card_prepare,
 };
 
+static int asoc_card_parse_dai(struct device_node *node,
+                               struct snd_soc_dai_link_component *dlc,
+                               int *is_single_link)
+{
+        struct of_phandle_args args;
+        int ret;
+
+        if (!node)
+                return 0;
+
+       ret = of_parse_phandle_with_args(node, DAI, CELL, 0, &args);
+        if (ret)
+                return ret;
+
+        ret = snd_soc_of_get_dai_name(node, &dlc->dai_name);
+        if (ret < 0)
+                return ret;
+
+        dlc->of_node = args.np;
+
+        if (is_single_link)
+                *is_single_link = !args.args_count;
+
+        return 0;
+}
+
+static int asoc_card_init_dai(struct snd_soc_dai *dai,
+                                     struct asoc_simple_dai *simple_dai)
+{
+        int ret;
+
+        if (!simple_dai)
+                return 0;
+
+        if (simple_dai->sysclk) {
+                ret = snd_soc_dai_set_sysclk(dai, 0, simple_dai->sysclk,
+                                             simple_dai->clk_direction);
+                if (ret && ret != -ENOTSUPP) {
+                        dev_err(dai->dev, "simple-card: set_sysclk error\n");
+                        return ret;
+                }
+        }
+
+        if (simple_dai->slots) {
+                ret = snd_soc_dai_set_tdm_slot(dai,
+                                               simple_dai->tx_slot_mask,
+                                               simple_dai->rx_slot_mask,
+                                               simple_dai->slots,
+                                               simple_dai->slot_width);
+                if (ret && ret != -ENOTSUPP) {
+                        dev_err(dai->dev, "simple-card: set_tdm_slot error\n");
+                        return ret;
+                }
+        }
+
+        return 0;
+}
+
 static int seeed_voice_card_dai_init(struct snd_soc_pcm_runtime *rtd)
 {
        struct seeed_card_data *priv =  snd_soc_card_get_drvdata(rtd->card);
@@ -241,11 +299,11 @@ static int seeed_voice_card_dai_init(struct snd_soc_pcm_runtime *rtd)
                seeed_priv_to_props(priv, rtd->num);
        int ret;
 
-       ret = asoc_simple_card_init_dai(codec, &dai_props->codec_dai);
+       ret = asoc_card_init_dai(codec, &dai_props->codec_dai);
        if (ret < 0)
                return ret;
 
-       ret = asoc_simple_card_init_dai(cpu, &dai_props->cpu_dai);
+       ret = asoc_card_init_dai(cpu, &dai_props->cpu_dai);
        if (ret < 0)
                return ret;
 
@@ -288,20 +346,19 @@ static int seeed_voice_card_dai_link_of(struct device_node *node,
                goto dai_link_of_err;
        }
 
-       ret = asoc_simple_card_parse_daifmt(dev, node, codec,
+       ret = asoc_simple_parse_daifmt(dev, node, codec,
                                            prefix, &dai_link->dai_fmt);
        if (ret < 0)
                goto dai_link_of_err;
 
        of_property_read_u32(node, "mclk-fs", &dai_props->mclk_fs);
 
-       ret = asoc_simple_card_parse_cpu(cpu, dai_link,
-                                        DAI, CELL, &single_cpu);
+       ret = asoc_card_parse_dai(cpu, dai_link->cpus, &single_cpu);
        if (ret < 0)
                goto dai_link_of_err;
 
        #if _SINGLE_CODEC
-       ret = asoc_simple_card_parse_codec(codec, dai_link, DAI, CELL);
+       ret = asoc_card_parse_dai(codec, dai_link->codecs, NULL);
        if (ret < 0)
                goto dai_link_of_err;
        #else
@@ -313,7 +370,7 @@ static int seeed_voice_card_dai_link_of(struct device_node *node,
        dev_dbg(dev, "dai_link num_codecs = %d\n", dai_link->num_codecs);
        #endif
 
-       ret = asoc_simple_card_parse_platform(plat, dai_link, DAI, CELL);
+       ret = asoc_card_parse_dai(plat, dai_link->platforms, NULL);
        if (ret < 0)
                goto dai_link_of_err;
 
@@ -321,7 +378,7 @@ static int seeed_voice_card_dai_link_of(struct device_node *node,
                                                &cpu_dai->rx_slot_mask,
                                                &cpu_dai->slots,
                                                &cpu_dai->slot_width);
-       dev_dbg(dev, "cpu_dai : slot,width,tx,rx = %d,%d,%d,%d\n", 
+       dev_dbg(dev, "cpu_dai : slot,width,tx,rx = %d,%d,%d,%d\n",
                        cpu_dai->slots, cpu_dai->slot_width,
                        cpu_dai->tx_slot_mask, cpu_dai->rx_slot_mask
                        );
@@ -336,32 +393,30 @@ static int seeed_voice_card_dai_link_of(struct device_node *node,
                goto dai_link_of_err;
 
        #if LINUX_VERSION_CODE <= KERNEL_VERSION(4,10,0)
-       ret = asoc_simple_card_parse_clk_cpu(cpu, dai_link, cpu_dai);
+       ret = asoc_simple_parse_clk_cpu(cpu, dai_link, cpu_dai);
        #else
-       ret = asoc_simple_card_parse_clk_cpu(dev, cpu, dai_link, cpu_dai);
+       ret = asoc_simple_parse_clk_cpu(dev, cpu, dai_link, cpu_dai);
        #endif
        if (ret < 0)
                goto dai_link_of_err;
 
        #if LINUX_VERSION_CODE <= KERNEL_VERSION(4,10,0)
-       ret = asoc_simple_card_parse_clk_codec(codec, dai_link, codec_dai);
+       ret = asoc_simple_parse_clk_codec(codec, dai_link, codec_dai);
        #else
-       ret = asoc_simple_card_parse_clk_codec(dev, codec, dai_link, codec_dai);
+       ret = asoc_simple_parse_clk_codec(dev, codec, dai_link, codec_dai);
        #endif
        if (ret < 0)
                goto dai_link_of_err;
 
        #if _SINGLE_CODEC
-       ret = asoc_simple_card_canonicalize_dailink(dai_link);
-       if (ret < 0)
-               goto dai_link_of_err;
+       asoc_simple_canonicalize_platform(dai_link);
        #endif
 
-       ret = asoc_simple_card_set_dailink_name(dev, dai_link,
+       ret = asoc_simple_set_dailink_name(dev, dai_link,
                                                "%s-%s",
-                                               dai_link->cpu_dai_name,
+                                               dai_link->cpus->dai_name,
                                                #if _SINGLE_CODEC
-                                               dai_link->codec_dai_name
+                                               dai_link->codecs->dai_name
                                                #else
                                                dai_link->codecs[0].dai_name
                                                #endif
@@ -375,17 +430,17 @@ static int seeed_voice_card_dai_link_of(struct device_node *node,
        dev_dbg(dev, "\tname : %s\n", dai_link->stream_name);
        dev_dbg(dev, "\tformat : %04x\n", dai_link->dai_fmt);
        dev_dbg(dev, "\tcpu : %s / %d\n",
-               dai_link->cpu_dai_name,
+               dai_link->cpus->dai_name,
                dai_props->cpu_dai.sysclk);
        dev_dbg(dev, "\tcodec : %s / %d\n",
                #if _SINGLE_CODEC
-               dai_link->codec_dai_name,
+               dai_link->codecs->dai_name,
                #else
                dai_link->codecs[0].dai_name,
                #endif
                dai_props->codec_dai.sysclk);
 
-       asoc_simple_card_canonicalize_cpu(dai_link, single_cpu);
+       asoc_simple_canonicalize_cpu(dai_link, single_cpu);
 
 dai_link_of_err:
        of_node_put(cpu);
@@ -417,7 +472,7 @@ static int seeed_voice_card_parse_aux_devs(struct device_node *node,
                aux_node = of_parse_phandle(node, PREFIX "aux-devs", i);
                if (!aux_node)
                        return -EINVAL;
-               priv->snd_card.aux_dev[i].codec_of_node = aux_node;
+               priv->snd_card.aux_dev[i].dlc.of_node = aux_node;
        }
 
        priv->snd_card.num_aux_devs = n;
@@ -477,7 +532,7 @@ static int seeed_voice_card_parse_of(struct device_node *node,
                        goto card_parse_end;
        }
 
-       ret = asoc_simple_card_parse_card_name(&priv->snd_card, PREFIX);
+       ret = asoc_simple_parse_card_name(&priv->snd_card, PREFIX);
        if (ret < 0)
                goto card_parse_end;
 
@@ -506,6 +561,7 @@ static int seeed_voice_card_probe(struct platform_device *pdev)
 {
        struct seeed_card_data *priv;
        struct snd_soc_dai_link *dai_link;
+       struct snd_soc_dai_link_component *compnent;
        struct seeed_dai_props *dai_props;
        struct device_node *np = pdev->dev.of_node;
        struct device *dev = &pdev->dev;
@@ -527,6 +583,17 @@ static int seeed_voice_card_probe(struct platform_device *pdev)
        if (!dai_props || !dai_link)
                return -ENOMEM;
 
+       compnent = devm_kzalloc(dev, 3 * sizeof(*compnent), GFP_KERNEL);
+       if (!compnent)
+               return -ENOMEM;
+
+       dai_link->cpus            = &compnent[0];
+       dai_link->num_cpus        = 1;
+       dai_link->codecs          = &compnent[1];
+       dai_link->num_codecs      = 1;
+       dai_link->platforms       = &compnent[2];
+       dai_link->num_platforms   = 1;
+
        priv->dai_props                 = dai_props;
        priv->dai_link                  = dai_link;
 
@@ -564,10 +631,10 @@ static int seeed_voice_card_probe(struct platform_device *pdev)
                priv->snd_card.name     = (cinfo->card) ? cinfo->card : cinfo->name;
                dai_link->name          = cinfo->name;
                dai_link->stream_name   = cinfo->name;
-               dai_link->platform_name = cinfo->platform;
-               dai_link->codec_name    = cinfo->codec;
-               dai_link->cpu_dai_name  = cinfo->cpu_dai.name;
-               dai_link->codec_dai_name = cinfo->codec_dai.name;
+               dai_link->platforms->name = cinfo->platform;
+               dai_link->codecs->dai_name = cinfo->codec;
+               dai_link->cpus->dai_name = cinfo->cpu_dai.name;
+               dai_link->codecs->dai_name = cinfo->codec_dai.name;
                dai_link->dai_fmt       = cinfo->daifmt;
                dai_link->init          = seeed_voice_card_dai_init;
                memcpy(&priv->dai_props->cpu_dai, &cinfo->cpu_dai,
@@ -589,7 +656,7 @@ static int seeed_voice_card_probe(struct platform_device *pdev)
                return ret;
 
 err:
-       asoc_simple_card_clean_reference(&priv->snd_card);
+       asoc_simple_clean_reference(&priv->snd_card);
 
        return ret;
 }
@@ -601,7 +668,7 @@ static int seeed_voice_card_remove(struct platform_device *pdev)
 
        if (cancel_work_sync(&priv->work_codec_clk) != 0) {
        }
-       return asoc_simple_card_clean_reference(card);
+       return asoc_simple_clean_reference(card);
 }
 
 static const struct of_device_id seeed_voice_of_match[] = {