* [U-Boot] [PATCH] AVR32: switch to generic mmc framework
@ 2011-10-12 13:09 Sven Schnelle
2011-10-12 13:09 ` [U-Boot] [PATCH 1/2] AVR32: use " Sven Schnelle
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Sven Schnelle @ 2011-10-12 13:09 UTC (permalink / raw)
To: u-boot
Hi List,
these patches switch all AVR32 boards to the generic MMC framework. Motivation
for doing so is to be able to boot from SDHC cards. The second patch removes
the legacy atmel_mci driver, as it is no longer used by any board.
I've only tried this code on the Atmel ATNGW100, as i have no other AVR32 boards.
Would be great if some other users could try that patch on different platforms.
It seems like the gen_atmel_mci driver doesn't work with Multible Block transfer on
AVR32, but the old code didn't used that mode either. So that's something for the TODO
list for future improvements.
Regards,
Sven
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 1/2] AVR32: use generic mmc framework
2011-10-12 13:09 [U-Boot] [PATCH] AVR32: switch to generic mmc framework Sven Schnelle
@ 2011-10-12 13:09 ` Sven Schnelle
2011-10-12 14:29 ` Andreas Bießmann
2011-10-12 13:09 ` [U-Boot] [PATCH 2/2] AVR32: remove old atmel_mci driver Sven Schnelle
2011-10-12 17:01 ` [U-Boot] [PATCH] AVR32: switch to generic mmc framework Reinhard Meyer
2 siblings, 1 reply; 14+ messages in thread
From: Sven Schnelle @ 2011-10-12 13:09 UTC (permalink / raw)
To: u-boot
gen_atmel_mci works on AVR32 as well, so no need to use the legacy
mmc driver. This also has the nice side effect of being able to use
SDHC cards an AVR32 boards.
Signed-off-by: Sven Schnelle <svens@stackframe.org>
---
arch/avr32/lib/board.c | 3 +++
board/atmel/atngw100/atngw100.c | 9 +++++++++
board/atmel/atstk1000/atstk1000.c | 9 +++++++++
include/configs/atngw100.h | 4 +++-
include/configs/atstk1002.h | 4 +++-
include/configs/atstk1003.h | 3 ++-
include/configs/atstk1004.h | 4 +++-
include/configs/atstk1006.h | 4 +++-
include/configs/favr-32-ezkit.h | 3 ++-
include/configs/hammerhead.h | 3 ++-
include/configs/mimc200.h | 3 ++-
include/mmc.h | 1 -
12 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/arch/avr32/lib/board.c b/arch/avr32/lib/board.c
index 3e1cc0d..694755c 100644
--- a/arch/avr32/lib/board.c
+++ b/arch/avr32/lib/board.c
@@ -334,6 +334,9 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)
eth_initialize(gd->bd);
#endif
+#ifdef CONFIG_GENERIC_ATMEL_MCI
+ mmc_initialize(gd->bd);
+#endif
for (;;) {
main_loop();
}
diff --git a/board/atmel/atngw100/atngw100.c b/board/atmel/atngw100/atngw100.c
index 59577b8..af22403 100644
--- a/board/atmel/atngw100/atngw100.c
+++ b/board/atmel/atngw100/atngw100.c
@@ -139,3 +139,12 @@ void spi_cs_deactivate(struct spi_slave *slave)
gpio_set_value(ATNGW100_DATAFLASH_CS_PIN, 1);
}
#endif /* CONFIG_ATMEL_SPI */
+
+#ifdef CONFIG_GENERIC_ATMEL_MCI
+int board_mmc_init(bd_t *bd)
+{
+ /* This calls the atmel_mci_init in gen_atmel_mci.c */
+ return atmel_mci_init((void *)ATMEL_BASE_MMCI);
+
+}
+#endif
diff --git a/board/atmel/atstk1000/atstk1000.c b/board/atmel/atstk1000/atstk1000.c
index 58048a4..93f8e43 100644
--- a/board/atmel/atstk1000/atstk1000.c
+++ b/board/atmel/atstk1000/atstk1000.c
@@ -139,3 +139,12 @@ int board_eth_init(bd_t *bi)
return 0;
}
#endif
+
+#ifdef CONFIG_GENERIC_ATMEL_MCI
+int board_mmc_init(bd_t *bd)
+{
+ /* This calls the atmel_mci_init in gen_atmel_mci.c */
+ return atmel_mci_init((void *)ATMEL_BASE_MMCI);
+
+}
+#endif
diff --git a/include/configs/atngw100.h b/include/configs/atngw100.h
index 8f9ed23..5e3155d 100644
--- a/include/configs/atngw100.h
+++ b/include/configs/atngw100.h
@@ -128,7 +128,9 @@
#define CONFIG_SYS_NR_PIOS 5
#define CONFIG_SYS_HSDRAMC
#define CONFIG_MMC
-#define CONFIG_ATMEL_MCI
+#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_GENERIC_MMC
+#define CONFIG_SYS_MMC_MAX_BLK_COUNT 1
#define CONFIG_ATMEL_SPI
#define CONFIG_SPI_FLASH
diff --git a/include/configs/atstk1002.h b/include/configs/atstk1002.h
index 44ce242..bb426f1 100644
--- a/include/configs/atstk1002.h
+++ b/include/configs/atstk1002.h
@@ -151,7 +151,9 @@
#define CONFIG_SYS_NR_PIOS 5
#define CONFIG_SYS_HSDRAMC
#define CONFIG_MMC
-#define CONFIG_ATMEL_MCI
+#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_GENERIC_MMC
+#define CONFIG_SYS_MMC_MAX_BLK_COUNT 1
#define CONFIG_SYS_DCACHE_LINESZ 32
#define CONFIG_SYS_ICACHE_LINESZ 32
diff --git a/include/configs/atstk1003.h b/include/configs/atstk1003.h
index c5e357f..a426f15 100644
--- a/include/configs/atstk1003.h
+++ b/include/configs/atstk1003.h
@@ -135,7 +135,8 @@
#define CONFIG_PORTMUX_PIO
#define CONFIG_SYS_HSDRAMC
#define CONFIG_MMC
-#define CONFIG_ATMEL_MCI
+#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_GENERIC_MMC
#define CONFIG_SYS_DCACHE_LINESZ 32
#define CONFIG_SYS_ICACHE_LINESZ 32
diff --git a/include/configs/atstk1004.h b/include/configs/atstk1004.h
index 3814732..1b4a1af 100644
--- a/include/configs/atstk1004.h
+++ b/include/configs/atstk1004.h
@@ -135,7 +135,9 @@
#define CONFIG_PORTMUX_PIO
#define CONFIG_SYS_HSDRAMC
#define CONFIG_MMC
-#define CONFIG_ATMEL_MCI
+#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_GENERIC_MMC
+#define CONFIG_SYS_MMC_MAX_BLK_COUNT 1
#define CONFIG_SYS_DCACHE_LINESZ 32
#define CONFIG_SYS_ICACHE_LINESZ 32
diff --git a/include/configs/atstk1006.h b/include/configs/atstk1006.h
index a30aa70..29fdd12 100644
--- a/include/configs/atstk1006.h
+++ b/include/configs/atstk1006.h
@@ -151,7 +151,9 @@
#define CONFIG_SYS_NR_PIOS 5
#define CONFIG_SYS_HSDRAMC
#define CONFIG_MMC
-#define CONFIG_ATMEL_MCI
+#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_GENERIC_MMC
+#define CONFIG_SYS_MMC_MAX_BLK_COUNT 1
#define CONFIG_SYS_DCACHE_LINESZ 32
#define CONFIG_SYS_ICACHE_LINESZ 32
diff --git a/include/configs/favr-32-ezkit.h b/include/configs/favr-32-ezkit.h
index 757636d..1c8da9f 100644
--- a/include/configs/favr-32-ezkit.h
+++ b/include/configs/favr-32-ezkit.h
@@ -150,7 +150,8 @@
#define CONFIG_SYS_NR_PIOS 5
#define CONFIG_SYS_HSDRAMC
#define CONFIG_MMC
-#define CONFIG_ATMEL_MCI
+#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_GENERIC_MMC
#define CONFIG_SYS_DCACHE_LINESZ 32
#define CONFIG_SYS_ICACHE_LINESZ 32
diff --git a/include/configs/hammerhead.h b/include/configs/hammerhead.h
index 94e680c..5570bdb 100644
--- a/include/configs/hammerhead.h
+++ b/include/configs/hammerhead.h
@@ -124,7 +124,8 @@
#define CONFIG_SYS_NR_PIOS 5
#define CONFIG_SYS_HSDRAMC
#define CONFIG_MMC
-#define CONFIG_ATMEL_MCI
+#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_GENERIC_MMC
#define CONFIG_SYS_DCACHE_LINESZ 32
#define CONFIG_SYS_ICACHE_LINESZ 32
diff --git a/include/configs/mimc200.h b/include/configs/mimc200.h
index d8d8256..8031a05 100644
--- a/include/configs/mimc200.h
+++ b/include/configs/mimc200.h
@@ -129,7 +129,8 @@
#define CONFIG_SYS_NR_PIOS 5
#define CONFIG_SYS_HSDRAMC
#define CONFIG_MMC
-#define CONFIG_ATMEL_MCI
+#define CONFIG_GENERIC_ATMEL_MCI
+#define CONFIG_GENERIC_MMC
#if defined(CONFIG_LCD)
#define CONFIG_CMD_BMP
diff --git a/include/mmc.h b/include/mmc.h
index 53aff9b..2607b4f 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -316,7 +316,6 @@ int board_mmc_getcd(u8 *cd, struct mmc *mmc);
int mmc_switch_part(int dev_num, unsigned int part_num);
#ifdef CONFIG_GENERIC_MMC
-int atmel_mci_init(void *regs);
#define mmc_host_is_spi(mmc) ((mmc)->host_caps & MMC_MODE_SPI)
struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode);
#else
--
1.7.6.3
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 2/2] AVR32: remove old atmel_mci driver
2011-10-12 13:09 [U-Boot] [PATCH] AVR32: switch to generic mmc framework Sven Schnelle
2011-10-12 13:09 ` [U-Boot] [PATCH 1/2] AVR32: use " Sven Schnelle
@ 2011-10-12 13:09 ` Sven Schnelle
2011-10-12 17:01 ` [U-Boot] [PATCH] AVR32: switch to generic mmc framework Reinhard Meyer
2 siblings, 0 replies; 14+ messages in thread
From: Sven Schnelle @ 2011-10-12 13:09 UTC (permalink / raw)
To: u-boot
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@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@emanuele.us>
+ * Reinhard Meyer, EMK Elektronik <reinhard.meyer@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@emanuele.us>
- * Reinhard Meyer, EMK Elektronik <reinhard.meyer@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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 1/2] AVR32: use generic mmc framework
2011-10-12 13:09 ` [U-Boot] [PATCH 1/2] AVR32: use " Sven Schnelle
@ 2011-10-12 14:29 ` Andreas Bießmann
2011-10-12 14:51 ` Sven Schnelle
0 siblings, 1 reply; 14+ messages in thread
From: Andreas Bießmann @ 2011-10-12 14:29 UTC (permalink / raw)
To: u-boot
Dear Sven,
Am 12.10.2011 15:09, schrieb Sven Schnelle:
> gen_atmel_mci works on AVR32 as well, so no need to use the legacy
> mmc driver. This also has the nice side effect of being able to use
> SDHC cards an AVR32 boards.
>
> Signed-off-by: Sven Schnelle <svens@stackframe.org>
I have to NACK this patch cause it produces new compile warnings.
$ PATH=$AVR32_PATH:$PATH BUILD_DIR=/tmp/build_uboot BUILD_NCPU=8
./MAKEALL atstk1002
Configuring for atstk1002 board...
board.c: In function 'board_init_r':
board.c:338: warning: implicit declaration of function 'mmc_initialize'
atstk1000.c: In function 'board_mmc_init':
atstk1000.c:147: warning: implicit declaration of function 'atmel_mci_init'
text data bss dec hex filename
106091 7504 211676 325271 4f697 /tmp/build_uboot/u-boot
--------------------- SUMMARY ----------------------------
Boards compiled: 1
Boards with warnings or errors: 1 ( atstk1002 )
----------------------------------------------------------
And does not work on device:
a) mmc init is not known? Is this not longer necessary?
---8<---
U-Boot> mmc init
Unknown command 'mmc' - try 'help'
U-Boot> mmc help
mmc - MMC sub system
Usage:
mmc read addr blk# cnt
mmc write addr blk# cnt
mmc erase blk# cnt
mmc rescan
mmc part - lists available partition on current mmc device
mmc dev [dev] [part] - show or set current mmc device [partition]
mmc list - lists available devices
U-Boot>
--->8---
b) ext2ls is not reliable:
---8<---
U-Boot> ext2ls mmc 0:1
<DIR> 1024 .
<DIR> 1024 ..
<DIR> 12288 lost+found
gen_atmel_mci: CMDR 00051051 (17) ARGR 02008600 (SR: 00400025) Data
Transfer Failed
** ext2fs_devread read error - last part
U-Boot>
--->8---
best regards
Andreas Bie?mann
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 1/2] AVR32: use generic mmc framework
2011-10-12 14:29 ` Andreas Bießmann
@ 2011-10-12 14:51 ` Sven Schnelle
2011-10-12 14:59 ` Andreas Bießmann
2011-10-12 17:54 ` Wolfgang Denk
0 siblings, 2 replies; 14+ messages in thread
From: Sven Schnelle @ 2011-10-12 14:51 UTC (permalink / raw)
To: u-boot
On 10/12/2011 04:29 PM, Andreas Bie?mann wrote:
> Dear Sven,
>
> Am 12.10.2011 15:09, schrieb Sven Schnelle:
>> gen_atmel_mci works on AVR32 as well, so no need to use the legacy
>> mmc driver. This also has the nice side effect of being able to use
>> SDHC cards an AVR32 boards.
>>
>> Signed-off-by: Sven Schnelle<svens@stackframe.org>
> I have to NACK this patch cause it produces new compile warnings.
>
> $ PATH=$AVR32_PATH:$PATH BUILD_DIR=/tmp/build_uboot BUILD_NCPU=8
> ./MAKEALL atstk1002
> Configuring for atstk1002 board...
> board.c: In function 'board_init_r':
> board.c:338: warning: implicit declaration of function 'mmc_initialize'
> atstk1000.c: In function 'board_mmc_init':
> atstk1000.c:147: warning: implicit declaration of function 'atmel_mci_init'
> text data bss dec hex filename
> 106091 7504 211676 325271 4f697 /tmp/build_uboot/u-boot
Oops. Should be easily fixable.
> --------------------- SUMMARY ----------------------------
> Boards compiled: 1
> Boards with warnings or errors: 1 ( atstk1002 )
> ----------------------------------------------------------
>
> And does not work on device:
>
> a) mmc init is not known? Is this not longer necessar
'mmc init' is only available if CONFIG_GENERIC_MMC isn't set, at least
that's how i unterstand the source code. (See common/cmd_mmc.c:29)
> b) ext2ls is not reliable:
>
> ---8<---
> U-Boot> ext2ls mmc 0:1
> <DIR> 1024 .
> <DIR> 1024 ..
> <DIR> 12288 lost+found
> gen_atmel_mci: CMDR 00051051 (17) ARGR 02008600 (SR: 00400025) Data
> Transfer Failed
> ** ext2fs_devread read error - last part
> U-Boot>
> --->8---
Hmm, that's really bad. What type of card is this? MMC, SD or SDHC?
Regards
Sven
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 1/2] AVR32: use generic mmc framework
2011-10-12 14:51 ` Sven Schnelle
@ 2011-10-12 14:59 ` Andreas Bießmann
2011-10-12 15:08 ` Sven Schnelle
2011-10-13 7:52 ` Sven Schnelle
2011-10-12 17:54 ` Wolfgang Denk
1 sibling, 2 replies; 14+ messages in thread
From: Andreas Bießmann @ 2011-10-12 14:59 UTC (permalink / raw)
To: u-boot
Dear Sven,
Am 12.10.2011 16:51, schrieb Sven Schnelle:
> On 10/12/2011 04:29 PM, Andreas Bie?mann wrote:
>> Dear Sven,
>>
>> Am 12.10.2011 15:09, schrieb Sven Schnelle:
<snip>
>> And does not work on device:
>>
>> a) mmc init is not known? Is this not longer necessar
> 'mmc init' is only available if CONFIG_GENERIC_MMC isn't set, at least
> that's how i unterstand the source code. (See common/cmd_mmc.c:29)
I see, my fault. Didn't know about this new framework.
>> b) ext2ls is not reliable:
>>
>> ---8<---
>> U-Boot> ext2ls mmc 0:1
>> <DIR> 1024 .
>> <DIR> 1024 ..
>> <DIR> 12288 lost+found
>> gen_atmel_mci: CMDR 00051051 (17) ARGR 02008600 (SR: 00400025) Data
>> Transfer Failed
>> ** ext2fs_devread read error - last part
>> U-Boot>
>> --->8---
> Hmm, that's really bad. What type of card is this? MMC, SD or SDHC?
It is SD card (the one delivered with my atstk1002, there is an Atmel
label on it ;).
When initialising mmc with old atmel_mci driver I get this:
---8<---
U-Boot> mmc init
Manufacturer ID: 03
OEM/Application ID: 5344
Product name: SD128
Product Revision: 5.8
Product Serial Number: 8227719
Manufacturing Date: 06/03
SD Card detected (RCA 58916)
CSD data: 00260032 1f5983c0 fefa4fff 924040ab
CSD structure version: 1.0
MMC System Spec version: 0
Card command classes: 1f5
Read block length: 512
Supports partial reads
Write block length: 512
Does not support partial writes
Supports group WP: 32
Card capacity: 125960192 bytes
File format: 0/0
Write protection:
mmc: Using 131072 cycles data timeout (DTOR=0x62)
.mmc1 is available
--->8---
best regards
Andreas Bie?mann
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 1/2] AVR32: use generic mmc framework
2011-10-12 14:59 ` Andreas Bießmann
@ 2011-10-12 15:08 ` Sven Schnelle
2011-10-12 15:18 ` Andreas Bießmann
2011-10-13 7:52 ` Sven Schnelle
1 sibling, 1 reply; 14+ messages in thread
From: Sven Schnelle @ 2011-10-12 15:08 UTC (permalink / raw)
To: u-boot
On 10/12/2011 04:59 PM, Andreas Bie?mann wrote:
> b) ext2ls is not reliable:
>>> ---8<---
>>> U-Boot> ext2ls mmc 0:1
>>> <DIR> 1024 .
>>> <DIR> 1024 ..
>>> <DIR> 12288 lost+found
>>> gen_atmel_mci: CMDR 00051051 (17) ARGR 02008600 (SR: 00400025) Data
>>> Transfer Failed
>>> ** ext2fs_devread read error - last part
>>> U-Boot>
>>> --->8---
>> Hmm, that's really bad. What type of card is this? MMC, SD or SDHC?
> It is SD card (the one delivered with my atstk1002, there is an Atmel
> label on it ;).
>
> When initialising mmc with old atmel_mci driver I get this:
>
> ---8<---
> U-Boot> mmc init
> Manufacturer ID: 03
> OEM/Application ID: 5344
> Product name: SD128
> Product Revision: 5.8
> Product Serial Number: 8227719
> Manufacturing Date: 06/03
> SD Card detected (RCA 58916)
> CSD data: 00260032 1f5983c0 fefa4fff 924040ab
> CSD structure version: 1.0
> MMC System Spec version: 0
> Card command classes: 1f5
> Read block length: 512
> Supports partial reads
> Write block length: 512
> Does not support partial writes
> Supports group WP: 32
> Card capacity: 125960192 bytes
> File format: 0/0
> Write protection:
> mmc: Using 131072 cycles data timeout (DTOR=0x62)
> .mmc1 is available
> --->8---
>
Thanks for the Info Andreas. Do you have some other SD/SDHC cards handy?
would be interesting if it doesn't work at all on your Board, or if this
is an card
specific issue...
Regards
Sven
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 1/2] AVR32: use generic mmc framework
2011-10-12 15:08 ` Sven Schnelle
@ 2011-10-12 15:18 ` Andreas Bießmann
2011-10-14 12:30 ` Andreas Bießmann
0 siblings, 1 reply; 14+ messages in thread
From: Andreas Bießmann @ 2011-10-12 15:18 UTC (permalink / raw)
To: u-boot
Dear Sven,
Am 12.10.2011 17:08, schrieb Sven Schnelle:
> On 10/12/2011 04:59 PM, Andreas Bie?mann wrote:
>> b) ext2ls is not reliable:
>>>> ---8<---
>>>> U-Boot> ext2ls mmc 0:1
>>>> <DIR> 1024 .
>>>> <DIR> 1024 ..
>>>> <DIR> 12288 lost+found
>>>> gen_atmel_mci: CMDR 00051051 (17) ARGR 02008600 (SR: 00400025) Data
>>>> Transfer Failed
>>>> ** ext2fs_devread read error - last part
>>>> U-Boot>
>>>> --->8---
>>> Hmm, that's really bad. What type of card is this? MMC, SD or SDHC?
>> It is SD card (the one delivered with my atstk1002, there is an Atmel
>> label on it ;).
>>
>> When initialising mmc with old atmel_mci driver I get this:
>>
>> ---8<---
>> U-Boot> mmc init
>> Manufacturer ID: 03
>> OEM/Application ID: 5344
>> Product name: SD128
>> Product Revision: 5.8
>> Product Serial Number: 8227719
>> Manufacturing Date: 06/03
>> SD Card detected (RCA 58916)
>> CSD data: 00260032 1f5983c0 fefa4fff 924040ab
>> CSD structure version: 1.0
>> MMC System Spec version: 0
>> Card command classes: 1f5
>> Read block length: 512
>> Supports partial reads
>> Write block length: 512
>> Does not support partial writes
>> Supports group WP: 32
>> Card capacity: 125960192 bytes
>> File format: 0/0
>> Write protection:
>> mmc: Using 131072 cycles data timeout (DTOR=0x62)
>> .mmc1 is available
>> --->8---
>>
>
> Thanks for the Info Andreas. Do you have some other SD/SDHC cards handy?
> would be interesting if it doesn't work at all on your Board, or if this
> is an card
> specific issue...
at least one other SD Card works:
---8<---
U-Boot> mmc part
Partition Map for MMC device 0 -- Partition Type: DOS
Partition Start Sector Num Sectors Type
1 247 1995529 6
U-Boot> mmc list
mci: 0
U-Boot> fatls mmc 0
11323605 ms-avr-svn4980.sh
11327707 ms-avr-svn4982-dirty.sh
11327707 ms-avr-svn4983-dirty.sh
11323605 ms-avr-svn4985.sh
1437538 uimage-svn4985-dirty.bin
11327701 ms-avr-svn4988.sh
10541275 ms-avr-svn4990-dirty.sh
1000/
43229 ms-update-dsp-svn4981.sh
22749 ms-update-msp-svn4986.sh
43230 ms-update-lpc-svn4990.sh
22749 ms-update-msp-svn5000.sh
43229 ms-update-dsp-svn4996.sh
10541275 ms-update-avr-svn5000-dirty.sh
43217 ms-dsp-test.sh
43229 ms-update-dsp-svn5005.sh
10586518 ms-qe11-test.sh
839 ecg-raw2-20111010-122711.dat
164 ecg-raw2-20111010-130305.dat
99944 ecg-raw1-20111010-131651.dat
6607604 ecg-raw2-20111010-134759.dat
906959 ecg-raw2-20111010-141628.dat
1601399 ecg-raw2-20111010-151814.dat
10586518 ms-qe11.sh
10488027 ms-update-avr-svn5019-dirty.sh
24 file(s), 1 dir(s)
--->8---
best regards
Andreas Bie?mann
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH] AVR32: switch to generic mmc framework
2011-10-12 13:09 [U-Boot] [PATCH] AVR32: switch to generic mmc framework Sven Schnelle
2011-10-12 13:09 ` [U-Boot] [PATCH 1/2] AVR32: use " Sven Schnelle
2011-10-12 13:09 ` [U-Boot] [PATCH 2/2] AVR32: remove old atmel_mci driver Sven Schnelle
@ 2011-10-12 17:01 ` Reinhard Meyer
2011-10-13 8:04 ` Andreas Bießmann
2 siblings, 1 reply; 14+ messages in thread
From: Reinhard Meyer @ 2011-10-12 17:01 UTC (permalink / raw)
To: u-boot
Dear Sven Schnelle,
> Hi List,
>
> these patches switch all AVR32 boards to the generic MMC framework. Motivation
> for doing so is to be able to boot from SDHC cards. The second patch removes
> the legacy atmel_mci driver, as it is no longer used by any board.
>
> I've only tried this code on the Atmel ATNGW100, as i have no other AVR32 boards.
> Would be great if some other users could try that patch on different platforms.
>
> It seems like the gen_atmel_mci driver doesn't work with Multible Block transfer on
> AVR32, but the old code didn't used that mode either. So that's something for the TODO
> list for future improvements.
1. your patch title is misleading, because it also affects the AT91 architecture.
use AVR32 when patches affect avr32 only
use AT91 when patches affect at91 only
use ATMEL when patches affect generic Atmel stuff
2. you should use the git rename feature to rename files
As I see it, all this should come as three patches:
1. switching *all* AVR32 and AT91 boards to use the *existing* generic driver
2. removal of the now obsolete legacy driver
3. renaming the existing generic driver into the old legacy name
(this is a pure cosmetic act)
I would tend to dispute whether 3. is really necessary and beneficial
Best Regards
Reinhard
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 1/2] AVR32: use generic mmc framework
2011-10-12 14:51 ` Sven Schnelle
2011-10-12 14:59 ` Andreas Bießmann
@ 2011-10-12 17:54 ` Wolfgang Denk
2011-10-13 7:45 ` Sven Schnelle
1 sibling, 1 reply; 14+ messages in thread
From: Wolfgang Denk @ 2011-10-12 17:54 UTC (permalink / raw)
To: u-boot
Dear Sven Schnelle,
In message <4E95A965.20504@stackframe.org> you wrote:
>
> > a) mmc init is not known? Is this not longer necessar
> 'mmc init' is only available if CONFIG_GENERIC_MMC isn't set, at least
> that's how i unterstand the source code. (See common/cmd_mmc.c:29)
Argh. No, we will not allow different implementations / feature sets.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Unser Kopf ist rund, damit das Denken die Richtung wechseln kann.
-- Francis Picabia
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 1/2] AVR32: use generic mmc framework
2011-10-12 17:54 ` Wolfgang Denk
@ 2011-10-13 7:45 ` Sven Schnelle
0 siblings, 0 replies; 14+ messages in thread
From: Sven Schnelle @ 2011-10-13 7:45 UTC (permalink / raw)
To: u-boot
Hi Wolfgang,
On 10/12/2011 07:54 PM, Wolfgang Denk wrote:
> Dear Sven Schnelle,
>
> In message<4E95A965.20504@stackframe.org> you wrote:
>>
>>> a) mmc init is not known? Is this not longer necessar
>> 'mmc init' is only available if CONFIG_GENERIC_MMC isn't set, at least
>> that's how i unterstand the source code. (See common/cmd_mmc.c:29)
>
> Argh. No, we will not allow different implementations / feature sets.
Can you please explain that statement? Actually i have no idea what
you're trying to say.
Regards
Sven
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 1/2] AVR32: use generic mmc framework
2011-10-12 14:59 ` Andreas Bießmann
2011-10-12 15:08 ` Sven Schnelle
@ 2011-10-13 7:52 ` Sven Schnelle
1 sibling, 0 replies; 14+ messages in thread
From: Sven Schnelle @ 2011-10-13 7:52 UTC (permalink / raw)
To: u-boot
On 10/12/2011 04:59 PM, Andreas Bie?mann wrote:
> Am 12.10.2011 16:51, schrieb Sven Schnelle:
>> On 10/12/2011 04:29 PM, Andreas Bie?mann wrote:
>>> Am 12.10.2011 15:09, schrieb Sven Schnelle:
>>> And does not work on device:
>>> b) ext2ls is not reliable:
>>>
>>> ---8<---
>>> U-Boot> ext2ls mmc 0:1
>>> <DIR> 1024 .
>>> <DIR> 1024 ..
>>> <DIR> 12288 lost+found
>>> gen_atmel_mci: CMDR 00051051 (17) ARGR 02008600 (SR: 00400025) Data
>>> Transfer Failed
>>> ** ext2fs_devread read error - last part
>>> U-Boot>
>>> --->8---
>> Hmm, that's really bad. What type of card is this? MMC, SD or SDHC?
>
> It is SD card (the one delivered with my atstk1002, there is an Atmel
> label on it ;).
>
> When initialising mmc with old atmel_mci driver I get this:
>
> ---8<---
> U-Boot> mmc init
> Manufacturer ID: 03
> OEM/Application ID: 5344
> Product name: SD128
> Product Revision: 5.8
> Product Serial Number: 8227719
> Manufacturing Date: 06/03
> SD Card detected (RCA 58916)
> CSD data: 00260032 1f5983c0 fefa4fff 924040ab
> CSD structure version: 1.0
> MMC System Spec version: 0
> Card command classes: 1f5
> Read block length: 512
> Supports partial reads
> Write block length: 512
> Does not support partial writes
> Supports group WP: 32
> Card capacity: 125960192 bytes
> File format: 0/0
> Write protection:
> mmc: Using 131072 cycles data timeout (DTOR=0x62)
> .mmc1 is available
> --->8---
>
> best regards
>
> Andreas Bie?mann
I've just tried all SD cards i have here, which are in particular:
Noname 32GB SDHC: works
'PLATINUM' 4GB SDHC: works
Sandisk 2GB SD: works
Sandisk 2GB Micro SD: works
So this seems to be an issue with the specific card - it would be nice
if you could enable CONFIG_MMC_TRACE, and send me the output.
Regards
Sven
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH] AVR32: switch to generic mmc framework
2011-10-12 17:01 ` [U-Boot] [PATCH] AVR32: switch to generic mmc framework Reinhard Meyer
@ 2011-10-13 8:04 ` Andreas Bießmann
0 siblings, 0 replies; 14+ messages in thread
From: Andreas Bießmann @ 2011-10-13 8:04 UTC (permalink / raw)
To: u-boot
Dear Reinhard,
Dear Sven,
Am 12.10.2011 19:01, schrieb Reinhard Meyer:
> Dear Sven Schnelle,
>> Hi List,
>>
<snip>
> As I see it, all this should come as three patches:
>
> 1. switching *all* AVR32 and AT91 boards to use the *existing* generic driver
>
> 2. removal of the now obsolete legacy driver
>
> 3. renaming the existing generic driver into the old legacy name
> (this is a pure cosmetic act)
>
> I would tend to dispute whether 3. is really necessary and beneficial
Now that Reinhard brings this up I would also say the name gen_atmel_mci
is better than atmel_mci here cause it implements the GENERIC_MMC
framework. So I guess it would be best to have again two patches:
1. switch all AVR32 (and AT91, if there are still some) to
gen_atmel_mci
2. remove legacy atmel_mci (but no renaming)
But before applying I would like to dig into my issue with the special
card. So maybe do 1) immediately and 2) later, I don't think I will get
the issue til merge window is closed and maybe not until final release
2011.12.
best regards
Andreas Bie?mann
^ permalink raw reply [flat|nested] 14+ messages in thread
* [U-Boot] [PATCH 1/2] AVR32: use generic mmc framework
2011-10-12 15:18 ` Andreas Bießmann
@ 2011-10-14 12:30 ` Andreas Bießmann
0 siblings, 0 replies; 14+ messages in thread
From: Andreas Bießmann @ 2011-10-14 12:30 UTC (permalink / raw)
To: u-boot
Hi all,
Am 12.10.2011 17:18, schrieb Andreas Bie?mann:
> Dear Sven,
>
> Am 12.10.2011 17:08, schrieb Sven Schnelle:
>> On 10/12/2011 04:59 PM, Andreas Bie?mann wrote:
>>> b) ext2ls is not reliable:
>>>>> ---8<---
>>>>> U-Boot> ext2ls mmc 0:1
>>>>> <DIR> 1024 .
>>>>> <DIR> 1024 ..
>>>>> <DIR> 12288 lost+found
>>>>> gen_atmel_mci: CMDR 00051051 (17) ARGR 02008600 (SR: 00400025) Data
>>>>> Transfer Failed
>>>>> ** ext2fs_devread read error - last part
>>>>> U-Boot>
>>>>> --->8---
>>>> Hmm, that's really bad. What type of card is this? MMC, SD or SDHC?
>>> It is SD card (the one delivered with my atstk1002, there is an Atmel
>>> label on it ;).
>>>
>>> When initialising mmc with old atmel_mci driver I get this:
>>>
>>> ---8<---
>>> U-Boot> mmc init
>>> Manufacturer ID: 03
>>> OEM/Application ID: 5344
>>> Product name: SD128
>>> Product Revision: 5.8
>>> Product Serial Number: 8227719
>>> Manufacturing Date: 06/03
>>> SD Card detected (RCA 58916)
>>> CSD data: 00260032 1f5983c0 fefa4fff 924040ab
>>> CSD structure version: 1.0
>>> MMC System Spec version: 0
>>> Card command classes: 1f5
>>> Read block length: 512
>>> Supports partial reads
>>> Write block length: 512
>>> Does not support partial writes
>>> Supports group WP: 32
>>> Card capacity: 125960192 bytes
>>> File format: 0/0
>>> Write protection:
>>> mmc: Using 131072 cycles data timeout (DTOR=0x62)
>>> .mmc1 is available
>>> --->8---
>>>
>>
>> Thanks for the Info Andreas. Do you have some other SD/SDHC cards handy?
>> would be interesting if it doesn't work at all on your Board, or if this
>> is an card
>> specific issue...
>
> at least one other SD Card works:
to sum it up:
* it is a timeout issue
* the timeout in gen_atmel_mci is set to a fixed value which is way to
small for my combination of card and bus-clock
best regards
Andreas Bie?mann
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2011-10-14 12:30 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-12 13:09 [U-Boot] [PATCH] AVR32: switch to generic mmc framework Sven Schnelle
2011-10-12 13:09 ` [U-Boot] [PATCH 1/2] AVR32: use " Sven Schnelle
2011-10-12 14:29 ` Andreas Bießmann
2011-10-12 14:51 ` Sven Schnelle
2011-10-12 14:59 ` Andreas Bießmann
2011-10-12 15:08 ` Sven Schnelle
2011-10-12 15:18 ` Andreas Bießmann
2011-10-14 12:30 ` Andreas Bießmann
2011-10-13 7:52 ` Sven Schnelle
2011-10-12 17:54 ` Wolfgang Denk
2011-10-13 7:45 ` Sven Schnelle
2011-10-12 13:09 ` [U-Boot] [PATCH 2/2] AVR32: remove old atmel_mci driver Sven Schnelle
2011-10-12 17:01 ` [U-Boot] [PATCH] AVR32: switch to generic mmc framework Reinhard Meyer
2011-10-13 8:04 ` Andreas Bießmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox