From 4a7d7b16e21a69a0a590b2356e8d8db2ae3452f6 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Mon, 2 Dec 2019 07:19:54 -0800 Subject: mci: imx-esdhc: Share code for esdhc_send_cmd() Versions of esdhc_send_cmd() in imx-esdhc.c and imx-esdhc-pbl.c implement almost the same algorithm. To avoid code repetition, move that code to imx-esdhc-common.c and adjust all of the users accordingly. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- drivers/mci/imx-esdhc.c | 102 +----------------------------------------------- 1 file changed, 1 insertion(+), 101 deletions(-) (limited to 'drivers/mci/imx-esdhc.c') diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c index 7e24b2b026..4816608a23 100644 --- a/drivers/mci/imx-esdhc.c +++ b/drivers/mci/imx-esdhc.c @@ -40,7 +40,6 @@ #include "imx-esdhc.h" -#define PRSSTAT_DAT0 0x01000000 #define PRSSTAT_SDSTB 0x00000008 @@ -53,108 +52,9 @@ static int esdhc_send_cmd(struct mci_host *mci, struct mci_cmd *cmd, struct mci_data *data) { - u32 xfertyp, mixctrl, command; - u32 irqstat; struct fsl_esdhc_host *host = to_fsl_esdhc(mci); - struct fsl_esdhc_dma_transfer tr = { 0 }; - int ret; - - sdhci_write32(&host->sdhci, SDHCI_INT_STATUS, -1); - - /* Wait at least 8 SD clock cycles before the next command */ - udelay(1); - - /* Set up for a data transfer if we have one */ - if (data) { - ret = esdhc_setup_data(host, data, &tr); - if (ret) - return ret; - } - - sdhci_set_cmd_xfer_mode(&host->sdhci, cmd, data, - !IS_ENABLED(CONFIG_MCI_IMX_ESDHC_PIO), &command, - &xfertyp); - - if ((host->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT) && - (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)) - command |= SDHCI_COMMAND_CMDTYP_ABORT; - - /* Send the command */ - sdhci_write32(&host->sdhci, SDHCI_ARGUMENT, cmd->cmdarg); - - if (esdhc_is_usdhc(host)) { - /* write lower-half of xfertyp to mixctrl */ - mixctrl = xfertyp; - /* Keep the bits 22-25 of the register as is */ - mixctrl |= (sdhci_read32(&host->sdhci, IMX_SDHCI_MIXCTRL) & (0xF << 22)); - sdhci_write32(&host->sdhci, IMX_SDHCI_MIXCTRL, mixctrl); - } - - sdhci_write32(&host->sdhci, SDHCI_TRANSFER_MODE__COMMAND, - command << 16 | xfertyp); - - /* Wait for the command to complete */ - ret = esdhc_poll(host, SDHCI_INT_STATUS, - SDHCI_INT_CMD_COMPLETE, SDHCI_INT_CMD_COMPLETE, - 100 * MSECOND); - if (ret) { - dev_dbg(host->dev, "timeout 1\n"); - return -ETIMEDOUT; - } - - irqstat = sdhci_read32(&host->sdhci, SDHCI_INT_STATUS); - sdhci_write32(&host->sdhci, SDHCI_INT_STATUS, irqstat); - if (irqstat & CMD_ERR) - return -EIO; - - if (irqstat & SDHCI_INT_TIMEOUT) - return -ETIMEDOUT; - - /* Workaround for ESDHC errata ENGcm03648 / ENGcm12360 */ - if (!data && (cmd->resp_type & MMC_RSP_BUSY)) { - /* - * Poll on DATA0 line for cmd with busy signal for - * timout / 10 usec since DLA polling can be insecure. - */ - ret = esdhc_poll(host, SDHCI_PRESENT_STATE, - PRSSTAT_DAT0, PRSSTAT_DAT0, - 2500 * MSECOND); - if (ret) { - dev_err(host->dev, "timeout PRSSTAT_DAT0\n"); - return -ETIMEDOUT; - } - } - - sdhci_read_response(&host->sdhci, cmd); - - /* Wait until all of the blocks are transferred */ - if (data) { - ret = esdhc_do_data(host, data, &tr); - if (ret) - return ret; - } - - sdhci_write32(&host->sdhci, SDHCI_INT_STATUS, -1); - - /* Wait for the bus to be idle */ - ret = esdhc_poll(host, SDHCI_PRESENT_STATE, - SDHCI_CMD_INHIBIT_CMD | SDHCI_CMD_INHIBIT_DATA, 0, - SECOND); - if (ret) { - dev_err(host->dev, "timeout 2\n"); - return -ETIMEDOUT; - } - - ret = esdhc_poll(host, SDHCI_PRESENT_STATE, - SDHCI_DATA_LINE_ACTIVE, 0, - 100 * MSECOND); - if (ret) { - dev_err(host->dev, "timeout 3\n"); - return -ETIMEDOUT; - } - - return 0; + return __esdhc_send_cmd(host, cmd, data); } static void set_sysctl(struct mci_host *mci, u32 clock) -- cgit v1.2.3