summaryrefslogtreecommitdiffstats
path: root/drivers/mci/imx-esdhc-pbl.c
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2019-12-02 07:19:54 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2019-12-04 08:37:12 +0100
commit4a7d7b16e21a69a0a590b2356e8d8db2ae3452f6 (patch)
tree425f079de216a6ca57d4cdda52902434285b9ba1 /drivers/mci/imx-esdhc-pbl.c
parent8780906b36046b6aab9cfffdca3323b8a3916b25 (diff)
downloadbarebox-4a7d7b16e21a69a0a590b2356e8d8db2ae3452f6.tar.gz
barebox-4a7d7b16e21a69a0a590b2356e8d8db2ae3452f6.tar.xz
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 <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mci/imx-esdhc-pbl.c')
-rw-r--r--drivers/mci/imx-esdhc-pbl.c87
1 files changed, 1 insertions, 86 deletions
diff --git a/drivers/mci/imx-esdhc-pbl.c b/drivers/mci/imx-esdhc-pbl.c
index d6c178651a..c0d27fb7eb 100644
--- a/drivers/mci/imx-esdhc-pbl.c
+++ b/drivers/mci/imx-esdhc-pbl.c
@@ -30,92 +30,7 @@
#define SECTOR_SIZE 512
#define SECTOR_WML (SECTOR_SIZE / sizeof(u32))
-static void __udelay(int us)
-{
- volatile int i;
-
- for (i = 0; i < us * 4; i++);
-}
-
-static int
-esdhc_send_cmd(struct fsl_esdhc_host *host, struct mci_cmd *cmd, struct mci_data *data)
-{
- struct fsl_esdhc_dma_transfer tr = { 0 };
- u32 xfertyp, mixctrl, command;
- u32 irqstat;
- int ret;
-
- sdhci_write32(&host->sdhci, SDHCI_INT_STATUS, -1);
-
- /* Wait at least 8 SD clock cycles before the next command */
- __udelay(1);
-
- if (data) {
- /* Set up for a data transfer if we have one */
- ret = esdhc_setup_data(host, data, &tr);
- if (ret)
- return ret;
- }
-
- sdhci_set_cmd_xfer_mode(&host->sdhci, cmd, data,
- false, &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 & 0xFFFF;
- /* 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)
- return ret;
-
- 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;
-
- /* Copy the response to the response buffer */
- cmd->response[0] = sdhci_read32(&host->sdhci, SDHCI_RESPONSE_0);
-
- /* 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 |
- SDHCI_DATA_LINE_ACTIVE, 0,
- 100 * MSECOND);
-
- return 0;
-}
+#define esdhc_send_cmd __esdhc_send_cmd
static int esdhc_read_blocks(struct fsl_esdhc_host *host, void *dst, size_t len)
{