mmc: dw_mmc: The "clock-freq-min-max" property was deprecated
[platform/kernel/linux-starfive.git] / drivers / mmc / host / dw_mmc.c
index 7c7cbb7..881ca3e 100644 (file)
@@ -236,7 +236,6 @@ static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg);
 
 static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
 {
-       struct mmc_data *data;
        struct dw_mci_slot *slot = mmc_priv(mmc);
        struct dw_mci *host = slot->host;
        u32 cmdr;
@@ -291,10 +290,9 @@ static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
        if (cmd->flags & MMC_RSP_CRC)
                cmdr |= SDMMC_CMD_RESP_CRC;
 
-       data = cmd->data;
-       if (data) {
+       if (cmd->data) {
                cmdr |= SDMMC_CMD_DAT_EXP;
-               if (data->flags & MMC_DATA_WRITE)
+               if (cmd->data->flags & MMC_DATA_WRITE)
                        cmdr |= SDMMC_CMD_DAT_WR;
        }
 
@@ -337,6 +335,9 @@ static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
        cmdr = stop->opcode | SDMMC_CMD_STOP |
                SDMMC_CMD_RESP_CRC | SDMMC_CMD_RESP_EXP;
 
+       if (!test_bit(DW_MMC_CARD_NO_USE_HOLD, &host->cur_slot->flags))
+               cmdr |= SDMMC_CMD_USE_HOLD_REG;
+
        return cmdr;
 }
 
@@ -382,7 +383,7 @@ static void dw_mci_start_command(struct dw_mci *host,
 
 static inline void send_stop_abort(struct dw_mci *host, struct mmc_data *data)
 {
-       struct mmc_command *stop = data->stop ? data->stop : &host->stop_abort;
+       struct mmc_command *stop = &host->stop_abort;
 
        dw_mci_start_command(host, stop, host->stop_cmdr);
 }
@@ -411,12 +412,13 @@ static void dw_mci_dma_cleanup(struct dw_mci *host)
 {
        struct mmc_data *data = host->data;
 
-       if (data)
-               if (!data->host_cookie)
-                       dma_unmap_sg(host->dev,
-                                    data->sg,
-                                    data->sg_len,
-                                    dw_mci_get_dma_dir(data));
+       if (data && data->host_cookie == COOKIE_MAPPED) {
+               dma_unmap_sg(host->dev,
+                            data->sg,
+                            data->sg_len,
+                            dw_mci_get_dma_dir(data));
+               data->host_cookie = COOKIE_UNMAPPED;
+       }
 }
 
 static void dw_mci_idmac_reset(struct dw_mci *host)
@@ -847,13 +849,13 @@ static const struct dw_mci_dma_ops dw_mci_edmac_ops = {
 
 static int dw_mci_pre_dma_transfer(struct dw_mci *host,
                                   struct mmc_data *data,
-                                  bool next)
+                                  int cookie)
 {
        struct scatterlist *sg;
        unsigned int i, sg_len;
 
-       if (!next && data->host_cookie)
-               return data->host_cookie;
+       if (data->host_cookie == COOKIE_PRE_MAPPED)
+               return data->sg_len;
 
        /*
         * We don't do DMA on "complex" transfers, i.e. with
@@ -878,8 +880,7 @@ static int dw_mci_pre_dma_transfer(struct dw_mci *host,
        if (sg_len == 0)
                return -EINVAL;
 
-       if (next)
-               data->host_cookie = sg_len;
+       data->host_cookie = cookie;
 
        return sg_len;
 }
@@ -894,13 +895,12 @@ static void dw_mci_pre_req(struct mmc_host *mmc,
        if (!slot->host->use_dma || !data)
                return;
 
-       if (data->host_cookie) {
-               data->host_cookie = 0;
-               return;
-       }
+       /* This data might be unmapped at this time */
+       data->host_cookie = COOKIE_UNMAPPED;
 
-       if (dw_mci_pre_dma_transfer(slot->host, mrq->data, 1) < 0)
-               data->host_cookie = 0;
+       if (dw_mci_pre_dma_transfer(slot->host, mrq->data,
+                               COOKIE_PRE_MAPPED) < 0)
+               data->host_cookie = COOKIE_UNMAPPED;
 }
 
 static void dw_mci_post_req(struct mmc_host *mmc,
@@ -913,12 +913,12 @@ static void dw_mci_post_req(struct mmc_host *mmc,
        if (!slot->host->use_dma || !data)
                return;
 
-       if (data->host_cookie)
+       if (data->host_cookie != COOKIE_UNMAPPED)
                dma_unmap_sg(slot->host->dev,
                             data->sg,
                             data->sg_len,
                             dw_mci_get_dma_dir(data));
-       data->host_cookie = 0;
+       data->host_cookie = COOKIE_UNMAPPED;
 }
 
 static void dw_mci_adjust_fifoth(struct dw_mci *host, struct mmc_data *data)
@@ -1024,7 +1024,7 @@ static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
        if (!host->use_dma)
                return -ENODEV;
 
-       sg_len = dw_mci_pre_dma_transfer(host, data, 0);
+       sg_len = dw_mci_pre_dma_transfer(host, data, COOKIE_MAPPED);
        if (sg_len < 0) {
                host->dma_ops->stop(host);
                return sg_len;
@@ -1275,10 +1275,7 @@ static void __dw_mci_start_request(struct dw_mci *host,
                spin_unlock_irqrestore(&host->irq_lock, irqflags);
        }
 
-       if (mrq->stop)
-               host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
-       else
-               host->stop_cmdr = dw_mci_prep_stop_abort(host, cmd);
+       host->stop_cmdr = dw_mci_prep_stop_abort(host, cmd);
 }
 
 static void dw_mci_start_request(struct dw_mci *host,
@@ -1888,8 +1885,7 @@ static void dw_mci_tasklet_func(unsigned long priv)
                        if (test_and_clear_bit(EVENT_DATA_ERROR,
                                               &host->pending_events)) {
                                dw_mci_stop_dma(host);
-                               if (data->stop ||
-                                   !(host->data_status & (SDMMC_INT_DRTO |
+                               if (!(host->data_status & (SDMMC_INT_DRTO |
                                                           SDMMC_INT_EBE)))
                                        send_stop_abort(host, data);
                                state = STATE_DATA_ERROR;
@@ -1925,8 +1921,7 @@ static void dw_mci_tasklet_func(unsigned long priv)
                        if (test_and_clear_bit(EVENT_DATA_ERROR,
                                               &host->pending_events)) {
                                dw_mci_stop_dma(host);
-                               if (data->stop ||
-                                   !(host->data_status & (SDMMC_INT_DRTO |
+                               if (!(host->data_status & (SDMMC_INT_DRTO |
                                                           SDMMC_INT_EBE)))
                                        send_stop_abort(host, data);
                                state = STATE_DATA_ERROR;
@@ -2002,7 +1997,7 @@ static void dw_mci_tasklet_func(unsigned long priv)
                        host->cmd = NULL;
                        host->data = NULL;
 
-                       if (mrq->stop)
+                       if (!mrq->sbc && mrq->stop)
                                dw_mci_command_complete(host, mrq->stop);
                        else
                                host->cmd_status = 0;
@@ -2614,6 +2609,8 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
                mmc->f_min = DW_MCI_FREQ_MIN;
                mmc->f_max = DW_MCI_FREQ_MAX;
        } else {
+               dev_info(host->dev,
+                       "'clock-freq-min-max' property was deprecated.\n");
                mmc->f_min = freq[0];
                mmc->f_max = freq[1];
        }