[U-Boot] [PATCH 2/2] AVR32: remove old atmel_mci driver

Sven Schnelle svens at stackframe.org
Wed Oct 12 15:09:09 CEST 2011


And while at it, rename gen_atmel_mci.c to atmel_mci.c and replace
CONFIG_GENERIC_ATMEL_MCI with CONFIG_ATMEL_MCI.

Signed-off-by: Sven Schnelle <svens at stackframe.org>
---
 arch/arm/cpu/arm926ejs/at91/at91sam9260_devices.c |    2 +-
 arch/avr32/lib/board.c                            |    2 +-
 board/atmel/atngw100/atngw100.c                   |    2 +-
 board/atmel/atstk1000/atstk1000.c                 |    2 +-
 board/emk/top9000/top9000.c                       |    2 +-
 doc/README.atmel_mci                              |    8 +-
 drivers/mmc/Makefile                              |    3 +-
 drivers/mmc/atmel_mci.c                           |  691 ++++++++-------------
 drivers/mmc/gen_atmel_mci.c                       |  356 -----------
 include/configs/atngw100.h                        |    2 +-
 include/configs/atstk1002.h                       |    2 +-
 include/configs/atstk1003.h                       |    2 +-
 include/configs/atstk1004.h                       |    2 +-
 include/configs/atstk1006.h                       |    2 +-
 include/configs/favr-32-ezkit.h                   |    2 +-
 include/configs/hammerhead.h                      |    2 +-
 include/configs/mimc200.h                         |    2 +-
 include/configs/top9000.h                         |    2 +-
 18 files changed, 276 insertions(+), 810 deletions(-)
 delete mode 100644 drivers/mmc/gen_atmel_mci.c

diff --git a/arch/arm/cpu/arm926ejs/at91/at91sam9260_devices.c b/arch/arm/cpu/arm926ejs/at91/at91sam9260_devices.c
index 65b8d51..9fc94df 100644
--- a/arch/arm/cpu/arm926ejs/at91/at91sam9260_devices.c
+++ b/arch/arm/cpu/arm926ejs/at91/at91sam9260_devices.c
@@ -196,7 +196,7 @@ void at91_macb_hw_init(void)
 }
 #endif
 
-#if defined(CONFIG_ATMEL_MCI) || defined(CONFIG_GENERIC_ATMEL_MCI)
+#if defined(CONFIG_ATMEL_MCI) || defined(CONFIG_ATMEL_MCI)
 void at91_mci_hw_init(void)
 {
 	at91_set_a_periph(AT91_PIO_PORTA, 8, 1);	/* MCCK */
diff --git a/arch/avr32/lib/board.c b/arch/avr32/lib/board.c
index 694755c..131b9bf 100644
--- a/arch/avr32/lib/board.c
+++ b/arch/avr32/lib/board.c
@@ -334,7 +334,7 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)
 	eth_initialize(gd->bd);
 #endif
 
-#ifdef CONFIG_GENERIC_ATMEL_MCI
+#ifdef CONFIG_ATMEL_MCI
 	mmc_initialize(gd->bd);
 #endif
 	for (;;) {
diff --git a/board/atmel/atngw100/atngw100.c b/board/atmel/atngw100/atngw100.c
index af22403..194f465 100644
--- a/board/atmel/atngw100/atngw100.c
+++ b/board/atmel/atngw100/atngw100.c
@@ -140,7 +140,7 @@ void spi_cs_deactivate(struct spi_slave *slave)
 }
 #endif /* CONFIG_ATMEL_SPI */
 
-#ifdef CONFIG_GENERIC_ATMEL_MCI
+#ifdef CONFIG_ATMEL_MCI
 int board_mmc_init(bd_t *bd)
 {
         /* This calls the atmel_mci_init in gen_atmel_mci.c */
diff --git a/board/atmel/atstk1000/atstk1000.c b/board/atmel/atstk1000/atstk1000.c
index 93f8e43..6885e09 100644
--- a/board/atmel/atstk1000/atstk1000.c
+++ b/board/atmel/atstk1000/atstk1000.c
@@ -140,7 +140,7 @@ int board_eth_init(bd_t *bi)
 }
 #endif
 
-#ifdef CONFIG_GENERIC_ATMEL_MCI
+#ifdef CONFIG_ATMEL_MCI
 int board_mmc_init(bd_t *bd)
 {
         /* This calls the atmel_mci_init in gen_atmel_mci.c */
diff --git a/board/emk/top9000/top9000.c b/board/emk/top9000/top9000.c
index 61dee62..11f0e97 100644
--- a/board/emk/top9000/top9000.c
+++ b/board/emk/top9000/top9000.c
@@ -91,7 +91,7 @@ static void macb_hw_init(void)
 }
 #endif
 
-#ifdef CONFIG_GENERIC_ATMEL_MCI
+#ifdef CONFIG_ATMEL_MCI
 /* this is a weak define that we are overriding */
 int board_mmc_init(bd_t *bd)
 {
diff --git a/doc/README.atmel_mci b/doc/README.atmel_mci
index dee0cf0..cd995dc 100644
--- a/doc/README.atmel_mci
+++ b/doc/README.atmel_mci
@@ -20,7 +20,7 @@ board/SoC specific manner before the driver is initialized:
 
 example: this is added to at91sam9260_devices.c:
 
-#if defined(CONFIG_ATMEL_MCI) || defined(CONFIG_GENERIC_ATMEL_MCI)
+#if defined(CONFIG_ATMEL_MCI) || defined(CONFIG_ATMEL_MCI)
 void at91_mci_hw_init(void)
 {
 	at91_set_a_periph(AT91_PIO_PORTA, 8, PUP);	/* MCCK */
@@ -42,11 +42,11 @@ void at91_mci_hw_init(void)
 
 the board specific file need added:
 ...
-#ifdef CONFIG_GENERIC_ATMEL_MCI
+#ifdef CONFIG_ATMEL_MCI
 # include <mmc.h>
 #endif
 ...
-#ifdef CONFIG_GENERIC_ATMEL_MCI
+#ifdef CONFIG_ATMEL_MCI
 /* this is a weak define that we are overriding */
 int board_mmc_init(bd_t *bd)
 {
@@ -79,7 +79,7 @@ and the board definition files needs:
 /* SD/MMC card */
 #define CONFIG_MMC			1
 #define CONFIG_GENERIC_MMC		1
-#define CONFIG_GENERIC_ATMEL_MCI	1
+#define CONFIG_ATMEL_MCI	1
 #define CONFIG_ATMEL_MCI_PORTB		1	/* Atmel XE-EK uses port B */
 #define CONFIG_SYS_MMC_CD_PIN		AT91_PIN_PC9
 #define CONFIG_CMD_MMC			1
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index 6e94860..9ae5f53 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -25,13 +25,12 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libmmc.o
 
-COBJS-$(CONFIG_ATMEL_MCI) += atmel_mci.o
 COBJS-$(CONFIG_BFIN_SDH) += bfin_sdh.o
 COBJS-$(CONFIG_DAVINCI_MMC) += davinci_mmc.o
 COBJS-$(CONFIG_FSL_ESDHC) += fsl_esdhc.o
 COBJS-$(CONFIG_FTSDC010) += ftsdc010_esdhc.o
 COBJS-$(CONFIG_GENERIC_MMC) += mmc.o
-COBJS-$(CONFIG_GENERIC_ATMEL_MCI) += gen_atmel_mci.o
+COBJS-$(CONFIG_ATMEL_MCI) += atmel_mci.o
 COBJS-$(CONFIG_MMC_SPI) += mmc_spi.o
 COBJS-$(CONFIG_ARM_PL180_MMCI) += arm_pl180_mmci.o
 COBJS-$(CONFIG_MV_SDHCI) += mv_sdhci.o
diff --git a/drivers/mmc/atmel_mci.c b/drivers/mmc/atmel_mci.c
index 0af8d42..f346b24 100644
--- a/drivers/mmc/atmel_mci.c
+++ b/drivers/mmc/atmel_mci.c
@@ -1,4 +1,9 @@
 /*
+ * Copyright (C) 2010
+ * Rob Emanuele <rob at emanuele.us>
+ * Reinhard Meyer, EMK Elektronik <reinhard.meyer at emk-elektronik.de>
+ *
+ * Original Driver:
  * Copyright (C) 2004-2006 Atmel Corporation
  *
  * See file CREDITS for list of people who contributed to this
@@ -11,7 +16,7 @@
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
@@ -19,515 +24,333 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  * MA 02111-1307 USA
  */
-#include <common.h>
 
-#include <part.h>
+#include <common.h>
 #include <mmc.h>
-
+#include <part.h>
+#include <malloc.h>
 #include <asm/io.h>
 #include <asm/errno.h>
 #include <asm/byteorder.h>
 #include <asm/arch/clk.h>
 #include <asm/arch/hardware.h>
-
 #include "atmel_mci.h"
 
-#ifdef DEBUG
-#define pr_debug(fmt, args...) printf(fmt, ##args)
-#else
-#define pr_debug(...) do { } while(0)
-#endif
-
 #ifndef CONFIG_SYS_MMC_CLK_OD
-#define CONFIG_SYS_MMC_CLK_OD		150000
+# define CONFIG_SYS_MMC_CLK_OD	150000
 #endif
 
-#ifndef CONFIG_SYS_MMC_CLK_PP
-#define CONFIG_SYS_MMC_CLK_PP		5000000
-#endif
+#define MMC_DEFAULT_BLKLEN	512
 
-#ifndef CONFIG_SYS_MMC_OP_COND
-#define CONFIG_SYS_MMC_OP_COND		0x00100000
+#if defined(CONFIG_ATMEL_MCI_PORTB)
+# define MCI_BUS 1
+#else
+# define MCI_BUS 0
 #endif
 
-#define MMC_DEFAULT_BLKLEN	512
-#define MMC_DEFAULT_RCA		1
-
-static unsigned int mmc_rca;
-static int mmc_card_is_sd;
-static block_dev_desc_t mmc_blkdev;
+static int initialized = 0;
 
-block_dev_desc_t *mmc_get_dev(int dev)
+/*
+ * Print command and status:
+ *
+ * - always when DEBUG is defined
+ * - on command errors
+ */
+static void dump_cmd(u32 cmdr, u32 arg, u32 status, const char* msg)
 {
-	return &mmc_blkdev;
+	printf("gen_atmel_mci: CMDR %08x (%2u) ARGR %08x (SR: %08x) %s\n",
+		cmdr, cmdr&0x3F, arg, status, msg);
 }
 
-static void mci_set_mode(unsigned long hz, unsigned long blklen)
+/* Setup for MCI Clock and Block Size */
+static void mci_set_mode(struct mmc *mmc, u32 hz, u32 blklen)
 {
-	unsigned long bus_hz;
-	unsigned long clkdiv;
-
-	bus_hz = get_mci_clk_rate();
-	clkdiv = (bus_hz / hz) / 2 - 1;
-
-	pr_debug("mmc: setting clock %lu Hz, block size %lu\n",
-		 hz, blklen);
-
-	if (clkdiv & ~255UL) {
-		clkdiv = 255;
-		printf("mmc: clock %lu too low; setting CLKDIV to 255\n",
-			hz);
+	atmel_mci_t *mci = (atmel_mci_t *)mmc->priv;
+	u32 bus_hz = get_mci_clk_rate();
+	u32 clkdiv = 255;
+
+	debug("mci: bus_hz is %u, setting clock %u Hz, block size %u\n",
+		bus_hz, hz, blklen);
+	if (hz > 0) {
+		/* find lowest clkdiv yielding a rate <= than requested */
+		for (clkdiv=0; clkdiv<255; clkdiv++) {
+			if ((bus_hz / (clkdiv+1) / 2) <= hz)
+				break;
+		}
 	}
+	printf("mci: setting clock %u Hz, block size %u\n",
+		(bus_hz / (clkdiv+1)) / 2, blklen);
 
 	blklen &= 0xfffc;
-	mmci_writel(MR, (MMCI_BF(CLKDIV, clkdiv)
-			 | MMCI_BF(BLKLEN, blklen)
-			 | MMCI_BIT(RDPROOF)
-			 | MMCI_BIT(WRPROOF)));
+	/* On some platforms RDPROOF and WRPROOF are ignored */
+	writel((MMCI_BF(CLKDIV, clkdiv)
+		 | MMCI_BF(BLKLEN, blklen)
+		 | MMCI_BIT(RDPROOF)
+		 | MMCI_BIT(WRPROOF)), &mci->mr);
+	initialized = 1;
 }
 
-#define RESP_NO_CRC	1
-#define R1		MMCI_BF(RSPTYP, 1)
-#define R2		MMCI_BF(RSPTYP, 2)
-#define R3		(R1 | RESP_NO_CRC)
-#define R6		R1
-#define NID		MMCI_BF(MAXLAT, 0)
-#define NCR		MMCI_BF(MAXLAT, 1)
-#define TRCMD_START	MMCI_BF(TRCMD, 1)
-#define TRDIR_READ	MMCI_BF(TRDIR, 1)
-#define TRTYP_BLOCK	MMCI_BF(TRTYP, 0)
-#define INIT_CMD	MMCI_BF(SPCMD, 1)
-#define OPEN_DRAIN	MMCI_BF(OPDCMD, 1)
-
-#define ERROR_FLAGS	(MMCI_BIT(DTOE)			\
-			 | MMCI_BIT(RDIRE)		\
-			 | MMCI_BIT(RENDE)		\
-			 | MMCI_BIT(RINDE)		\
-			 | MMCI_BIT(RTOE))
-
-static int
-mmc_cmd(unsigned long cmd, unsigned long arg,
-	void *resp, unsigned long flags)
+/* Return the CMDR with flags for a given command and data packet */
+static u32 mci_encode_cmd(
+	struct mmc_cmd *cmd, struct mmc_data *data, u32* error_flags)
 {
-	unsigned long *response = resp;
-	int i, response_words = 0;
-	unsigned long error_flags;
-	u32 status;
+	u32 cmdr = 0;
 
-	pr_debug("mmc: CMD%lu 0x%lx (flags 0x%lx)\n",
-		 cmd, arg, flags);
+	/* Default Flags for Errors */
+	*error_flags |= (MMCI_BIT(DTOE) | MMCI_BIT(RDIRE) | MMCI_BIT(RENDE) |
+		MMCI_BIT(RINDE) | MMCI_BIT(RTOE));
 
-	error_flags = ERROR_FLAGS;
-	if (!(flags & RESP_NO_CRC))
-		error_flags |= MMCI_BIT(RCRCE);
+	/* Default Flags for the Command */
+	cmdr |= MMCI_BIT(MAXLAT);
 
-	flags &= ~MMCI_BF(CMDNB, ~0UL);
-
-	if (MMCI_BFEXT(RSPTYP, flags) == MMCI_RSPTYP_48_BIT_RESP)
-		response_words = 1;
-	else if (MMCI_BFEXT(RSPTYP, flags) == MMCI_RSPTYP_136_BIT_RESP)
-		response_words = 4;
-
-	mmci_writel(ARGR, arg);
-	mmci_writel(CMDR, cmd | flags);
-	do {
-		udelay(40);
-		status = mmci_readl(SR);
-	} while (!(status & MMCI_BIT(CMDRDY)));
+	if (data) {
+		cmdr |= MMCI_BF(TRCMD, 1);
+		if (data->blocks > 1)
+			cmdr |= MMCI_BF(TRTYP, 1);
+		if (data->flags & MMC_DATA_READ)
+			cmdr |= MMCI_BIT(TRDIR);
+	}
 
-	pr_debug("mmc: status 0x%08x\n", status);
+	if (cmd->resp_type & MMC_RSP_CRC)
+		*error_flags |= MMCI_BIT(RCRCE);
+	if (cmd->resp_type & MMC_RSP_136)
+		cmdr |= MMCI_BF(RSPTYP, 2);
+	else if (cmd->resp_type & MMC_RSP_BUSY)
+		cmdr |= MMCI_BF(RSPTYP, 3);
+	else if (cmd->resp_type & MMC_RSP_PRESENT)
+		cmdr |= MMCI_BF(RSPTYP, 1);
 
-	if (status & error_flags) {
-		printf("mmc: command %lu failed (status: 0x%08x)\n",
-		       cmd, status);
-		return -EIO;
-	}
+	return cmdr | MMCI_BF(CMDNB, cmd->cmdidx);
+}
 
-	if (response_words)
-		pr_debug("mmc: response:");
+/* Entered into function pointer in mci_send_cmd */
+static u32 mci_data_read(atmel_mci_t *mci, u32* data, u32 error_flags)
+{
+	u32 status;
 
-	for (i = 0; i < response_words; i++) {
-		response[i] = mmci_readl(RSPR);
-		pr_debug(" %08lx", response[i]);
+	do {
+		status = readl(&mci->sr);
+		if (status & (error_flags | MMCI_BIT(OVRE)))
+			goto io_fail;
+	} while (!(status & MMCI_BIT(RXRDY)));
+
+	if (status & MMCI_BIT(RXRDY)) {
+		*data = readl(&mci->rdr);
+		status = 0;
 	}
-	pr_debug("\n");
-
-	return 0;
+io_fail:
+	return status;
 }
 
-static int mmc_acmd(unsigned long cmd, unsigned long arg,
-		    void *resp, unsigned long flags)
+/* Entered into function pointer in mci_send_cmd */
+static u32 mci_data_write(atmel_mci_t *mci, u32* data, u32 error_flags)
 {
-	unsigned long aresp[4];
-	int ret;
+	u32 status;
 
-	/*
-	 * Seems like the APP_CMD part of an ACMD has 64 cycles max
-	 * latency even though the ACMD part doesn't. This isn't
-	 * entirely clear in the SD Card spec, but some cards refuse
-	 * to work if we attempt to use 5 cycles max latency here...
-	 */
-	ret = mmc_cmd(MMC_CMD_APP_CMD, 0, aresp,
-		      R1 | NCR | (flags & OPEN_DRAIN));
-	if (ret)
-		return ret;
-	if ((aresp[0] & (R1_ILLEGAL_COMMAND | R1_APP_CMD)) != R1_APP_CMD)
-		return -ENODEV;
-
-	ret = mmc_cmd(cmd, arg, resp, flags);
-	return ret;
+	do {
+		status = readl(&mci->sr);
+		if (status & (error_flags | MMCI_BIT(UNRE)))
+			goto io_fail;
+	} while (!(status & MMCI_BIT(TXRDY)));
+
+	if (status & MMCI_BIT(TXRDY)) {
+		writel(*data, &mci->tdr);
+		status = 0;
+	}
+io_fail:
+	return status;
 }
 
-static unsigned long
-mmc_bread(int dev, unsigned long start, lbaint_t blkcnt,
-	  void *buffer)
+/*
+ * Entered into mmc structure during driver init
+ *
+ * Sends a command out on the bus and deals with the block data.
+ * Takes the mmc pointer, a command pointer, and an optional data pointer.
+ */
+static int
+mci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 {
-	int ret, i = 0;
-	unsigned long resp[4];
-	unsigned long card_status, data;
-	unsigned long wordcount;
-	u32 *p = buffer;
+	atmel_mci_t *mci = (atmel_mci_t *)mmc->priv;
+	u32 cmdr;
+	u32 error_flags = 0;
 	u32 status;
 
-	if (blkcnt == 0)
-		return 0;
+	if (!initialized) {
+		puts ("MCI not initialized!\n");
+		return COMM_ERR;
+	}
 
-	pr_debug("mmc_bread: dev %d, start %lx, blkcnt %lx\n",
-		 dev, start, blkcnt);
+	/* Figure out the transfer arguments */
+	cmdr = mci_encode_cmd(cmd, data, &error_flags);
 
-	/* Put the device into Transfer state */
-	ret = mmc_cmd(MMC_CMD_SELECT_CARD, mmc_rca << 16, resp, R1 | NCR);
-	if (ret) goto out;
+	/* Send the command */
+	writel(cmd->cmdarg, &mci->argr);
+	writel(cmdr, &mci->cmdr);
 
-	/* Set block length */
-	ret = mmc_cmd(MMC_CMD_SET_BLOCKLEN, mmc_blkdev.blksz, resp, R1 | NCR);
-	if (ret) goto out;
+#ifdef DEBUG
+	dump_cmd(cmdr, cmd->cmdarg, 0, "DEBUG");
+#endif
 
-	pr_debug("MCI_DTOR = %08lx\n", mmci_readl(DTOR));
+	/* Wait for the command to complete */
+	while (!((status = readl(&mci->sr)) & MMCI_BIT(CMDRDY)));
 
-	for (i = 0; i < blkcnt; i++, start++) {
-		ret = mmc_cmd(MMC_CMD_READ_SINGLE_BLOCK,
-			      start * mmc_blkdev.blksz, resp,
-			      (R1 | NCR | TRCMD_START | TRDIR_READ
-			       | TRTYP_BLOCK));
-		if (ret) goto out;
+	if (status & error_flags) {
+		dump_cmd(cmdr, cmd->cmdarg, status, "Command Failed");
+		return COMM_ERR;
+	}
 
-		ret = -EIO;
-		wordcount = 0;
-		do {
+	/* Copy the response to the response buffer */
+	if (cmd->resp_type & MMC_RSP_136) {
+		cmd->response[0] = readl(&mci->rspr);
+		cmd->response[1] = readl(&mci->rspr1);
+		cmd->response[2] = readl(&mci->rspr2);
+		cmd->response[3] = readl(&mci->rspr3);
+	} else
+		cmd->response[0] = readl(&mci->rspr);
+
+	/* transfer all of the blocks */
+	if (data) {
+		u32 word_count, block_count;
+		u32* ioptr;
+		u32 sys_blocksize, dummy, i;
+		u32 (*mci_data_op)
+			(atmel_mci_t *mci, u32* data, u32 error_flags);
+
+		if (data->flags & MMC_DATA_READ) {
+			mci_data_op = mci_data_read;
+			sys_blocksize = mmc->read_bl_len;
+			ioptr = (u32*)data->dest;
+		} else {
+			mci_data_op = mci_data_write;
+			sys_blocksize = mmc->write_bl_len;
+			ioptr = (u32*)data->src;
+		}
+
+		status = 0;
+		for (block_count = 0;
+				block_count < data->blocks && !status;
+				block_count++) {
+			word_count = 0;
 			do {
-				status = mmci_readl(SR);
-				if (status & (ERROR_FLAGS | MMCI_BIT(OVRE)))
-					goto read_error;
-			} while (!(status & MMCI_BIT(RXRDY)));
-
-			if (status & MMCI_BIT(RXRDY)) {
-				data = mmci_readl(RDR);
-				/* pr_debug("%x\n", data); */
-				*p++ = data;
-				wordcount++;
+				status = mci_data_op(mci, ioptr, error_flags);
+				word_count++;
+				ioptr++;
+			} while (!status && word_count < (data->blocksize/4));
+#ifdef DEBUG
+			if (data->flags & MMC_DATA_READ)
+			{
+				printf("Read Data:\n");
+				print_buffer(0, data->dest, 1,
+					word_count*4, 0);
 			}
-		} while(wordcount < (mmc_blkdev.blksz / 4));
-
-		pr_debug("mmc: read %u words, waiting for BLKE\n", wordcount);
+#endif
+#ifdef DEBUG
+			if (!status && word_count < (sys_blocksize / 4))
+				printf("filling rest of block...\n");
+#endif
+			/* fill the rest of a full block */
+			while (!status && word_count < (sys_blocksize / 4)) {
+				status = mci_data_op(mci, &dummy,
+					error_flags);
+				word_count++;
+			}
+			if (status) {
+				dump_cmd(cmdr, cmd->cmdarg, status,
+					"Data Transfer Failed");
+				return COMM_ERR;
+			}
+		}
 
+		/* Wait for Transfer End */
+		i = 0;
 		do {
-			status = mmci_readl(SR);
-		} while (!(status & MMCI_BIT(BLKE)));
+			status = readl(&mci->sr);
 
-		putc('.');
+			if (status & error_flags) {
+				dump_cmd(cmdr, cmd->cmdarg, status,
+					"DTIP Wait Failed");
+				return COMM_ERR;
+			}
+			i++;
+		} while ((status & MMCI_BIT(DTIP)) && i < 10000);
+		if (status & MMCI_BIT(DTIP)) {
+			dump_cmd(cmdr, cmd->cmdarg, status,
+				"XFER DTIP never unset, ignoring");
+		}
 	}
 
-out:
-	/* Put the device back into Standby state */
-	mmc_cmd(MMC_CMD_SELECT_CARD, 0, resp, NCR);
-	return i;
-
-read_error:
-	mmc_cmd(MMC_CMD_SEND_STATUS, mmc_rca << 16, &card_status, R1 | NCR);
-	printf("mmc: bread failed, status = %08x, card status = %08lx\n",
-	       status, card_status);
-	goto out;
+	return 0;
 }
 
-static void mmc_parse_cid(struct mmc_cid *cid, unsigned long *resp)
+/* Entered into mmc structure during driver init */
+static void mci_set_ios(struct mmc *mmc)
 {
-	cid->mid = resp[0] >> 24;
-	cid->oid = (resp[0] >> 8) & 0xffff;
-	cid->pnm[0] = resp[0];
-	cid->pnm[1] = resp[1] >> 24;
-	cid->pnm[2] = resp[1] >> 16;
-	cid->pnm[3] = resp[1] >> 8;
-	cid->pnm[4] = resp[1];
-	cid->pnm[5] = resp[2] >> 24;
-	cid->pnm[6] = 0;
-	cid->prv = resp[2] >> 16;
-	cid->psn = (resp[2] << 16) | (resp[3] >> 16);
-	cid->mdt = resp[3] >> 8;
-}
+	atmel_mci_t *mci = (atmel_mci_t *)mmc->priv;
+	int busw = (mmc->bus_width == 4) ? 1 : 0;
 
-static void sd_parse_cid(struct mmc_cid *cid, unsigned long *resp)
-{
-	cid->mid = resp[0] >> 24;
-	cid->oid = (resp[0] >> 8) & 0xffff;
-	cid->pnm[0] = resp[0];
-	cid->pnm[1] = resp[1] >> 24;
-	cid->pnm[2] = resp[1] >> 16;
-	cid->pnm[3] = resp[1] >> 8;
-	cid->pnm[4] = resp[1];
-	cid->pnm[5] = 0;
-	cid->pnm[6] = 0;
-	cid->prv = resp[2] >> 24;
-	cid->psn = (resp[2] << 8) | (resp[3] >> 24);
-	cid->mdt = (resp[3] >> 8) & 0x0fff;
-}
+	/* Set the clock speed */
+	mci_set_mode(mmc, mmc->clock, MMC_DEFAULT_BLKLEN);
 
-static void mmc_dump_cid(const struct mmc_cid *cid)
-{
-	printf("Manufacturer ID:       %02X\n", cid->mid);
-	printf("OEM/Application ID:    %04X\n", cid->oid);
-	printf("Product name:          %s\n", cid->pnm);
-	printf("Product Revision:      %u.%u\n",
-	       cid->prv >> 4, cid->prv & 0x0f);
-	printf("Product Serial Number: %lu\n", cid->psn);
-	printf("Manufacturing Date:    %02u/%02u\n",
-	       cid->mdt >> 4, cid->mdt & 0x0f);
+	/*
+	 * set the bus width and select slot for this interface
+	 * there is no capability for multiple slots on the same interface yet
+	 * Bitfield SCDBUS needs to be expanded to 2 bits for 8-bit buses
+	 */
+	writel(MMCI_BF(SCDBUS, busw) | MMCI_BF(SCDSEL, MCI_BUS), &mci->sdcr);
 }
 
-static void mmc_dump_csd(const struct mmc_csd *csd)
+/* Entered into mmc structure during driver init */
+static int mci_init(struct mmc *mmc)
 {
-	unsigned long *csd_raw = (unsigned long *)csd;
-	printf("CSD data: %08lx %08lx %08lx %08lx\n",
-	       csd_raw[0], csd_raw[1], csd_raw[2], csd_raw[3]);
-	printf("CSD structure version:   1.%u\n", csd->csd_structure);
-	printf("MMC System Spec version: %u\n", csd->spec_vers);
-	printf("Card command classes:    %03x\n", csd->ccc);
-	printf("Read block length:       %u\n", 1 << csd->read_bl_len);
-	if (csd->read_bl_partial)
-		puts("Supports partial reads\n");
-	else
-		puts("Does not support partial reads\n");
-	printf("Write block length:      %u\n", 1 << csd->write_bl_len);
-	if (csd->write_bl_partial)
-		puts("Supports partial writes\n");
-	else
-		puts("Does not support partial writes\n");
-	if (csd->wp_grp_enable)
-		printf("Supports group WP:      %u\n", csd->wp_grp_size + 1);
-	else
-		puts("Does not support group WP\n");
-	printf("Card capacity:		%u bytes\n",
-	       (csd->c_size + 1) * (1 << (csd->c_size_mult + 2)) *
-	       (1 << csd->read_bl_len));
-	printf("File format:            %u/%u\n",
-	       csd->file_format_grp, csd->file_format);
-	puts("Write protection:        ");
-	if (csd->perm_write_protect)
-		puts(" permanent");
-	if (csd->tmp_write_protect)
-		puts(" temporary");
-	putc('\n');
-}
+	atmel_mci_t *mci = (atmel_mci_t *)mmc->priv;
 
-static int mmc_idle_cards(void)
-{
-	int ret;
+	/* Initialize controller */
+	writel(MMCI_BIT(SWRST), &mci->cr);	/* soft reset */
+	writel(MMCI_BIT(PWSDIS), &mci->cr);	/* disable power save */
+	writel(MMCI_BIT(MCIEN), &mci->cr);	/* enable mci */
+	writel(MMCI_BF(SCDSEL, MCI_BUS), &mci->sdcr);	/* select port */
 
-	/* Reset and initialize all cards */
-	ret = mmc_cmd(MMC_CMD_GO_IDLE_STATE, 0, NULL, 0);
-	if (ret)
-		return ret;
+	/* Initial Time-outs */
+	writel(0x5f, &mci->dtor);
+	/* Disable Interrupts */
+	writel(~0UL, &mci->idr);
 
-	/* Keep the bus idle for 74 clock cycles */
-	return mmc_cmd(0, 0, NULL, INIT_CMD);
-}
+	/* Set default clocks and blocklen */
+	mci_set_mode(mmc, CONFIG_SYS_MMC_CLK_OD, MMC_DEFAULT_BLKLEN);
 
-static int sd_init_card(struct mmc_cid *cid, int verbose)
-{
-	unsigned long resp[4];
-	int i, ret = 0;
-
-	mmc_idle_cards();
-	for (i = 0; i < 1000; i++) {
-		ret = mmc_acmd(SD_CMD_APP_SEND_OP_COND, CONFIG_SYS_MMC_OP_COND,
-			       resp, R3 | NID);
-		if (ret || (resp[0] & 0x80000000))
-			break;
-		ret = -ETIMEDOUT;
-	}
-
-	if (ret)
-		return ret;
-
-	ret = mmc_cmd(MMC_CMD_ALL_SEND_CID, 0, resp, R2 | NID);
-	if (ret)
-		return ret;
-	sd_parse_cid(cid, resp);
-	if (verbose)
-		mmc_dump_cid(cid);
-
-	/* Get RCA of the card that responded */
-	ret = mmc_cmd(SD_CMD_SEND_RELATIVE_ADDR, 0, resp, R6 | NCR);
-	if (ret)
-		return ret;
-
-	mmc_rca = resp[0] >> 16;
-	if (verbose)
-		printf("SD Card detected (RCA %u)\n", mmc_rca);
-	mmc_card_is_sd = 1;
 	return 0;
 }
 
-static int mmc_init_card(struct mmc_cid *cid, int verbose)
-{
-	unsigned long resp[4];
-	int i, ret = 0;
-
-	mmc_idle_cards();
-	for (i = 0; i < 1000; i++) {
-		ret = mmc_cmd(MMC_CMD_SEND_OP_COND, CONFIG_SYS_MMC_OP_COND, resp,
-			      R3 | NID | OPEN_DRAIN);
-		if (ret || (resp[0] & 0x80000000))
-			break;
-		ret = -ETIMEDOUT;
-	}
-
-	if (ret)
-		return ret;
-
-	/* Get CID of all cards. FIXME: Support more than one card */
-	ret = mmc_cmd(MMC_CMD_ALL_SEND_CID, 0, resp, R2 | NID | OPEN_DRAIN);
-	if (ret)
-		return ret;
-	mmc_parse_cid(cid, resp);
-	if (verbose)
-		mmc_dump_cid(cid);
-
-	/* Set Relative Address of the card that responded */
-	ret = mmc_cmd(MMC_CMD_SET_RELATIVE_ADDR, mmc_rca << 16, resp,
-		      R1 | NCR | OPEN_DRAIN);
-	return ret;
-}
-
-static void mci_set_data_timeout(struct mmc_csd *csd)
-{
-	static const unsigned int dtomul_to_shift[] = {
-		0, 4, 7, 8, 10, 12, 16, 20,
-	};
-	static const unsigned int taac_exp[] = {
-		1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
-	};
-	static const unsigned int taac_mant[] = {
-		0,  10, 12, 13, 15, 60, 25, 30,
-		35, 40, 45, 50, 55, 60, 70, 80,
-	};
-	unsigned int timeout_ns, timeout_clks;
-	unsigned int e, m;
-	unsigned int dtocyc, dtomul;
-	unsigned int shift;
-	u32 dtor;
-
-	e = csd->taac & 0x07;
-	m = (csd->taac >> 3) & 0x0f;
-
-	timeout_ns = (taac_exp[e] * taac_mant[m] + 9) / 10;
-	timeout_clks = csd->nsac * 100;
-
-	timeout_clks += (((timeout_ns + 9) / 10)
-			 * ((CONFIG_SYS_MMC_CLK_PP + 99999) / 100000) + 9999) / 10000;
-	if (!mmc_card_is_sd)
-		timeout_clks *= 10;
-	else
-		timeout_clks *= 100;
-
-	dtocyc = timeout_clks;
-	dtomul = 0;
-	shift = 0;
-	while (dtocyc > 15 && dtomul < 8) {
-		dtomul++;
-		shift = dtomul_to_shift[dtomul];
-		dtocyc = (timeout_clks + (1 << shift) - 1) >> shift;
-	}
-
-	if (dtomul >= 8) {
-		dtomul = 7;
-		dtocyc = 15;
-		puts("Warning: Using maximum data timeout\n");
-	}
-
-	dtor = (MMCI_BF(DTOMUL, dtomul)
-		| MMCI_BF(DTOCYC, dtocyc));
-	mmci_writel(DTOR, dtor);
-
-	printf("mmc: Using %u cycles data timeout (DTOR=0x%x)\n",
-	       dtocyc << shift, dtor);
-}
-
-int mmc_legacy_init(int verbose)
+/*
+ * This is the only exported function
+ *
+ * Call it with the MCI register base address
+ */
+int atmel_mci_init(void *regs)
 {
-	struct mmc_cid cid;
-	struct mmc_csd csd;
-	unsigned int max_blksz;
-	int ret;
-
-	/* Initialize controller */
-	mmci_writel(CR, MMCI_BIT(SWRST));
-	mmci_writel(CR, MMCI_BIT(MCIEN));
-	mmci_writel(DTOR, 0x5f);
-	mmci_writel(IDR, ~0UL);
-	mci_set_mode(CONFIG_SYS_MMC_CLK_OD, MMC_DEFAULT_BLKLEN);
-
-	mmc_card_is_sd = 0;
-
-	ret = sd_init_card(&cid, verbose);
-	if (ret) {
-		mmc_rca = MMC_DEFAULT_RCA;
-		ret = mmc_init_card(&cid, verbose);
-	}
-	if (ret)
-		return ret;
-
-	/* Get CSD from the card */
-	ret = mmc_cmd(MMC_CMD_SEND_CSD, mmc_rca << 16, &csd, R2 | NCR);
-	if (ret)
-		return ret;
-	if (verbose)
-		mmc_dump_csd(&csd);
-
-	mci_set_data_timeout(&csd);
-
-	/* Initialize the blockdev structure */
-	mmc_blkdev.if_type = IF_TYPE_MMC;
-	mmc_blkdev.part_type = PART_TYPE_DOS;
-	mmc_blkdev.block_read = mmc_bread;
-	sprintf((char *)mmc_blkdev.vendor,
-		"Man %02x%04x Snr %08lx",
-		cid.mid, cid.oid, cid.psn);
-	strncpy((char *)mmc_blkdev.product, cid.pnm,
-		sizeof(mmc_blkdev.product));
-	sprintf((char *)mmc_blkdev.revision, "%x %x",
-		cid.prv >> 4, cid.prv & 0x0f);
-
+	struct mmc *mmc = malloc(sizeof(struct mmc));
+
+	if (!mmc)
+		return -1;
+	strcpy(mmc->name, "mci");
+	mmc->priv = regs;
+	mmc->send_cmd = mci_send_cmd;
+	mmc->set_ios = mci_set_ios;
+	mmc->init = mci_init;
+
+	/* need to be able to pass these in on a board by board basis */
+	mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
+	mmc->host_caps = MMC_MODE_4BIT;
 	/*
-	 * If we can't use 512 byte blocks, refuse to deal with the
-	 * card. Tons of code elsewhere seems to depend on this.
+	 * min and max frequencies determined by
+	 * max and min of clock divider
 	 */
-	max_blksz = 1 << csd.read_bl_len;
-	if (max_blksz < 512 || (max_blksz > 512 && !csd.read_bl_partial)) {
-		printf("Card does not support 512 byte reads, aborting.\n");
-		return -ENODEV;
-	}
-	mmc_blkdev.blksz = 512;
-	mmc_blkdev.lba = (csd.c_size + 1) * (1 << (csd.c_size_mult + 2));
+	mmc->f_min = get_mci_clk_rate() / (2*256);
+	mmc->f_max = get_mci_clk_rate() / (2*1);
 
-	mci_set_mode(CONFIG_SYS_MMC_CLK_PP, mmc_blkdev.blksz);
+	mmc->b_max = 0;
 
-#if 0
-	if (fat_register_device(&mmc_blkdev, 1))
-		printf("Could not register MMC fat device\n");
-#else
-	init_part(&mmc_blkdev);
-#endif
+	mmc_register(mmc);
 
 	return 0;
 }
diff --git a/drivers/mmc/gen_atmel_mci.c b/drivers/mmc/gen_atmel_mci.c
deleted file mode 100644
index f346b24..0000000
--- a/drivers/mmc/gen_atmel_mci.c
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- * Copyright (C) 2010
- * Rob Emanuele <rob at emanuele.us>
- * Reinhard Meyer, EMK Elektronik <reinhard.meyer at emk-elektronik.de>
- *
- * Original Driver:
- * Copyright (C) 2004-2006 Atmel Corporation
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-
-#include <common.h>
-#include <mmc.h>
-#include <part.h>
-#include <malloc.h>
-#include <asm/io.h>
-#include <asm/errno.h>
-#include <asm/byteorder.h>
-#include <asm/arch/clk.h>
-#include <asm/arch/hardware.h>
-#include "atmel_mci.h"
-
-#ifndef CONFIG_SYS_MMC_CLK_OD
-# define CONFIG_SYS_MMC_CLK_OD	150000
-#endif
-
-#define MMC_DEFAULT_BLKLEN	512
-
-#if defined(CONFIG_ATMEL_MCI_PORTB)
-# define MCI_BUS 1
-#else
-# define MCI_BUS 0
-#endif
-
-static int initialized = 0;
-
-/*
- * Print command and status:
- *
- * - always when DEBUG is defined
- * - on command errors
- */
-static void dump_cmd(u32 cmdr, u32 arg, u32 status, const char* msg)
-{
-	printf("gen_atmel_mci: CMDR %08x (%2u) ARGR %08x (SR: %08x) %s\n",
-		cmdr, cmdr&0x3F, arg, status, msg);
-}
-
-/* Setup for MCI Clock and Block Size */
-static void mci_set_mode(struct mmc *mmc, u32 hz, u32 blklen)
-{
-	atmel_mci_t *mci = (atmel_mci_t *)mmc->priv;
-	u32 bus_hz = get_mci_clk_rate();
-	u32 clkdiv = 255;
-
-	debug("mci: bus_hz is %u, setting clock %u Hz, block size %u\n",
-		bus_hz, hz, blklen);
-	if (hz > 0) {
-		/* find lowest clkdiv yielding a rate <= than requested */
-		for (clkdiv=0; clkdiv<255; clkdiv++) {
-			if ((bus_hz / (clkdiv+1) / 2) <= hz)
-				break;
-		}
-	}
-	printf("mci: setting clock %u Hz, block size %u\n",
-		(bus_hz / (clkdiv+1)) / 2, blklen);
-
-	blklen &= 0xfffc;
-	/* On some platforms RDPROOF and WRPROOF are ignored */
-	writel((MMCI_BF(CLKDIV, clkdiv)
-		 | MMCI_BF(BLKLEN, blklen)
-		 | MMCI_BIT(RDPROOF)
-		 | MMCI_BIT(WRPROOF)), &mci->mr);
-	initialized = 1;
-}
-
-/* Return the CMDR with flags for a given command and data packet */
-static u32 mci_encode_cmd(
-	struct mmc_cmd *cmd, struct mmc_data *data, u32* error_flags)
-{
-	u32 cmdr = 0;
-
-	/* Default Flags for Errors */
-	*error_flags |= (MMCI_BIT(DTOE) | MMCI_BIT(RDIRE) | MMCI_BIT(RENDE) |
-		MMCI_BIT(RINDE) | MMCI_BIT(RTOE));
-
-	/* Default Flags for the Command */
-	cmdr |= MMCI_BIT(MAXLAT);
-
-	if (data) {
-		cmdr |= MMCI_BF(TRCMD, 1);
-		if (data->blocks > 1)
-			cmdr |= MMCI_BF(TRTYP, 1);
-		if (data->flags & MMC_DATA_READ)
-			cmdr |= MMCI_BIT(TRDIR);
-	}
-
-	if (cmd->resp_type & MMC_RSP_CRC)
-		*error_flags |= MMCI_BIT(RCRCE);
-	if (cmd->resp_type & MMC_RSP_136)
-		cmdr |= MMCI_BF(RSPTYP, 2);
-	else if (cmd->resp_type & MMC_RSP_BUSY)
-		cmdr |= MMCI_BF(RSPTYP, 3);
-	else if (cmd->resp_type & MMC_RSP_PRESENT)
-		cmdr |= MMCI_BF(RSPTYP, 1);
-
-	return cmdr | MMCI_BF(CMDNB, cmd->cmdidx);
-}
-
-/* Entered into function pointer in mci_send_cmd */
-static u32 mci_data_read(atmel_mci_t *mci, u32* data, u32 error_flags)
-{
-	u32 status;
-
-	do {
-		status = readl(&mci->sr);
-		if (status & (error_flags | MMCI_BIT(OVRE)))
-			goto io_fail;
-	} while (!(status & MMCI_BIT(RXRDY)));
-
-	if (status & MMCI_BIT(RXRDY)) {
-		*data = readl(&mci->rdr);
-		status = 0;
-	}
-io_fail:
-	return status;
-}
-
-/* Entered into function pointer in mci_send_cmd */
-static u32 mci_data_write(atmel_mci_t *mci, u32* data, u32 error_flags)
-{
-	u32 status;
-
-	do {
-		status = readl(&mci->sr);
-		if (status & (error_flags | MMCI_BIT(UNRE)))
-			goto io_fail;
-	} while (!(status & MMCI_BIT(TXRDY)));
-
-	if (status & MMCI_BIT(TXRDY)) {
-		writel(*data, &mci->tdr);
-		status = 0;
-	}
-io_fail:
-	return status;
-}
-
-/*
- * Entered into mmc structure during driver init
- *
- * Sends a command out on the bus and deals with the block data.
- * Takes the mmc pointer, a command pointer, and an optional data pointer.
- */
-static int
-mci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
-{
-	atmel_mci_t *mci = (atmel_mci_t *)mmc->priv;
-	u32 cmdr;
-	u32 error_flags = 0;
-	u32 status;
-
-	if (!initialized) {
-		puts ("MCI not initialized!\n");
-		return COMM_ERR;
-	}
-
-	/* Figure out the transfer arguments */
-	cmdr = mci_encode_cmd(cmd, data, &error_flags);
-
-	/* Send the command */
-	writel(cmd->cmdarg, &mci->argr);
-	writel(cmdr, &mci->cmdr);
-
-#ifdef DEBUG
-	dump_cmd(cmdr, cmd->cmdarg, 0, "DEBUG");
-#endif
-
-	/* Wait for the command to complete */
-	while (!((status = readl(&mci->sr)) & MMCI_BIT(CMDRDY)));
-
-	if (status & error_flags) {
-		dump_cmd(cmdr, cmd->cmdarg, status, "Command Failed");
-		return COMM_ERR;
-	}
-
-	/* Copy the response to the response buffer */
-	if (cmd->resp_type & MMC_RSP_136) {
-		cmd->response[0] = readl(&mci->rspr);
-		cmd->response[1] = readl(&mci->rspr1);
-		cmd->response[2] = readl(&mci->rspr2);
-		cmd->response[3] = readl(&mci->rspr3);
-	} else
-		cmd->response[0] = readl(&mci->rspr);
-
-	/* transfer all of the blocks */
-	if (data) {
-		u32 word_count, block_count;
-		u32* ioptr;
-		u32 sys_blocksize, dummy, i;
-		u32 (*mci_data_op)
-			(atmel_mci_t *mci, u32* data, u32 error_flags);
-
-		if (data->flags & MMC_DATA_READ) {
-			mci_data_op = mci_data_read;
-			sys_blocksize = mmc->read_bl_len;
-			ioptr = (u32*)data->dest;
-		} else {
-			mci_data_op = mci_data_write;
-			sys_blocksize = mmc->write_bl_len;
-			ioptr = (u32*)data->src;
-		}
-
-		status = 0;
-		for (block_count = 0;
-				block_count < data->blocks && !status;
-				block_count++) {
-			word_count = 0;
-			do {
-				status = mci_data_op(mci, ioptr, error_flags);
-				word_count++;
-				ioptr++;
-			} while (!status && word_count < (data->blocksize/4));
-#ifdef DEBUG
-			if (data->flags & MMC_DATA_READ)
-			{
-				printf("Read Data:\n");
-				print_buffer(0, data->dest, 1,
-					word_count*4, 0);
-			}
-#endif
-#ifdef DEBUG
-			if (!status && word_count < (sys_blocksize / 4))
-				printf("filling rest of block...\n");
-#endif
-			/* fill the rest of a full block */
-			while (!status && word_count < (sys_blocksize / 4)) {
-				status = mci_data_op(mci, &dummy,
-					error_flags);
-				word_count++;
-			}
-			if (status) {
-				dump_cmd(cmdr, cmd->cmdarg, status,
-					"Data Transfer Failed");
-				return COMM_ERR;
-			}
-		}
-
-		/* Wait for Transfer End */
-		i = 0;
-		do {
-			status = readl(&mci->sr);
-
-			if (status & error_flags) {
-				dump_cmd(cmdr, cmd->cmdarg, status,
-					"DTIP Wait Failed");
-				return COMM_ERR;
-			}
-			i++;
-		} while ((status & MMCI_BIT(DTIP)) && i < 10000);
-		if (status & MMCI_BIT(DTIP)) {
-			dump_cmd(cmdr, cmd->cmdarg, status,
-				"XFER DTIP never unset, ignoring");
-		}
-	}
-
-	return 0;
-}
-
-/* Entered into mmc structure during driver init */
-static void mci_set_ios(struct mmc *mmc)
-{
-	atmel_mci_t *mci = (atmel_mci_t *)mmc->priv;
-	int busw = (mmc->bus_width == 4) ? 1 : 0;
-
-	/* Set the clock speed */
-	mci_set_mode(mmc, mmc->clock, MMC_DEFAULT_BLKLEN);
-
-	/*
-	 * set the bus width and select slot for this interface
-	 * there is no capability for multiple slots on the same interface yet
-	 * Bitfield SCDBUS needs to be expanded to 2 bits for 8-bit buses
-	 */
-	writel(MMCI_BF(SCDBUS, busw) | MMCI_BF(SCDSEL, MCI_BUS), &mci->sdcr);
-}
-
-/* Entered into mmc structure during driver init */
-static int mci_init(struct mmc *mmc)
-{
-	atmel_mci_t *mci = (atmel_mci_t *)mmc->priv;
-
-	/* Initialize controller */
-	writel(MMCI_BIT(SWRST), &mci->cr);	/* soft reset */
-	writel(MMCI_BIT(PWSDIS), &mci->cr);	/* disable power save */
-	writel(MMCI_BIT(MCIEN), &mci->cr);	/* enable mci */
-	writel(MMCI_BF(SCDSEL, MCI_BUS), &mci->sdcr);	/* select port */
-
-	/* Initial Time-outs */
-	writel(0x5f, &mci->dtor);
-	/* Disable Interrupts */
-	writel(~0UL, &mci->idr);
-
-	/* Set default clocks and blocklen */
-	mci_set_mode(mmc, CONFIG_SYS_MMC_CLK_OD, MMC_DEFAULT_BLKLEN);
-
-	return 0;
-}
-
-/*
- * This is the only exported function
- *
- * Call it with the MCI register base address
- */
-int atmel_mci_init(void *regs)
-{
-	struct mmc *mmc = malloc(sizeof(struct mmc));
-
-	if (!mmc)
-		return -1;
-	strcpy(mmc->name, "mci");
-	mmc->priv = regs;
-	mmc->send_cmd = mci_send_cmd;
-	mmc->set_ios = mci_set_ios;
-	mmc->init = mci_init;
-
-	/* need to be able to pass these in on a board by board basis */
-	mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
-	mmc->host_caps = MMC_MODE_4BIT;
-	/*
-	 * min and max frequencies determined by
-	 * max and min of clock divider
-	 */
-	mmc->f_min = get_mci_clk_rate() / (2*256);
-	mmc->f_max = get_mci_clk_rate() / (2*1);
-
-	mmc->b_max = 0;
-
-	mmc_register(mmc);
-
-	return 0;
-}
diff --git a/include/configs/atngw100.h b/include/configs/atngw100.h
index 5e3155d..7775697 100644
--- a/include/configs/atngw100.h
+++ b/include/configs/atngw100.h
@@ -128,7 +128,7 @@
 #define CONFIG_SYS_NR_PIOS			5
 #define CONFIG_SYS_HSDRAMC
 #define CONFIG_MMC
-#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_ATMEL_MCI
 #define CONFIG_GENERIC_MMC
 #define CONFIG_SYS_MMC_MAX_BLK_COUNT 1
 #define CONFIG_ATMEL_SPI
diff --git a/include/configs/atstk1002.h b/include/configs/atstk1002.h
index bb426f1..793b43d 100644
--- a/include/configs/atstk1002.h
+++ b/include/configs/atstk1002.h
@@ -151,7 +151,7 @@
 #define CONFIG_SYS_NR_PIOS			5
 #define CONFIG_SYS_HSDRAMC
 #define CONFIG_MMC
-#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_ATMEL_MCI
 #define CONFIG_GENERIC_MMC
 #define CONFIG_SYS_MMC_MAX_BLK_COUNT 1
 
diff --git a/include/configs/atstk1003.h b/include/configs/atstk1003.h
index a426f15..8b485a1 100644
--- a/include/configs/atstk1003.h
+++ b/include/configs/atstk1003.h
@@ -135,7 +135,7 @@
 #define CONFIG_PORTMUX_PIO
 #define CONFIG_SYS_HSDRAMC
 #define CONFIG_MMC
-#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_ATMEL_MCI
 #define CONFIG_GENERIC_MMC
 
 #define CONFIG_SYS_DCACHE_LINESZ		32
diff --git a/include/configs/atstk1004.h b/include/configs/atstk1004.h
index 1b4a1af..5eb5ba0 100644
--- a/include/configs/atstk1004.h
+++ b/include/configs/atstk1004.h
@@ -135,7 +135,7 @@
 #define CONFIG_PORTMUX_PIO
 #define CONFIG_SYS_HSDRAMC
 #define CONFIG_MMC
-#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_ATMEL_MCI
 #define CONFIG_GENERIC_MMC
 #define CONFIG_SYS_MMC_MAX_BLK_COUNT 1
 
diff --git a/include/configs/atstk1006.h b/include/configs/atstk1006.h
index 29fdd12..958fdf5 100644
--- a/include/configs/atstk1006.h
+++ b/include/configs/atstk1006.h
@@ -151,7 +151,7 @@
 #define CONFIG_SYS_NR_PIOS			5
 #define CONFIG_SYS_HSDRAMC
 #define CONFIG_MMC
-#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_ATMEL_MCI
 #define CONFIG_GENERIC_MMC
 #define CONFIG_SYS_MMC_MAX_BLK_COUNT 1
 
diff --git a/include/configs/favr-32-ezkit.h b/include/configs/favr-32-ezkit.h
index 1c8da9f..b301f14 100644
--- a/include/configs/favr-32-ezkit.h
+++ b/include/configs/favr-32-ezkit.h
@@ -150,7 +150,7 @@
 #define CONFIG_SYS_NR_PIOS			5
 #define CONFIG_SYS_HSDRAMC
 #define CONFIG_MMC
-#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_ATMEL_MCI
 #define CONFIG_GENERIC_MMC
 
 #define CONFIG_SYS_DCACHE_LINESZ		32
diff --git a/include/configs/hammerhead.h b/include/configs/hammerhead.h
index 5570bdb..56b5ffe 100644
--- a/include/configs/hammerhead.h
+++ b/include/configs/hammerhead.h
@@ -124,7 +124,7 @@
 #define CONFIG_SYS_NR_PIOS			5
 #define CONFIG_SYS_HSDRAMC
 #define CONFIG_MMC
-#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_ATMEL_MCI
 #define CONFIG_GENERIC_MMC
 
 #define CONFIG_SYS_DCACHE_LINESZ		32
diff --git a/include/configs/mimc200.h b/include/configs/mimc200.h
index 8031a05..d60eff4 100644
--- a/include/configs/mimc200.h
+++ b/include/configs/mimc200.h
@@ -129,7 +129,7 @@
 #define CONFIG_SYS_NR_PIOS			5
 #define CONFIG_SYS_HSDRAMC
 #define CONFIG_MMC
-#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_ATMEL_MCI
 #define CONFIG_GENERIC_MMC
 
 #if defined(CONFIG_LCD)
diff --git a/include/configs/top9000.h b/include/configs/top9000.h
index 2c66f33..d2b8b9a 100644
--- a/include/configs/top9000.h
+++ b/include/configs/top9000.h
@@ -95,7 +95,7 @@
 /* SD/MMC card */
 #define CONFIG_MMC
 #define CONFIG_GENERIC_MMC
-#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_ATMEL_MCI
 #define CONFIG_SYS_MMC_CD_PIN		AT91_PIN_PC9
 #define CONFIG_CMD_MMC
 
-- 
1.7.6.3



More information about the U-Boot mailing list