rt5631: add i2s clk support up to 192khz samplerate
[firefly-linux-kernel-4.4.55.git] / sound / soc / rk29 / rk29_rt5631.c
old mode 100644 (file)
new mode 100755 (executable)
index 0b93043..89462da
@@ -19,7 +19,6 @@
 #include <sound/soc-dapm.h>
 #include <asm/io.h>
 #include <mach/hardware.h>
-#include <mach/rk29_iomap.h>
 #include "../codecs/rt5631.h"
 #include "rk29_pcm.h"
 #include "rk29_i2s.h"
 static int rk29_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
-        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-        struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
-        struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
+       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 lrclk = 0;
         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->ops->hw_params(substream, params, codec_dai); //by Vincent
+               ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai); //by Vincent
                DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
         }
         else
@@ -85,11 +83,15 @@ static int rk29_hw_params(struct snd_pcm_substream *substream,
         case 24000:
         case 32000:
         case 48000:
+        case 96000:
+        case 192000:
                 pll_out = 12288000;
                 break;
         case 11025:
         case 22050:
         case 44100:
+        case 88100:
+        case 176400:
                 pll_out = 11289600;
                 break;
         default:
@@ -97,9 +99,24 @@ static int rk29_hw_params(struct snd_pcm_substream *substream,
                 return -EINVAL;
                 break;
         }
-        DBG("Enter:%s, %d, rate=%d\n",__FUNCTION__,__LINE__,params_rate(params));
-
-               #if defined (CONFIG_SND_RK29_CODEC_SOC_SLAVE)
+        DBG("Enter:%s, %d, LRCK=%d rate=%d\n",__FUNCTION__,__LINE__,(pll_out/4)/params_rate(params),params_rate(params));
+#if defined (CONFIG_SND_RK29_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);
+       switch(params_rate(params)) {
+               case 96000:
+        case 88100:            
+                       snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 1);  
+                       break;
+        case 176400:           
+               case 192000:
+                       snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 0);  
+                       break;
+               default:
+                       snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 3);  
+                       break;
+       }       
+               
 #if 0          //use pll from blck
           /*Set the pll of rt5631,the Pll source from BITCLK on CPU is master mode*/
          //bitclk is 64fs           
@@ -110,33 +127,20 @@ static int rk29_hw_params(struct snd_pcm_substream *substream,
                           return ret;
                    }
 #endif     
-                  /*Set the system clk for codec*/
-                   ret=snd_soc_dai_set_sysclk(codec_dai, 0,pll_out,SND_SOC_CLOCK_IN);
-                   if (ret < 0)
-                   {
-                      DBG("rk29_hw_params_rt5631:failed to set the sysclk for codec side\n"); 
-                          return ret;
-                       }           
-               #endif
-  
-
-        #if defined (CONFIG_SND_RK29_CODEC_SOC_MASTER) 
-               
-                       //      snd_soc_dai_set_pll(codec_dai,0,pll_out, 22579200);
-                               snd_soc_dai_set_sysclk(codec_dai,0,pll_out, SND_SOC_CLOCK_IN);                                          
-      
-        #endif
-
-
-        #if defined (CONFIG_SND_RK29_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
+       /*Set the system clk for codec*/
+       ret=snd_soc_dai_set_sysclk(codec_dai, 0,pll_out,SND_SOC_CLOCK_IN);
+       if (ret < 0)
+       {
+               DBG("rk29_hw_params_rt5631:failed to set the sysclk for codec side\n"); 
+               return ret;
+       }           
+#endif
 
-        DBG("Enter:%s, %d, LRCK=%d\n",__FUNCTION__,__LINE__,(pll_out/4)/params_rate(params));
-        
-        return 0;
+#if defined (CONFIG_SND_RK29_CODEC_SOC_MASTER) 
+       //snd_soc_dai_set_pll(codec_dai,0,pll_out, 22579200);
+       snd_soc_dai_set_sysclk(codec_dai,0,pll_out, SND_SOC_CLOCK_IN);                                                
+#endif       
+       return 0;
 }
 
 static const struct snd_soc_dapm_widget rt5631_dapm_widgets[] = {
@@ -164,28 +168,28 @@ static const struct snd_soc_dapm_route audio_map[]={
 /*
  * Logic for a rt5631 as connected on a rockchip board.
  */
-static int rk29_rt5631_init(struct snd_soc_codec *codec)
+static int rk29_rt5631_init(struct snd_soc_pcm_runtime *rtd)
 {
-       struct snd_soc_dai *codec_dai = &codec->dai[0];
-       int ret;
-         
+       struct snd_soc_codec *codec = rtd->codec;
+       struct snd_soc_dapm_context *dapm = &codec->dapm;
+
         DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
 
         /* Add specific widgets */
-       snd_soc_dapm_new_controls(codec, rt5631_dapm_widgets,
+       snd_soc_dapm_new_controls(dapm, rt5631_dapm_widgets,
                                  ARRAY_SIZE(rt5631_dapm_widgets));
        DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
         /* Set up specific audio path audio_mapnects */
-        snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
+        snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
         DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
-//        snd_soc_dapm_nc_pin(codec, "HP_L");
+        snd_soc_dapm_nc_pin(dapm, "HP_L");
         DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
-//     snd_soc_dapm_nc_pin(codec, "HP_R");
+       snd_soc_dapm_nc_pin(dapm, "HP_R");
        DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
-        snd_soc_dapm_sync(codec);
+        snd_soc_dapm_sync(dapm);
         DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
 
-        return 0;
+       return 0;
 }
 
 static struct snd_soc_ops rk29_ops = {
@@ -193,44 +197,45 @@ static struct snd_soc_ops rk29_ops = {
 };
 
 static struct snd_soc_dai_link rk29_dai = {
-         .name = "RT5631",
-         .stream_name = "RT5631 PCM",
-         .cpu_dai = &rk29_i2s_dai[0],
-         .codec_dai = &rt5631_dai,
-         .init = rk29_rt5631_init,
-         .ops = &rk29_ops,
+       .name = "RT5631",
+       .stream_name = "RT5631 PCM",
+       .codec_name = "RT5631.0-001a",
+       .platform_name = "rockchip-audio",
+#if defined(CONFIG_SND_RK29_SOC_I2S_8CH)       
+       .cpu_dai_name = "rk29_i2s.0",
+#elif defined(CONFIG_SND_RK29_SOC_I2S_2CH)
+       .cpu_dai_name = "rk29_i2s.1",
+#else
+       .cpu_dai_name = "rk29_i2s.2",
+#endif
+       .codec_dai_name = "RT5631 HiFi",
+       .init = rk29_rt5631_init,
+       .ops = &rk29_ops,
 };
 
 static struct snd_soc_card snd_soc_card_rk29 = {
-         .name = "RK29_RT5631",
-         .platform = &rk29_soc_platform,
-         .dai_link = &rk29_dai,
-         .num_links = 1,
-};
-
-
-static struct snd_soc_device rk29_snd_devdata = {
-         .card = &snd_soc_card_rk29,
-         .codec_dev = &soc_codec_dev_rt5631,
+       .name = "RK29_RT5631",
+       .dai_link = &rk29_dai,
+       .num_links = 1,
 };
 
 static struct platform_device *rk29_snd_device;
 
 static int __init audio_card_init(void)
 {
-       int ret =0;     
+       int ret =0;
+
         DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
        rk29_snd_device = platform_device_alloc("soc-audio", -1);
        if (!rk29_snd_device) {
-                 DBG("platform device allocation failed\n");
+                 printk("platform device allocation failed\n");
                  ret = -ENOMEM;
                  return ret;
        }
-       platform_set_drvdata(rk29_snd_device, &rk29_snd_devdata);
-       rk29_snd_devdata.dev = &rk29_snd_device->dev;
+       platform_set_drvdata(rk29_snd_device, &snd_soc_card_rk29);
        ret = platform_device_add(rk29_snd_device);
        if (ret) {
-               DBG("platform device add failed\n");
+               printk("platform device add failed\n");
                platform_device_put(rk29_snd_device);
        }
        return ret;