Merge tag 'lsk-android-14.05' into develop-3.10
[firefly-linux-kernel-4.4.55.git] / sound / soc / rockchip / rk_es8323.c
index b78eedf8defd97504c5a469332b5ef8c35e97b4a..1cbb4448bec35eaeb92d3fad3ede15b7fbc07896 100755 (executable)
 #include <sound/soc-dapm.h>
 
 #include "../codecs/es8323.h"
+#include "card_info.h"
 #include "rk_pcm.h"
-#include "rk29_i2s.h"
+#include "rk_i2s.h"
 
 #ifdef CONFIG_MACH_RK_FAC
 #include <plat/config.h>
 extern int codec_type;
 #endif
 
-#if 1
+#if 0
 #define        DBG(x...)       printk(KERN_INFO x)
 #else
 #define        DBG(x...)
@@ -43,43 +44,25 @@ static int rk29_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
        struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-        unsigned int pll_out = 0
+        unsigned int pll_out = 0, dai_fmt = rtd->card->dai_link->dai_fmt;
         int ret;
 
         DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);    
-        /*by Vincent Hsiung for EQ Vol Change*/
-        #define HW_PARAMS_FLAG_EQVOL_ON 0x21
-        #define HW_PARAMS_FLAG_EQVOL_OFF 0x22
-        if ((params->flags == HW_PARAMS_FLAG_EQVOL_ON)||(params->flags == HW_PARAMS_FLAG_EQVOL_OFF))
-        {
-               ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai); //by Vincent
-       DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
-    }
-    else
-    {
-           /* set codec DAI configuration */
-           #if defined (CONFIG_SND_RK_CODEC_SOC_SLAVE) 
-                ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
-               SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); 
-           #endif      
-           #if defined (CONFIG_SND_RK_CODEC_SOC_MASTER) 
-                ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
-               SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM ); 
-           #endif
-           if (ret < 0)
-                 return ret; 
-           /* set cpu DAI configuration */
-           #if defined (CONFIG_SND_RK_CODEC_SOC_SLAVE) 
-                ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
-               SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
-           #endif      
-           #if defined (CONFIG_SND_RK_CODEC_SOC_MASTER) 
-                ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
-               SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); 
-           #endif              
-           if (ret < 0)
-                 return ret;
-         }
+
+       /* set codec DAI configuration */
+       ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
+       if (ret < 0) {
+               printk("%s():failed to set the format for codec side\n", __FUNCTION__);
+               return ret;
+       }
+
+       /* set cpu DAI configuration */
+       ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
+       if (ret < 0) {
+               printk("%s():failed to set the format for cpu side\n", __FUNCTION__);
+               return ret;
+       }
+
         switch(params_rate(params)) {
         case 8000:
         case 16000:
@@ -100,11 +83,11 @@ static int rk29_hw_params(struct snd_pcm_substream *substream,
         }
         DBG("Enter:%s, %d, rate=%d\n",__FUNCTION__,__LINE__,params_rate(params));
        
-        #if defined (CONFIG_SND_RK_CODEC_SOC_SLAVE)
-        snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
-        snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_BCLK, (pll_out/4)/params_rate(params)-1);
-        snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 3);
-        #endif
+       if ((dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBS_CFS) {
+               snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
+               snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_BCLK, (pll_out/4)/params_rate(params)-1);
+               snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 3);
+       }
 
         DBG("Enter:%s, %d, LRCK=%d\n",__FUNCTION__,__LINE__,(pll_out/4)/params_rate(params));
          return 0;
@@ -147,6 +130,7 @@ static int rk29_es8323_init(struct snd_soc_pcm_runtime *rtd)
        }
        
     /* Add specific widgets */
+#if 0
        snd_soc_dapm_new_controls(dapm, rk29_dapm_widgets,
                                  ARRAY_SIZE(rk29_dapm_widgets));
        //snd_soc_dapm_nc_pin(codec, "LOUT2");
@@ -156,7 +140,7 @@ static int rk29_es8323_init(struct snd_soc_pcm_runtime *rtd)
         snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
        
         snd_soc_dapm_sync(dapm);
+#endif
     return 0;
 }
 
@@ -167,15 +151,6 @@ static struct snd_soc_ops rk29_ops = {
 static struct snd_soc_dai_link rk29_dai = {
        .name = "ES8323",
        .stream_name = "ES8323 PCM",
-       .codec_name = "ES8323.0-0010",  // ES8323.0-0010
-       .platform_name = "rockchip-pcm",
-#if defined(CONFIG_SND_RK_SOC_I2S_8CH) 
-       .cpu_dai_name = "rockchip-i2s.0",
-#elif defined(CONFIG_SND_RK_SOC_I2S_2CH)
-       .cpu_dai_name = "rockchip-i2s.1",  //Ó²¼þÉÏÊǽӵ½IIS0ÉÏ£¬µ«ÊÇÓÉÓÚxxÔ­Òò£¬Õâ±ß¶¨ÒåΪIIS1ÉÏ
-#else
-       .cpu_dai_name = "rockchip-i2s.2",
-#endif
        .codec_dai_name = "ES8323 HiFi",
        .init = rk29_es8323_init,
        .ops = &rk29_ops,
@@ -194,8 +169,13 @@ static int rockchip_es8323_audio_probe(struct platform_device *pdev)
 
        card->dev = &pdev->dev;
 
-       ret = snd_soc_register_card(card);
+       ret = rockchip_of_get_sound_card_info(card);
+       if (ret) {
+               printk("%s() get sound card info failed:%d\n", __FUNCTION__, ret);
+               return ret;
+       }
 
+       ret = snd_soc_register_card(card);
        if (ret)
                printk("%s() register card failed:%d\n", __FUNCTION__, ret);
 
@@ -213,20 +193,21 @@ static int rockchip_es8323_audio_remove(struct platform_device *pdev)
 
 #ifdef CONFIG_OF
 static const struct of_device_id rockchip_es8323_of_match[] = {
-        { .compatible = "rockchip-es8323", },
-        {},
+       { .compatible = "rockchip-es8323", },
+       {},
 };
 MODULE_DEVICE_TABLE(of, rockchip_es8323_of_match);
 #endif /* CONFIG_OF */
 
 static struct platform_driver rockchip_es8323_audio_driver = {
-        .driver         = {
-                .name   = "rockchip-es8323",
-                .owner  = THIS_MODULE,
-                .of_match_table = of_match_ptr(rockchip_es8323_of_match),
-        },
-        .probe          = rockchip_es8323_audio_probe,
-        .remove         = rockchip_es8323_audio_remove,
+       .driver         = {
+               .name   = "rockchip-es8323",
+               .owner  = THIS_MODULE,
+               .pm = &snd_soc_pm_ops,
+               .of_match_table = of_match_ptr(rockchip_es8323_of_match),
+       },
+       .probe          = rockchip_es8323_audio_probe,
+       .remove         = rockchip_es8323_audio_remove,
 };
 
 module_platform_driver(rockchip_es8323_audio_driver);