]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mmc: dw_mmc: Extract FIFO data transfer into a separate routine
authorSam Protsenko <semen.protsenko@linaro.org>
Thu, 8 Aug 2024 03:14:12 +0000 (22:14 -0500)
committerMinkyu Kang <mk7.kang@samsung.com>
Mon, 19 Aug 2024 07:09:06 +0000 (16:09 +0900)
FIFO data transfer is implemented as quite a massive chunk of code.
Extract it into a dedicated function to make dwmci_data_transfer()
easier to read and reduce the indentation level of the code.

No functional change.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
drivers/mmc/dw_mmc.c

index b9c14fe6857bff19eb8249e42fa3280b6ee2fc76..b99f63a6f8bd0036915c9935922e3e70c4358f47 100644 (file)
@@ -139,25 +139,67 @@ static unsigned int dwmci_get_timeout(struct mmc *mmc, const unsigned int size)
        return timeout;
 }
 
-static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data)
+static int dwmci_data_transfer_fifo(struct dwmci_host *host,
+                                   struct mmc_data *data, u32 mask)
 {
-       struct mmc *mmc = host->mmc;
+       const u32 fifo_depth = (((host->fifoth_val & RX_WMARK_MASK) >>
+                                RX_WMARK_SHIFT) + 1) * 2;
+       const u32 int_rx = mask & (DWMCI_INTMSK_RXDR | DWMCI_INTMSK_DTO);
+       const u32 int_tx = mask & DWMCI_INTMSK_TXDR;
        int ret = 0;
-       u32 timeout, mask, size, i, len = 0;
-       u32 *buf = NULL;
-       ulong start = get_timer(0);
-       u32 fifo_depth = (((host->fifoth_val & RX_WMARK_MASK) >>
-                           RX_WMARK_SHIFT) + 1) * 2;
+       u32 len = 0, size, i;
+       u32 *buf;
+
+       size = (data->blocksize * data->blocks) / 4;
+       if (!host->fifo_mode || !size)
+               return 0;
 
-       size = data->blocksize * data->blocks;
        if (data->flags == MMC_DATA_READ)
                buf = (unsigned int *)data->dest;
        else
                buf = (unsigned int *)data->src;
 
-       timeout = dwmci_get_timeout(mmc, size);
+       if (data->flags == MMC_DATA_READ && int_rx) {
+               dwmci_writel(host, DWMCI_RINTSTS, int_rx);
+               while (size) {
+                       ret = dwmci_fifo_ready(host, DWMCI_FIFO_EMPTY, &len);
+                       if (ret < 0)
+                               break;
+
+                       len = (len >> DWMCI_FIFO_SHIFT) & DWMCI_FIFO_MASK;
+                       len = min(size, len);
+                       for (i = 0; i < len; i++)
+                               *buf++ = dwmci_readl(host, DWMCI_DATA);
+                       size = size > len ? (size - len) : 0;
+               }
+       } else if (data->flags == MMC_DATA_WRITE && int_tx) {
+               while (size) {
+                       ret = dwmci_fifo_ready(host, DWMCI_FIFO_FULL, &len);
+                       if (ret < 0)
+                               break;
+
+                       len = fifo_depth - ((len >> DWMCI_FIFO_SHIFT) &
+                                           DWMCI_FIFO_MASK);
+                       len = min(size, len);
+                       for (i = 0; i < len; i++)
+                               dwmci_writel(host, DWMCI_DATA, *buf++);
+                       size = size > len ? (size - len) : 0;
+               }
+               dwmci_writel(host, DWMCI_RINTSTS, DWMCI_INTMSK_TXDR);
+       }
 
-       size /= 4;
+       return ret;
+}
+
+static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data)
+{
+       struct mmc *mmc = host->mmc;
+       int ret = 0;
+       u32 timeout, mask, size;
+       ulong start = get_timer(0);
+
+       size = data->blocksize * data->blocks;
+       timeout = dwmci_get_timeout(mmc, size);
 
        for (;;) {
                mask = dwmci_readl(host, DWMCI_RINTSTS);
@@ -168,50 +210,7 @@ static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data)
                        break;
                }
 
-               if (host->fifo_mode && size) {
-                       len = 0;
-                       if (data->flags == MMC_DATA_READ &&
-                           (mask & (DWMCI_INTMSK_RXDR | DWMCI_INTMSK_DTO))) {
-                               dwmci_writel(host, DWMCI_RINTSTS,
-                                            mask & (DWMCI_INTMSK_RXDR |
-                                                    DWMCI_INTMSK_DTO));
-                               while (size) {
-                                       ret = dwmci_fifo_ready(host,
-                                                       DWMCI_FIFO_EMPTY,
-                                                       &len);
-                                       if (ret < 0)
-                                               break;
-
-                                       len = (len >> DWMCI_FIFO_SHIFT) &
-                                                   DWMCI_FIFO_MASK;
-                                       len = min(size, len);
-                                       for (i = 0; i < len; i++)
-                                               *buf++ =
-                                               dwmci_readl(host, DWMCI_DATA);
-                                       size = size > len ? (size - len) : 0;
-                               }
-                       } else if (data->flags == MMC_DATA_WRITE &&
-                                  (mask & DWMCI_INTMSK_TXDR)) {
-                               while (size) {
-                                       ret = dwmci_fifo_ready(host,
-                                                       DWMCI_FIFO_FULL,
-                                                       &len);
-                                       if (ret < 0)
-                                               break;
-
-                                       len = fifo_depth - ((len >>
-                                                  DWMCI_FIFO_SHIFT) &
-                                                  DWMCI_FIFO_MASK);
-                                       len = min(size, len);
-                                       for (i = 0; i < len; i++)
-                                               dwmci_writel(host, DWMCI_DATA,
-                                                            *buf++);
-                                       size = size > len ? (size - len) : 0;
-                               }
-                               dwmci_writel(host, DWMCI_RINTSTS,
-                                            DWMCI_INTMSK_TXDR);
-                       }
-               }
+               ret = dwmci_data_transfer_fifo(host, data, mask);
 
                /* Data arrived correctly. */
                if (mask & DWMCI_INTMSK_DTO) {