They are close to identical, so consolidate.

Suggested-by: Marek Vasut <[email protected]>
Signed-off-by: Ian Campbell <[email protected]>
---
 drivers/mmc/sunxi_mmc.c | 39 ++++++++++++---------------------------
 1 file changed, 12 insertions(+), 27 deletions(-)

diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c
index cf065f4..564d55c 100644
--- a/drivers/mmc/sunxi_mmc.c
+++ b/drivers/mmc/sunxi_mmc.c
@@ -308,41 +308,26 @@ static int mmc_core_init(struct mmc *mmc)
 static int mmc_trans_data_by_cpu(struct mmc *mmc, struct mmc_data *data)
 {
        struct sunxi_mmc_host *mmchost = (struct sunxi_mmc_host *)mmc->priv;
+       const int reading = !!(data->flags & MMC_DATA_READ);
+       const uint32_t status_bit = reading ? SUNXI_MMC_STATUS_FIFO_EMPTY :
+                                             SUNXI_MMC_STATUS_FIFO_FULL;
        unsigned i;
        unsigned byte_cnt = data->blocksize * data->blocks;
-       unsigned *buff;
        unsigned timeout = 0xfffff;
+       unsigned *buff = (unsigned int *)(reading ? data->dest : data->src);
 
-       if (data->flags & MMC_DATA_READ) {
-               buff = (unsigned int *)data->dest;
-               for (i = 0; i < (byte_cnt >> 2); i++) {
-                       while (--timeout &&
-                              (readl(&mmchost->reg->status) &
-                               SUNXI_MMC_STATUS_FIFO_EMPTY))
-                               ;
-                       if (timeout <= 0)
-                               goto out;
+       for (i = 0; i < (byte_cnt >> 2); i++) {
+               while (--timeout && (readl(&mmchost->reg->status) & status_bit))
+                       ;
+               if (timeout <= 0)
+                       return -1;
+
+               if (reading)
                        buff[i] = readl(mmchost->database);
-                       timeout = 0xfffff;
-               }
-       } else {
-               buff = (unsigned int *)data->src;
-               for (i = 0; i < (byte_cnt >> 2); i++) {
-                       while (--timeout &&
-                              (readl(&mmchost->reg->status) &
-                               SUNXI_MMC_STATUS_FIFO_FULL))
-                               ;
-                       if (timeout <= 0)
-                               goto out;
+               else
                        writel(buff[i], mmchost->database);
-                       timeout = 0xfffff;
-               }
        }
 
-out:
-       if (timeout <= 0)
-               return -1;
-
        return 0;
 }
 
-- 
1.9.0

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to