Skip to contentSkip to conversation

DaVinci: MMC: MMC/SD controller driver for DaVinci/DM6446.

PATCH In review Purushotam Kumar 4 participants 9 messages Mar 16, 2009 – Mar 26, 2009 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DaVinci: MMC: MMC/SD controller driver for DaVinci/DM6446.

From: Purshotam Kumar <[email protected]>

This patch adds support for DaVinci (DM6446) MMC/SD controller driver. This patch has been generated against latest 2.6.29 mainline kernel. This patch will not compile currently because it depends notably on the EDMA utilities and chip/board setup, that will come at some point through the ARM tree. Please use currently DaVinci GIT tree for EDMA utilities and chip/board setup etc.

Many thanks to David Brownell ([email protected]) for his all support.

---
 drivers/mmc/host/Kconfig       |    8 +
 drivers/mmc/host/Makefile      |    1 +
 drivers/mmc/host/davinci_mmc.c | 1256 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1265 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mmc/host/davinci_mmc.c
drivers/mmc/host/Kconfig +8 -0
index 99d4b28..f1086ac 100644
@@ -171,6 +171,14 @@ config MMC_TIFM_SD
           To compile this driver as a module, choose M here: the
 	  module will be called tifm_sd.
 
+config MMC_DAVINCI
+        tristate "TI DAVINCI Multimedia Card Interface support"
+        depends on MMC
+        help
+          This selects the TI DAVINCI Multimedia card Interface.
+          If you have an DAVINCI board with a Multimedia Card slot,
+          say Y or M here.  If unsure, say N.
+
 config MMC_SPI
 	tristate "MMC/SD/SDIO over SPI"
 	depends on SPI_MASTER && !HIGHMEM && HAS_DMA
drivers/mmc/host/Makefile +1 -0
index dedec55..6bc91b1 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_MMC_OMAP_HS)	+= omap_hsmmc.o
 obj-$(CONFIG_MMC_AT91)		+= at91_mci.o
 obj-$(CONFIG_MMC_ATMELMCI)	+= atmel-mci.o
 obj-$(CONFIG_MMC_TIFM_SD)	+= tifm_sd.o
+obj-$(CONFIG_MMC_DAVINCI)       += davinci_mmc.o
 obj-$(CONFIG_MMC_SPI)		+= mmc_spi.o
 ifeq ($(CONFIG_OF),y)
 obj-$(CONFIG_MMC_SPI)		+= of_mmc_spi.o
drivers/mmc/host/davinci_mmc.c new file +1256 -0

1,256 lines not on this page · raw message

Signature · 1 line
1.5.4.1
#1 lore raw

Hi Purshotam,

drivers/mmc/host/davinci_mmc.c line 132

Quoted 3 lines
drivers/mmc/host/davinci_mmc.c new file +3 -0
+
+
+/* MMCSD Init clock in Hz in opendain mode */

s/opendain/opendrain

drivers/mmc/host/davinci_mmc.c line 868

Quoted 4 lines
drivers/mmc/host/davinci_mmc.c new file +4 -0
+
+static irqreturn_t mmc_davinci_irq(int irq, void *dev_id)
+{
+       struct mmc_davinci_host *host = (struct mmc_davinci_host *)dev_id;

Unnecessary casting from void *.

Quoted 3 lines

+
+       ret = -EBUSY;
+       mem_size = r->end - r->start + 1;

How about using resource_size(...) ?

drivers/mmc/host/davinci_mmc.c line 1255

Quoted 7 lines

+       mem = request_mem_region(r->start, mem_size, pdev->name);
+       if (!mem)
+               goto out;

drivers/mmc/host/davinci_mmc.c new file +4 -0
+
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("MMC/SD driver for Davinci MMC controller");

Adding MODULE_AUTHOR and MODULE_ALIAS would be great. You can also add MAINTAINERS entry if you want.

Signature · 3 lines
---Trilok Soni
http://triloksoni.wordpress.com
http://www.linkedin.com/in/triloksoni
#2 lore raw
Quoted 4 lines
Quoted 3 lines

+/* MMCSD Init clock in Hz in opendain mode */

s/opendain/opendrain

I will make this modification while incorporating review comments.

Quoted 4 lines

drivers/mmc/host/davinci_mmc.c line 868

Quoted 3 lines
drivers/mmc/host/davinci_mmc.c new file +3 -0
+static irqreturn_t mmc_davinci_irq(int irq, void *dev_id)
+{
+       struct mmc_davinci_host *host = (struct mmc_davinci_host *)dev_id;

Unnecessary casting from void *.

I think it always to cast void* pointer and use it.

Quoted 10 lines
Quoted 4 lines

+
+       ret = -EBUSY;
+       mem_size = r->end - r->start + 1;

How about using resource_size(...) ?

Quoted 3 lines

+       mem = request_mem_region(r->start, mem_size, pdev->name);
+       if (!mem)
+               goto out;

I could use resource_size.

Quoted 5 lines

drivers/mmc/host/davinci_mmc.c line 1255

Quoted 2 lines
drivers/mmc/host/davinci_mmc.c new file +2 -0
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("MMC/SD driver for Davinci MMC controller");

Adding MODULE_AUTHOR and MODULE_ALIAS would be great. You can also add MAINTAINERS entry if you want.

I will add MODULE_AUTHOR and MODULE_ALIAS
-Purushotam

#3 lore raw
In reply to Purushotam Kumar
Quoted 3 lines · Purushotam Kumar

From: Purshotam Kumar <[email protected]>

This patch adds support for DaVinci (DM6446) MMC/SD controller driver. This

The dm6446 is the only chip with current mainline support; but dm355 can use it too, "support on the way" to mainline. (Only for 2.6.30 if Kevin still has time...)

And there are other DaVinci chips that support MMC too ... some are compatible with those two chips, some not, all should use a version of this driver. (And OMAP-L137 too, same tech family but with a different marketing label.)

So I'd remove the implication that DaVinci == DM6446, or that this driver is specific to that SoC.

drivers/mmc/host/Kconfig config MMC_TIFM_SD · line 176

Quoted 7 lines
drivers/mmc/host/Kconfig +3 -0
@@ -171,6 +171,14 @@ config MMC_TIFM_SD
           To compile this driver as a module, choose M here: the
 	  module will be called tifm_sd.
 
+config MMC_DAVINCI
+        tristate "TI DAVINCI Multimedia Card Interface support"
+        depends on MMC

Everything in that menu depends on MMC. This should depend on ARCH_DAVINCI instead. :)

drivers/mmc/host/davinci_mmc.c line 1094

Quoted 1 line
drivers/mmc/host/davinci_mmc.c new file +1 -0
+       host->clk = clk_get(&pdev->dev, NULL);

The NULL won't work with the clock code currently included in mainline ... "MMCSDCLK" will though.

It's probably simplest to list the updated DaVinci clock framework code as a runtime dependency, much like EDMA support is a build-time one, for this patch.

drivers/mmc/host/davinci_mmc.c line 1122

Quoted 4 lines
drivers/mmc/host/davinci_mmc.c new file +4 -0
+       if (pdata->max_freq)
+               mmc->f_max = pdata->max_freq;
+       if (pdata->caps)
+               mmc->caps |= pdata->caps;

A build-time issue is that "struct davinci_mmc_config" is missing. You could update this patch to include "arch/arm/mach-davinci/include/mach/mmc.h" too.

- Dave

#4 lore raw
Quoted 8 lines

And there are other DaVinci chips that support MMC too ... some are compatible with those two chips, some not, all should use a version of this driver. (And OMAP-L137 too, same tech family but with a different marketing label.)

So I'd remove the implication that DaVinci == DM6446, or that this driver is specific to that SoC.

I will update the description as suggested by you when I will re-submit.

Quoted 6 lines

drivers/mmc/host/Kconfig config MMC_TIFM_SD · line 176

Quoted 3 lines
drivers/mmc/host/Kconfig +3 -0
+config MMC_DAVINCI
+        tristate "TI DAVINCI Multimedia Card Interface support"
+        depends on MMC

Everything in that menu depends on MMC. This should depend on ARCH_DAVINCI instead. :)

I will add "depends on ARCH_DAVINCI"

Quoted 4 lines
Quoted 1 line

+       host->clk = clk_get(&pdev->dev, NULL);

The NULL won't work with the clock code currently included in mainline ... "MMCSDCLK" will though.

I will take care of this by changing to "MMCSDCLK" from NULL.

Quoted 8 lines
Quoted 4 lines

+       if (pdata->max_freq)
+               mmc->f_max = pdata->max_freq;
+       if (pdata->caps)
+               mmc->caps |= pdata->caps;

A build-time issue is that "struct davinci_mmc_config" is missing. You could update this patch to include "arch/arm/mach-davinci/include/mach/mmc.h" too.

I will add in the patch as well.
- Purushotam

#5 lore raw
In reply to Purushotam Kumar

I noticed a newish bug in probe() ...

Quoted 2 lines · Purushotam Kumar

+       if (!pdata || pdata->wires == 4 || pdata->wires == 0) +               mmc->caps |= MMC_CAP_4_BIT_DATA;

So pdata may be null. But, if it is, then ...

Quoted 6 lines

+
+       mmc->ops = &mmc_davinci_ops;
+       mmc->f_min = 312500;
+       mmc->f_max = 25000000;
+       if (pdata->max_freq)
+               mmc->f_max = pdata->max_freq;

Oops!

Quoted 2 lines

+       if (pdata->caps)
+               mmc->caps |= pdata->caps;

Double oops!

#6 lore raw
Quoted 15 lines

I noticed a newish bug in probe() ...

Quoted 2 lines · Purushotam Kumar

+       if (!pdata || pdata->wires == 4 || pdata->wires == 0) +               mmc->caps |= MMC_CAP_4_BIT_DATA;

So pdata may be null. But, if it is, then ...

Quoted 6 lines

+
+       mmc->ops = &mmc_davinci_ops;
+       mmc->f_min = 312500;
+       mmc->f_max = 25000000;
+       if (pdata->max_freq)
+               mmc->f_max = pdata->max_freq;

Quoted 7 lines

Oops!

Quoted 2 lines

+       if (pdata->caps)
+               mmc->caps |= pdata->caps;

Double oops!

I will add NULL checking for pdata.
-Purushotam

#7 lore raw
In reply to Purushotam Kumar

drivers/mmc/host/davinci_mmc.c line 205

Quoted 7 lines · On Mon, 16 Mar 2009 20:12:39 +0530 Purushotam Kumar <[email protected]> wrote:
drivers/mmc/host/davinci_mmc.c new file +7 -0
+
+/* PIO only */
+static void mmc_davinci_sg_to_buf(struct mmc_davinci_host *host)
+{
+	struct scatterlist *sg;
+
+	sg = host->data->sg + host->sg_idx;

You cannot do this to scatterlists any more. You need to use the iterator functions to walk the list.

drivers/mmc/host/davinci_mmc.c line 210

Quoted 5 lines
drivers/mmc/host/davinci_mmc.c new file +5 -0
+	host->buffer_bytes_left = sg_dma_len(sg);
+	host->buffer = sg_virt(sg);
+	if (host->buffer_bytes_left > host->bytes_left)
+		host->buffer_bytes_left = host->bytes_left;
+}

This is not HIGHMEM compatible. Probably not any issue right now, but might be in the future.

drivers/mmc/host/davinci_mmc.c line 313

Quoted 3 lines
drivers/mmc/host/davinci_mmc.c new file +3 -0
+	/* Setting initialize clock */
+	if (cmd->opcode == 0)
+		cmd_reg |= MMCCMD_INITCK;

This is not good. What does this do and is it really needed?

drivers/mmc/host/davinci_mmc.c line 356

Quoted 6 lines
drivers/mmc/host/davinci_mmc.c new file +6 -0
+	/*
+	 * Before non-DMA WRITE commands the controller needs priming:
+	 * FIFO should be populated with 32 bytes
+	 */
+	if (!host->do_dma && (host->data_dir == DAVINCI_MMC_DATADIR_WRITE))
+		davinci_fifo_data_trans(host, 32);

What if the transfer is smaller than 32 bytes?

drivers/mmc/host/davinci_mmc.c line 484

Quoted 2 lines
drivers/mmc/host/davinci_mmc.c new file +2 -0
+	/* We know sg_len and ccnt will never be out of range because
+	 * we told the block layer to ensure that it only hands us one

mmc layer really

drivers/mmc/host/davinci_mmc.c line 490

Quoted 6 lines
drivers/mmc/host/davinci_mmc.c new file +6 -0
+	 * scatterlist segment per EDMA PARAM entry.  Update the PARAM
+	 * entries needed for each segment of this scatterlist.
+	 */
+	for (slot = channel, link = 0, sg = data->sg, sg_len = host->sg_len;
+			sg_len-- != 0 && bytes_left;
+			sg++, slot = host->links[link++]) {

Incorrect way of traversing the sg list. Use sg_next().

drivers/mmc/host/davinci_mmc.c line 633

Quoted 6 lines
drivers/mmc/host/davinci_mmc.c new file +6 -0
+	/* Convert ns to clock cycles by assuming 20MHz frequency
+	 * 1 cycle at 20MHz = 500 ns
+	 */
+	timeout = data->timeout_clks + data->timeout_ns / 500;
+	if (timeout > 0xffff)
+		timeout = 0xffff;

So this might time out too early if we run at a lower clock frequency?

drivers/mmc/host/davinci_mmc.c line 755

Quoted 7 lines
drivers/mmc/host/davinci_mmc.c new file +7 -0
+	if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
+		u32 temp;
+		open_drain_freq = ((unsigned int)cpu_arm_clk
+				/ (2 * MMCSD_INIT_CLOCK)) - 1;
+		temp = readl(host->base + DAVINCI_MMCCLK) & ~0xFF;
+		temp |= open_drain_freq;
+		writel(temp, host->base + DAVINCI_MMCCLK);

Why are you ignoring the given frequency if in open drain mode?

drivers/mmc/host/davinci_mmc.c line 855

Quoted 9 lines
drivers/mmc/host/davinci_mmc.c new file +9 -0
+static void
+davinci_abort_data(struct mmc_davinci_host *host, struct mmc_data *data)
+{
+	u32 temp;
+
+	/* record how much data we transferred */
+	temp = readl(host->base + DAVINCI_MMCNBLC);
+	data->bytes_xfered += (data->blocks - temp) * data->blksz;
+

Does MMCNBLC record how many blocks you've sent, or how many blocks that the card has acked? If it's not the latter, then you cannot use it for bytes_xfered.

drivers/mmc/host/davinci_mmc.c line 911

Quoted 12 lines
drivers/mmc/host/davinci_mmc.c new file +12 -0
+
+	if (qstatus & MMCST0_DATDNE) {
+		/* All blocks sent/received, and CRC checks passed */
+		if (data != NULL) {
+			if ((host->do_dma == 0) && (host->bytes_left > 0)) {
+				/* if datasize < rw_threshold
+				 * no RX ints are generated
+				 */
+				davinci_fifo_data_trans(host, host->bytes_left);
+			}
+			end_transfer = 1;
+			data->bytes_xfered += data->blocks * data->blksz;

Why += and not =?

drivers/mmc/host/davinci_mmc.c line 978

Quoted 11 lines
drivers/mmc/host/davinci_mmc.c new file +11 -0
+
+	if (qstatus & MMCST0_CRCRS) {
+		/* Command CRC error */
+		dev_dbg(mmc_dev(host->mmc), "Command CRC error\n");
+		if (host->cmd) {
+			/* Ignore CMD CRC errors during high speed operation */
+			if (host->mmc->ios.clock <= 25000000)
+				host->cmd->error = -EILSEQ;
+			end_command = 1;
+		}
+	}

?!!

Signature · 9 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  rdesktop, core developer          http://www.rdesktop.org

  WARNING: This correspondence is being monitored by the
  Swedish government. Make sure your server uses encryption
  for SMTP traffic and consider using PGP for end-to-end
  encryption.
#8 lore raw
Quoted 11 lines

drivers/mmc/host/davinci_mmc.c line 205

Quoted 6 lines · On Mon, 16 Mar 2009 20:12:39 +0530 Purushotam Kumar <[email protected]> wrote:
drivers/mmc/host/davinci_mmc.c new file +6 -0
+/* PIO only */
+static void mmc_davinci_sg_to_buf(struct mmc_davinci_host *host)
+{
+	struct scatterlist *sg;
+
+	sg = host->data->sg + host->sg_idx;

You cannot do this to scatterlists any more. You need to use the iterator functions to walk the list.

I will incorporate this comment.

Quoted 6 lines

drivers/mmc/host/davinci_mmc.c line 209

Quoted 4 lines
drivers/mmc/host/davinci_mmc.c new file +4 -0
+	host->buffer_bytes_left = sg_dma_len(sg);
+	host->buffer = sg_virt(sg);
+	if (host->buffer_bytes_left > host->bytes_left)
+		host->buffer_bytes_left = host->bytes_left;

This is not HIGHMEM compatible. Probably not any issue right now, but might be in the future.

As you have suggested that it is not an issue at this point and so I will look into this latter if needed.

Quoted 4 lines

drivers/mmc/host/davinci_mmc.c line 313

Quoted 3 lines
drivers/mmc/host/davinci_mmc.c new file +3 -0
+	/* Setting initialize clock */
+	if (cmd->opcode == 0)
+		cmd_reg |= MMCCMD_INITCK;

This is not good. What does this do and is it really needed?

I think you are right and it is needed. I will check it and do needful.

Quoted 6 lines

drivers/mmc/host/davinci_mmc.c line 356

Quoted 5 lines
drivers/mmc/host/davinci_mmc.c new file +5 -0
+	 * Before non-DMA WRITE commands the controller needs priming:
+	 * FIFO should be populated with 32 bytes
+	 */
+	if (!host->do_dma && (host->data_dir == DAVINCI_MMC_DATADIR_WRITE))
+		davinci_fifo_data_trans(host, 32);

What if the transfer is smaller than 32 bytes?

This is required only for CMD24 and CMD25 on this controller and I will add that check in the code for CMD24 and CMD25. It is equal to depth of FIFO which defined by rw_threshold in the code. Now, transfer on CMD24 and CMD25 will also be multiple of 32.

Quoted 4 lines

drivers/mmc/host/davinci_mmc.c line 484

Quoted 2 lines
drivers/mmc/host/davinci_mmc.c new file +2 -0
+	/* We know sg_len and ccnt will never be out of range because
+	 * we told the block layer to ensure that it only hands us one

mmc layer really

I will update comments here.

Quoted 8 lines

drivers/mmc/host/davinci_mmc.c line 490

Quoted 6 lines
drivers/mmc/host/davinci_mmc.c new file +6 -0
+	 * scatterlist segment per EDMA PARAM entry.  Update the PARAM
+	 * entries needed for each segment of this scatterlist.
+	 */
+	for (slot = channel, link = 0, sg = data->sg, sg_len = host->sg_len;
+			sg_len-- != 0 && bytes_left;
+			sg++, slot = host->links[link++]) {

Incorrect way of traversing the sg list. Use sg_next().

I will look into this and update the patch.

Quoted 8 lines

drivers/mmc/host/davinci_mmc.c line 633

Quoted 6 lines
drivers/mmc/host/davinci_mmc.c new file +6 -0
+	/* Convert ns to clock cycles by assuming 20MHz frequency
+	 * 1 cycle at 20MHz = 500 ns
+	 */
+	timeout = data->timeout_clks + data->timeout_ns / 500;
+	if (timeout > 0xffff)
+		timeout = 0xffff;

So this might time out too early if we run at a lower clock frequency?

I will look into this. As such timeout on this controller is 24 bit value. 16 bit value on DAVINCI_MMCTOD register and remaining 8 bit value on DAVINCI_MMCTOR register.

Quoted 9 lines

drivers/mmc/host/davinci_mmc.c line 755

Quoted 7 lines
drivers/mmc/host/davinci_mmc.c new file +7 -0
+	if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
+		u32 temp;
+		open_drain_freq = ((unsigned int)cpu_arm_clk
+				/ (2 * MMCSD_INIT_CLOCK)) - 1;
+		temp = readl(host->base + DAVINCI_MMCCLK) & ~0xFF;
+		temp |= open_drain_freq;
+		writel(temp, host->base + DAVINCI_MMCCLK);

Why are you ignoring the given frequency if in open drain mode?

This has been done in order to fix inter operability with different card. We have observed that some of cards have not been detected at 400KHz on our controller.

Quoted 11 lines

drivers/mmc/host/davinci_mmc.c line 854

Quoted 8 lines
drivers/mmc/host/davinci_mmc.c new file +8 -0
+static void
+davinci_abort_data(struct mmc_davinci_host *host, struct mmc_data *data)
+{
+	u32 temp;
+
+	/* record how much data we transferred */
+	temp = readl(host->base + DAVINCI_MMCNBLC);
+	data->bytes_xfered += (data->blocks - temp) * data->blksz;

Does MMCNBLC record how many blocks you've sent, or how many blocks that the card has acked? If it's not the latter, then you cannot use it for bytes_xfered.

This is self decrementing register and it provides information on number of blocks has been transferred and not acked. In fact, there is no cleaner way to detect number of blocks acked by cards. May be in such case, we could increment bytes_xfered by 0 for particular transaction.

Quoted 5 lines
Quoted 5 lines
drivers/mmc/host/davinci_mmc.c new file +5 -0
+
+	if (qstatus & MMCST0_DATDNE) {
+		/* All blocks sent/received, and CRC checks passed */
+		if (data != NULL) {
+			if ((host->do_dma == 0) && (host->bytes_left > 0)) {
Quoted 8 lines

drivers/mmc/host/davinci_mmc.c line 911

Quoted 7 lines
drivers/mmc/host/davinci_mmc.c new file +7 -0
+				/* if datasize < rw_threshold
+				 * no RX ints are generated
+				 */
+				davinci_fifo_data_trans(host, host->bytes_left);
+			}
+			end_transfer = 1;
+			data->bytes_xfered += data->blocks * data->blksz;

Why += and not =?

I will look into and it seems that we could use =

Quoted 9 lines

drivers/mmc/host/davinci_mmc.c line 976

Quoted 9 lines
drivers/mmc/host/davinci_mmc.c new file +9 -0
+
+	if (qstatus & MMCST0_CRCRS) {
+		/* Command CRC error */
+		dev_dbg(mmc_dev(host->mmc), "Command CRC error\n");
+		if (host->cmd) {
+			/* Ignore CMD CRC errors during high speed operation */
+			if (host->mmc->ios.clock <= 25000000)
+				host->cmd->error = -EILSEQ;
+			end_command = 1;

I agree with you and I remove check of whether clock is less than 25MHz or not.

I will work on these comments and submit updated patch in next 4-5 days. -Purushotam