Skip to contentSkip to conversation

Samsung S3C24xx SD/MMC driver

PATCH In review Harald Welte 2 participants 3 messages Dec 19, 2007 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Samsung S3C24xx SD/MMC driver

Hi!

This is a MMC/SD driver for the Samsung S3C24xx SD/MMC controller, originally developed years ago by Thomas Kleffel <[email protected]>.

Due to time constraints, he had no time to further maintain the driver and follow the mainline Linux changes in the SD/MMC stack.

With his authorization, I have taken over the task of making it compliant to the current mainline SD/MMC API and take care of the mainline kernel merge.

So please advise on whatever changes you deem neccessary and I'll try to do my best to incorporate them for a hopefully not-too-distant mainline merge.

After a potential kernel inclusion, we would co-maintain the driver.

---

include/asm-arm/arch-s3c2410/regs-sdi.h +17 -3
Index: linux-2.6/include/asm-arm/arch-s3c2410/regs-sdi.h
===================================================================
@@ -28,9 +28,15 @@
 #define S3C2410_SDIDCNT               (0x30)
 #define S3C2410_SDIDSTA               (0x34)
 #define S3C2410_SDIFSTA               (0x38)
+
 #define S3C2410_SDIDATA               (0x3C)
 #define S3C2410_SDIIMSK               (0x40)
 
+#define S3C2440_SDIDATA               (0x40)
+#define S3C2440_SDIIMSK               (0x3C)
+
+#define S3C2440_SDICON_SDRESET        (1<<8)
+#define S3C2440_SDICON_MMCCLOCK       (1<<5)
 #define S3C2410_SDICON_BYTEORDER      (1<<4)
 #define S3C2410_SDICON_SDIOIRQ        (1<<3)
 #define S3C2410_SDICON_RWAITEN        (1<<2)
@@ -42,7 +48,8 @@
 #define S3C2410_SDICMDCON_LONGRSP     (1<<10)
 #define S3C2410_SDICMDCON_WAITRSP     (1<<9)
 #define S3C2410_SDICMDCON_CMDSTART    (1<<8)
-#define S3C2410_SDICMDCON_INDEX       (0xff)
+#define S3C2410_SDICMDCON_SENDERHOST  (1<<6)
+#define S3C2410_SDICMDCON_INDEX       (0x3f)
 
 #define S3C2410_SDICMDSTAT_CRCFAIL    (1<<12)
 #define S3C2410_SDICMDSTAT_CMDSENT    (1<<11)
@@ -51,6 +58,9 @@
 #define S3C2410_SDICMDSTAT_XFERING    (1<<8)
 #define S3C2410_SDICMDSTAT_INDEX      (0xff)
 
+#define S3C2440_SDIDCON_DS_BYTE       (0<<22)
+#define S3C2440_SDIDCON_DS_HALFWORD   (1<<22)
+#define S3C2440_SDIDCON_DS_WORD       (2<<22)
 #define S3C2410_SDIDCON_IRQPERIOD     (1<<21)
 #define S3C2410_SDIDCON_TXAFTERRESP   (1<<20)
 #define S3C2410_SDIDCON_RXAFTERCMD    (1<<19)
@@ -59,6 +69,7 @@
 #define S3C2410_SDIDCON_WIDEBUS       (1<<16)
 #define S3C2410_SDIDCON_DMAEN         (1<<15)
 #define S3C2410_SDIDCON_STOP          (1<<14)
+#define S3C2440_SDIDCON_DATSTART      (1<<14)
 #define S3C2410_SDIDCON_DATMODE	      (3<<12)
 #define S3C2410_SDIDCON_BLKNUM        (0x7ff)
 
@@ -68,6 +79,7 @@
 #define S3C2410_SDIDCON_XFER_RXSTART  (2<<12)
 #define S3C2410_SDIDCON_XFER_TXSTART  (3<<12)
 
+#define S3C2410_SDIDCON_BLKNUM_MASK   (0xFFF)
 #define S3C2410_SDIDCNT_BLKNUM_SHIFT  (12)
 
 #define S3C2410_SDIDSTA_RDYWAITREQ    (1<<10)
@@ -82,10 +94,12 @@
 #define S3C2410_SDIDSTA_TXDATAON      (1<<1)
 #define S3C2410_SDIDSTA_RXDATAON      (1<<0)
 
+#define S3C2440_SDIFSTA_FIFORESET      (1<<16)
+#define S3C2440_SDIFSTA_FIFOFAIL       (3<<14)  /* 3 is correct (2 bits) */
 #define S3C2410_SDIFSTA_TFDET          (1<<13)
 #define S3C2410_SDIFSTA_RFDET          (1<<12)
-#define S3C2410_SDIFSTA_TXHALF         (1<<11)
-#define S3C2410_SDIFSTA_TXEMPTY        (1<<10)
+#define S3C2410_SDIFSTA_TFHALF         (1<<11)
+#define S3C2410_SDIFSTA_TFEMPTY        (1<<10)
 #define S3C2410_SDIFSTA_RFLAST         (1<<9)
 #define S3C2410_SDIFSTA_RFFULL         (1<<8)
 #define S3C2410_SDIFSTA_RFHALF         (1<<7)
drivers/mmc/host/s3cmci.c new file +1409 -0

1,409 lines not on this page · raw message

drivers/mmc/host/s3cmci.h new file +71 -0

71 lines not on this page · raw message

drivers/mmc/host/Kconfig +11 -0
Index: linux-2.6/drivers/mmc/host/Kconfig
===================================================================
@@ -130,3 +130,14 @@
 
 	  If unsure, or if your system has no SPI master driver, say N.
 
+config MMC_S3C
+	tristate "Samsung S3C24xx SD/MMC Card Interface support"
+	depends on ARCH_S3C2410 && MMC
+	help
+	  This selects a driver for the MCI interface found in
+	  Samsung's S3C2410, S3C2412, S3C2440, S3C2442 CPUs.
+	  If you have a board based on one of those and a MMC/SD
+	  slot, say Y or M here.
+
+	  If unsure, say N.
+
drivers/mmc/host/Makefile +1 -1
Index: linux-2.6/drivers/mmc/host/Makefile
===================================================================
@@ -17,4 +17,4 @@
 obj-$(CONFIG_MMC_AT91)		+= at91_mci.o
 obj-$(CONFIG_MMC_TIFM_SD)	+= tifm_sd.o
 obj-$(CONFIG_MMC_SPI)		+= mmc_spi.o
-
+obj-$(CONFIG_MMC_S3C)   	+= s3cmci.o
Signature · 3 lines
- Harald Welte <[email protected]>          	        http://openmoko.org/
============================================================================
Software for the world's first truly open Free Software mobile phone
#1 lore raw
Quoted 16 lines · On Wed, 19 Dec 2007 15:22:13 +0100 Harald Welte <[email protected]> wrote:

Hi!

This is a MMC/SD driver for the Samsung S3C24xx SD/MMC controller, originally developed years ago by Thomas Kleffel <[email protected]>.

Due to time constraints, he had no time to further maintain the driver and follow the mainline Linux changes in the SD/MMC stack.

With his authorization, I have taken over the task of making it compliant to the current mainline SD/MMC API and take care of the mainline kernel merge.

So please advise on whatever changes you deem neccessary and I'll try to do my best to incorporate them for a hopefully not-too-distant mainline merge.

Quoted 6 lines

After a potential kernel inclusion, we would co-maintain the driver.

---

Well, my biggest beef with this driver is the excessive debug code. I did a cleanup in an older version of the driver, but it shouldn't be to difficult to do the same for this one. I've included my patch for reference.

drivers/mmc/host/s3cmci.c

Quoted 6 lines

Index: linux-2.6/drivers/mmc/host/s3cmci.c
===================================================================

drivers/mmc/host/s3cmci.c new file +1 -0
 
+#include <linux/mmc/mmc.h>

This is always a warning sign. It should never be needed in a host driver.

Quoted 12 lines
drivers/mmc/host/s3cmci.c new file +12 -0
+
+static inline int get_data_buffer(struct s3cmci_host *host,
+				  u32 *words, u32 **pointer)
+{
+	struct scatterlist *sg;
+
+	if (host->pio_active == XFER_NONE)
+		return -EINVAL;
+
+	if ((!host->mrq) || (!host->mrq->data))
+		return -EINVAL;
+

drivers/mmc/host/s3cmci.c

Quoted 10 lines
drivers/mmc/host/s3cmci.c new file +10 -0
+	if (host->pio_sgptr >= host->mrq->data->sg_len) {
+		dbg(host, dbg_debug, "no more buffers (%i/%i)\n",
+		      host->pio_sgptr, host->mrq->data->sg_len);
+		return -EBUSY;
+	}
+	sg = &host->mrq->data->sg[host->pio_sgptr];
+
+	*words = sg->length >> 2;
+	*pointer = page_address(sg_page(sg)) + sg->offset;
+

The length might not be a multiple of four. And it might also be completely unaligned. Make sure you can either handle such requests, or fail them with -EINVAL.

Rgds

Signature · 5 lines
     -- Pierre Ossman

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

commit 4e47c91b7ca45940af384d3c9919a0eb160a2fb9

Author: Pierre Ossman <[email protected]>
Date:   Fri Jun 1 08:19:15 2007 +0200

s3mci: remove extra debug info

Remove excessive and unmaintained debug strings. This kind of debug info should also be in the MMC layer, not drivers.

drivers/mmc/Makefile +0 -1
index 7c2eb45..42fa90f 100644
@@ -30,6 +30,5 @@ mmc_core-y := mmc.o mmc_sysfs.o
 mmc_core-$(CONFIG_BLOCK) += mmc_queue.o
 
 ifeq ($(CONFIG_MMC_DEBUG),y)
-obj-$(CONFIG_MMC)		+= mmc_debug.o
 EXTRA_CFLAGS += -DDEBUG
 endif
drivers/mmc/mmc_debug.c deleted +0 -59

59 lines not on this page · raw message

drivers/mmc/mmc_debug.h deleted +0 -7
deleted file mode 100644
index 5a84852..0000000
@@ -1,7 +0,0 @@
-#ifndef MMC_DEBUG_H
-#define MMC_DEBUG_H
-
-char *mmc_cmd2str(int err);
-char *mmc_err2str(int err);
-
-#endif /* MMC_DEBUG_H */
drivers/mmc/s3cmci.c +7 -10
index 9b15310..4069f50 100644
@@ -24,7 +24,6 @@
 #include <asm/arch/regs-gpio.h>
 #include <asm/arch/mci.h>
 
-#include "mmc_debug.h"
 #include "s3cmci.h"
 
 #define DRIVER_NAME "s3c-mci"
@@ -106,8 +105,8 @@ static void prepare_dbgmsg(struct s3cmci_host *host, struct mmc_command *cmd,
 								int stop)
 {
  	snprintf(host->dbgmsg_cmd, 300,
-		"#%u%s op:%s(%i) arg:0x%08x flags:0x08%x retries:%u",
-		host->ccnt, (stop?" (STOP)":""), mmc_cmd2str(cmd->opcode),
+		"#%u%s op:CMD%d arg:0x%08x flags:0x08%x retries:%u",
+		host->ccnt, (stop?" (STOP)":""),
 		cmd->opcode, cmd->arg, cmd->flags, cmd->retries);
 
 	if (cmd->data) {
@@ -134,20 +133,18 @@ static void dbg_dumpcmd(struct s3cmci_host *host, struct mmc_command *cmd,
 		dbg(host, dbglvl, "CMD[OK] %s R0:0x%08x\n",
 			host->dbgmsg_cmd, cmd->resp[0]);
 	} else {
-		dbg(host, dbglvl, "CMD[%s] %s Status:%s\n",
-			mmc_err2str(cmd->error), host->dbgmsg_cmd,
-			host->status);
+		dbg(host, dbglvl, "CMD[FAIL(%d)] %s Status:%s\n",
+			cmd->error, host->dbgmsg_cmd, host->status);
 	}
 
 	if (!cmd->data)
 		return;
 
 	if (cmd->data->error == MMC_ERR_NONE) {
-		dbg(host, dbglvl, "DAT[%s] %s\n",
-			mmc_err2str(cmd->data->error), host->dbgmsg_dat);
+		dbg(host, dbglvl, "DAT[OK] %s\n", host->dbgmsg_dat);
 	} else {
-		dbg(host, dbglvl, "DAT[%s] %s DCNT:0x%08x\n",
-			mmc_err2str(cmd->data->error), host->dbgmsg_dat,
+		dbg(host, dbglvl, "DAT[FAIL(%d)] %s DCNT:0x%08x\n",
+			cmd->data->error, host->dbgmsg_dat,
 			readl(host->base + S3C2410_SDIDCNT));
 	}
 }
#2 lore raw

Hi Pierre,

thanks for your comments.

Quoted 4 lines · Pierre Ossman

Well, my biggest beef with this driver is the excessive debug code. I did a cleanup in an older version of the driver, but it shouldn't be to difficult to do the same for this one. I've included my patch for reference.

ok, I'll re-work the patch according to your sample and re-submit.

The debugging was needed during development, and might still be needed to debug some weird issues.

btw: OpenMoko is currently working on an ar6k wifi driver on top of the new mainline kernel SDIO support using the s3c_mci host controller driver as basis. So within not-too-distant-time we should also be able to have SDIO working and tested on s3c_mci.

Quoted 8 lines

drivers/mmc/host/s3cmci.c

Quoted 6 lines

Index: linux-2.6/drivers/mmc/host/s3cmci.c
===================================================================

drivers/mmc/host/s3cmci.c new file +1 -0
 
+#include <linux/mmc/mmc.h>

This is always a warning sign. It should never be needed in a host driver.

ok, will see how to remove it.

Quoted 7 lines

drivers/mmc/host/s3cmci.c

Quoted 3 lines
drivers/mmc/host/s3cmci.c new file +3 -0
+	*words = sg->length >> 2;
+	*pointer = page_address(sg_page(sg)) + sg->offset;
+

The length might not be a multiple of four. And it might also be completely unaligned. Make sure you can either handle such requests, or fail them with -EINVAL.

ok, will update before submitting the next version.

Signature · 3 lines
- Harald Welte <[email protected]>          	        http://openmoko.org/
============================================================================
Software for the world's first truly open Free Software mobile phone