SDMMC: gather each reset code into functions
authorxbw <xbw@rock-chips.com>
Fri, 28 Mar 2014 09:59:17 +0000 (17:59 +0800)
committerxbw <xbw@rock-chips.com>
Fri, 28 Mar 2014 10:02:06 +0000 (18:02 +0800)
drivers/mmc/host/rk_sdmmc.c

index 542fec6d23bac0134c38eba2b450bbbbff144a50..22d24e14f10c31f88d1a174cc978cb6f9e8b9514 100755 (executable)
@@ -121,6 +121,10 @@ static const u8 tuning_blk_pattern_8bit[] = {
        0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee,
 };
 
+static inline bool dw_mci_fifo_reset(struct dw_mci *host);
+static inline bool dw_mci_ctrl_all_reset(struct dw_mci *host);
+static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset);
+
 /*printk the all register of current host*/
 static int dw_mci_regs_printk(struct dw_mci *host)
 {
@@ -728,10 +732,8 @@ static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
        if (host->prev_blksz != data->blksz)
                dw_mci_adjust_fifoth(host, data);
 
-    /* Reset DMA FIFO*/
-       temp = mci_readl(host, CTRL);
-       temp |= (SDMMC_CTRL_DMA_RESET | SDMMC_CTRL_FIFO_RESET);
-       mci_writel(host, CTRL, temp);
+       /* Reset DMA FIFO*/
+       dw_mci_ctrl_reset(host, SDMMC_CTRL_DMA_RESET);// | SDMMC_CTRL_FIFO_RESET); //dange to fifo-reset; noted by xbw,at 2014-03-28
 
        /* Enable the DMA interface */
        temp = mci_readl(host, CTRL);
@@ -759,9 +761,7 @@ static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
        host->data = data;
 
        /* Reset FIFO*/
-       temp = mci_readl(host, CTRL);
-       temp |= (SDMMC_CTRL_DMA_RESET | SDMMC_CTRL_FIFO_RESET);
-       mci_writel(host, CTRL, temp);
+       dw_mci_ctrl_reset(host, SDMMC_CTRL_DMA_RESET);// | SDMMC_CTRL_FIFO_RESET);//dange to fifo-reset; noted by xbw,at 2014-03-28
 
        if (data->flags & MMC_DATA_READ) {
                host->dir_status = DW_MCI_RECV_STATUS;
@@ -923,7 +923,8 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
 }
 
 static void dw_mci_wait_unbusy(struct dw_mci *host)
-{\r   
+{
+   
     unsigned int    timeout= SDMMC_DATA_TIMEOUT_SDIO;
     unsigned long   time_loop;
     unsigned int    status;
@@ -1622,11 +1623,7 @@ static void dw_mci_tasklet_func(unsigned long priv)
                                 * generates a block interrupt, hence setting
                                 * the scatter-gather pointer to NULL.
                                 */
-                               sg_miter_stop(&host->sg_miter);
-                               host->sg = NULL;
-                               ctrl = mci_readl(host, CTRL);
-                               ctrl |= SDMMC_CTRL_FIFO_RESET;
-                               mci_writel(host, CTRL, ctrl);
+                               dw_mci_fifo_reset(host);
                        } else {
                                data->bytes_xfered = data->blocks * data->blksz;
                                data->error = 0;
@@ -1674,11 +1671,7 @@ static void dw_mci_tasklet_func(unsigned long priv)
                         
              /* CMD error in data command */
                        if (host->mrq->cmd->error && host->mrq->data) {
-                               sg_miter_stop(&host->sg_miter);
-                               host->sg = NULL;
-                               ctrl = mci_readl(host, CTRL);
-                               ctrl |= SDMMC_CTRL_FIFO_RESET;
-                               mci_writel(host, CTRL, ctrl);
+                               dw_mci_fifo_reset(host);
                        }
 
                        host->cmd = NULL;
@@ -2314,13 +2307,7 @@ static void dw_mci_work_routine_card(struct work_struct *work)
                                 * block interrupt, hence setting the
                                 * scatter-gather pointer to NULL.
                                 */
-                               sg_miter_stop(&host->sg_miter);
-                               host->sg = NULL;
-
-                               ctrl = mci_readl(host, CTRL);
-                               ctrl |= SDMMC_CTRL_FIFO_RESET;
-                               mci_writel(host, CTRL, ctrl);
-
+                               dw_mci_fifo_reset(host);
 #ifdef CONFIG_MMC_DW_IDMAC
                                dw_mci_idmac_reset(host);
 #endif
@@ -2755,27 +2742,51 @@ no_dma:
        return;
 }
 
-static bool mci_wait_reset(struct device *dev, struct dw_mci *host)
+static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
 {
        unsigned long timeout = jiffies + msecs_to_jiffies(500);
-       unsigned int ctrl;
+       u32 ctrl;
 
-       mci_writel(host, CTRL, (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET |
-                               SDMMC_CTRL_DMA_RESET));
+       ctrl = mci_readl(host, CTRL);
+       ctrl |= reset;
+       mci_writel(host, CTRL, ctrl);
 
        /* wait till resets clear */
        do {
                ctrl = mci_readl(host, CTRL);
-               if (!(ctrl & (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET |
-                             SDMMC_CTRL_DMA_RESET)))
+               if (!(ctrl & reset))
                        return true;
        } while (time_before(jiffies, timeout));
 
-       dev_err(dev, "Timeout resetting block (ctrl %#x)\n", ctrl);
+       dev_err(host->dev,
+               "Timeout resetting block (ctrl reset %#x)\n",
+               ctrl & reset);
 
        return false;
 }
 
+static inline bool dw_mci_fifo_reset(struct dw_mci *host)
+{
+       /*
+        * Reseting generates a block interrupt, hence setting
+        * the scatter-gather pointer to NULL.
+        */
+       if (host->sg) {
+               sg_miter_stop(&host->sg_miter);
+               host->sg = NULL;
+       }
+
+       return dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET);
+}
+
+static inline bool dw_mci_ctrl_all_reset(struct dw_mci *host)
+{
+       return dw_mci_ctrl_reset(host,
+                                SDMMC_CTRL_FIFO_RESET |
+                                SDMMC_CTRL_RESET |
+                                SDMMC_CTRL_DMA_RESET);
+}
+
 #ifdef CONFIG_OF
 static struct dw_mci_of_quirks {
        char *quirk;
@@ -2960,7 +2971,7 @@ int dw_mci_probe(struct dw_mci *host)
        }
 
        /* Reset all blocks */
-       if (!mci_wait_reset(host->dev, host))
+       if (!dw_mci_ctrl_all_reset(host))
                return -ENODEV;
 
        host->dma_ops = host->pdata->dma_ops;
@@ -3155,7 +3166,7 @@ int dw_mci_resume(struct dw_mci *host)
                }
        }
 
-       if (!mci_wait_reset(host->dev, host)) {
+       if (!dw_mci_ctrl_all_reset(host)) {
                ret = -ENODEV;
                return ret;
        }