mmc: sdhci: reduce code duplication for aligned buffer 57/268157/2
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Fri, 14 Feb 2020 07:40:22 +0000 (16:40 +0900)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Thu, 16 Dec 2021 16:18:05 +0000 (17:18 +0100)
The same code is run for both SDHCI_QUIRK_32BIT_DMA_ADDR and
define(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER).

Unify the code.

Change-Id: I1c7210da5638ec5049663df5d3c6a2032ac52f66
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
drivers/mmc/sdhci.c
include/sdhci.h

index 4d15ef940c68bd1f7c27f3fd77871833b88ec76e..82a6393464f19e44c7c7f9744efb568e88506895 100644 (file)
@@ -140,8 +140,9 @@ static void sdhci_prepare_dma(struct sdhci_host *host, struct mmc_data *data,
        sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
 
        if (host->flags & USE_SDMA) {
-               if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) &&
-                   (host->start_addr & 0x7) != 0x0) {
+               if (host->force_align_buffer ||
+                   (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR &&
+                    (host->start_addr & 0x7) != 0x0)) {
                        *is_aligned = 0;
                        host->start_addr = (unsigned long)host->align_buffer;
                        if (data->flags != MMC_DATA_READ)
@@ -149,19 +150,7 @@ static void sdhci_prepare_dma(struct sdhci_host *host, struct mmc_data *data,
                                       trans_bytes);
                }
 
-#if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER)
-               /*
-                * Always use this bounce-buffer when
-                * CONFIG_FIXED_SDHCI_ALIGNED_BUFFER is defined
-                */
-               *is_aligned = 0;
-               host->start_addr = (unsigned long)host->align_buffer;
-               if (data->flags != MMC_DATA_READ)
-                       memcpy(host->align_buffer, data->src, trans_bytes);
-#endif
-               sdhci_writel(host, phys_to_bus((ulong)host->start_addr),
-                               SDHCI_DMA_ADDRESS);
-
+               sdhci_writel(host, host->start_addr, SDHCI_DMA_ADDRESS);
        } else if (host->flags & (USE_ADMA | USE_ADMA64)) {
                sdhci_prepare_adma_table(host, data);
 
@@ -628,6 +617,11 @@ static int sdhci_init(struct mmc *mmc)
 
 #if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER)
        host->align_buffer = (void *)CONFIG_FIXED_SDHCI_ALIGNED_BUFFER;
+       /*
+        * Always use this bounce-buffer when CONFIG_FIXED_SDHCI_ALIGNED_BUFFER
+        * is defined.
+        */
+       host->force_align_buffer = true;
 #else
        if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) {
                host->align_buffer = memalign(8, 512 * 1024);
index 1358218270b8dd74034398b015c16d1e0e89527a..7f8feefa450bfa82d98c560576fe711eb98fdad9 100644 (file)
@@ -9,6 +9,7 @@
 #ifndef __SDHCI_HW_H
 #define __SDHCI_HW_H
 
+#include <linux/types.h>
 #include <asm/io.h>
 #include <mmc.h>
 #include <asm/gpio.h>
@@ -322,6 +323,7 @@ struct sdhci_host {
 
        struct mmc_config cfg;
        void *align_buffer;
+       bool force_align_buffer;
        dma_addr_t start_addr;
        int flags;
 #define USE_SDMA       (0x1 << 0)