]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ASoC: fsl_sai: Add asynchronous mode support
authorNicolin Chen <Guangyu.Chen@freescale.com>
Tue, 5 Aug 2014 07:32:05 +0000 (15:32 +0800)
committerMark Brown <broonie@linaro.org>
Sat, 16 Aug 2014 22:06:23 +0000 (17:06 -0500)
SAI supports these operation modes:
1) asynchronous mode
   Both Tx and Rx are set to be asynchronous.
2) synchronous mode (Rx sync with Tx)
   Tx is set to be asynchronous, Rx is set to be synchronous.
3) synchronous mode (Tx sync with Rx)
   Rx is set to be asynchronous, Tx is set to be synchronous.
4) synchronous mode (Tx/Rx sync with another SAI's Tx)
5) synchronous mode (Tx/Rx sync with another SAI's Rx)

* 4) and 5) are beyond this patch because they are related with another SAI.

As the initial version of this SAI driver, it supported 2) as default while
the others were totally missing.

So this patch just adds supports for 1) and 3).

Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Documentation/devicetree/bindings/sound/fsl-sai.txt
sound/soc/fsl/fsl_sai.c
sound/soc/fsl/fsl_sai.h

index 0f4e23828190f7bda8d9b829ab7410276b2ead5f..77864f4dd352baf5af7e6591cdc9130a5d92ecfc 100644 (file)
@@ -24,6 +24,22 @@ Required properties:
 - big-endian-data: If this property is absent, the little endian mode will
   be in use as default, or the big endian mode will be in use for all the
   fifo data.
+- fsl,sai-synchronous-rx: This is a boolean property. If present, indicating
+  that SAI will work in the synchronous mode (sync Tx with Rx) which means
+  both the transimitter and receiver will send and receive data by following
+  receiver's bit clocks and frame sync clocks.
+- fsl,sai-asynchronous: This is a boolean property. If present, indicating
+  that SAI will work in the asynchronous mode, which means both transimitter
+  and receiver will send and receive data by following their own bit clocks
+  and frame sync clocks separately.
+
+Note:
+- If both fsl,sai-asynchronous and fsl,sai-synchronous-rx are absent, the
+  default synchronous mode (sync Rx with Tx) will be used, which means both
+  transimitter and receiver will send and receive data by following clocks
+  of transimitter.
+- fsl,sai-asynchronous will be ignored if fsl,sai-synchronous-rx property is
+  already present.
 
 Example:
 sai2: sai@40031000 {
index 3d865ad466ad4e0a1cfd77b5e205f84dced19b67..ef7c758627b1e2dc4c6532a6877a586bbedec20e 100644 (file)
@@ -330,12 +330,14 @@ static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd,
        u32 xcsr, count = 100;
 
        /*
-        * The transmitter bit clock and frame sync are to be
-        * used by both the transmitter and receiver.
+        * Asynchronous mode: Clear SYNC for both Tx and Rx.
+        * Rx sync with Tx clocks: Clear SYNC for Tx, set it for Rx.
+        * Tx sync with Rx clocks: Clear SYNC for Rx, set it for Tx.
         */
-       regmap_update_bits(sai->regmap, FSL_SAI_TCR2, FSL_SAI_CR2_SYNC, 0);
+       regmap_update_bits(sai->regmap, FSL_SAI_TCR2, FSL_SAI_CR2_SYNC,
+                          sai->synchronous[TX] ? FSL_SAI_CR2_SYNC : 0);
        regmap_update_bits(sai->regmap, FSL_SAI_RCR2, FSL_SAI_CR2_SYNC,
-                          FSL_SAI_CR2_SYNC);
+                          sai->synchronous[RX] ? FSL_SAI_CR2_SYNC : 0);
 
        /*
         * It is recommended that the transmitter is the last enabled
@@ -625,6 +627,26 @@ static int fsl_sai_probe(struct platform_device *pdev)
                return ret;
        }
 
+       /* Sync Tx with Rx as default by following old DT binding */
+       sai->synchronous[RX] = true;
+       sai->synchronous[TX] = false;
+       fsl_sai_dai.symmetric_rates = 1;
+       fsl_sai_dai.symmetric_channels = 1;
+       fsl_sai_dai.symmetric_samplebits = 1;
+
+       if (of_find_property(np, "fsl,sai-synchronous-rx", NULL)) {
+               /* Sync Rx with Tx */
+               sai->synchronous[RX] = false;
+               sai->synchronous[TX] = true;
+       } else if (of_find_property(np, "fsl,sai-asynchronous", NULL)) {
+               /* Discard all settings for asynchronous mode */
+               sai->synchronous[RX] = false;
+               sai->synchronous[TX] = false;
+               fsl_sai_dai.symmetric_rates = 0;
+               fsl_sai_dai.symmetric_channels = 0;
+               fsl_sai_dai.symmetric_samplebits = 0;
+       }
+
        sai->dma_params_rx.addr = res->start + FSL_SAI_RDR;
        sai->dma_params_tx.addr = res->start + FSL_SAI_TDR;
        sai->dma_params_rx.maxburst = FSL_SAI_MAXBURST_RX;
index 8e1feab7c2a05d83c19ba8c95baf188bb110d1c6..b3d8864cd5f289414d02bb3794e5f16d85a52d89 100644 (file)
@@ -136,9 +136,13 @@ struct fsl_sai {
        bool big_endian_data;
        bool is_dsp_mode;
        bool sai_on_imx;
+       bool synchronous[2];
 
        struct snd_dmaengine_dai_dma_data dma_params_rx;
        struct snd_dmaengine_dai_dma_data dma_params_tx;
 };
 
+#define TX 1
+#define RX 0
+
 #endif /* __FSL_SAI_H */