Skip to contentSkip to conversation

DaVinci: MMC: V4: MMC/SD controller driver for DaVinci family.

PATCH In review Purushotam Kumar 3 participants 6 messages Apr 2, 2009 – Apr 28, 2009

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DaVinci: MMC: V4: MMC/SD controller driver for DaVinci family.

From: Purshotam Kumar <[email protected]>

This patch adds support for MMC/SD controller driver for DaVinci family SoC. This patch will work for SoC like DM6446 and DM355. SoC like DM365 and DA830 also has same controller with small variations and could supported/added easily by using this version of patch. It means that this version of patch could be used for all SoC which has been derived from DaVinci family.

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.

This updated patch incorporates most of review comments given by Pierre Ossman. Many thanks for Pierre Ossman for reviewing.

---
 arch/arm/mach-davinci/include/mach/mmc.h |   25 +
 drivers/mmc/host/Kconfig                 |    8 +
 drivers/mmc/host/Makefile                |    1 +
 drivers/mmc/host/davinci_mmc.c           | 1264 ++++++++++++++++++++++++++++++
 4 files changed, 1298 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-davinci/include/mach/mmc.h
 create mode 100644 drivers/mmc/host/davinci_mmc.c
arch/arm/mach-davinci/include/mach/mmc.h new file +25 -0
new file mode 100644
index 0000000..8fee158
@@ -0,0 +1,25 @@
+/*
+ *  Board-specific MMC configuration
+ */
+
+#ifndef _DAVINCI_MMC_H
+#define _DAVINCI_MMC_H
+
+#include <linux/types.h>
+#include <linux/mmc/host.h>
+
+struct davinci_mmc_config {
+	/* get_cd()/get_wp() may sleep */
+	int (*get_cd)(int module);
+	int (*get_ro)(int module);
+	/* wires == 0 is equivalent to wires == 4 (4-bit parallel) */
+	u8 wires;
+
+	u32 max_freq;
+
+	/* any additional host capabilities: OR'd in to mmc->f_caps */
+	u32 caps;
+};
+void davinci_setup_mmc(int module, struct davinci_mmc_config *config);
+
+#endif
drivers/mmc/host/Kconfig +8 -0
index 99d4b28..311d00f 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 ARCH_DAVINCI
+        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 +1264 -0

1,264 lines not on this page · raw message

Signature · 1 line
1.5.4.1
#1 lore raw
Quoted 7 lines · On Thu, 2 Apr 2009 15:26:36 +0530 Purushotam Kumar <[email protected]> wrote:
 arch/arm/mach-davinci/include/mach/mmc.h |   25 +
 drivers/mmc/host/Kconfig                 |    8 +
 drivers/mmc/host/Makefile                |    1 +
 drivers/mmc/host/davinci_mmc.c           | 1264 ++++++++++++++++++++++++++++++
 4 files changed, 1298 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-davinci/include/mach/mmc.h
 create mode 100644 drivers/mmc/host/davinci_mmc.c

I want a MAINTAINERS entry for this driver as well.

drivers/mmc/host/davinci_mmc.c line 354

Quoted 8 lines
drivers/mmc/host/davinci_mmc.c new file +8 -0
+	/*
+	 * Before non-DMA WRITE commands the controller needs priming:
+	 * FIFO should be populated with 32 bytes i.e. whatever is the FIFO size
+	 */
+	if (!host->do_dma && (host->data_dir == DAVINCI_MMC_DATADIR_WRITE) &&
+		((cmd->opcode == MMC_WRITE_BLOCK) ||
+		(cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK)))
+		davinci_fifo_data_trans(host, DAVINCI_MMC_FIFO_SIZE_BYTE);

I'm still not following the requirements here. Why would the hardware only need to have the FIFO primed for those two commands and not every kind of write?

drivers/mmc/host/davinci_mmc.c line 489

Quoted 10 lines
drivers/mmc/host/davinci_mmc.c new file +10 -0
+
+	/* We know sg_len and ccnt will never be out of range because
+	 * we told the mmc layer which in turn tells the block layer
+	 * to ensure that it only hands us one 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 = sg_next(sg), slot = host->links[link++]) {

You might be able to make this cleaner using the for_each_sg helper.

Quoted 6 lines
drivers/mmc/host/davinci_mmc.c new file +6 -0
+static unsigned int calculate_freq_for_card(struct mmc_davinci_host *host,
+	unsigned int mmc_req_freq)
+{
+	unsigned int mmc_freq = 0, cpu_arm_clk = 0, mmc_push_pull = 0;
+
+	cpu_arm_clk = host->mmc_input_clk;

drivers/mmc/host/davinci_mmc.c line 717

Quoted 10 lines
drivers/mmc/host/davinci_mmc.c new file +10 -0
+	if (mmc_req_freq && cpu_arm_clk > (2 * mmc_req_freq))
+		mmc_push_pull = ((unsigned int)cpu_arm_clk
+				/ (2 * mmc_req_freq)) - 1;
+	else
+		mmc_push_pull = 0;
+
+	mmc_freq = (unsigned int)cpu_arm_clk / (2 * (mmc_push_pull + 1));
+
+	if (mmc_freq > mmc_req_freq)
+		mmc_push_pull = mmc_push_pull + 1;

The naming of the divider is a bit confusing here. :)

drivers/mmc/host/davinci_mmc.c line 726

Quoted 9 lines
drivers/mmc/host/davinci_mmc.c new file +9 -0
+
+	/* Convert ns to clock cycles */
+	if (mmc_req_freq < 400000)
+		ns_in_one_cycle = 1000000 / ((cpu_arm_clk
+					/ (2 * (mmc_push_pull + 1)))/1000);
+	else
+		ns_in_one_cycle = 1000000 / ((cpu_arm_clk
+					/ (2 * (mmc_push_pull + 1)))/1000000);
+

The clock frequency is per host, so store this in the mmc_davinci_host structure.

Quoted 8 lines
drivers/mmc/host/davinci_mmc.c new file +8 -0
+	if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
+		u32 temp;
+
+		/* Ignoring the init clock value passed for fixing the inter
+		 * operability with different cards.
+		 */
+		open_drain_freq = ((unsigned int)cpu_arm_clk
+				/ (2 * MMCSD_INIT_CLOCK)) - 1;

drivers/mmc/host/davinci_mmc.c line 768

Quoted 10 lines
drivers/mmc/host/davinci_mmc.c new file +10 -0
+
+		if (open_drain_freq > 0xFF)
+			open_drain_freq = 0xFF;
+
+		temp = readl(host->base + DAVINCI_MMCCLK) & ~MMCCLK_CLKRT_MASK;
+		temp |= open_drain_freq;
+		writel(temp, host->base + DAVINCI_MMCCLK);
+
+		/* Convert ns to clock cycles */
+		ns_in_one_cycle = (1000000) / (MMCSD_INIT_CLOCK/1000);

I'm still not sure why you need this. Open drain mode is always used at a low frequency anyway.

Rgds

Signature · 10 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  rdesktop, core developer          http://www.rdesktop.org
  TigerVNC, core developer          http://www.tigervnc.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.
#2 lore raw
Quoted 6 lines
Quoted 4 lines
 drivers/mmc/host/davinci_mmc.c           | 1264 ++++++++++++++++++++++++++++++
 4 files changed, 1298 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-davinci/include/mach/mmc.h
 create mode 100644 drivers/mmc/host/davinci_mmc.c

I want a MAINTAINERS entry for this driver as well.

I will add this and re-submit the patch. I will provide e-mail id in the MODULE_AUTHOR.

Quoted 13 lines

drivers/mmc/host/davinci_mmc.c line 354

Quoted 9 lines
drivers/mmc/host/davinci_mmc.c new file +8 -0
+	/*
+	 * Before non-DMA WRITE commands the controller needs priming:
+	 * FIFO should be populated with 32 bytes i.e. whatever is the FIFO size
+	 */
+	if (!host->do_dma && (host->data_dir == DAVINCI_MMC_DATADIR_WRITE) &&
+		((cmd->opcode == MMC_WRITE_BLOCK) ||
+		(cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK)))
+		davinci_fifo_data_trans(host, DAVINCI_MMC_FIFO_SIZE_BYTE);

I'm still not following the requirements here. Why would the hardware only need to have the FIFO primed for those two commands and not every kind of write?

This required by SD controller as suggested by IP designer. Please look at SD controller spec at http://www.ti.com/litv/pdf/sprue30d . Please check section 3.2/3.6 and point no 11/10 in the controller spec. It does not talk about priming by 32 bytes for any other command. This restriction is from SD controller.

Quoted 13 lines

drivers/mmc/host/davinci_mmc.c line 489

Quoted 11 lines
drivers/mmc/host/davinci_mmc.c new file +10 -0
+
+	/* We know sg_len and ccnt will never be out of range because
+	 * we told the mmc layer which in turn tells the block layer
+	 * to ensure that it only hands us one 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 = sg_next(sg), slot = host->links[link++]) {

You might be able to make this cleaner using the for_each_sg helper.

That particular loop can't use for_each_sg() since it's also iterating the EDMA slots: channel, then links[]

Quoted 11 lines
Quoted 11 lines
drivers/mmc/host/davinci_mmc.c new file +10 -0
+static unsigned int calculate_freq_for_card(struct mmc_davinci_host *host,
+	unsigned int mmc_req_freq)
+{
+	unsigned int mmc_freq = 0, cpu_arm_clk = 0, mmc_push_pull = 0;
+
+	cpu_arm_clk = host->mmc_input_clk;
+	if (mmc_req_freq && cpu_arm_clk > (2 * mmc_req_freq))
+		mmc_push_pull = ((unsigned int)cpu_arm_clk
+				/ (2 * mmc_req_freq)) - 1;
+	else
Quoted 8 lines

drivers/mmc/host/davinci_mmc.c line 717

Quoted 6 lines
drivers/mmc/host/davinci_mmc.c new file +6 -0
+		mmc_push_pull = 0;
+
+	mmc_freq = (unsigned int)cpu_arm_clk / (2 * (mmc_push_pull + 1));
+
+	if (mmc_freq > mmc_req_freq)
+		mmc_push_pull = mmc_push_pull + 1;

The naming of the divider is a bit confusing here. :)

I am thinking to change " mmc_push_pull" to " mmc_push_pull_divider". Please suggest other appropriate name.

Quoted 13 lines

drivers/mmc/host/davinci_mmc.c line 726

Quoted 10 lines
drivers/mmc/host/davinci_mmc.c new file +9 -0
+
+	/* Convert ns to clock cycles */
+	if (mmc_req_freq < 400000)
+		ns_in_one_cycle = 1000000 / ((cpu_arm_clk
+					/ (2 * (mmc_push_pull + 1)))/1000);
+	else
+		ns_in_one_cycle = 1000000 / ((cpu_arm_clk
+					/ (2 * (mmc_push_pull + 1)))/1000000);
+

The clock frequency is per host, so store this in the mmc_davinci_host structure.

You are correct and I will implement and re-submit the patch.

Quoted 14 lines
Quoted 14 lines
drivers/mmc/host/davinci_mmc.c new file +13 -0
+	if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
+		u32 temp;
+
+		/* Ignoring the init clock value passed for fixing the inter
+		 * operability with different cards.
+		 */
+		open_drain_freq = ((unsigned int)cpu_arm_clk
+				/ (2 * MMCSD_INIT_CLOCK)) - 1;
+
+		if (open_drain_freq > 0xFF)
+			open_drain_freq = 0xFF;
+
+		temp = readl(host->base + DAVINCI_MMCCLK) & ~MMCCLK_CLKRT_MASK;
Quoted 8 lines

drivers/mmc/host/davinci_mmc.c line 768

Quoted 5 lines
drivers/mmc/host/davinci_mmc.c new file +5 -0
+		temp |= open_drain_freq;
+		writel(temp, host->base + DAVINCI_MMCCLK);
+
+		/* Convert ns to clock cycles */
+		ns_in_one_cycle = (1000000) / (MMCSD_INIT_CLOCK/1000);

I'm still not sure why you need this. Open drain mode is always used at a low frequency anyway.

If my understanding is correct you are suggesting that at lower freq. there is no need to update the timeout parameter and can use the default value of ns_in_one_cycle.

The mmc_davinci_prepare_data() may be called even during open drain frequency mode and here we are calculating the timeout value and updating the timeout reg. So ns_in_one_cycle should hold a proper value once we call mmc_davinci_prepare_data(). I think there is no harm in having this calculation here.

Regards,
Purushotam

#3 lore raw
Quoted 8 lines · Purushotam
Quoted 4 lines

I'm still not following the requirements here. Why would the hardware only need to have the FIFO primed for those two commands and not every kind of write?

This required by SD controller as suggested by IP designer. Please look at SD controller spec at http://www.ti.com/litv/pdf/sprue30d . Please check section 3.2/3.6 and point no 11/10 in the controller spec.

Those are in Chapter 3, "Procedures for Common Operations" ... that is, examples. Examples, as a rule, are there just to elaborate ("unpack") the more detailed text, not substitute for clear specification. (And TI is generally pretty good about providing sane documentation, thank you! Fewer problems than with "some" vendors.)

In this case the spec says in a note in 2.7.2 that priming the fifo is needed for "write transactions" ... since no "fifo became empty" IRQ is generated. It does not limit it to the WRITE_BLOCK and WRITE_MULTIPLE_BLOCK commands.

Those examples are for writing single and multiple blocks; there are no SDIO write operations shown, for example, or password passing operations. Those would also suffer from the lack of a "fifo became empty" IRQ.

Quoted 1 line

It does not talk about priming by 32 bytes for any other command.

Said diffferently, *every* PIO write transaction shown primes the fifo ... but there are no examples of non-block writes.

Quoted 1 line

This restriction is from SD controller.

Could you confirm that interpretation with the folk who have provided that silicon block?

If your reading is correct, and it's really a restriction to those two commands, the documentation should change to say that "single and multiple block write commands" require FIFO priming ... not all "write transactions" as now written.

- Dave

#4 lore raw
Quoted 10 lines
Quoted 4 lines

This required by SD controller as suggested by IP designer. Please look at SD controller spec at http://www.ti.com/litv/pdf/sprue30d . Please check section 3.2/3.6 and point no 11/10 in the controller spec.

In this case the spec says in a note in 2.7.2 that priming the fifo is needed for "write transactions" ... since no "fifo became empty" IRQ is generated. It does not limit it to the WRITE_BLOCK and WRITE_MULTIPLE_BLOCK commands.

Quoted 5 lines

Those examples are for writing single and multiple blocks; there are no SDIO write operations shown, for example, or password passing operations. Those would also suffer from the lack of a "fifo became empty" IRQ.

It seems you are right that FIFO is required to be primed before any write transaction.

Quoted 3 lines
Quoted 1 line

It does not talk about priming by 32 bytes for any other command.

Said diffferently, *every* PIO write transaction shown primes the fifo ... but there are no examples of non-block writes.

We need to prime the FIFO beforehand with whatever data we intend to transfer. We looked into SDIO driver on DM6446 and observed that it requires priming.

Quoted 9 lines
Quoted 1 line

This restriction is from SD controller.

Could you confirm that interpretation with the folk who have provided that silicon block?

If your reading is correct, and it's really a restriction to those two commands, the documentation should change to say that "single and multiple block write commands" require FIFO priming ... not all "write transactions" as now written.

Apart from above there was a doubt for:

	if (!host->do_dma && (host->data_dir == DAVINCI_MMC_DATADIR_WRITE))
		davinci_fifo_data_trans(host, 32);

We will also remove check for CMD25 and CMD24 before priming and so it will allow priming for all commands.

Although there does seem to be a bug there ... it should never fill the fifo with more data than is being sent.

The second parameter is rightly justified as it is the length of fifo. If you see inside the davinci_fifo_data_trans() the FIFO is only primed based upon the data size during that transfer. So in a way we are not filling the fifo with more data.

We will re-submit patch tomorrow. Please let us know if you have any further concerns. Regards,
Purushotam

#5 lore raw
In reply to Kumar, Purushotam
Quoted 8 lines · Purushotam
Quoted 5 lines

drivers/mmc/host/davinci_mmc.c line 717

Quoted 3 lines
drivers/mmc/host/davinci_mmc.c new file +3 -0
+
+	if (mmc_freq > mmc_req_freq)
+		mmc_push_pull = mmc_push_pull + 1;

The naming of the divider is a bit confusing here. :)

I am thinking to change " mmc_push_pull" to " mmc_push_pull_divider". Please suggest other appropriate name.

Or just "divider". The rest should be clear from the context.

Quoted 23 lines
Quoted 13 lines
Quoted 13 lines
drivers/mmc/host/davinci_mmc.c new file +13 -0
+	if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
+		u32 temp;
+
+		/* Ignoring the init clock value passed for fixing the inter
+		 * operability with different cards.
+		 */
+		open_drain_freq = ((unsigned int)cpu_arm_clk
+				/ (2 * MMCSD_INIT_CLOCK)) - 1;
+
+		if (open_drain_freq > 0xFF)
+			open_drain_freq = 0xFF;
+
+		temp = readl(host->base + DAVINCI_MMCCLK) & ~MMCCLK_CLKRT_MASK;
Quoted 8 lines

drivers/mmc/host/davinci_mmc.c line 768

Quoted 5 lines
drivers/mmc/host/davinci_mmc.c new file +5 -0
+		temp |= open_drain_freq;
+		writel(temp, host->base + DAVINCI_MMCCLK);
+
+		/* Convert ns to clock cycles */
+		ns_in_one_cycle = (1000000) / (MMCSD_INIT_CLOCK/1000);

I'm still not sure why you need this. Open drain mode is always used at a low frequency anyway.

Quoted 4 lines

If my understanding is correct you are suggesting that at lower freq. there is no need to update the timeout parameter and can use the default value of ns_in_one_cycle.

The mmc_davinci_prepare_data() may be called even during open drain frequency mode and here we are calculating the timeout value and updating the timeout reg. So ns_in_one_cycle should hold a proper value once we call mmc_davinci_prepare_data(). I think there is no harm in having this calculation here.

I see. I thought this was some fiddling to override the core's decision on clock frequency.

Why do you need to calculate the timeout differently based on push-pull/open drain mode though?

Rgds

Signature · 10 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  rdesktop, core developer          http://www.rdesktop.org
  TigerVNC, core developer          http://www.tigervnc.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.