mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/3] mci: imx-esdhc: Use IS_ENABLED() instead of #ifdef
Date: Wed, 13 May 2015 08:20:35 +0200	[thread overview]
Message-ID: <1431498037-31789-1-git-send-email-s.hauer@pengutronix.de> (raw)

To get rid of some #ifdefery.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/imx-esdhc.c | 124 +++++++++++++++++++++++++++---------------------
 1 file changed, 69 insertions(+), 55 deletions(-)

diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index 8b45500..178967a 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -60,9 +60,10 @@ static u32 esdhc_xfertyp(struct mci_cmd *cmd, struct mci_data *data)
 
 	if (data) {
 		xfertyp |= COMMAND_DPSEL;
-#ifndef CONFIG_MCI_IMX_ESDHC_PIO
-		xfertyp |= TRANSFER_MODE_DMAEN;
-#endif
+
+		if (!IS_ENABLED(CONFIG_MCI_IMX_ESDHC_PIO))
+			xfertyp |= TRANSFER_MODE_DMAEN;
+
 		if (data->blocks > 1) {
 			xfertyp |= TRANSFER_MODE_MSBSEL;
 			xfertyp |= TRANSFER_MODE_BCEN;
@@ -89,7 +90,6 @@ static u32 esdhc_xfertyp(struct mci_cmd *cmd, struct mci_data *data)
 	return COMMAND_CMD(cmd->cmdidx) | xfertyp;
 }
 
-#ifdef CONFIG_MCI_IMX_ESDHC_PIO
 /*
  * PIO Read/Write Mode reduce the performace as DMA is not used in this mode.
  */
@@ -153,52 +153,84 @@ esdhc_pio_read_write(struct mci_host *mci, struct mci_data *data)
 		}
 	}
 }
-#endif
 
 static int esdhc_setup_data(struct mci_host *mci, struct mci_data *data)
 {
 	struct fsl_esdhc_host *host = to_fsl_esdhc(mci);
 	void __iomem *regs = host->regs;
-#ifndef CONFIG_MCI_IMX_ESDHC_PIO
 	u32 wml_value;
 
-	wml_value = data->blocksize/4;
-
-	if (data->flags & MMC_DATA_READ) {
-		if (wml_value > 0x10)
-			wml_value = 0x10;
-
-		esdhc_clrsetbits32(regs + IMX_SDHCI_WML, WML_RD_WML_MASK, wml_value);
-		esdhc_write32(regs + SDHCI_DMA_ADDRESS, (u32)data->dest);
-	} else {
-		if (wml_value > 0x80)
-			wml_value = 0x80;
-		if ((esdhc_read32(regs + SDHCI_PRESENT_STATE) & PRSSTAT_WPSPL) == 0) {
-			printf("\nThe SD card is locked. Can not write to a locked card.\n\n");
-			return -ETIMEDOUT;
+	if (IS_ENABLED(CONFIG_MCI_IMX_ESDHC_PIO)) {
+		if (!(data->flags & MMC_DATA_READ)) {
+			if ((esdhc_read32(regs + SDHCI_PRESENT_STATE) & PRSSTAT_WPSPL) == 0) {
+				printf("\nThe SD card is locked. "
+					"Can not write to a locked card.\n\n");
+				return -ETIMEDOUT;
+			}
+			esdhc_write32(regs + SDHCI_DMA_ADDRESS, (u32)data->src);
+		} else {
+			esdhc_write32(regs + SDHCI_DMA_ADDRESS, (u32)data->dest);
 		}
+	} else {
+		wml_value = data->blocksize/4;
+
+		if (data->flags & MMC_DATA_READ) {
+			if (wml_value > 0x10)
+				wml_value = 0x10;
+
+			esdhc_clrsetbits32(regs + IMX_SDHCI_WML, WML_RD_WML_MASK, wml_value);
+			esdhc_write32(regs + SDHCI_DMA_ADDRESS, (u32)data->dest);
+		} else {
+			if (wml_value > 0x80)
+				wml_value = 0x80;
+			if ((esdhc_read32(regs + SDHCI_PRESENT_STATE) & PRSSTAT_WPSPL) == 0) {
+				printf("\nThe SD card is locked. Can not write to a locked card.\n\n");
+				return -ETIMEDOUT;
+			}
 
-		esdhc_clrsetbits32(regs + IMX_SDHCI_WML, WML_WR_WML_MASK,
-					wml_value << 16);
-		esdhc_write32(regs + SDHCI_DMA_ADDRESS, (u32)data->src);
-	}
-#else	/* CONFIG_MCI_IMX_ESDHC_PIO */
-	if (!(data->flags & MMC_DATA_READ)) {
-		if ((esdhc_read32(regs + SDHCI_PRESENT_STATE) & PRSSTAT_WPSPL) == 0) {
-			printf("\nThe SD card is locked. "
-				"Can not write to a locked card.\n\n");
-			return -ETIMEDOUT;
+			esdhc_clrsetbits32(regs + IMX_SDHCI_WML, WML_WR_WML_MASK,
+						wml_value << 16);
+			esdhc_write32(regs + SDHCI_DMA_ADDRESS, (u32)data->src);
 		}
-		esdhc_write32(regs + SDHCI_DMA_ADDRESS, (u32)data->src);
-	} else
-		esdhc_write32(regs + SDHCI_DMA_ADDRESS, (u32)data->dest);
-#endif	/* CONFIG_MCI_IMX_ESDHC_PIO */
+	}
 
 	esdhc_write32(regs + SDHCI_BLOCK_SIZE__BLOCK_COUNT, data->blocks << 16 | data->blocksize);
 
 	return 0;
 }
 
+static int esdhc_do_data(struct mci_host *mci, struct mci_data *data)
+{
+	struct fsl_esdhc_host *host = to_fsl_esdhc(mci);
+	void __iomem *regs = host->regs;
+	unsigned int num_bytes = data->blocks * data->blocksize;
+	u32 irqstat;
+
+	if (IS_ENABLED(CONFIG_MCI_IMX_ESDHC_PIO)) {
+		esdhc_pio_read_write(mci, data);
+		return 0;
+	}
+
+	do {
+		irqstat = esdhc_read32(regs + SDHCI_INT_STATUS);
+
+		if (irqstat & DATA_ERR)
+			return -EIO;
+
+		if (irqstat & IRQSTAT_DTOE)
+			return -ETIMEDOUT;
+	} while (!(irqstat & IRQSTAT_TC) &&
+		(esdhc_read32(regs + SDHCI_PRESENT_STATE) & PRSSTAT_DLA));
+
+	if (data->flags & MMC_DATA_WRITE)
+		dma_sync_single_for_cpu((unsigned long)data->src,
+					num_bytes, DMA_TO_DEVICE);
+	else
+		dma_sync_single_for_cpu((unsigned long)data->dest,
+					num_bytes, DMA_FROM_DEVICE);
+
+	return 0;
+}
 
 /*
  * Sends a command out on the bus.  Takes the mci pointer,
@@ -303,27 +335,9 @@ esdhc_send_cmd(struct mci_host *mci, struct mci_cmd *cmd, struct mci_data *data)
 
 	/* Wait until all of the blocks are transferred */
 	if (data) {
-#ifdef CONFIG_MCI_IMX_ESDHC_PIO
-		esdhc_pio_read_write(mci, data);
-#else
-		do {
-			irqstat = esdhc_read32(regs + SDHCI_INT_STATUS);
-
-			if (irqstat & DATA_ERR)
-				return -EIO;
-
-			if (irqstat & IRQSTAT_DTOE)
-				return -ETIMEDOUT;
-		} while (!(irqstat & IRQSTAT_TC) &&
-				(esdhc_read32(regs + SDHCI_PRESENT_STATE) & PRSSTAT_DLA));
-
-		if (data->flags & MMC_DATA_WRITE)
-			dma_sync_single_for_cpu((unsigned long)data->src,
-						num_bytes, DMA_TO_DEVICE);
-		else
-			dma_sync_single_for_cpu((unsigned long)data->dest,
-						num_bytes, DMA_FROM_DEVICE);
-#endif
+		ret = esdhc_do_data(mci, data);
+		if (ret)
+			return ret;
 	}
 
 	esdhc_write32(regs + SDHCI_INT_STATUS, -1);
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2015-05-13  6:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-13  6:20 Sascha Hauer [this message]
2015-05-13  6:20 ` [PATCH 2/3] mci: imx-esdhc: Check for errors in esdhc_pio_read_write Sascha Hauer
2015-05-13  6:20 ` [PATCH 3/3] mci: imx-esdhc: Replace printf with dev_* Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431498037-31789-1-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox