ASoC: Fix resource reclaim for osk5912
[linux-2.6.git] / sound / soc / omap / osk5912.c
index cd41a94..65ae00e 100644 (file)
@@ -31,7 +31,7 @@
 #include <asm/mach-types.h>
 #include <mach/hardware.h>
 #include <linux/gpio.h>
-#include <mach/mcbsp.h>
+#include <plat/mcbsp.h>
 
 #include "omap-mcbsp.h"
 #include "omap-pcm.h"
@@ -55,14 +55,14 @@ static int osk_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_dai *codec_dai = rtd->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
        int err;
 
        /* Set codec DAI configuration */
        err = snd_soc_dai_set_fmt(codec_dai,
                                  SND_SOC_DAIFMT_DSP_B |
-                                 SND_SOC_DAIFMT_NB_IF |
+                                 SND_SOC_DAIFMT_NB_NF |
                                  SND_SOC_DAIFMT_CBM_CFM);
        if (err < 0) {
                printk(KERN_ERR "can't set codec DAI configuration\n");
@@ -72,7 +72,7 @@ static int osk_hw_params(struct snd_pcm_substream *substream,
        /* Set cpu DAI configuration */
        err = snd_soc_dai_set_fmt(cpu_dai,
                                  SND_SOC_DAIFMT_DSP_B |
-                                 SND_SOC_DAIFMT_NB_IF |
+                                 SND_SOC_DAIFMT_NB_NF |
                                  SND_SOC_DAIFMT_CBM_CFM);
        if (err < 0) {
                printk(KERN_ERR "can't set cpu DAI configuration\n");
@@ -113,8 +113,9 @@ static const struct snd_soc_dapm_route audio_map[] = {
        {"MICIN", NULL, "Mic Jack"},
 };
 
-static int osk_tlv320aic23_init(struct snd_soc_codec *codec)
+static int osk_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
 {
+       struct snd_soc_codec *codec = rtd->codec;
 
        /* Add osk5912 specific widgets */
        snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets,
@@ -136,8 +137,10 @@ static int osk_tlv320aic23_init(struct snd_soc_codec *codec)
 static struct snd_soc_dai_link osk_dai = {
        .name = "TLV320AIC23",
        .stream_name = "AIC23",
-       .cpu_dai = &omap_mcbsp_dai[0],
-       .codec_dai = &tlv320aic23_dai,
+       .cpu_dai_name = "omap-mcbsp-dai.0",
+       .codec_dai_name = "tlv320aic23-hifi",
+       .platform_name = "omap-pcm-audio",
+       .codec_name = "tlv320aic23-codec",
        .init = osk_tlv320aic23_init,
        .ops = &osk_ops,
 };
@@ -145,17 +148,10 @@ static struct snd_soc_dai_link osk_dai = {
 /* Audio machine driver */
 static struct snd_soc_card snd_soc_card_osk = {
        .name = "OSK5912",
-       .platform = &omap_soc_platform,
        .dai_link = &osk_dai,
        .num_links = 1,
 };
 
-/* Audio subsystem */
-static struct snd_soc_device osk_snd_devdata = {
-       .card = &snd_soc_card_osk,
-       .codec_dev = &soc_codec_dev_tlv320aic23,
-};
-
 static struct platform_device *osk_snd_device;
 
 static int __init osk_soc_init(void)
@@ -171,9 +167,7 @@ static int __init osk_soc_init(void)
        if (!osk_snd_device)
                return -ENOMEM;
 
-       platform_set_drvdata(osk_snd_device, &osk_snd_devdata);
-       osk_snd_devdata.dev = &osk_snd_device->dev;
-       *(unsigned int *)osk_dai.cpu_dai->private_data = 0;     /* McBSP1 */
+       platform_set_drvdata(osk_snd_device, &snd_soc_card_osk);
        err = platform_device_add(osk_snd_device);
        if (err)
                goto err1;
@@ -183,14 +177,8 @@ static int __init osk_soc_init(void)
        tlv320aic23_mclk = clk_get(dev, "mclk");
        if (IS_ERR(tlv320aic23_mclk)) {
                printk(KERN_ERR "Could not get mclk clock\n");
-               return -ENODEV;
-       }
-
-       if (clk_get_usecount(tlv320aic23_mclk) > 0) {
-               /* MCLK is already in use */
-               printk(KERN_WARNING
-                      "MCLK in use at %d Hz. We change it to %d Hz\n",
-                      (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK);
+               err = PTR_ERR(tlv320aic23_mclk);
+               goto err2;
        }
 
        /*
@@ -201,18 +189,20 @@ static int __init osk_soc_init(void)
                if (clk_set_rate(tlv320aic23_mclk, CODEC_CLOCK)) {
                        printk(KERN_ERR "Cannot set MCLK for AIC23 CODEC\n");
                        err = -ECANCELED;
-                       goto err1;
+                       goto err3;
                }
        }
 
-       printk(KERN_INFO "MCLK = %d [%d], usecount = %d\n",
-              (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK,
-              clk_get_usecount(tlv320aic23_mclk));
+       printk(KERN_INFO "MCLK = %d [%d]\n",
+              (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK);
 
        return 0;
-err1:
+
+err3:
        clk_put(tlv320aic23_mclk);
+err2:
        platform_device_del(osk_snd_device);
+err1:
        platform_device_put(osk_snd_device);
 
        return err;
@@ -221,6 +211,7 @@ err1:
 
 static void __exit osk_soc_exit(void)
 {
+       clk_put(tlv320aic23_mclk);
        platform_device_unregister(osk_snd_device);
 }