spi: fsi: Print status on error
authorEddie James <eajames@linux.ibm.com>
Mon, 4 Oct 2021 19:51:49 +0000 (14:51 -0500)
committerMark Brown <broonie@kernel.org>
Tue, 5 Oct 2021 12:10:01 +0000 (13:10 +0100)
Print the SPI engine status register when an error is detected. This
will aid tremendously in debugging failed transactions.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
Link: https://lore.kernel.org/r/20211004195149.29759-1-eajames@linux.ibm.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-fsi.c

index 829770b8ec74c2bb67fc2d8c857dd6c6ac4c0184..9be18db037223683174d90d93e438f09a6d069d4 100644 (file)
@@ -234,6 +234,26 @@ static int fsi_spi_reset(struct fsi_spi *ctx)
        return fsi_spi_write_reg(ctx, SPI_FSI_STATUS, 0ULL);
 }
 
+static int fsi_spi_status(struct fsi_spi *ctx, u64 *status, const char *dir)
+{
+       int rc = fsi_spi_read_reg(ctx, SPI_FSI_STATUS, status);
+
+       if (rc)
+               return rc;
+
+       if (*status & SPI_FSI_STATUS_ANY_ERROR) {
+               dev_err(ctx->dev, "%s error: %08llx\n", dir, *status);
+
+               rc = fsi_spi_reset(ctx);
+               if (rc)
+                       return rc;
+
+               return -EREMOTEIO;
+       }
+
+       return 0;
+}
+
 static void fsi_spi_sequence_add(struct fsi_spi_sequence *seq, u8 val)
 {
        /*
@@ -273,18 +293,9 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,
                                return rc;
 
                        do {
-                               rc = fsi_spi_read_reg(ctx, SPI_FSI_STATUS,
-                                                     &status);
+                               rc = fsi_spi_status(ctx, &status, "TX");
                                if (rc)
                                        return rc;
-
-                               if (status & SPI_FSI_STATUS_ANY_ERROR) {
-                                       rc = fsi_spi_reset(ctx);
-                                       if (rc)
-                                               return rc;
-
-                                       return -EREMOTEIO;
-                               }
                        } while (status & SPI_FSI_STATUS_TDR_FULL);
 
                        sent += nb;
@@ -296,18 +307,9 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,
 
                while (transfer->len > recv) {
                        do {
-                               rc = fsi_spi_read_reg(ctx, SPI_FSI_STATUS,
-                                                     &status);
+                               rc = fsi_spi_status(ctx, &status, "RX");
                                if (rc)
                                        return rc;
-
-                               if (status & SPI_FSI_STATUS_ANY_ERROR) {
-                                       rc = fsi_spi_reset(ctx);
-                                       if (rc)
-                                               return rc;
-
-                                       return -EREMOTEIO;
-                               }
                        } while (!(status & SPI_FSI_STATUS_RDR_FULL));
 
                        rc = fsi_spi_read_reg(ctx, SPI_FSI_DATA_RX, &in);
@@ -348,8 +350,12 @@ static int fsi_spi_transfer_init(struct fsi_spi *ctx)
                if (status & (SPI_FSI_STATUS_ANY_ERROR |
                              SPI_FSI_STATUS_TDR_FULL |
                              SPI_FSI_STATUS_RDR_FULL)) {
-                       if (reset)
+                       if (reset) {
+                               dev_err(ctx->dev,
+                                       "Initialization error: %08llx\n",
+                                       status);
                                return -EIO;
+                       }
 
                        rc = fsi_spi_reset(ctx);
                        if (rc)