All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2] mmc: dw_mmc: change to use recommended reset procedure
@ 2014-05-13  1:38 ` Sonny Rao
  0 siblings, 0 replies; 75+ messages in thread
From: Sonny Rao @ 2014-05-13  1:38 UTC (permalink / raw)
  To: linux-mmc
  Cc: grundler, linux-samsung-soc, linux-arm-kernel, jh80.chung, cjb,
	tgih.jun, kgene.kim, joshi, t.figa, dianders, Yuvaraj Kumar C D,
	Sonny Rao

This patch changes the fifo reset code to follow the reset procedure
outlined in the documentation of Synopsys  Mobile storage host databook
7.2.13.

v2: Add Generic DMA support
    per the documentation, move interrupt clear before wait
    make the test for DMA host->use_dma rather than host->using_dma
    add proper return values (although it appears no caller checks)

Signed-off-by: Sonny Rao <sonnyrao@chromium.org>
Signed-off-by: Yuvaraj Kumar C D <yuvaraj.cd@samsung.com>
---
 drivers/mmc/host/dw_mmc.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/mmc/host/dw_mmc.h |  1 +
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 55cd110..aff57e1 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -2325,6 +2325,7 @@ static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
 
 static inline bool dw_mci_fifo_reset(struct dw_mci *host)
 {
+	u32 flags = SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET;
 	/*
 	 * Reseting generates a block interrupt, hence setting
 	 * the scatter-gather pointer to NULL.
@@ -2334,7 +2335,59 @@ static inline bool dw_mci_fifo_reset(struct dw_mci *host)
 		host->sg = NULL;
 	}
 
-	return dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET);
+	/*
+	 * The recommended method for resetting is to always reset the
+	 * controller and the fifo, but differs slightly depending on the mode.
+	 * The Generic DMA mode (non IDMAC) also needs to reset DMA where IDMAC
+	 * mode resets IDMAC at the end.
+	 *
+	 */
+#ifndef CONFIG_MMC_DW_IDMAC
+	if (host->use_dma)
+		flags |= SDMMC_CTRL_DMA_RESET;
+#endif
+	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) {
+			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) {
+				dev_err(host->dev,
+					"%s: Timeout waiting for dma_req to "
+					"clear during reset", __func__);
+				return false;
+			}
+
+			/* when using DMA next we reset the fifo again */
+			dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET);
+		}
+	} else {
+		dev_err(host->dev, "%s: Reset bits didn't clear", __func__);
+		return false;
+	}
+
+#ifdef CONFIG_MMC_DW_IDMAC
+	/* It is also recommended that we reset and reprogram idmac */
+	dw_mci_idmac_reset(host);
+#endif
+
+	/* After a CTRL reset we need to have CIU set clock registers  */
+	mci_send_cmd(host->cur_slot, SDMMC_CMD_UPD_CLK, 0);
+
+	return true;
 }
 
 static inline bool dw_mci_ctrl_all_reset(struct dw_mci *host)
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index 6bf24ab..2505804 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -129,6 +129,7 @@
 #define SDMMC_CMD_INDX(n)		((n) & 0x1F)
 /* Status register defines */
 #define SDMMC_GET_FCNT(x)		(((x)>>17) & 0x1FFF)
+#define SDMMC_STATUS_DMA_REQ		BIT(31)
 /* FIFOTH register defines */
 #define SDMMC_SET_FIFOTH(m, r, t)	(((m) & 0x7) << 28 | \
 					 ((r) & 0xFFF) << 16 | \
-- 
1.9.1.423.g4596e3a

^ permalink raw reply related	[flat|nested] 75+ messages in thread
* Re: linux-next: build failure after merge of the mmc-uh tree
@ 2014-08-04 13:44 Ulf Hansson
  2014-08-05  1:19   ` Sonny Rao
  0 siblings, 1 reply; 75+ messages in thread
From: Ulf Hansson @ 2014-08-04 13:44 UTC (permalink / raw)
  To: Sonny Rao; +Cc: Stephen Rothwell, linux-next, linux-kernel

On 28 July 2014 19:58, Sonny Rao <sonnyrao@chromium.org> wrote:
> On Sun, Jul 27, 2014 at 9:46 PM, Stephen Rothwell <sfr@canb.auug.org.au> wrote:
>> Hi Ulf,
>>
>> After merging the mmc-uh tree, today's linux-next build (arm
>> multi_v7_defconfig) failed like this:
>>
>> drivers/mmc/host/dw_mmc.c: In function 'dw_mci_reset':
>> drivers/mmc/host/dw_mmc.c:2262:3: error: implicit declaration of function 'dw_mci_idmac_reset' [-Werror=implicit-function-declaration]
>>    dw_mci_idmac_reset(host);
>>    ^
>
> Hi, sorry about that.  It looks like it fails to build when
> CONFIG_MMC_DW_IDMAC is not set.
> I changed that bit of code from using #ifdef to using just C if
> statement, but I think in this case the function being called doesn't
> exist when CONFIG_MMC_DW_IDMAC is not set, so that was incorrect and
> we should go back to using something like:
>
> #if IS_ENABLED(CONFIG_MMC_DW_IDMAC)
>         /* It is also recommended that we reset and reprogram idmac */
>         dw_mci_idmac_reset(host);
> #endif
>
>
> Ulf, I can respin the patch if you'd like or feel free to fix it
> yourself too.  Thanks.

I haven't got the time to fix this yet, sorry.

It would simplify a bit if you respin the patch, so please do so.

Kind regards
Uffe

>
>
>>
>> Caused by commit 25f7dadbd982 ("mmc: dw_mmc: change to use recommended
>> reset procedure").
>>
>> I have used the mmc-uh tree from next-20140725 for today.
>> --
>> Cheers,
>> Stephen Rothwell                    sfr@canb.auug.org.au

^ permalink raw reply	[flat|nested] 75+ messages in thread
* [PATCH] mmc: dw_mmc: change to use recommended reset procedure
@ 2014-03-26 11:46 ` Yuvaraj Kumar C D
  0 siblings, 0 replies; 75+ messages in thread
From: Yuvaraj Kumar C D @ 2014-03-26 11:46 UTC (permalink / raw)
  To: grundler, linux-samsung-soc, linux-arm-kernel, jh80.chung, cjb,
	tgih.jun, linux-mmc, sonnyrao, kgene.kim, joshi
  Cc: t.figa, Yuvaraj Kumar C D

From: Sonny Rao <sonnyrao@chromium.org>

This patch changes the fifo reset code to follow the reset procedure
outlined in the documentation of Synopsys  Mobile storage host databook
7.2.13.
Without this patch, we could able to see eMMC was not detected after
multiple reboots due to driver hangs while eMMC tuning for HS200.

Signed-off-by: Sonny Rao <sonnyrao@chromium.org>
Signed-off-by: Yuvaraj Kumar C D <yuvaraj.cd@samsung.org>
---
 drivers/mmc/host/dw_mmc.c |   48 ++++++++++++++++++++++++++++++++++++++++++++-
 drivers/mmc/host/dw_mmc.h |    1 +
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 32dd81d..1d77431 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -2220,7 +2220,53 @@ static inline bool dw_mci_fifo_reset(struct dw_mci *host)
 		host->sg = NULL;
 	}
 
-	return dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET);
+	/*
+	 * The recommended method for resetting is to always reset the
+	 * controller and the fifo, but differs slightly depending on the mode.
+	 * Note that this doesn't handle the "generic DMA" (not IDMAC) case.
+	 */
+	if (dw_mci_ctrl_reset(host, SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET)) {
+		unsigned long timeout = jiffies + msecs_to_jiffies(500);
+		u32 status, rint;
+
+		/* if using dma we wait for dma_req to clear */
+		if (host->using_dma) {
+			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)
+				dev_err(host->dev,
+					"%s: Timeout waiting for dma_req to "
+					"clear during reset", __func__);
+
+			/* when using DMA next we reset the fifo again */
+			dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET);
+		}
+		/*
+		 * In all cases we clear the RAWINTS register to clear any
+		 * interrupts.
+		 */
+		rint = mci_readl(host, RINTSTS);
+		rint = rint & (~mci_readl(host, MINTSTS));
+		if (rint)
+			mci_writel(host, RINTSTS, rint);
+
+	} else
+		dev_err(host->dev, "%s: Reset bits didn't clear", __func__);
+
+ #ifdef CONFIG_MMC_DW_IDMAC
+	/* It is also recommended that we reset and reprogram idmac */
+	dw_mci_idmac_reset(host);
+ #endif
+
+	/* After a CTRL reset we need to have CIU set clock registers  */
+	mci_send_cmd(host->cur_slot, SDMMC_CMD_UPD_CLK, 0);
+
+	return true;
 }
 
 static inline bool dw_mci_ctrl_all_reset(struct dw_mci *host)
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index 738fa24..037e47a 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -129,6 +129,7 @@
 #define SDMMC_CMD_INDX(n)		((n) & 0x1F)
 /* Status register defines */
 #define SDMMC_GET_FCNT(x)		(((x)>>17) & 0x1FFF)
+#define SDMMC_STATUS_DMA_REQ		BIT(31)
 /* FIFOTH register defines */
 #define SDMMC_SET_FIFOTH(m, r, t)	(((m) & 0x7) << 28 | \
 					 ((r) & 0xFFF) << 16 | \
-- 
1.7.10.4

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

end of thread, other threads:[~2014-08-11  7:55 UTC | newest]

Thread overview: 75+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-13  1:38 [PATCHv2] mmc: dw_mmc: change to use recommended reset procedure Sonny Rao
2014-05-13  1:38 ` Sonny Rao
2014-05-13  5:02 ` Seungwon Jeon
2014-05-13  5:02   ` Seungwon Jeon
2014-05-13  7:16   ` Sonny Rao
2014-05-13  7:16     ` Sonny Rao
2014-05-13 11:09     ` Seungwon Jeon
2014-05-13 11:09       ` Seungwon Jeon
2014-05-17  0:36       ` Sonny Rao
2014-05-17  0:36         ` Sonny Rao
2014-05-20  1:49         ` Seungwon Jeon
2014-05-20  1:49           ` Seungwon Jeon
2014-05-22 18:54           ` Sonny Rao
2014-05-22 18:54             ` Sonny Rao
2014-05-29  0:35             ` [PATCH] " Sonny Rao
2014-05-29  0:35               ` Sonny Rao
2014-05-29  5:17               ` Jaehoon Chung
2014-05-29  5:17                 ` Jaehoon Chung
2014-06-09 21:35                 ` Sonny Rao
2014-06-09 21:35                   ` Sonny Rao
2014-06-09 22:00                   ` Sonny Rao
2014-06-09 22:00                     ` Sonny Rao
2014-07-10 12:28                     ` Seungwon Jeon
2014-07-10 12:28                       ` Seungwon Jeon
2014-07-10 22:35                       ` Sonny Rao
2014-07-10 22:35                         ` Sonny Rao
2014-07-11 10:20                         ` Seungwon Jeon
2014-07-11 10:20                           ` Seungwon Jeon
2014-07-11 19:48                           ` Sonny Rao
2014-07-11 19:48                             ` Sonny Rao
2014-07-11 20:53                             ` [PATCHv5] " Sonny Rao
2014-07-11 20:53                               ` Sonny Rao
2014-07-14  5:52                               ` Jaehoon Chung
2014-07-14  5:52                                 ` Jaehoon Chung
2014-07-14 22:06                                 ` [PATCHv6] " Sonny Rao
2014-07-14 22:06                                   ` Sonny Rao
2014-07-18 13:37                                   ` Seungwon Jeon
2014-07-18 13:37                                     ` Seungwon Jeon
2014-07-26  9:55                                   ` Ulf Hansson
2014-07-26  9:55                                     ` Ulf Hansson
2014-05-13  5:19 ` [PATCHv2] " Kukjin Kim
2014-05-13  5:19   ` Kukjin Kim
2014-05-13  8:46 ` Arnd Bergmann
2014-05-13  8:46   ` Arnd Bergmann
  -- strict thread matches above, loose matches on Subject: below --
2014-08-04 13:44 linux-next: build failure after merge of the mmc-uh tree Ulf Hansson
2014-08-05  1:19 ` [PATCH] mmc: dw_mmc: change to use recommended reset procedure Sonny Rao
2014-08-05  1:19   ` Sonny Rao
2014-08-07  8:40   ` Jaehoon Chung
2014-08-07  8:40     ` Jaehoon Chung
2014-08-11  7:55   ` Ulf Hansson
2014-08-11  7:55     ` Ulf Hansson
2014-08-11  7:55     ` Ulf Hansson
2014-03-26 11:46 Yuvaraj Kumar C D
2014-03-26 11:46 ` Yuvaraj Kumar C D
2014-05-08  9:40 ` Yuvaraj Kumar
2014-05-08  9:40   ` Yuvaraj Kumar
2014-05-09  1:15   ` Jaehoon Chung
2014-05-09  1:15     ` Jaehoon Chung
2014-05-09  1:34     ` Sonny Rao
2014-05-09  1:34       ` Sonny Rao
2014-05-09  4:27       ` Jaehoon Chung
2014-05-09  4:27         ` Jaehoon Chung
2014-05-09  7:32         ` Jaehoon Chung
2014-05-09  7:32           ` Jaehoon Chung
2014-05-10  3:36           ` Sonny Rao
2014-05-10  3:36             ` Sonny Rao
2014-05-10 14:08             ` Seungwon Jeon
2014-05-10 14:08               ` Seungwon Jeon
2014-05-12 21:14               ` Sonny Rao
2014-05-12 21:14                 ` Sonny Rao
2014-05-12 21:44             ` Sonny Rao
2014-05-12 21:44               ` Sonny Rao
2014-05-13  0:40               ` Sonny Rao
2014-05-13  0:40                 ` Sonny Rao
2014-05-13 10:13               ` James Hogan
2014-05-13 10:13                 ` James Hogan

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.