ASoC: S3C: I2S: Move set_sysclk to common code
[safe/jmp/linux-2.6] / sound / soc / s3c24xx / s3c2412-i2s.c
index 23718ea..709adef 100644 (file)
 #include <sound/soc.h>
 #include <mach/hardware.h>
 
-#include <plat/regs-s3c2412-iis.h>
-
 #include <mach/regs-gpio.h>
 #include <mach/dma.h>
 
-#include "s3c24xx-pcm.h"
+#include "s3c-dma.h"
+#include "regs-i2s-v2.h"
 #include "s3c2412-i2s.h"
 
 #define S3C2412_I2S_DEBUG 0
@@ -66,44 +65,11 @@ static struct s3c_dma_params s3c2412_i2s_pcm_stereo_in = {
 
 static struct s3c_i2sv2_info s3c2412_i2s;
 
-/*
- * Set S3C2412 Clock source
- */
-static int s3c2412_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
-                                 int clk_id, unsigned int freq, int dir)
+static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
 {
-       u32 iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
-
-       pr_debug("%s(%p, %d, %u, %d)\n", __func__, cpu_dai, clk_id,
-           freq, dir);
-
-       switch (clk_id) {
-       case S3C2412_CLKSRC_PCLK:
-               s3c2412_i2s.master = 1;
-               iismod &= ~S3C2412_IISMOD_MASTER_MASK;
-               iismod |= S3C2412_IISMOD_MASTER_INTERNAL;
-               break;
-       case S3C2412_CLKSRC_I2SCLK:
-               s3c2412_i2s.master = 0;
-               iismod &= ~S3C2412_IISMOD_MASTER_MASK;
-               iismod |= S3C2412_IISMOD_MASTER_EXTERNAL;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       writel(iismod, s3c2412_i2s.regs + S3C2412_IISMOD);
-       return 0;
+       return cpu_dai->private_data;
 }
 
-
-struct clk *s3c2412_get_iisclk(void)
-{
-       return s3c2412_i2s.iis_clk;
-}
-EXPORT_SYMBOL_GPL(s3c2412_get_iisclk);
-
-
 static int s3c2412_i2s_probe(struct platform_device *pdev,
                             struct snd_soc_dai *dai)
 {
@@ -142,13 +108,48 @@ static int s3c2412_i2s_probe(struct platform_device *pdev,
        return 0;
 }
 
+static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
+                                struct snd_pcm_hw_params *params,
+                                struct snd_soc_dai *cpu_dai)
+{
+       struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
+       struct s3c_dma_params *dma_data;
+       u32 iismod;
+
+       pr_debug("Entered %s\n", __func__);
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               dma_data = i2s->dma_playback;
+       else
+               dma_data = i2s->dma_capture;
+
+       snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
+
+       iismod = readl(i2s->regs + S3C2412_IISMOD);
+       pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
+
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S8:
+               iismod |= S3C2412_IISMOD_8BIT;
+               break;
+       case SNDRV_PCM_FORMAT_S16_LE:
+               iismod &= ~S3C2412_IISMOD_8BIT;
+               break;
+       }
+
+       writel(iismod, i2s->regs + S3C2412_IISMOD);
+       pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
+
+       return 0;
+}
+
 #define S3C2412_I2S_RATES \
        (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
        SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
        SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
 
 static struct snd_soc_dai_ops s3c2412_i2s_dai_ops = {
-       .set_sysclk     = s3c2412_i2s_set_sysclk,
+       .hw_params      = s3c2412_i2s_hw_params,
 };
 
 struct snd_soc_dai s3c2412_i2s_dai = {