Skip to contentSkip to conversation

:Blackfin SD Host Controller Driver

PATCH RESEND In review [email protected] 4 participants 5 messages Apr 16, 2009 – May 3, 2009 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 :Blackfin SD Host Controller Driver

From: Cliff Cai <[email protected]>

---
 drivers/mmc/host/Kconfig    |   19 ++
 drivers/mmc/host/Makefile   |    1 +
 drivers/mmc/host/bfin_sdh.c |  648 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 668 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mmc/host/bfin_sdh.c
drivers/mmc/host/Kconfig +19 -0
index b4cf691..588813f 100644
@@ -241,3 +241,22 @@ config MMC_TMIO
 	help
 	  This provides support for the SD/MMC cell found in TC6393XB,
 	  T7L66XB and also ipaq ASIC3
+
+config SDH_BFIN
+	tristate "Blackfin Secure Digital Host support"
+	depends on MMC && ((BF54x && !BF544) || (BF51x && !BF512))
+	help
+	  If you say yes here you will get support for the Blackfin on-chip
+	  Secure Digital Host interface.  This includes support for MMC and
+	  SD cards.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called bfin_sdh.
+
+	  If unsure, say N.
+
+config SDH_BFIN_MISSING_CMD_PULLUP_WORKAROUND
+	bool "Blackfin EZkit Missing SDH_CMD Pull Up Resistor Workaround"
+	depends on SDH_BFIN
+	help
+	  If you say yes here SD-Cards may work on the EZkit.
drivers/mmc/host/Makefile +1 -0
index 3d3a4a3..0af1f7a 100644
@@ -29,3 +29,4 @@ endif
 obj-$(CONFIG_MMC_S3C)   	+= s3cmci.o
 obj-$(CONFIG_MMC_SDRICOH_CS)	+= sdricoh_cs.o
 obj-$(CONFIG_MMC_TMIO)		+= tmio_mmc.o
+obj-$(CONFIG_SDH_BFIN)		+= bfin_sdh.o
drivers/mmc/host/bfin_sdh.c new file +648 -0

648 lines not on this page · raw message

Signature · 1 line
1.6.2.2
#1 lore raw
Quoted 1 line · On Thu, Apr 16, 2009 at 13:40, <[email protected]> wrote:

+#define NR_SG  32

seems silly to have a define when it's used only once

Quoted 3 lines

+struct sdh_host {
+       struct mmc_host         *mmc;
+       spinlock_t              lock; /* Why I have to give a comment here? */

why ?

drivers/mmc/host/bfin_sdh.c line 138

Quoted 3 lines
drivers/mmc/host/bfin_sdh.c new file +3 -0
+static void sdh_setup_data(struct sdh_host *host, struct mmc_data *data)
+{
+       pr_debug("%s enter flags:0x%x\n", __func__, data->flags);

i wonder why these fixes exist in this patch but not the Blackfin tree (__FUNCTION__ -> __func__) ...

also, many of these pr_debug()'s should probably be dev_dbg() ...

Quoted 1 line

+/* RSI DMA doesn't work in array mode */

comment should be indented

drivers/mmc/host/bfin_sdh.c line 345

Quoted 5 lines
drivers/mmc/host/bfin_sdh.c new file +5 -0
+static int sdh_get_ro(struct mmc_host *mmc)
+{
+       /* Host doesn't support read only detection so assume writeable */
+       return -ENOSYS;
+}

the common code already checks to see if get_ro is NULL before calling it, so we dont want this stub

Quoted 6 lines

+       if (ios->bus_width == MMC_BUS_WIDTH_4) {
+               cfg = bfin_read_SDH_CFG();
+               cfg &= ~0x80;
+               cfg |= 0x40;
+               /* Enable 4 bit SDIO */
+               cfg |= 0x0c;

shouldnt these magic numbers be defines ?

drivers/mmc/host/bfin_sdh.c line 479

Quoted 4 lines
drivers/mmc/host/bfin_sdh.c new file +4 -0
+static int __devinit sdh_probe(struct platform_device *pdev)
+{
+       struct mmc_host *mmc;
+       struct sdh_host *host = NULL;

dont think this is actually needed

Quoted 1 line

+       mmc = mmc_alloc_host(sizeof(struct sdh_host), &pdev->dev);

sizeof(*mmc)

Quoted 2 lines

+       mmc->f_min = get_sclk() >> 9;
+       mmc->f_max = get_sclk();

store get_sclk() once to avoid calling this function twice mmc->f_max = get_sclk();
mmc->f_min = mmc->f_max >> 9;

Quoted 4 lines

+       sd_entry = create_proc_entry("driver/sdh", 0600, NULL);
+       sd_entry->read_proc = NULL;
+       sd_entry->write_proc = proc_write;
+       sd_entry->data = host;

and if create_proc_entry() returns NULL ? like when procfs support is turned off ?

Quoted 3 lines

+static struct platform_driver sdh_driver = {
+       .probe          = sdh_probe,
+       .remove         = sdh_remove,

shouldnt that be __devexit_p(sdh_remove) ?
-mike

#2 lore raw
In reply to [email protected]
Quoted 10 lines · On Fri, 17 Apr 2009 01:40:41 +0800 [email protected] wrote:

From: Cliff Cai <[email protected]>

---
 drivers/mmc/host/Kconfig    |   19 ++
 drivers/mmc/host/Makefile   |    1 +
 drivers/mmc/host/bfin_sdh.c |  648 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 668 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mmc/host/bfin_sdh.c

I'd also like a MAINTAINERS entry for the driver.

drivers/mmc/host/Kconfig config MMC_TMIO · line 247

Quoted 3 lines
drivers/mmc/host/Kconfig +3 -0
+config SDH_BFIN
+	tristate "Blackfin Secure Digital Host support"
+	depends on MMC && ((BF54x && !BF544) || (BF51x && !BF512))

You don't need "depends on MMC" as the entire block is conditioned on MMC already.

Quoted 5 lines

+/* In term of ADSP_BF5xx_Blackfin_Processor_Peripheral_Hardware_Reference,
+ * the SDH allows software to detect a card when it is inserted into its slot.
+ * The SD_DATA3 pin powers up low due to a special pull-down resistor. When an
+ * SD Card is inserted in its slot, the resistance increases and a rising edge
+ * is detected by the SDH module.

Quoted 8 lines

+ * But this doesn't work sometimes. When a MMC/SD card is inserted, the voltage
+ * doesn't rise on SD_DATA3. In term of The MultiMediaCard System Specification,
+ * SD_DATA3 is used as CS pin in SPI mode. The MultiMediaCard wakes up in the
+ * MultiMediaCard mode. During the scan procedure, host will send CMD0 to reset
+ * MMC card, if CS pin is low, MMC card will enter SPI mode. Of course Secure
+ * Digital Host controller is not a SPI controller. So the Card detect function
+ * has to be disabled. After card is inserted run "echo 0 > /proc/driver/sdh"
+ * to trigger card scanning */

If the controller can only do DAT3-detection, then I think it's best if we put it into polling mode.

drivers/mmc/host/bfin_sdh.c line 152

Quoted 1 line
drivers/mmc/host/bfin_sdh.c new file +1 -0
+	BUG_ON(data->blksz & (data->blksz -1));

Not a bug so you need to deal with this. Most likely fail the request with EINVAL.

drivers/mmc/host/bfin_sdh.c line 171

Quoted 4 lines
drivers/mmc/host/bfin_sdh.c new file +4 -0
+#if defined(CONFIG_BF54x)
+	dma_cfg |= DMAFLOW_ARRAY | NDSIZE_5 | RESTART | WDSIZE_32 | DMAEN;
+	for (i = 0; i < host->dma_len; i++) {
+		host->sg_cpu[i].start_addr = sg_dma_address(&data->sg[i]);

You cannot index sg lists directly anymore. You have to iterate over them using the iteration helpers.

drivers/mmc/host/bfin_sdh.c line 307

Quoted 5 lines
drivers/mmc/host/bfin_sdh.c new file +5 -0
+	if (!data->error)
+		data->bytes_xfered = data->blocks * data->blksz;
+	else
+		data->bytes_xfered = data->blocks * data->blksz - \
+				     bfin_read_SDH_DATA_CNT();

This is probably wrong. You need to set bytes_xfered to the number of bytes acked by the card, not the number of bytes sent over the wire (for writes that is). If your hardware can provide that then fine, otherwise set bytes_xfered to 0 on failure.

drivers/mmc/host/bfin_sdh.c line 500

Quoted 5 lines
drivers/mmc/host/bfin_sdh.c new file +5 -0
+	mmc->ops = &sdh_ops;
+	mmc->max_phys_segs = NR_SG;
+	mmc->max_seg_size = 1 << 16;
+	mmc->max_blk_size = 2 << 11;
+	mmc->max_blk_count = 2 << 16;

You forgot max_req_size.

Review

Quoted 2 lines
(quoted diff) +2 -0
+out3:
+	free_dma(host->dma_ch);

You need a mmc_remove_host() here.

Also check Mike's comments.

Rgds

Signature · 6 lines
     -- Pierre Ossman

  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.
#3 lore raw
Quoted 57 lines

-----Original Message-----
From: Pierre Ossman [mailto:[email protected]]
Sent: Monday, April 27, 2009 3:51 AM
To: [email protected]
Cc: [email protected]; Cai, Cliff; Cliff Cai
Subject: Re: [PATCH][RESEND][mmc/host]:Blackfin SD Host Controller Driver

Quoted 11 lines · On Fri, 17 Apr 2009 01:40:41 +0800 [email protected] wrote:

From: Cliff Cai <[email protected]>

---
 drivers/mmc/host/Kconfig    |   19 ++
 drivers/mmc/host/Makefile   |    1 +
 drivers/mmc/host/bfin_sdh.c |  648 
+++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 668 insertions(+), 0 deletions(-)  create mode 

100644 drivers/mmc/host/bfin_sdh.c

I'd also like a MAINTAINERS entry for the driver.

drivers/mmc/host/Kconfig config MMC_TMIO · line 247

Quoted 3 lines
drivers/mmc/host/Kconfig +3 -0
+config SDH_BFIN
+	tristate "Blackfin Secure Digital Host support"
+	depends on MMC && ((BF54x && !BF544) || (BF51x && !BF512))

You don't need "depends on MMC" as the entire block is conditioned on MMC already.

Review

Quoted 3 lines
(quoted diff) +3 -0
+/* In term of 
+ADSP_BF5xx_Blackfin_Processor_Peripheral_Hardware_Reference,
+ * the SDH allows software to detect a card when it is 

inserted into its slot.

Quoted 8 lines

+ * The SD_DATA3 pin powers up low due to a special pull-down

(quoted diff) +7 -0
+resistor. When an
+ * SD Card is inserted in its slot, the resistance increases and a 
+rising edge
+ * is detected by the SDH module.
+ * But this doesn't work sometimes. When a MMC/SD card is inserted, 
+the voltage
+ * doesn't rise on SD_DATA3. In term of The MultiMediaCard System 

Review

Quoted 10 lines
(quoted diff) +10 -0
+Specification,
+ * SD_DATA3 is used as CS pin in SPI mode. The MultiMediaCard wakes 
+up in the
+ * MultiMediaCard mode. During the scan procedure, host will send 
+CMD0 to reset
+ * MMC card, if CS pin is low, MMC card will enter SPI mode. Of 
+course Secure
+ * Digital Host controller is not a SPI controller. So the Card 
+detect function
+ * has to be disabled. After card is inserted run "echo 0 > 

/proc/driver/sdh"

Quoted 4 lines
Quoted 1 line

+ * to trigger card scanning */

If the controller can only do DAT3-detection, then I think it's best if we put it into polling mode.

What did you mean the polling mode,using a timer?

Quoted 8 lines

drivers/mmc/host/bfin_sdh.c line 152

Quoted 1 line
drivers/mmc/host/bfin_sdh.c new file +1 -0
+	BUG_ON(data->blksz & (data->blksz -1));

Not a bug so you need to deal with this. Most likely fail the request with EINVAL.

Review

Quoted 2 lines
(quoted diff) +2 -0
+#if defined(CONFIG_BF54x)
+	dma_cfg |= DMAFLOW_ARRAY | NDSIZE_5 | RESTART | 

WDSIZE_32 | DMAEN;

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	for (i = 0; i < host->dma_len; i++) {
+		host->sg_cpu[i].start_addr = 

sg_dma_address(&data->sg[i]);

You cannot index sg lists directly anymore. You have to iterate over them using the iteration helpers.

Why?

Quoted 19 lines

drivers/mmc/host/bfin_sdh.c line 307

Quoted 5 lines
drivers/mmc/host/bfin_sdh.c new file +5 -0
+	if (!data->error)
+		data->bytes_xfered = data->blocks * data->blksz;
+	else
+		data->bytes_xfered = data->blocks * data->blksz - \
+				     bfin_read_SDH_DATA_CNT();

This is probably wrong. You need to set bytes_xfered to the number of bytes acked by the card, not the number of bytes sent over the wire (for writes that is). If your hardware can provide that then fine, otherwise set bytes_xfered to 0 on failure.

drivers/mmc/host/bfin_sdh.c line 500

Quoted 5 lines
drivers/mmc/host/bfin_sdh.c new file +5 -0
+	mmc->ops = &sdh_ops;
+	mmc->max_phys_segs = NR_SG;
+	mmc->max_seg_size = 1 << 16;
+	mmc->max_blk_size = 2 << 11;
+	mmc->max_blk_count = 2 << 16;

You forgot max_req_size.

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+out3:
+	free_dma(host->dma_ch);

You need a mmc_remove_host() here.

Also check Mike's comments.

I will.

Thanks

Cliff

#4 lore raw
Quoted 6 lines · Cliff
Quoted 3 lines

If the controller can only do DAT3-detection, then I think it's best if we put it into polling mode.

What did you mean the polling mode,using a timer?

The MMC core handles it for you. Just set MMC_CAP_NEEDS_POLL.

Quoted 6 lines
Quoted 3 lines

You cannot index sg lists directly anymore. You have to iterate over them using the iteration helpers.

Why?

Because you'll read bogus data otherwise and can even cause a oops. The sg lists can be linked, which introduces special entries.

Rgds

Signature · 6 lines
     -- Pierre Ossman

  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.