All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] Some cleanup for dwmmc
@ 2017-02-17  2:56 ` Shawn Lin
  2017-02-17  2:56   ` [PATCH 1/7] mmc: dw_mmc: improve the timeout polling code Shawn Lin
                     ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Shawn Lin @ 2017-02-17  2:56 UTC (permalink / raw)
  To: Jaehoon Chung; +Cc: Ulf Hansson, linux-mmc, Shawn Lin


Hi Jaehoon,

This is the first part of long term cleanup for dwmmc we need.
No functional changes here, but just to remove the unnecessary
function declare and improve the logic of dw_mci_reset for better
understood.



Shawn Lin (7):
  mmc: dw_mmc: improve the timeout polling code
  mmc: dw_mmc: move dw_mci_reset forward to avoid declaration
  mmc: dw_mmc: move dw_mci_ctrl_reset forward to avoid declaration
  mmc: dw_mmc: move dw_mci_get_cd forward to avoid declaration
  mmc: dw_mmc: remove declaration of dw_mci_card_busy
  mmc: dw_mmc: move mci_send_cmd forward to avoid declaration
  mmc: dw_mmc: improve dw_mci_reset a bit

 drivers/mmc/host/dw_mmc.c | 383 ++++++++++++++++++++++------------------------
 1 file changed, 182 insertions(+), 201 deletions(-)

-- 
1.9.1



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/7] mmc: dw_mmc: improve the timeout polling code
  2017-02-17  2:56 ` [PATCH 0/7] Some cleanup for dwmmc Shawn Lin
@ 2017-02-17  2:56   ` Shawn Lin
  2017-02-17  2:56   ` [PATCH 2/7] mmc: dw_mmc: move dw_mci_reset forward to avoid declaration Shawn Lin
                     ` (7 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Shawn Lin @ 2017-02-17  2:56 UTC (permalink / raw)
  To: Jaehoon Chung; +Cc: Ulf Hansson, linux-mmc, Shawn Lin

Just use the readl_poll_timeout{_atomic} to avold open
coding them.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

 drivers/mmc/host/dw_mmc.c | 92 ++++++++++++++++++++---------------------------
 1 file changed, 39 insertions(+), 53 deletions(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index a9ac0b4..a1ddbb8 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -19,6 +19,7 @@
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
+#include <linux/iopoll.h>
 #include <linux/ioport.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
@@ -64,6 +65,8 @@
 
 struct idmac_desc_64addr {
 	u32		des0;	/* Control Descriptor */
+#define IDMAC_OWN_CLR64(x) \
+	!((x) & cpu_to_le32(IDMAC_DES0_OWN))
 
 	u32		des1;	/* Reserved */
 
@@ -342,7 +345,7 @@ static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
 
 static void dw_mci_wait_while_busy(struct dw_mci *host, u32 cmd_flags)
 {
-	unsigned long timeout = jiffies + msecs_to_jiffies(500);
+	u32 status;
 
 	/*
 	 * Databook says that before issuing a new data transfer command
@@ -354,14 +357,11 @@ static void dw_mci_wait_while_busy(struct dw_mci *host, u32 cmd_flags)
 	 */
 	if ((cmd_flags & SDMMC_CMD_PRV_DAT_WAIT) &&
 	    !(cmd_flags & SDMMC_CMD_VOLT_SWITCH)) {
-		while (mci_readl(host, STATUS) & SDMMC_STATUS_BUSY) {
-			if (time_after(jiffies, timeout)) {
-				/* Command will fail; we'll pass error then */
-				dev_err(host->dev, "Busy; trying anyway\n");
-				break;
-			}
-			udelay(10);
-		}
+		if (readl_poll_timeout_atomic(host->regs + SDMMC_STATUS,
+					      status,
+					      !(status & SDMMC_STATUS_BUSY),
+					      10, 500 * USEC_PER_MSEC))
+			dev_err(host->dev, "Busy; trying anyway\n");
 	}
 }
 
@@ -554,7 +554,7 @@ static inline int dw_mci_prepare_desc64(struct dw_mci *host,
 {
 	unsigned int desc_len;
 	struct idmac_desc_64addr *desc_first, *desc_last, *desc;
-	unsigned long timeout;
+	u32 val;
 	int i;
 
 	desc_first = desc_last = desc = host->sg_cpu;
@@ -576,12 +576,10 @@ static inline int dw_mci_prepare_desc64(struct dw_mci *host,
 			 * isn't still owned by IDMAC as IDMAC's write
 			 * ops and CPU's read ops are asynchronous.
 			 */
-			timeout = jiffies + msecs_to_jiffies(100);
-			while (readl(&desc->des0) & IDMAC_DES0_OWN) {
-				if (time_after(jiffies, timeout))
-					goto err_own_bit;
-				udelay(10);
-			}
+			if (readl_poll_timeout_atomic(&desc->des0, val,
+						!(val & IDMAC_DES0_OWN),
+						10, 100 * USEC_PER_MSEC))
+				goto err_own_bit;
 
 			/*
 			 * Set the OWN bit and disable interrupts
@@ -628,7 +626,7 @@ static inline int dw_mci_prepare_desc32(struct dw_mci *host,
 {
 	unsigned int desc_len;
 	struct idmac_desc *desc_first, *desc_last, *desc;
-	unsigned long timeout;
+	u32 val;
 	int i;
 
 	desc_first = desc_last = desc = host->sg_cpu;
@@ -650,13 +648,11 @@ static inline int dw_mci_prepare_desc32(struct dw_mci *host,
 			 * isn't still owned by IDMAC as IDMAC's write
 			 * ops and CPU's read ops are asynchronous.
 			 */
-			timeout = jiffies + msecs_to_jiffies(100);
-			while (readl(&desc->des0) &
-			       cpu_to_le32(IDMAC_DES0_OWN)) {
-				if (time_after(jiffies, timeout))
-					goto err_own_bit;
-				udelay(10);
-			}
+			if (readl_poll_timeout_atomic(&desc->des0, val,
+						      IDMAC_OWN_CLR64(val),
+						      10,
+						      100 * USEC_PER_MSEC))
+				goto err_own_bit;
 
 			/*
 			 * Set the OWN bit and disable interrupts
@@ -1135,7 +1131,6 @@ static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
 static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
 {
 	struct dw_mci *host = slot->host;
-	unsigned long timeout = jiffies + msecs_to_jiffies(500);
 	unsigned int cmd_status = 0;
 
 	mci_writel(host, CMDARG, arg);
@@ -1143,14 +1138,12 @@ static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
 	dw_mci_wait_while_busy(host, cmd);
 	mci_writel(host, CMD, SDMMC_CMD_START | cmd);
 
-	while (time_before(jiffies, timeout)) {
-		cmd_status = mci_readl(host, CMD);
-		if (!(cmd_status & SDMMC_CMD_START))
-			return;
-	}
-	dev_err(&slot->mmc->class_dev,
-		"Timeout sending command (cmd %#x arg %#x status %#x)\n",
-		cmd, arg, cmd_status);
+	if (readl_poll_timeout_atomic(host->regs + SDMMC_CMD, cmd_status,
+				      !(cmd_status & SDMMC_CMD_START),
+				      1, 500 * USEC_PER_MSEC))
+		dev_err(&slot->mmc->class_dev,
+			"Timeout sending command (cmd %#x arg %#x status %#x)\n",
+			cmd, arg, cmd_status);
 }
 
 static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
@@ -2825,7 +2818,6 @@ static void dw_mci_init_dma(struct dw_mci *host)
 
 static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
 {
-	unsigned long timeout = jiffies + msecs_to_jiffies(500);
 	u32 ctrl;
 
 	ctrl = mci_readl(host, CTRL);
@@ -2833,17 +2825,16 @@ static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
 	mci_writel(host, CTRL, ctrl);
 
 	/* wait till resets clear */
-	do {
-		ctrl = mci_readl(host, CTRL);
-		if (!(ctrl & reset))
-			return true;
-	} while (time_before(jiffies, timeout));
-
-	dev_err(host->dev,
-		"Timeout resetting block (ctrl reset %#x)\n",
-		ctrl & reset);
+	if (readl_poll_timeout_atomic(host->regs + SDMMC_CTRL, ctrl,
+				      !(ctrl & reset),
+				      1, 500 * USEC_PER_MSEC)) {
+		dev_err(host->dev,
+			"Timeout resetting block (ctrl reset %#x)\n",
+			ctrl & reset);
+		return false;
+	}
 
-	return false;
+	return true;
 }
 
 static bool dw_mci_reset(struct dw_mci *host)
@@ -2872,17 +2863,12 @@ static bool dw_mci_reset(struct dw_mci *host)
 
 		/* if using dma we wait for dma_req to clear */
 		if (host->use_dma) {
-			unsigned long timeout = jiffies + msecs_to_jiffies(500);
 			u32 status;
 
-			do {
-				status = mci_readl(host, STATUS);
-				if (!(status & SDMMC_STATUS_DMA_REQ))
-					break;
-				cpu_relax();
-			} while (time_before(jiffies, timeout));
-
-			if (status & SDMMC_STATUS_DMA_REQ) {
+			if (readl_poll_timeout_atomic(host->regs + SDMMC_STATUS,
+						      status,
+						      !(status & SDMMC_STATUS_DMA_REQ),
+						      1, 500 * USEC_PER_MSEC)) {
 				dev_err(host->dev,
 					"%s: Timeout waiting for dma_req to clear during reset\n",
 					__func__);
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/7] mmc: dw_mmc: move dw_mci_reset forward to avoid declaration
  2017-02-17  2:56 ` [PATCH 0/7] Some cleanup for dwmmc Shawn Lin
  2017-02-17  2:56   ` [PATCH 1/7] mmc: dw_mmc: improve the timeout polling code Shawn Lin
@ 2017-02-17  2:56   ` Shawn Lin
  2017-02-17  2:56   ` [PATCH 3/7] mmc: dw_mmc: move dw_mci_ctrl_reset " Shawn Lin
                     ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Shawn Lin @ 2017-02-17  2:56 UTC (permalink / raw)
  To: Jaehoon Chung; +Cc: Ulf Hansson, linux-mmc, Shawn Lin

No functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

 drivers/mmc/host/dw_mmc.c | 131 +++++++++++++++++++++++-----------------------
 1 file changed, 65 insertions(+), 66 deletions(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index a1ddbb8..20fe96c8 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -106,7 +106,6 @@ struct idmac_desc {
 /* Each descriptor can transfer up to 4KB of data in chained mode */
 #define DW_MCI_DESC_DATA_LENGTH	0x1000
 
-static bool dw_mci_reset(struct dw_mci *host);
 static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset);
 static int dw_mci_card_busy(struct mmc_host *mmc);
 static int dw_mci_get_cd(struct mmc_host *mmc);
@@ -1674,6 +1673,71 @@ static int dw_mci_prepare_hs400_tuning(struct mmc_host *mmc,
 	return 0;
 }
 
+static bool dw_mci_reset(struct dw_mci *host)
+{
+	u32 flags = SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET;
+	bool ret = false;
+
+	/*
+	 * Resetting generates a block interrupt, hence setting
+	 * the scatter-gather pointer to NULL.
+	 */
+	if (host->sg) {
+		sg_miter_stop(&host->sg_miter);
+		host->sg = NULL;
+	}
+
+	if (host->use_dma)
+		flags |= SDMMC_CTRL_DMA_RESET;
+
+	if (dw_mci_ctrl_reset(host, flags)) {
+		/*
+		 * In all cases we clear the RAWINTS register to clear any
+		 * interrupts.
+		 */
+		mci_writel(host, RINTSTS, 0xFFFFFFFF);
+
+		/* if using dma we wait for dma_req to clear */
+		if (host->use_dma) {
+			u32 status;
+
+			if (readl_poll_timeout_atomic(host->regs + SDMMC_STATUS,
+						      status,
+						      !(status & SDMMC_STATUS_DMA_REQ),
+						      1, 500 * USEC_PER_MSEC)) {
+				dev_err(host->dev,
+					"%s: Timeout waiting for dma_req to clear during reset\n",
+					__func__);
+				goto ciu_out;
+			}
+
+			/* when using DMA next we reset the fifo again */
+			if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET))
+				goto ciu_out;
+		}
+	} else {
+		/* if the controller reset bit did clear, then set clock regs */
+		if (!(mci_readl(host, CTRL) & SDMMC_CTRL_RESET)) {
+			dev_err(host->dev,
+				"%s: fifo/dma reset bits didn't clear but ciu was reset, doing clock update\n",
+				__func__);
+			goto ciu_out;
+		}
+	}
+
+	if (host->use_dma == TRANS_MODE_IDMAC)
+		/* It is also recommended that we reset and reprogram idmac */
+		dw_mci_idmac_reset(host);
+
+	ret = true;
+
+ciu_out:
+	/* After a CTRL reset we need to have CIU set clock registers  */
+	mci_send_cmd(host->cur_slot, SDMMC_CMD_UPD_CLK, 0);
+
+	return ret;
+}
+
 static const struct mmc_host_ops dw_mci_ops = {
 	.request		= dw_mci_request,
 	.pre_req		= dw_mci_pre_req,
@@ -2837,71 +2901,6 @@ static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
 	return true;
 }
 
-static bool dw_mci_reset(struct dw_mci *host)
-{
-	u32 flags = SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET;
-	bool ret = false;
-
-	/*
-	 * 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;
-	}
-
-	if (host->use_dma)
-		flags |= SDMMC_CTRL_DMA_RESET;
-
-	if (dw_mci_ctrl_reset(host, flags)) {
-		/*
-		 * In all cases we clear the RAWINTS register to clear any
-		 * interrupts.
-		 */
-		mci_writel(host, RINTSTS, 0xFFFFFFFF);
-
-		/* if using dma we wait for dma_req to clear */
-		if (host->use_dma) {
-			u32 status;
-
-			if (readl_poll_timeout_atomic(host->regs + SDMMC_STATUS,
-						      status,
-						      !(status & SDMMC_STATUS_DMA_REQ),
-						      1, 500 * USEC_PER_MSEC)) {
-				dev_err(host->dev,
-					"%s: Timeout waiting for dma_req to clear during reset\n",
-					__func__);
-				goto ciu_out;
-			}
-
-			/* when using DMA next we reset the fifo again */
-			if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET))
-				goto ciu_out;
-		}
-	} else {
-		/* if the controller reset bit did clear, then set clock regs */
-		if (!(mci_readl(host, CTRL) & SDMMC_CTRL_RESET)) {
-			dev_err(host->dev,
-				"%s: fifo/dma reset bits didn't clear but ciu was reset, doing clock update\n",
-				__func__);
-			goto ciu_out;
-		}
-	}
-
-	if (host->use_dma == TRANS_MODE_IDMAC)
-		/* It is also recommended that we reset and reprogram idmac */
-		dw_mci_idmac_reset(host);
-
-	ret = true;
-
-ciu_out:
-	/* After a CTRL reset we need to have CIU set clock registers  */
-	mci_send_cmd(host->cur_slot, SDMMC_CMD_UPD_CLK, 0);
-
-	return ret;
-}
-
 static void dw_mci_cmd11_timer(unsigned long arg)
 {
 	struct dw_mci *host = (struct dw_mci *)arg;
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/7] mmc: dw_mmc: move dw_mci_ctrl_reset forward to avoid declaration
  2017-02-17  2:56 ` [PATCH 0/7] Some cleanup for dwmmc Shawn Lin
  2017-02-17  2:56   ` [PATCH 1/7] mmc: dw_mmc: improve the timeout polling code Shawn Lin
  2017-02-17  2:56   ` [PATCH 2/7] mmc: dw_mmc: move dw_mci_reset forward to avoid declaration Shawn Lin
@ 2017-02-17  2:56   ` Shawn Lin
  2017-02-17  2:56   ` [PATCH 4/7] mmc: dw_mmc: move dw_mci_get_cd " Shawn Lin
                     ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Shawn Lin @ 2017-02-17  2:56 UTC (permalink / raw)
  To: Jaehoon Chung; +Cc: Ulf Hansson, linux-mmc, Shawn Lin

No functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

 drivers/mmc/host/dw_mmc.c | 42 ++++++++++++++++++++----------------------
 1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 20fe96c8..e87fd95 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -106,7 +106,6 @@ struct idmac_desc {
 /* Each descriptor can transfer up to 4KB of data in chained mode */
 #define DW_MCI_DESC_DATA_LENGTH	0x1000
 
-static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset);
 static int dw_mci_card_busy(struct mmc_host *mmc);
 static int dw_mci_get_cd(struct mmc_host *mmc);
 
@@ -234,6 +233,26 @@ static void dw_mci_init_debugfs(struct dw_mci_slot *slot)
 #endif /* defined(CONFIG_DEBUG_FS) */
 
 static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg);
+static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
+{
+	u32 ctrl;
+
+	ctrl = mci_readl(host, CTRL);
+	ctrl |= reset;
+	mci_writel(host, CTRL, ctrl);
+
+	/* wait till resets clear */
+	if (readl_poll_timeout_atomic(host->regs + SDMMC_CTRL, ctrl,
+				      !(ctrl & reset),
+				      1, 500 * USEC_PER_MSEC)) {
+		dev_err(host->dev,
+			"Timeout resetting block (ctrl reset %#x)\n",
+			ctrl & reset);
+		return false;
+	}
+
+	return true;
+}
 
 static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
 {
@@ -2880,27 +2899,6 @@ static void dw_mci_init_dma(struct dw_mci *host)
 	host->use_dma = TRANS_MODE_PIO;
 }
 
-static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
-{
-	u32 ctrl;
-
-	ctrl = mci_readl(host, CTRL);
-	ctrl |= reset;
-	mci_writel(host, CTRL, ctrl);
-
-	/* wait till resets clear */
-	if (readl_poll_timeout_atomic(host->regs + SDMMC_CTRL, ctrl,
-				      !(ctrl & reset),
-				      1, 500 * USEC_PER_MSEC)) {
-		dev_err(host->dev,
-			"Timeout resetting block (ctrl reset %#x)\n",
-			ctrl & reset);
-		return false;
-	}
-
-	return true;
-}
-
 static void dw_mci_cmd11_timer(unsigned long arg)
 {
 	struct dw_mci *host = (struct dw_mci *)arg;
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/7] mmc: dw_mmc: move dw_mci_get_cd forward to avoid declaration
  2017-02-17  2:56 ` [PATCH 0/7] Some cleanup for dwmmc Shawn Lin
                     ` (2 preceding siblings ...)
  2017-02-17  2:56   ` [PATCH 3/7] mmc: dw_mmc: move dw_mci_ctrl_reset " Shawn Lin
@ 2017-02-17  2:56   ` Shawn Lin
  2017-02-17  2:59   ` [PATCH 5/7] mmc: dw_mmc: remove declaration of dw_mci_card_busy Shawn Lin
                     ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Shawn Lin @ 2017-02-17  2:56 UTC (permalink / raw)
  To: Jaehoon Chung; +Cc: Ulf Hansson, linux-mmc, Shawn Lin

No functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

 drivers/mmc/host/dw_mmc.c | 83 +++++++++++++++++++++++------------------------
 1 file changed, 41 insertions(+), 42 deletions(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index e87fd95..936de76 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -107,7 +107,6 @@ struct idmac_desc {
 #define DW_MCI_DESC_DATA_LENGTH	0x1000
 
 static int dw_mci_card_busy(struct mmc_host *mmc);
-static int dw_mci_get_cd(struct mmc_host *mmc);
 
 #if defined(CONFIG_DEBUG_FS)
 static int dw_mci_req_show(struct seq_file *s, void *v)
@@ -933,6 +932,47 @@ static void dw_mci_post_req(struct mmc_host *mmc,
 	data->host_cookie = COOKIE_UNMAPPED;
 }
 
+static int dw_mci_get_cd(struct mmc_host *mmc)
+{
+	int present;
+	struct dw_mci_slot *slot = mmc_priv(mmc);
+	struct dw_mci *host = slot->host;
+	int gpio_cd = mmc_gpio_get_cd(mmc);
+
+	/* Use platform get_cd function, else try onboard card detect */
+	if (((mmc->caps & MMC_CAP_NEEDS_POLL)
+				|| !mmc_card_is_removable(mmc))) {
+		present = 1;
+
+		if (!test_bit(DW_MMC_CARD_PRESENT, &slot->flags)) {
+			if (mmc->caps & MMC_CAP_NEEDS_POLL) {
+				dev_info(&mmc->class_dev,
+					"card is polling.\n");
+			} else {
+				dev_info(&mmc->class_dev,
+					"card is non-removable.\n");
+			}
+			set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
+		}
+
+		return present;
+	} else if (gpio_cd >= 0)
+		present = gpio_cd;
+	else
+		present = (mci_readl(slot->host, CDETECT) & (1 << slot->id))
+			== 0 ? 1 : 0;
+
+	spin_lock_bh(&host->lock);
+	if (present && !test_and_set_bit(DW_MMC_CARD_PRESENT, &slot->flags))
+		dev_dbg(&mmc->class_dev, "card is present\n");
+	else if (!present &&
+			!test_and_clear_bit(DW_MMC_CARD_PRESENT, &slot->flags))
+		dev_dbg(&mmc->class_dev, "card is not present\n");
+	spin_unlock_bh(&host->lock);
+
+	return present;
+}
+
 static void dw_mci_adjust_fifoth(struct dw_mci *host, struct mmc_data *data)
 {
 	unsigned int blksz = data->blksz;
@@ -1544,47 +1584,6 @@ static int dw_mci_get_ro(struct mmc_host *mmc)
 	return read_only;
 }
 
-static int dw_mci_get_cd(struct mmc_host *mmc)
-{
-	int present;
-	struct dw_mci_slot *slot = mmc_priv(mmc);
-	struct dw_mci *host = slot->host;
-	int gpio_cd = mmc_gpio_get_cd(mmc);
-
-	/* Use platform get_cd function, else try onboard card detect */
-	if (((mmc->caps & MMC_CAP_NEEDS_POLL)
-				|| !mmc_card_is_removable(mmc))) {
-		present = 1;
-
-		if (!test_bit(DW_MMC_CARD_PRESENT, &slot->flags)) {
-			if (mmc->caps & MMC_CAP_NEEDS_POLL) {
-				dev_info(&mmc->class_dev,
-					"card is polling.\n");
-			} else {
-				dev_info(&mmc->class_dev,
-					"card is non-removable.\n");
-			}
-			set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
-		}
-
-		return present;
-	} else if (gpio_cd >= 0)
-		present = gpio_cd;
-	else
-		present = (mci_readl(slot->host, CDETECT) & (1 << slot->id))
-			== 0 ? 1 : 0;
-
-	spin_lock_bh(&host->lock);
-	if (present && !test_and_set_bit(DW_MMC_CARD_PRESENT, &slot->flags))
-		dev_dbg(&mmc->class_dev, "card is present\n");
-	else if (!present &&
-			!test_and_clear_bit(DW_MMC_CARD_PRESENT, &slot->flags))
-		dev_dbg(&mmc->class_dev, "card is not present\n");
-	spin_unlock_bh(&host->lock);
-
-	return present;
-}
-
 static void dw_mci_hw_reset(struct mmc_host *mmc)
 {
 	struct dw_mci_slot *slot = mmc_priv(mmc);
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/7] mmc: dw_mmc: remove declaration of dw_mci_card_busy
  2017-02-17  2:56 ` [PATCH 0/7] Some cleanup for dwmmc Shawn Lin
                     ` (3 preceding siblings ...)
  2017-02-17  2:56   ` [PATCH 4/7] mmc: dw_mmc: move dw_mci_get_cd " Shawn Lin
@ 2017-02-17  2:59   ` Shawn Lin
  2017-02-17  2:59   ` [PATCH 6/7] mmc: dw_mmc: move mci_send_cmd forward to avoid declaration Shawn Lin
                     ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Shawn Lin @ 2017-02-17  2:59 UTC (permalink / raw)
  To: Jaehoon Chung; +Cc: Ulf Hansson, linux-mmc, Shawn Lin

No need to declar it there, remove it.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

 drivers/mmc/host/dw_mmc.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 936de76..e8c5ee2 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -106,8 +106,6 @@ struct idmac_desc {
 /* Each descriptor can transfer up to 4KB of data in chained mode */
 #define DW_MCI_DESC_DATA_LENGTH	0x1000
 
-static int dw_mci_card_busy(struct mmc_host *mmc);
-
 #if defined(CONFIG_DEBUG_FS)
 static int dw_mci_req_show(struct seq_file *s, void *v)
 {
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 6/7] mmc: dw_mmc: move mci_send_cmd forward to avoid declaration
  2017-02-17  2:56 ` [PATCH 0/7] Some cleanup for dwmmc Shawn Lin
                     ` (4 preceding siblings ...)
  2017-02-17  2:59   ` [PATCH 5/7] mmc: dw_mmc: remove declaration of dw_mci_card_busy Shawn Lin
@ 2017-02-17  2:59   ` Shawn Lin
  2017-02-17  2:59   ` [PATCH 7/7] mmc: dw_mmc: improve dw_mci_reset a bit Shawn Lin
                     ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Shawn Lin @ 2017-02-17  2:59 UTC (permalink / raw)
  To: Jaehoon Chung; +Cc: Ulf Hansson, linux-mmc, Shawn Lin

No functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

 drivers/mmc/host/dw_mmc.c | 81 +++++++++++++++++++++++------------------------
 1 file changed, 40 insertions(+), 41 deletions(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index e8c5ee2..a4a43e6 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -229,7 +229,6 @@ static void dw_mci_init_debugfs(struct dw_mci_slot *slot)
 }
 #endif /* defined(CONFIG_DEBUG_FS) */
 
-static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg);
 static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
 {
 	u32 ctrl;
@@ -251,6 +250,46 @@ static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
 	return true;
 }
 
+static void dw_mci_wait_while_busy(struct dw_mci *host, u32 cmd_flags)
+{
+	u32 status;
+
+	/*
+	 * Databook says that before issuing a new data transfer command
+	 * we need to check to see if the card is busy.  Data transfer commands
+	 * all have SDMMC_CMD_PRV_DAT_WAIT set, so we'll key off that.
+	 *
+	 * ...also allow sending for SDMMC_CMD_VOLT_SWITCH where busy is
+	 * expected.
+	 */
+	if ((cmd_flags & SDMMC_CMD_PRV_DAT_WAIT) &&
+	    !(cmd_flags & SDMMC_CMD_VOLT_SWITCH)) {
+		if (readl_poll_timeout_atomic(host->regs + SDMMC_STATUS,
+					      status,
+					      !(status & SDMMC_STATUS_BUSY),
+					      10, 500 * USEC_PER_MSEC))
+			dev_err(host->dev, "Busy; trying anyway\n");
+	}
+}
+
+static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
+{
+	struct dw_mci *host = slot->host;
+	unsigned int cmd_status = 0;
+
+	mci_writel(host, CMDARG, arg);
+	wmb(); /* drain writebuffer */
+	dw_mci_wait_while_busy(host, cmd);
+	mci_writel(host, CMD, SDMMC_CMD_START | cmd);
+
+	if (readl_poll_timeout_atomic(host->regs + SDMMC_CMD, cmd_status,
+				      !(cmd_status & SDMMC_CMD_START),
+				      1, 500 * USEC_PER_MSEC))
+		dev_err(&slot->mmc->class_dev,
+			"Timeout sending command (cmd %#x arg %#x status %#x)\n",
+			cmd, arg, cmd_status);
+}
+
 static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
 {
 	struct dw_mci_slot *slot = mmc_priv(mmc);
@@ -358,28 +397,6 @@ static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
 	return cmdr;
 }
 
-static void dw_mci_wait_while_busy(struct dw_mci *host, u32 cmd_flags)
-{
-	u32 status;
-
-	/*
-	 * Databook says that before issuing a new data transfer command
-	 * we need to check to see if the card is busy.  Data transfer commands
-	 * all have SDMMC_CMD_PRV_DAT_WAIT set, so we'll key off that.
-	 *
-	 * ...also allow sending for SDMMC_CMD_VOLT_SWITCH where busy is
-	 * expected.
-	 */
-	if ((cmd_flags & SDMMC_CMD_PRV_DAT_WAIT) &&
-	    !(cmd_flags & SDMMC_CMD_VOLT_SWITCH)) {
-		if (readl_poll_timeout_atomic(host->regs + SDMMC_STATUS,
-					      status,
-					      !(status & SDMMC_STATUS_BUSY),
-					      10, 500 * USEC_PER_MSEC))
-			dev_err(host->dev, "Busy; trying anyway\n");
-	}
-}
-
 static void dw_mci_start_command(struct dw_mci *host,
 				 struct mmc_command *cmd, u32 cmd_flags)
 {
@@ -1184,24 +1201,6 @@ static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
 	}
 }
 
-static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
-{
-	struct dw_mci *host = slot->host;
-	unsigned int cmd_status = 0;
-
-	mci_writel(host, CMDARG, arg);
-	wmb(); /* drain writebuffer */
-	dw_mci_wait_while_busy(host, cmd);
-	mci_writel(host, CMD, SDMMC_CMD_START | cmd);
-
-	if (readl_poll_timeout_atomic(host->regs + SDMMC_CMD, cmd_status,
-				      !(cmd_status & SDMMC_CMD_START),
-				      1, 500 * USEC_PER_MSEC))
-		dev_err(&slot->mmc->class_dev,
-			"Timeout sending command (cmd %#x arg %#x status %#x)\n",
-			cmd, arg, cmd_status);
-}
-
 static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
 {
 	struct dw_mci *host = slot->host;
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 7/7] mmc: dw_mmc: improve dw_mci_reset a bit
  2017-02-17  2:56 ` [PATCH 0/7] Some cleanup for dwmmc Shawn Lin
                     ` (5 preceding siblings ...)
  2017-02-17  2:59   ` [PATCH 6/7] mmc: dw_mmc: move mci_send_cmd forward to avoid declaration Shawn Lin
@ 2017-02-17  2:59   ` Shawn Lin
  2017-02-27 11:41   ` [PATCH 0/7] Some cleanup for dwmmc Jaehoon Chung
  2017-03-03  2:01   ` Jaehoon Chung
  8 siblings, 0 replies; 11+ messages in thread
From: Shawn Lin @ 2017-02-17  2:59 UTC (permalink / raw)
  To: Jaehoon Chung; +Cc: Ulf Hansson, linux-mmc, Shawn Lin

Too much condition iteration makes the code
less readable. Slightly improve it.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>

---

 drivers/mmc/host/dw_mmc.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index a4a43e6..e165db05 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -1692,6 +1692,7 @@ static bool dw_mci_reset(struct dw_mci *host)
 {
 	u32 flags = SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET;
 	bool ret = false;
+	u32 status = 0;
 
 	/*
 	 * Resetting generates a block interrupt, hence setting
@@ -1707,29 +1708,30 @@ static bool dw_mci_reset(struct dw_mci *host)
 
 	if (dw_mci_ctrl_reset(host, flags)) {
 		/*
-		 * In all cases we clear the RAWINTS register to clear any
-		 * interrupts.
+		 * In all cases we clear the RAWINTS
+		 * register to clear any interrupts.
 		 */
 		mci_writel(host, RINTSTS, 0xFFFFFFFF);
 
-		/* if using dma we wait for dma_req to clear */
-		if (host->use_dma) {
-			u32 status;
-
-			if (readl_poll_timeout_atomic(host->regs + SDMMC_STATUS,
-						      status,
-						      !(status & SDMMC_STATUS_DMA_REQ),
-						      1, 500 * USEC_PER_MSEC)) {
-				dev_err(host->dev,
-					"%s: Timeout waiting for dma_req to clear during reset\n",
-					__func__);
-				goto ciu_out;
-			}
+		if (!host->use_dma) {
+			ret = true;
+			goto ciu_out;
+		}
 
-			/* when using DMA next we reset the fifo again */
-			if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET))
-				goto ciu_out;
+		/* Wait for dma_req to be cleared */
+		if (readl_poll_timeout_atomic(host->regs + SDMMC_STATUS,
+					      status,
+					      !(status & SDMMC_STATUS_DMA_REQ),
+					      1, 500 * USEC_PER_MSEC)) {
+			dev_err(host->dev,
+				"%s: Timeout waiting for dma_req to be cleared\n",
+				__func__);
+			goto ciu_out;
 		}
+
+		/* when using DMA next we reset the fifo again */
+		if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET))
+			goto ciu_out;
 	} else {
 		/* if the controller reset bit did clear, then set clock regs */
 		if (!(mci_readl(host, CTRL) & SDMMC_CTRL_RESET)) {
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/7] Some cleanup for dwmmc
  2017-02-17  2:56 ` [PATCH 0/7] Some cleanup for dwmmc Shawn Lin
                     ` (6 preceding siblings ...)
  2017-02-17  2:59   ` [PATCH 7/7] mmc: dw_mmc: improve dw_mci_reset a bit Shawn Lin
@ 2017-02-27 11:41   ` Jaehoon Chung
  2017-03-03  2:01   ` Jaehoon Chung
  8 siblings, 0 replies; 11+ messages in thread
From: Jaehoon Chung @ 2017-02-27 11:41 UTC (permalink / raw)
  To: Shawn Lin; +Cc: Ulf Hansson, linux-mmc

Hi Shawn,

On 02/17/2017 11:56 AM, Shawn Lin wrote:
> Hi Jaehoon,
> 
> This is the first part of long term cleanup for dwmmc we need.
> No functional changes here, but just to remove the unnecessary
> function declare and improve the logic of dw_mci_reset for better
> understood.
> 

Thanks for sending patches. I'm doing the other things now..
So i will apply on these patches within this week. After checking.

I think this patches will be for 4.12..Sorry for late.

Best Regards,
Jaehoon Chung

> 
> 
> Shawn Lin (7):
>   mmc: dw_mmc: improve the timeout polling code
>   mmc: dw_mmc: move dw_mci_reset forward to avoid declaration
>   mmc: dw_mmc: move dw_mci_ctrl_reset forward to avoid declaration
>   mmc: dw_mmc: move dw_mci_get_cd forward to avoid declaration
>   mmc: dw_mmc: remove declaration of dw_mci_card_busy
>   mmc: dw_mmc: move mci_send_cmd forward to avoid declaration
>   mmc: dw_mmc: improve dw_mci_reset a bit
> 
>  drivers/mmc/host/dw_mmc.c | 383 ++++++++++++++++++++++------------------------
>  1 file changed, 182 insertions(+), 201 deletions(-)
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/7] Some cleanup for dwmmc
  2017-02-17  2:56 ` [PATCH 0/7] Some cleanup for dwmmc Shawn Lin
                     ` (7 preceding siblings ...)
  2017-02-27 11:41   ` [PATCH 0/7] Some cleanup for dwmmc Jaehoon Chung
@ 2017-03-03  2:01   ` Jaehoon Chung
  2017-03-03  2:11     ` Shawn Lin
  8 siblings, 1 reply; 11+ messages in thread
From: Jaehoon Chung @ 2017-03-03  2:01 UTC (permalink / raw)
  To: Shawn Lin; +Cc: Ulf Hansson, linux-mmc

On 02/17/2017 11:56 AM, Shawn Lin wrote:
> Hi Jaehoon,
> 
> This is the first part of long term cleanup for dwmmc we need.
> No functional changes here, but just to remove the unnecessary
> function declare and improve the logic of dw_mci_reset for better
> understood.
> 

Applied on my repository. Thanks!

Best Regards,
Jaehoon Chung

> 
> 
> Shawn Lin (7):
>   mmc: dw_mmc: improve the timeout polling code
>   mmc: dw_mmc: move dw_mci_reset forward to avoid declaration
>   mmc: dw_mmc: move dw_mci_ctrl_reset forward to avoid declaration
>   mmc: dw_mmc: move dw_mci_get_cd forward to avoid declaration
>   mmc: dw_mmc: remove declaration of dw_mci_card_busy
>   mmc: dw_mmc: move mci_send_cmd forward to avoid declaration
>   mmc: dw_mmc: improve dw_mci_reset a bit
> 
>  drivers/mmc/host/dw_mmc.c | 383 ++++++++++++++++++++++------------------------
>  1 file changed, 182 insertions(+), 201 deletions(-)
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/7] Some cleanup for dwmmc
  2017-03-03  2:01   ` Jaehoon Chung
@ 2017-03-03  2:11     ` Shawn Lin
  0 siblings, 0 replies; 11+ messages in thread
From: Shawn Lin @ 2017-03-03  2:11 UTC (permalink / raw)
  To: Jaehoon Chung; +Cc: shawn.lin, Ulf Hansson, linux-mmc

On 2017/3/3 10:01, Jaehoon Chung wrote:
> On 02/17/2017 11:56 AM, Shawn Lin wrote:
>> Hi Jaehoon,
>>
>> This is the first part of long term cleanup for dwmmc we need.
>> No functional changes here, but just to remove the unnecessary
>> function declare and improve the logic of dw_mci_reset for better
>> understood.
>>
>
> Applied on my repository. Thanks!

Thanks, Jeahoon!

>
> Best Regards,
> Jaehoon Chung
>
>>
>>
>> Shawn Lin (7):
>>   mmc: dw_mmc: improve the timeout polling code
>>   mmc: dw_mmc: move dw_mci_reset forward to avoid declaration
>>   mmc: dw_mmc: move dw_mci_ctrl_reset forward to avoid declaration
>>   mmc: dw_mmc: move dw_mci_get_cd forward to avoid declaration
>>   mmc: dw_mmc: remove declaration of dw_mci_card_busy
>>   mmc: dw_mmc: move mci_send_cmd forward to avoid declaration
>>   mmc: dw_mmc: improve dw_mci_reset a bit
>>
>>  drivers/mmc/host/dw_mmc.c | 383 ++++++++++++++++++++++------------------------
>>  1 file changed, 182 insertions(+), 201 deletions(-)
>>
>
>
>
>


-- 
Best Regards
Shawn Lin


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-03-03  3:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170217025924epcas3p2fdf980ca678240d2dc0ece07472202b6@epcas3p2.samsung.com>
2017-02-17  2:56 ` [PATCH 0/7] Some cleanup for dwmmc Shawn Lin
2017-02-17  2:56   ` [PATCH 1/7] mmc: dw_mmc: improve the timeout polling code Shawn Lin
2017-02-17  2:56   ` [PATCH 2/7] mmc: dw_mmc: move dw_mci_reset forward to avoid declaration Shawn Lin
2017-02-17  2:56   ` [PATCH 3/7] mmc: dw_mmc: move dw_mci_ctrl_reset " Shawn Lin
2017-02-17  2:56   ` [PATCH 4/7] mmc: dw_mmc: move dw_mci_get_cd " Shawn Lin
2017-02-17  2:59   ` [PATCH 5/7] mmc: dw_mmc: remove declaration of dw_mci_card_busy Shawn Lin
2017-02-17  2:59   ` [PATCH 6/7] mmc: dw_mmc: move mci_send_cmd forward to avoid declaration Shawn Lin
2017-02-17  2:59   ` [PATCH 7/7] mmc: dw_mmc: improve dw_mci_reset a bit Shawn Lin
2017-02-27 11:41   ` [PATCH 0/7] Some cleanup for dwmmc Jaehoon Chung
2017-03-03  2:01   ` Jaehoon Chung
2017-03-03  2:11     ` Shawn Lin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.