spi: cadence-qspi: Add direct mode support
[oweals/u-boot.git] / drivers / spi / fsl_dspi.c
index f7ed8fbe08b7733583e705751d892f85649d91da..a68a51945e4e474ae0e131032cbdc85fd765a160 100644 (file)
@@ -273,7 +273,18 @@ static int dspi_xfer(struct fsl_dspi_priv *priv, uint cs, unsigned int bitlen,
        if (len > 1) {
                int tmp_len = len - 1;
                while (tmp_len--) {
-                       if (dout != NULL) {
+                       if ((dout != NULL) && (din != NULL)) {
+                               if (priv->charbit == 16) {
+                                       dspi_tx(priv, ctrl, *spi_wr16++);
+                                       *spi_rd16++ = dspi_rx(priv);
+                               }
+                               else {
+                                       dspi_tx(priv, ctrl, *spi_wr++);
+                                       *spi_rd++ = dspi_rx(priv);
+                               }
+                       }
+
+                       else if (dout != NULL) {
                                if (priv->charbit == 16)
                                        dspi_tx(priv, ctrl, *spi_wr16++);
                                else
@@ -281,7 +292,7 @@ static int dspi_xfer(struct fsl_dspi_priv *priv, uint cs, unsigned int bitlen,
                                dspi_rx(priv);
                        }
 
-                       if (din != NULL) {
+                       else if (din != NULL) {
                                dspi_tx(priv, ctrl, DSPI_IDLE_VAL);
                                if (priv->charbit == 16)
                                        *spi_rd16++ = dspi_rx(priv);
@@ -297,7 +308,18 @@ static int dspi_xfer(struct fsl_dspi_priv *priv, uint cs, unsigned int bitlen,
                ctrl &= ~DSPI_TFR_CONT;
 
        if (len) {
-               if (dout != NULL) {
+               if ((dout != NULL) && (din != NULL)) {
+                       if (priv->charbit == 16) {
+                               dspi_tx(priv, ctrl, *spi_wr16++);
+                               *spi_rd16++ = dspi_rx(priv);
+                       }
+                       else {
+                               dspi_tx(priv, ctrl, *spi_wr++);
+                               *spi_rd++ = dspi_rx(priv);
+                       }
+               }
+
+               else if (dout != NULL) {
                        if (priv->charbit == 16)
                                dspi_tx(priv, ctrl, *spi_wr16);
                        else
@@ -305,7 +327,7 @@ static int dspi_xfer(struct fsl_dspi_priv *priv, uint cs, unsigned int bitlen,
                        dspi_rx(priv);
                }
 
-               if (din != NULL) {
+               else if (din != NULL) {
                        dspi_tx(priv, ctrl, DSPI_IDLE_VAL);
                        if (priv->charbit == 16)
                                *spi_rd16 = dspi_rx(priv);
@@ -390,11 +412,6 @@ static int fsl_dspi_cfg_speed(struct fsl_dspi_priv *priv, uint speed)
        return 0;
 }
 #ifndef CONFIG_DM_SPI
-void spi_init(void)
-{
-       /* Nothing to do */
-}
-
 int spi_cs_is_valid(unsigned int bus, unsigned int cs)
 {
        if (((cs >= 0) && (cs < 8)) && ((bus >= 0) && (bus < 8)))