]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - sound/soc/pxa/pxa-ssp.c
Merge branch 'origin' into devel
[linux-2.6-omap-h63xx.git] / sound / soc / pxa / pxa-ssp.c
index 52d97c4b82b19725e9528706eeae02c1c044c004..7acd3febf8b007bfc7f87035cd071f3e95c22a20 100644 (file)
@@ -1,4 +1,3 @@
-#define DEBUG
 /*
  * pxa-ssp.c  --  ALSA Soc Audio Layer
  *
@@ -31,7 +30,7 @@
 #include <sound/pxa2xx-lib.h>
 
 #include <mach/hardware.h>
-#include <mach/pxa-regs.h>
+#include <mach/dma.h>
 #include <mach/regs-ssp.h>
 #include <mach/audio.h>
 #include <mach/ssp.h>
@@ -558,18 +557,18 @@ static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
 
        switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
        case SND_SOC_DAIFMT_I2S:
-               sscr0 |= SSCR0_MOD | SSCR0_PSP;
+               sscr0 |= SSCR0_PSP;
                sscr1 |= SSCR1_RWOT | SSCR1_TRAIL;
 
+               /* See hw_params() */
                switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
                case SND_SOC_DAIFMT_NB_NF:
-                       sspsp |= SSPSP_FSRT;
+                       sspsp |= SSPSP_SFRMP;
                        break;
                case SND_SOC_DAIFMT_NB_IF:
-                       sspsp |= SSPSP_SFRMP | SSPSP_FSRT;
                        break;
                case SND_SOC_DAIFMT_IB_IF:
-                       sspsp |= SSPSP_SFRMP;
+                       sspsp |= SSPSP_SCMODE(3);
                        break;
                default:
                        return -EINVAL;
@@ -655,33 +654,65 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
                        sscr0 |= SSCR0_FPCKE;
 #endif
                sscr0 |= SSCR0_DataSize(16);
-               /* use network mode (2 slots) for 16 bit stereo */
                break;
        case SNDRV_PCM_FORMAT_S24_LE:
                sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(8));
-               /* we must be in network mode (2 slots) for 24 bit stereo */
                break;
        case SNDRV_PCM_FORMAT_S32_LE:
                sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16));
-               /* we must be in network mode (2 slots) for 32 bit stereo */
                break;
        }
        ssp_write_reg(ssp, SSCR0, sscr0);
 
        switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
        case SND_SOC_DAIFMT_I2S:
-               /* Cleared when the DAI format is set */
-               sspsp = ssp_read_reg(ssp, SSPSP) | SSPSP_SFRMWDTH(width);
+              sspsp = ssp_read_reg(ssp, SSPSP);
+
+               if (((sscr0 & SSCR0_SCR) == SSCR0_SerClkDiv(4)) &&
+                    (width == 16)) {
+                       /* This is a special case where the bitclk is 64fs
+                       * and we're not dealing with 2*32 bits of audio
+                       * samples.
+                       *
+                       * The SSP values used for that are all found out by
+                       * trying and failing a lot; some of the registers
+                       * needed for that mode are only available on PXA3xx.
+                       */
+
+#ifdef CONFIG_PXA3xx
+                       if (!cpu_is_pxa3xx())
+                               return -EINVAL;
+
+                       sspsp |= SSPSP_SFRMWDTH(width * 2);
+                       sspsp |= SSPSP_SFRMDLY(width * 4);
+                       sspsp |= SSPSP_EDMYSTOP(3);
+                       sspsp |= SSPSP_DMYSTOP(3);
+                       sspsp |= SSPSP_DMYSTRT(1);
+#else
+                       return -EINVAL;
+#endif
+               } else {
+                       /* The frame width is the width the LRCLK is
+                        * asserted for; the delay is expressed in
+                        * half cycle units.  We need the extra cycle
+                        * because the data starts clocking out one BCLK
+                        * after LRCLK changes polarity.
+                        */
+                       sspsp |= SSPSP_SFRMWDTH(width + 1);
+                       sspsp |= SSPSP_SFRMDLY((width + 1) * 2);
+                       sspsp |= SSPSP_DMYSTRT(1);
+               }
+
                ssp_write_reg(ssp, SSPSP, sspsp);
                break;
        default:
                break;
        }
 
-       /* We always use a network mode so we always require TDM slots
+       /* When we use a network mode, we always require TDM slots
         * - complain loudly and fail if they've not been set up yet.
         */
-       if (!(ssp_read_reg(ssp, SSTSA) & 0xf)) {
+       if ((sscr0 & SSCR0_MOD) && !(ssp_read_reg(ssp, SSTSA) & 0xf)) {
                dev_err(&ssp->pdev->dev, "No TDM timeslot configured\n");
                return -EINVAL;
        }
@@ -794,6 +825,19 @@ static void pxa_ssp_remove(struct platform_device *pdev,
                            SNDRV_PCM_FMTBIT_S24_LE |   \
                            SNDRV_PCM_FMTBIT_S32_LE)
 
+static struct snd_soc_dai_ops pxa_ssp_dai_ops = {
+       .startup        = pxa_ssp_startup,
+       .shutdown       = pxa_ssp_shutdown,
+       .trigger        = pxa_ssp_trigger,
+       .hw_params      = pxa_ssp_hw_params,
+       .set_sysclk     = pxa_ssp_set_dai_sysclk,
+       .set_clkdiv     = pxa_ssp_set_dai_clkdiv,
+       .set_pll        = pxa_ssp_set_dai_pll,
+       .set_fmt        = pxa_ssp_set_dai_fmt,
+       .set_tdm_slot   = pxa_ssp_set_dai_tdm_slot,
+       .set_tristate   = pxa_ssp_set_dai_tristate,
+};
+
 struct snd_soc_dai pxa_ssp_dai[] = {
        {
                .name = "pxa2xx-ssp1",
@@ -814,18 +858,7 @@ struct snd_soc_dai pxa_ssp_dai[] = {
                        .rates = PXA_SSP_RATES,
                        .formats = PXA_SSP_FORMATS,
                 },
-               .ops = {
-                       .startup = pxa_ssp_startup,
-                       .shutdown = pxa_ssp_shutdown,
-                       .trigger = pxa_ssp_trigger,
-                       .hw_params = pxa_ssp_hw_params,
-                       .set_sysclk = pxa_ssp_set_dai_sysclk,
-                       .set_clkdiv = pxa_ssp_set_dai_clkdiv,
-                       .set_pll = pxa_ssp_set_dai_pll,
-                       .set_fmt = pxa_ssp_set_dai_fmt,
-                       .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
-                       .set_tristate = pxa_ssp_set_dai_tristate,
-               },
+               .ops = &pxa_ssp_dai_ops,
        },
        {       .name = "pxa2xx-ssp2",
                .id = 1,
@@ -845,18 +878,7 @@ struct snd_soc_dai pxa_ssp_dai[] = {
                        .rates = PXA_SSP_RATES,
                        .formats = PXA_SSP_FORMATS,
                 },
-               .ops = {
-                       .startup = pxa_ssp_startup,
-                       .shutdown = pxa_ssp_shutdown,
-                       .trigger = pxa_ssp_trigger,
-                       .hw_params = pxa_ssp_hw_params,
-                       .set_sysclk = pxa_ssp_set_dai_sysclk,
-                       .set_clkdiv = pxa_ssp_set_dai_clkdiv,
-                       .set_pll = pxa_ssp_set_dai_pll,
-                       .set_fmt = pxa_ssp_set_dai_fmt,
-                       .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
-                       .set_tristate = pxa_ssp_set_dai_tristate,
-               },
+               .ops = &pxa_ssp_dai_ops,
        },
        {
                .name = "pxa2xx-ssp3",
@@ -877,18 +899,7 @@ struct snd_soc_dai pxa_ssp_dai[] = {
                        .rates = PXA_SSP_RATES,
                        .formats = PXA_SSP_FORMATS,
                 },
-               .ops = {
-                       .startup = pxa_ssp_startup,
-                       .shutdown = pxa_ssp_shutdown,
-                       .trigger = pxa_ssp_trigger,
-                       .hw_params = pxa_ssp_hw_params,
-                       .set_sysclk = pxa_ssp_set_dai_sysclk,
-                       .set_clkdiv = pxa_ssp_set_dai_clkdiv,
-                       .set_pll = pxa_ssp_set_dai_pll,
-                       .set_fmt = pxa_ssp_set_dai_fmt,
-                       .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
-                       .set_tristate = pxa_ssp_set_dai_tristate,
-               },
+               .ops = &pxa_ssp_dai_ops,
        },
        {
                .name = "pxa2xx-ssp4",
@@ -909,18 +920,7 @@ struct snd_soc_dai pxa_ssp_dai[] = {
                        .rates = PXA_SSP_RATES,
                        .formats = PXA_SSP_FORMATS,
                 },
-               .ops = {
-                       .startup = pxa_ssp_startup,
-                       .shutdown = pxa_ssp_shutdown,
-                       .trigger = pxa_ssp_trigger,
-                       .hw_params = pxa_ssp_hw_params,
-                       .set_sysclk = pxa_ssp_set_dai_sysclk,
-                       .set_clkdiv = pxa_ssp_set_dai_clkdiv,
-                       .set_pll = pxa_ssp_set_dai_pll,
-                       .set_fmt = pxa_ssp_set_dai_fmt,
-                       .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
-                       .set_tristate = pxa_ssp_set_dai_tristate,
-               },
+               .ops = &pxa_ssp_dai_ops,
        },
 };
 EXPORT_SYMBOL_GPL(pxa_ssp_dai);