ASoC: simple-card: add asoc_simple_dai for initializing
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Fri, 11 Jan 2013 00:49:11 +0000 (16:49 -0800)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Sun, 13 Jan 2013 21:55:43 +0000 (06:55 +0900)
Current simple-card driver calls asoc_simple_card_dai_init()
if platform had a asoc_simple_card_dai_init pointer.
And, this initialization function works only
when platform has an applicable initial value for each dai settings.
And basically, almost all sound card requires certain initialization.
This means that almost all platform has initialization settings,
and driver do nothing if it doesn't have settings.

And additionally, current simple-card supports sysclk settings but it was
only for codec.  In order to abolish deviation between cpu and codec,
and in order to simplify processing,
this patch adds asoc_simple_dai, and removed pointless
struct asoc_simple_dai_init_info which was trigger of
calling asoc_simple_card_dai_init().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
arch/arm/mach-shmobile/board-ap4evb.c
arch/arm/mach-shmobile/board-armadillo800eva.c
arch/arm/mach-shmobile/board-kzm9g.c
arch/arm/mach-shmobile/board-mackerel.c
arch/sh/boards/mach-ecovec24/setup.c
arch/sh/boards/mach-se/7724/setup.c
include/sound/simple_card.h
sound/soc/generic/simple-card.c

index 4c979039d97ec0b465fec6074c923e39f03b9321..08294fa9e0d47a84b4f478298dba40b865dcf5ba 100644 (file)
@@ -686,21 +686,21 @@ static struct platform_device fsi_device = {
        },
 };
 
-static struct asoc_simple_dai_init_info fsi2_ak4643_init_info = {
-       .fmt            = SND_SOC_DAIFMT_LEFT_J,
-       .codec_daifmt   = SND_SOC_DAIFMT_CBM_CFM,
-       .cpu_daifmt     = SND_SOC_DAIFMT_CBS_CFS,
-       .sysclk         = 11289600,
-};
-
 static struct asoc_simple_card_info fsi2_ak4643_info = {
        .name           = "AK4643",
        .card           = "FSI2A-AK4643",
-       .cpu_dai        = "fsia-dai",
        .codec          = "ak4642-codec.0-0013",
        .platform       = "sh_fsi2",
-       .codec_dai      = "ak4642-hifi",
-       .init           = &fsi2_ak4643_init_info,
+       .daifmt         = SND_SOC_DAIFMT_LEFT_J,
+       .cpu_dai = {
+               .name   = "fsia-dai",
+               .fmt    = SND_SOC_DAIFMT_CBS_CFS,
+       },
+       .codec_dai = {
+               .name   = "ak4642-hifi",
+               .fmt    = SND_SOC_DAIFMT_CBM_CFM,
+               .sysclk = 11289600,
+       },
 };
 
 static struct platform_device fsi_ak4643_device = {
@@ -809,19 +809,18 @@ static struct platform_device lcdc1_device = {
        },
 };
 
-static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
-       .cpu_daifmt     = SND_SOC_DAIFMT_CBM_CFM |
-                         SND_SOC_DAIFMT_IB_NF,
-};
-
 static struct asoc_simple_card_info fsi2_hdmi_info = {
        .name           = "HDMI",
        .card           = "FSI2B-HDMI",
-       .cpu_dai        = "fsib-dai",
        .codec          = "sh-mobile-hdmi",
        .platform       = "sh_fsi2",
-       .codec_dai      = "sh_mobile_hdmi-hifi",
-       .init           = &fsi2_hdmi_init_info,
+       .cpu_dai = {
+               .name   = "fsib-dai",
+               .fmt    = SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF,
+       },
+       .codec_dai = {
+               .name   = "sh_mobile_hdmi-hifi",
+       },
 };
 
 static struct platform_device fsi_hdmi_device = {
index 5353adf6b828a55446933e070968c9b4bec20a94..0679ca6bf1f67bfaf64c0d1d118a6c908b044655 100644 (file)
@@ -806,21 +806,21 @@ static struct platform_device fsi_device = {
 };
 
 /* FSI-WM8978 */
-static struct asoc_simple_dai_init_info fsi_wm8978_init_info = {
-       .fmt            = SND_SOC_DAIFMT_I2S,
-       .codec_daifmt   = SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_NB_NF,
-       .cpu_daifmt     = SND_SOC_DAIFMT_CBS_CFS,
-       .sysclk         = 12288000,
-};
-
 static struct asoc_simple_card_info fsi_wm8978_info = {
        .name           = "wm8978",
        .card           = "FSI2A-WM8978",
-       .cpu_dai        = "fsia-dai",
        .codec          = "wm8978.0-001a",
        .platform       = "sh_fsi2",
-       .codec_dai      = "wm8978-hifi",
-       .init           = &fsi_wm8978_init_info,
+       .daifmt         = SND_SOC_DAIFMT_I2S,
+       .cpu_dai = {
+               .name   = "fsia-dai",
+               .fmt    = SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_IB_NF,
+       },
+       .codec_dai = {
+               .name   = "wm8978-hifi",
+               .fmt    = SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_NB_NF,
+               .sysclk = 12288000,
+       },
 };
 
 static struct platform_device fsi_wm8978_device = {
@@ -832,18 +832,18 @@ static struct platform_device fsi_wm8978_device = {
 };
 
 /* FSI-HDMI */
-static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
-       .cpu_daifmt     = SND_SOC_DAIFMT_CBM_CFM,
-};
-
 static struct asoc_simple_card_info fsi2_hdmi_info = {
        .name           = "HDMI",
        .card           = "FSI2B-HDMI",
-       .cpu_dai        = "fsib-dai",
        .codec          = "sh-mobile-hdmi",
        .platform       = "sh_fsi2",
-       .codec_dai      = "sh_mobile_hdmi-hifi",
-       .init           = &fsi2_hdmi_init_info,
+       .cpu_dai = {
+               .name   = "fsib-dai",
+               .fmt    = SND_SOC_DAIFMT_CBM_CFM,
+       },
+       .codec_dai = {
+               .name = "sh_mobile_hdmi-hifi",
+       },
 };
 
 static struct platform_device fsi_hdmi_device = {
index c02448d6847f40aba1d2906e9957e376aecd0df4..f41b71e8df3eb331eedd4816ea876cd3b10313c5 100644 (file)
@@ -525,21 +525,21 @@ static struct platform_device fsi_device = {
        },
 };
 
-static struct asoc_simple_dai_init_info fsi2_ak4648_init_info = {
-       .fmt            = SND_SOC_DAIFMT_LEFT_J,
-       .codec_daifmt   = SND_SOC_DAIFMT_CBM_CFM,
-       .cpu_daifmt     = SND_SOC_DAIFMT_CBS_CFS,
-       .sysclk         = 11289600,
-};
-
 static struct asoc_simple_card_info fsi2_ak4648_info = {
        .name           = "AK4648",
        .card           = "FSI2A-AK4648",
-       .cpu_dai        = "fsia-dai",
        .codec          = "ak4642-codec.0-0012",
        .platform       = "sh_fsi2",
-       .codec_dai      = "ak4642-hifi",
-       .init           = &fsi2_ak4648_init_info,
+       .daifmt         = SND_SOC_DAIFMT_LEFT_J,
+       .cpu_dai = {
+               .name   = "fsia-dai",
+               .fmt    = SND_SOC_DAIFMT_CBS_CFS,
+       },
+       .codec_dai = {
+               .name   = "ak4642-hifi",
+               .fmt    = SND_SOC_DAIFMT_CBM_CFM,
+               .sysclk = 11289600,
+       },
 };
 
 static struct platform_device fsi_ak4648_device = {
index b5d210b4264c00e8c71ae417602cf7ada05c59b7..3fd716dae40544d33f11fe1f45556304446fe165 100644 (file)
@@ -502,19 +502,18 @@ static struct platform_device hdmi_lcdc_device = {
        },
 };
 
-static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
-       .cpu_daifmt     = SND_SOC_DAIFMT_CBM_CFM |
-                         SND_SOC_DAIFMT_IB_NF,
-};
-
 static struct asoc_simple_card_info fsi2_hdmi_info = {
        .name           = "HDMI",
        .card           = "FSI2B-HDMI",
-       .cpu_dai        = "fsib-dai",
        .codec          = "sh-mobile-hdmi",
        .platform       = "sh_fsi2",
-       .codec_dai      = "sh_mobile_hdmi-hifi",
-       .init           = &fsi2_hdmi_init_info,
+       .cpu_dai = {
+               .name   = "fsib-dai",
+               .fmt    = SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF,
+       },
+       .codec_dai = {
+               .name   = "sh_mobile_hdmi-hifi",
+       },
 };
 
 static struct platform_device fsi_hdmi_device = {
@@ -893,21 +892,21 @@ static struct platform_device fsi_device = {
        },
 };
 
-static struct asoc_simple_dai_init_info fsi2_ak4643_init_info = {
-       .fmt            = SND_SOC_DAIFMT_LEFT_J,
-       .codec_daifmt   = SND_SOC_DAIFMT_CBM_CFM,
-       .cpu_daifmt     = SND_SOC_DAIFMT_CBS_CFS,
-       .sysclk         = 11289600,
-};
-
 static struct asoc_simple_card_info fsi2_ak4643_info = {
        .name           = "AK4643",
        .card           = "FSI2A-AK4643",
-       .cpu_dai        = "fsia-dai",
        .codec          = "ak4642-codec.0-0013",
        .platform       = "sh_fsi2",
-       .codec_dai      = "ak4642-hifi",
-       .init           = &fsi2_ak4643_init_info,
+       .daifmt         = SND_SOC_DAIFMT_LEFT_J,
+       .cpu_dai = {
+               .name   = "fsia-dai",
+               .fmt    = SND_SOC_DAIFMT_CBS_CFS,
+       },
+       .codec_dai = {
+               .name   = "ak4642-hifi",
+               .fmt    = SND_SOC_DAIFMT_CBM_CFM,
+               .sysclk = 11289600,
+       },
 };
 
 static struct platform_device fsi_ak4643_device = {
index 8ebe4c7a766b13395ece224310bb503385f78582..065e9600fae68ea14c6a1e895cc9a9d447cb7e79 100644 (file)
@@ -897,21 +897,20 @@ static struct platform_device fsi_device = {
        .resource       = fsi_resources,
 };
 
-static struct asoc_simple_dai_init_info fsi_da7210_init_info = {
-       .fmt            = SND_SOC_DAIFMT_I2S,
-       .codec_daifmt   = SND_SOC_DAIFMT_CBM_CFM,
-       .cpu_daifmt     = SND_SOC_DAIFMT_CBS_CFS |
-                         SND_SOC_DAIFMT_IB_NF,
-};
-
 static struct asoc_simple_card_info fsi_da7210_info = {
        .name           = "DA7210",
        .card           = "FSIB-DA7210",
-       .cpu_dai        = "fsib-dai",
        .codec          = "da7210.0-001a",
        .platform       = "sh_fsi.0",
-       .codec_dai      = "da7210-hifi",
-       .init           = &fsi_da7210_init_info,
+       .daifmt         = SND_SOC_DAIFMT_I2S,
+       .cpu_dai = {
+               .name   = "fsib-dai",
+               .fmt    = SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_IB_NF,
+       },
+       .codec_dai = {
+               .name   = "da7210-hifi",
+               .fmt    = SND_SOC_DAIFMT_CBM_CFM,
+       },
 };
 
 static struct platform_device fsi_da7210_device = {
index 975608f5e8054d21b65dad51c2663500416b7210..4010e63e82d8491422457d32459a8d216455d4ef 100644 (file)
@@ -299,22 +299,21 @@ static struct platform_device fsi_device = {
        .resource       = fsi_resources,
 };
 
-static struct asoc_simple_dai_init_info fsi2_ak4642_init_info = {
-       .fmt            = SND_SOC_DAIFMT_LEFT_J,
-       .codec_daifmt   = SND_SOC_DAIFMT_CBM_CFM,
-       .cpu_daifmt     = SND_SOC_DAIFMT_CBS_CFS |
-                         SND_SOC_DAIFMT_IB_NF,
-       .sysclk         = 11289600,
-};
-
 static struct asoc_simple_card_info fsi_ak4642_info = {
        .name           = "AK4642",
        .card           = "FSIA-AK4642",
-       .cpu_dai        = "fsia-dai",
        .codec          = "ak4642-codec.0-0012",
        .platform       = "sh_fsi.0",
-       .codec_dai      = "ak4642-hifi",
-       .init           = &fsi2_ak4642_init_info,
+       .daifmt         = SND_SOC_DAIFMT_LEFT_J,
+       .cpu_dai = {
+               .name   = "fsia-dai",
+               .fmt    = SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_IB_NF,
+       },
+       .codec_dai = {
+               .name   = "ak4642-hifi",
+               .fmt    = SND_SOC_DAIFMT_CBM_CFM,
+               .sysclk = 11289600,
+       },
 };
 
 static struct platform_device fsi_ak4642_device = {
index 4b62b8dc6a4fd2baddef3e1c7f60b24c9ed2a1ae..6c74527d4926b3e476428fb6327652d9ca22dfbb 100644 (file)
 
 #include <sound/soc.h>
 
-struct asoc_simple_dai_init_info {
+struct asoc_simple_dai {
+       const char *name;
        unsigned int fmt;
-       unsigned int cpu_daifmt;
-       unsigned int codec_daifmt;
        unsigned int sysclk;
 };
 
 struct asoc_simple_card_info {
        const char *name;
        const char *card;
-       const char *cpu_dai;
        const char *codec;
        const char *platform;
-       const char *codec_dai;
-       struct asoc_simple_dai_init_info *init; /* for snd_link.init */
+
+       unsigned int daifmt;
+       struct asoc_simple_dai cpu_dai;
+       struct asoc_simple_dai codec_dai;
 
        /* used in simple-card.c */
        struct snd_soc_dai_link snd_link;
index bc050ec8680a36974f01f500030a91490f46988f..6cf8355a8542656c89dda5f1564c721d3f2cb4aa 100644 (file)
 #define asoc_simple_get_card_info(p) \
        container_of(p->dai_link, struct asoc_simple_card_info, snd_link)
 
+static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
+                                      struct asoc_simple_dai *set,
+                                      unsigned int daifmt)
+{
+       int ret = 0;
+
+       daifmt |= set->fmt;
+
+       if (!ret && daifmt)
+               ret = snd_soc_dai_set_fmt(dai, daifmt);
+
+       if (!ret && set->sysclk)
+               ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0);
+
+       return ret;
+}
+
 static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
 {
-       struct asoc_simple_card_info *cinfo = asoc_simple_get_card_info(rtd);
-       struct asoc_simple_dai_init_info *iinfo = cinfo->init;
+       struct asoc_simple_card_info *info = asoc_simple_get_card_info(rtd);
        struct snd_soc_dai *codec = rtd->codec_dai;
        struct snd_soc_dai *cpu = rtd->cpu_dai;
-       unsigned int cpu_daifmt = iinfo->fmt | iinfo->cpu_daifmt;
-       unsigned int codec_daifmt = iinfo->fmt | iinfo->codec_daifmt;
+       unsigned int daifmt = info->daifmt;
        int ret;
 
-       if (codec_daifmt) {
-               ret = snd_soc_dai_set_fmt(codec, codec_daifmt);
-               if (ret < 0)
-                       return ret;
-       }
-
-       if (iinfo->sysclk) {
-               ret = snd_soc_dai_set_sysclk(codec, 0, iinfo->sysclk, 0);
-               if (ret < 0)
-                       return ret;
-       }
+       ret = __asoc_simple_card_dai_init(codec, &info->codec_dai, daifmt);
+       if (ret < 0)
+               return ret;
 
-       if (cpu_daifmt) {
-               ret = snd_soc_dai_set_fmt(cpu, cpu_daifmt);
-               if (ret < 0)
-                       return ret;
-       }
+       ret = __asoc_simple_card_dai_init(cpu, &info->cpu_dai, daifmt);
+       if (ret < 0)
+               return ret;
 
        return 0;
 }
@@ -59,10 +64,10 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 
        if (!cinfo->name        ||
            !cinfo->card        ||
-           !cinfo->cpu_dai     ||
            !cinfo->codec       ||
            !cinfo->platform    ||
-           !cinfo->codec_dai) {
+           !cinfo->cpu_dai.name ||
+           !cinfo->codec_dai.name) {
                dev_err(dev, "insufficient asoc_simple_card_info settings\n");
                return -EINVAL;
        }
@@ -72,14 +77,11 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
         */
        cinfo->snd_link.name            = cinfo->name;
        cinfo->snd_link.stream_name     = cinfo->name;
-       cinfo->snd_link.cpu_dai_name    = cinfo->cpu_dai;
+       cinfo->snd_link.cpu_dai_name    = cinfo->cpu_dai.name;
        cinfo->snd_link.platform_name   = cinfo->platform;
        cinfo->snd_link.codec_name      = cinfo->codec;
-       cinfo->snd_link.codec_dai_name  = cinfo->codec_dai;
-
-       /* enable snd_link.init if cinfo has settings */
-       if (cinfo->init)
-               cinfo->snd_link.init    = asoc_simple_card_dai_init;
+       cinfo->snd_link.codec_dai_name  = cinfo->codec_dai.name;
+       cinfo->snd_link.init            = asoc_simple_card_dai_init;
 
        /*
         * init snd_soc_card