Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* fsl_ssi.c: Getting channel slips with fsl_ssi.c in TDM (network) mode.
@ 2015-10-19 15:55 Caleb Crome
  2015-10-20  7:36 ` arnaud.mouiche
  0 siblings, 1 reply; 61+ messages in thread
From: Caleb Crome @ 2015-10-19 15:55 UTC (permalink / raw)
  To: Arnaud Mouiche, alsa-devel@alsa-project.org

Hello Arnaud, all,

I'm trying to get the i.MX6 SSI working in 16-channel TDM mode.  FYI, I'm
working with the stock 4.3 kernel at https://github.com/torvalds/linux.

When I apply the patch below, the SSI does all configure properly and even
starts streaming properly with all the bits in the right place on the SSI
pins.  However, given a little bit of time and/or IO to the SD card, the
bit-stream slips by 1 slot, causing all of the channels to be misaligned.

My changes to the SSI driver are very minimal (shown below), and amount to
forcing it into network (TDM) mode, and changing the maximum channels, and
setting the STCCR DC mask.

There is no indication from user space that anything has slipped, so the
data stream just continues on shifted by 1 slot.

You (Arnaud) mentioned in a previous thread ("Multiple codecs on one sound
card for multi-channel sound card"), that I should just have to set
channels_max (and presumably the other changes I mentioned), and it'll work
mostly.  However, it's very unreliable at the moment.

Any thoughts to how I can diagnose this problem would be greatly
appreciated!

So, what happens is this:

The SSI Starts sending data like this:
SLOT 0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15
DATA 0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15

But then after time, something slips and without warning it goes to:
SLOT 0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15
DATA 15 0  1  2  3  4  5  6  7  8  9  10 11 12 13 14

diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index 37c5cd4..73778c2 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -749,7 +749,10 @@ static int fsl_ssi_hw_params(struct snd_pcm_substream
*substream,
                 CCSR_SSI_SCR_NET | CCSR_SSI_SCR_I2S_MODE_MASK,
                 channels == 1 ? 0 : i2smode);
     }
-
+    ssi_private->i2s_mode = CCSR_SSI_SCR_I2S_MODE_NORMAL |
CCSR_SSI_SCR_NET;
+    regmap_update_bits(regs, CCSR_SSI_SCR,
+               CCSR_SSI_SCR_NET | CCSR_SSI_SCR_I2S_MODE_MASK,
+               ssi_private->i2s_mode);
     /*
      * FIXME: The documentation says that SxCCR[WL] should not be
      * modified while the SSI is enabled.  The only time this can
@@ -863,6 +866,15 @@ static int _fsl_ssi_set_dai_fmt(struct device *dev,
         return -EINVAL;
     }
     scr |= ssi_private->i2s_mode;
+    // Set to 16 slots/frame
+    regmap_update_bits(regs, CCSR_SSI_STCCR,
+               CCSR_SSI_SxCCR_DC_MASK,
+               CCSR_SSI_SxCCR_DC(16));
+
+    regmap_update_bits(regs, CCSR_SSI_SRCCR,
+               CCSR_SSI_SxCCR_DC_MASK,
+               CCSR_SSI_SxCCR_DC(16));
+

     /* DAI clock inversion */
     switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
@@ -1084,14 +1099,14 @@ static struct snd_soc_dai_driver
fsl_ssi_dai_template = {
     .playback = {
         .stream_name = "CPU-Playback",
         .channels_min = 1,
-        .channels_max = 2,
+        .channels_max = 16,
         .rates = FSLSSI_I2S_RATES,
         .formats = FSLSSI_I2S_FORMATS,
     },
     .capture = {
         .stream_name = "CPU-Capture",
         .channels_min = 1,
-        .channels_max = 2,
+        .channels_max = 16,
         .rates = FSLSSI_I2S_RATES,
         .formats = FSLSSI_I2S_FORMATS,
     },

Another thing I have tried is changing the watermark level for the fifo to
give the DMA interrupt some extra time.  The problem still happens, but
seems to be a bit better.

The fifo watermark change is this:
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index 73778c2..7c2e4b0 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -54,6 +54,8 @@
 #include "fsl_ssi.h"
 #include "imx-pcm.h"

+#define WATERMARK 8
+
 /**
  * FSLSSI_I2S_RATES: sample rates supported by the I2S
  *
@@ -943,7 +950,7 @@ static int _fsl_ssi_set_dai_fmt(struct device *dev,
      * size.
      */
     if (ssi_private->use_dma)
-        wm = ssi_private->fifo_depth - 2;
+        wm = ssi_private->fifo_depth - WATERMARK;
     else
         wm = ssi_private->fifo_depth;

@@ -1260,8 +1267,8 @@ static int fsl_ssi_imx_probe(struct platform_device
*pdev,
      * We have burstsize be "fifo_depth - 2" to match the SSI
      * watermark setting in fsl_ssi_startup().
      */
-    ssi_private->dma_params_tx.maxburst = ssi_private->fifo_depth - 2;
-    ssi_private->dma_params_rx.maxburst = ssi_private->fifo_depth - 2;
+    ssi_private->dma_params_tx.maxburst = ssi_private->fifo_depth -
WATERMARK;
+    ssi_private->dma_params_rx.maxburst = ssi_private->fifo_depth -
WATERMARK;
     ssi_private->dma_params_tx.addr = ssi_private->ssi_phys +
CCSR_SSI_STX0;
     ssi_private->dma_params_rx.addr = ssi_private->ssi_phys +
CCSR_SSI_SRX0;


Thanks,
  -Caleb

^ permalink raw reply related	[flat|nested] 61+ messages in thread

end of thread, other threads:[~2015-11-02 17:22 UTC | newest]

Thread overview: 61+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-19 15:55 fsl_ssi.c: Getting channel slips with fsl_ssi.c in TDM (network) mode Caleb Crome
2015-10-20  7:36 ` arnaud.mouiche
2015-10-20 17:43   ` Caleb Crome
2015-10-21  7:32     ` arnaud.mouiche
2015-10-21 19:37       ` Caleb Crome
2015-10-26 17:31         ` Caleb Crome
2015-10-27  7:13           ` Markus Pargmann
2015-10-27  9:41             ` Fabio Estevam
2015-10-27 16:02               ` Caleb Crome
2015-10-27 16:10                 ` Fabio Estevam
2015-10-27 16:42                   ` Caleb Crome
2015-10-27 16:45                     ` Fabio Estevam
2015-10-27 18:57                       ` Fabio Estevam
2015-10-28  8:11                         ` Roberto Fichera
2015-10-28 13:59                           ` Caleb Crome
2015-10-28 14:05                             ` Roberto Fichera
2015-10-28 14:24                               ` Caleb Crome
2015-10-28 14:48                                 ` Roberto Fichera
2015-10-28 22:09                             ` Caleb Crome
2015-10-29  8:04                               ` Roberto Fichera
2015-10-29 23:04                           ` Nicolin Chen
2015-10-30 11:42                             ` Roberto Fichera
2015-10-30 17:21                               ` Nicolin Chen
2015-10-28 13:53                       ` Caleb Crome
2015-10-27 20:11             ` Nicolin Chen
2015-10-28  8:23               ` Roberto Fichera
2015-10-29 23:05                 ` Nicolin Chen
2015-10-28 22:06               ` Caleb Crome
2015-10-29  4:53                 ` Nicolin Chen
2015-10-29 13:44                   ` Caleb Crome
2015-10-29 14:55                     ` Caleb Crome
2015-10-29 15:37                       ` Roberto Fichera
2015-10-29 15:54                         ` Caleb Crome
2015-10-29 16:02                           ` Roberto Fichera
2015-10-29 16:19                             ` Caleb Crome
2015-10-29 16:34                             ` Roberto Fichera
2015-10-29 16:39                               ` Caleb Crome
2015-10-29 16:59                                 ` Roberto Fichera
2015-10-29 18:36                           ` Nicolin Chen
2015-10-29 19:08                             ` Caleb Crome
2015-10-29 23:22                         ` Nicolin Chen
2015-10-29 18:11                       ` Nicolin Chen
2015-10-29 17:19                     ` Nicolin Chen
2015-10-29 19:06                       ` Caleb Crome
2015-10-29 19:28                         ` Nicolin Chen
2015-10-29 22:23                           ` Caleb Crome
2015-10-29 22:47                             ` Nicolin Chen
2015-10-29 23:33                               ` Caleb Crome
2015-10-30  1:29                                 ` Nicolin Chen
2015-10-30  8:29                                   ` arnaud.mouiche
2015-10-30  8:45                                     ` arnaud.mouiche
2015-10-30 16:07                                       ` Nicolin Chen
2015-10-30 15:49                                     ` Nicolin Chen
2015-10-30 18:10                                       ` Caleb Crome
2015-10-30 22:04                                   ` Caleb Crome
2015-10-30 22:35                                     ` Caleb Crome
2015-10-31  1:32                                       ` Nicolin Chen
2015-10-31 16:12                                         ` Caleb Crome
2015-10-31  1:48                                     ` Nicolin Chen
2015-10-31 16:22                                       ` Caleb Crome
2015-11-02 17:22                                         ` Nicolin Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox