Skip to contentSkip to conversation

generic mmc_spi driver

PATCH Superseded Thomas Chou 5 participants 22 messages Dec 24, 2010 – Apr 18, 2011

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

cover generic mmc_spi driver

This is the v9 update of the mmc_spi driver. Please enable DEBUG on the top of mmc_spi.c and help me perform the tests.

A new spi_set_speed() is added to meet the 400KHz clock requirement during mmc card initialization. An example update to bfin_spi is included. The altera_spi core does not support speed change, so I am going to post a new opencore ip for this.

The driver now claims and releases the spi bus for each mmc command, as Mike suggested.

Thomas Chou (4):
lib: add crc7 from Linux
spi: add spi_set_speed func
bfin_spi: add spi_set_speed
mmc: add generic mmc spi driver

 common/Makefile        |    1 +
 common/cmd_mmc_spi.c   |   88 +++++++++++++++
 drivers/mmc/Makefile   |    1 +
 drivers/mmc/mmc.c      |   93 +++++++++++++----
 drivers/mmc/mmc_spi.c  |  278 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/spi/Makefile   |    1 +
 drivers/spi/bfin_spi.c |   32 ++++---
 drivers/spi/spi.c      |    9 ++
 include/linux/crc7.h   |   14 +++
 include/mmc.h          |    5 +
 include/spi.h          |    8 ++
 lib/Makefile           |    1 +
 lib/crc7.c             |   62 +++++++++++
 13 files changed, 560 insertions(+), 33 deletions(-)
 create mode 100644 common/cmd_mmc_spi.c
 create mode 100644 drivers/mmc/mmc_spi.c
 create mode 100644 drivers/spi/spi.c
 create mode 100644 include/linux/crc7.h
 create mode 100644 lib/crc7.c
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH 1/4 lib: add crc7 from Linux

Crc7 is used to compute mmc spi comamnd packet checksum.

---
 include/linux/crc7.h |   14 +++++++++++
 lib/Makefile         |    1 +
 lib/crc7.c           |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/crc7.h
 create mode 100644 lib/crc7.c
include/linux/crc7.h new file +14 -0
new file mode 100644
index 0000000..1786e77
@@ -0,0 +1,14 @@
+#ifndef _LINUX_CRC7_H
+#define _LINUX_CRC7_H
+#include <linux/types.h>
+
+extern const u8 crc7_syndrome_table[256];
+
+static inline u8 crc7_byte(u8 crc, u8 data)
+{
+	return crc7_syndrome_table[(crc << 1) ^ data];
+}
+
+extern u8 crc7(u8 crc, const u8 *buffer, size_t len);
+
+#endif
lib/Makefile +1 -0
index ffdee7d..fcfe351 100644
@@ -32,6 +32,7 @@ COBJS-$(CONFIG_BZIP2) += bzlib_decompress.o
 COBJS-$(CONFIG_BZIP2) += bzlib_randtable.o
 COBJS-$(CONFIG_BZIP2) += bzlib_huffman.o
 COBJS-$(CONFIG_USB_TTY) += circbuf.o
+COBJS-y += crc7.o
 COBJS-y += crc16.o
 COBJS-y += crc32.o
 COBJS-y += ctype.o
lib/crc7.c new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#2 lore raw

PATCH 1/4 lib: add crc7 from Linux

Dear Thomas Chou,

Quoted 1 line · In message <[email protected]> you wrote:

Crc7 is used to compute mmc spi comamnd packet checksum.

s/comamnd/sommand/

Quoted 1 line

Please fix the typos, and provide proper attribution where this code is coming from - see
http://www.denx.de/wiki/view/U-Boot/Patches#Attributing_Code_Copyrights_Sign
for details.

Thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
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
Commitment, n.:      Commitment can be illustrated by a breakfast
of ham and eggs. The chicken was involved, the pig was committed.
#3 lore raw

PATCH v2 1/1 lib: add crc7 from Linux

Crc7 is used to compute mmc spi command packet checksum.

Copy from linux-2.6 lib/crc7.c include/linux/crc7.h commit ad241528c4919505afccb022acbab3eeb0db4d80

---
v2 update attribution as Wolfgang suggested.

 include/linux/crc7.h |   14 +++++++++++
 lib/Makefile         |    1 +
 lib/crc7.c           |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/crc7.h
 create mode 100644 lib/crc7.c
include/linux/crc7.h new file +14 -0
new file mode 100644
index 0000000..1786e77
@@ -0,0 +1,14 @@
+#ifndef _LINUX_CRC7_H
+#define _LINUX_CRC7_H
+#include <linux/types.h>
+
+extern const u8 crc7_syndrome_table[256];
+
+static inline u8 crc7_byte(u8 crc, u8 data)
+{
+	return crc7_syndrome_table[(crc << 1) ^ data];
+}
+
+extern u8 crc7(u8 crc, const u8 *buffer, size_t len);
+
+#endif
lib/Makefile +1 -0
index ffdee7d..fcfe351 100644
@@ -32,6 +32,7 @@ COBJS-$(CONFIG_BZIP2) += bzlib_decompress.o
 COBJS-$(CONFIG_BZIP2) += bzlib_randtable.o
 COBJS-$(CONFIG_BZIP2) += bzlib_huffman.o
 COBJS-$(CONFIG_USB_TTY) += circbuf.o
+COBJS-y += crc7.o
 COBJS-y += crc16.o
 COBJS-y += crc32.o
 COBJS-y += ctype.o
lib/crc7.c new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#4 lore raw

PATCH v2 1/1 lib: add crc7 from Linux

Dear Thomas Chou,

Quoted 9 lines · In message <[email protected]> you wrote:

Crc7 is used to compute mmc spi command packet checksum.

Copy from linux-2.6 lib/crc7.c include/linux/crc7.h commit ad241528c4919505afccb022acbab3eeb0db4d80

---
v2 update attribution as Wolfgang suggested.

Quoted 6 lines
 include/linux/crc7.h |   14 +++++++++++
 lib/Makefile         |    1 +
 lib/crc7.c           |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/crc7.h
 create mode 100644 lib/crc7.c

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
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
A witty saying proves nothing, but saying  something  pointless  gets
people's attention.
#5 lore raw

PATCH 2/4 spi: add spi_set_speed func

In reply to Thomas Chou

This func helps mmc_spi driver set correct speed for mmc/sd, as mmc card needs 400KHz clock for spi mode initialization.

---
 drivers/spi/Makefile |    1 +
 drivers/spi/spi.c    |    9 +++++++++
 include/spi.h        |    8 ++++++++
 3 files changed, 18 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/spi.c
drivers/spi/Makefile +1 -0
index e34a124..c4eb627 100644
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libspi.o
 
+COBJS-$(CONFIG_MMC_SPI) += spi.o
 COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o
 COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
drivers/spi/spi.c new file +9 -0
new file mode 100644
index 0000000..944466a
@@ -0,0 +1,9 @@
+#include <common.h>
+#include <spi.h>
+
+/* default func for SPI driver without set speed func */
+static void __spi_set_speed(struct spi_slave *slave, uint hz)
+{
+}
+void spi_set_speed(struct spi_slave *slave, uint hz)
+	__attribute__((weak, alias("__spi_set_speed")));
include/spi.h +8 -0
index 320e50e..7887d0f 100644
@@ -176,6 +176,14 @@ void spi_cs_activate(struct spi_slave *slave);
 void spi_cs_deactivate(struct spi_slave *slave);
 
 /*-----------------------------------------------------------------------
+ * Set transfer speed.
+ * This sets a new speed to be applied for next spi_xfer().
+ *   slave:	The SPI slave
+ *   hz:	The transfer speed
+ */
+void spi_set_speed(struct spi_slave *slave, uint hz);
+
+/*-----------------------------------------------------------------------
  * Write 8 bits, then read 8 bits.
  *   slave:	The SPI slave we're communicating with
  *   byte:	Byte to be written
Signature · 1 line
1.7.3.4
#6 lore raw

PATCH 2/4 spi: add spi_set_speed func

drivers/spi/spi.c line 9

Quoted 12 lines · On Friday, December 24, 2010 02:16:07 Thomas Chou wrote:
drivers/spi/spi.c new file +9 -0
@@ -0,0 +1,9 @@
+#include <common.h>
+#include <spi.h>
+
+/* default func for SPI driver without set speed func */
+static void __spi_set_speed(struct spi_slave *slave, uint hz)
+{
+}
+void spi_set_speed(struct spi_slave *slave, uint hz)
+	__attribute__((weak, alias("__spi_set_speed")));

let's not go this route. just add the prototype to the header and when the respective spi bus maintainer wants to support this new func, they can implement it. i'd rather people know about the problem up front rather than have things randomly not work.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20101224/9999498e/attachment.pgp

#7 lore raw

PATCH v2 2/4 spi: add spi_set_speed func

In reply to Thomas Chou

This func helps mmc_spi driver set correct speed for mmc/sd, as mmc card needs 400KHz clock for spi mode initialization.

---
v2 remove weak func as Mike suggested.

 include/spi.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
include/spi.h +8 -0
index 320e50e..7887d0f 100644
@@ -176,6 +176,14 @@ void spi_cs_activate(struct spi_slave *slave);
 void spi_cs_deactivate(struct spi_slave *slave);
 
 /*-----------------------------------------------------------------------
+ * Set transfer speed.
+ * This sets a new speed to be applied for next spi_xfer().
+ *   slave:	The SPI slave
+ *   hz:	The transfer speed
+ */
+void spi_set_speed(struct spi_slave *slave, uint hz);
+
+/*-----------------------------------------------------------------------
  * Write 8 bits, then read 8 bits.
  *   slave:	The SPI slave we're communicating with
  *   byte:	Byte to be written
Signature · 1 line
1.7.3.4
#8 lore raw

PATCH v2 2/4 spi: add spi_set_speed func

Dear Thomas Chou,

Quoted 15 lines · In message <[email protected]> you wrote:

This func helps mmc_spi driver set correct speed for mmc/sd, as mmc card needs 400KHz clock for spi mode initialization.

---
v2 remove weak func as Mike suggested.

 include/spi.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
include/spi.h +0 -0
index 320e50e..7887d0f 100644

include/spi.h void spi_cs_activate(struct spi_slave *slave); · line 183

Quoted 8 lines
include/spi.h +5 -0
@@ -176,6 +176,14 @@ void spi_cs_activate(struct spi_slave *slave);
 void spi_cs_deactivate(struct spi_slave *slave);
 
 /*-----------------------------------------------------------------------
+ * Set transfer speed.
+ * This sets a new speed to be applied for next spi_xfer().
+ *   slave:	The SPI slave
+ *   hz:	The transfer speed
+ */

Incorrect multiline comment style.

Best regards,

Wolfgang Denk

Signature · 5 lines
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
Wenn Du ein' weise Antwort verlangst, Mu?t Du vern?nftig fragen.
                                                -- Goethe, Invektiven
#9 lore raw

PATCH v3 2/4 spi: add spi_set_speed func

This func helps mmc_spi driver set correct speed for mmc/sd, as mmc card needs 400KHz clock for spi mode initialization.

---
v2 remove weak func as Mike suggested.
v3 comment style fix as Wolfgang suggested.

 include/spi.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
include/spi.h +8 -0
index 320e50e..e364d2d 100644
@@ -175,6 +175,14 @@ void spi_cs_activate(struct spi_slave *slave);
  */
 void spi_cs_deactivate(struct spi_slave *slave);
 
+/*
+ * Set transfer speed.
+ * This sets a new speed to be applied for next spi_xfer().
+ *   slave:	The SPI slave
+ *   hz:	The transfer speed
+ */
+void spi_set_speed(struct spi_slave *slave, uint hz);
+
 /*-----------------------------------------------------------------------
  * Write 8 bits, then read 8 bits.
  *   slave:	The SPI slave we're communicating with
Signature · 1 line
1.7.3.4
#10 lore raw

PATCH 3/4 bfin_spi: add spi_set_speed

In reply to Thomas Chou

The new speed will be applied by spi_claim_bus.

---
 drivers/spi/bfin_spi.c |   32 +++++++++++++++++++-------------
 1 files changed, 19 insertions(+), 13 deletions(-)
drivers/spi/bfin_spi.c +19 -13
index d7e1474..bfecdaf 100644
@@ -138,13 +138,29 @@ static const unsigned short cs_pins[][7] = {
 #endif
 };
 
+void spi_set_speed(struct spi_slave *slave, uint hz)
+{
+	struct bfin_spi_slave *bss = to_bfin_spi_slave(slave);
+	ulong sclk;
+	u32 baud;
+
+	sclk = get_sclk();
+	baud = sclk / (2 * hz);
+	/* baud should be rounded up */
+	if (sclk % (2 * hz))
+		baud += 1;
+	if (baud < 2)
+		baud = 2;
+	else if (baud > (u16)-1)
+		baud = -1;
+	bss->baud = baud;
+}
+
 struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 		unsigned int max_hz, unsigned int mode)
 {
 	struct bfin_spi_slave *bss;
-	ulong sclk;
 	u32 mmr_base;
-	u32 baud;
 
 	if (!spi_cs_is_valid(bus, cs))
 		return NULL;
@@ -166,16 +182,6 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 		default: return NULL;
 	}
 
-	sclk = get_sclk();
-	baud = sclk / (2 * max_hz);
-	/* baud should be rounded up */
-	if (sclk % (2 * max_hz))
-		baud += 1;
-	if (baud < 2)
-		baud = 2;
-	else if (baud > (u16)-1)
-		baud = -1;
-
 	bss = malloc(sizeof(*bss));
 	if (!bss)
 		return NULL;
@@ -187,8 +193,8 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	if (mode & SPI_CPHA) bss->ctl |= CPHA;
 	if (mode & SPI_CPOL) bss->ctl |= CPOL;
 	if (mode & SPI_LSB_FIRST) bss->ctl |= LSBF;
-	bss->baud = baud;
 	bss->flg = mode & SPI_CS_HIGH ? 1 : 0;
+	spi_set_speed(&bss->slave, max_hz);
 
 	debug("%s: bus:%i cs:%i mmr:%x ctl:%x baud:%i flg:%i\n", __func__,
 		bus, cs, mmr_base, bss->ctl, baud, bss->flg);
Signature · 1 line
1.7.3.4
#11 lore raw

PATCH 3/4 bfin_spi: add spi_set_speed

Quoted 1 line · On Friday, December 24, 2010 02:16:08 Thomas Chou wrote:

The new speed will be applied by spi_claim_bus.

-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20101224/4263ee3e/attachment.pgp

#12 lore raw

PATCH 4/4 mmc: add generic mmc spi driver

In reply to Thomas Chou

This patch supports mmc/sd card with spi interface. It is based on the generic mmc framework. It works with SDHC and supports multi blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

---
 common/Makefile       |    1 +
 common/cmd_mmc_spi.c  |   88 ++++++++++++++++
 drivers/mmc/Makefile  |    1 +
 drivers/mmc/mmc.c     |   93 +++++++++++++----
 drivers/mmc/mmc_spi.c |  278 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/mmc.h         |    5 +
 6 files changed, 446 insertions(+), 20 deletions(-)
 create mode 100644 common/cmd_mmc_spi.c
 create mode 100644 drivers/mmc/mmc_spi.c
common/Makefile +1 -0
index abea91c..381ac38 100644
@@ -117,6 +117,7 @@ COBJS-$(CONFIG_CMD_MII) += miiphyutil.o
 COBJS-$(CONFIG_CMD_MII) += cmd_mii.o
 COBJS-$(CONFIG_CMD_MISC) += cmd_misc.o
 COBJS-$(CONFIG_CMD_MMC) += cmd_mmc.o
+COBJS-$(CONFIG_CMD_MMC_SPI) += cmd_mmc_spi.o
 COBJS-$(CONFIG_MP) += cmd_mp.o
 COBJS-$(CONFIG_CMD_MTDPARTS) += cmd_mtdparts.o
 COBJS-$(CONFIG_CMD_NAND) += cmd_nand.o
common/cmd_mmc_spi.c new file +88 -0

88 lines not on this page · raw message

drivers/mmc/Makefile +1 -0
index 68afd30..599105f 100644
@@ -30,6 +30,7 @@ COBJS-$(CONFIG_BFIN_SDH) += bfin_sdh.o
 COBJS-$(CONFIG_FSL_ESDHC) += fsl_esdhc.o
 COBJS-$(CONFIG_GENERIC_MMC) += mmc.o
 COBJS-$(CONFIG_GENERIC_ATMEL_MCI) += gen_atmel_mci.o
+COBJS-$(CONFIG_MMC_SPI) += mmc_spi.o
 COBJS-$(CONFIG_MXC_MMC) += mxcmmc.o
 COBJS-$(CONFIG_OMAP3_MMC) += omap3_mmc.o
 COBJS-$(CONFIG_OMAP_HSMMC) += omap_hsmmc.o
drivers/mmc/mmc.c +73 -20

158 lines not on this page · raw message

drivers/mmc/mmc_spi.c new file +278 -0

278 lines not on this page · raw message

include/mmc.h +5 -0
index 74c0b1d..0b1e064 100644
@@ -44,6 +44,7 @@
 #define MMC_MODE_HS_52MHz	0x010
 #define MMC_MODE_4BIT		0x100
 #define MMC_MODE_8BIT		0x200
+#define MMC_MODE_SPI		0x400
 
 #define SD_DATA_4BIT	0x00040000
 
@@ -75,6 +76,8 @@
 #define MMC_CMD_WRITE_SINGLE_BLOCK	24
 #define MMC_CMD_WRITE_MULTIPLE_BLOCK	25
 #define MMC_CMD_APP_CMD			55
+#define MMC_CMD_SPI_READ_OCR		58
+#define MMC_CMD_SPI_CRC_ON_OFF		59
 
 #define SD_CMD_SEND_RELATIVE_ADDR	3
 #define SD_CMD_SWITCH_FUNC		6
@@ -288,6 +291,8 @@ int board_mmc_getcd(u8 *cd, struct mmc *mmc);
 
 #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
 int mmc_legacy_init(int verbose);
 #endif
Signature · 1 line
1.7.3.4
#13 lore raw

PATCH v10 4/4 mmc: add generic mmc spi driver

This patch supports mmc/sd card with spi interface. It is based on the generic mmc framework. It works with SDHC and supports multi blocks read/write.

The crc checksum on data packet is enabled with the def,

There is a subcomamnd "mmc_spi" to setup spi bus and cs at run time.

---
v10 set speed to 400KHz for deactived 144 clock, 18 bytes, initialization.

 common/Makefile       |    1 +
 common/cmd_mmc_spi.c  |   88 +++++++++++++++
 drivers/mmc/Makefile  |    1 +
 drivers/mmc/mmc.c     |   93 +++++++++++++----
 drivers/mmc/mmc_spi.c |  280 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/mmc.h         |    5 +
 6 files changed, 448 insertions(+), 20 deletions(-)
 create mode 100644 common/cmd_mmc_spi.c
 create mode 100644 drivers/mmc/mmc_spi.c
common/Makefile +1 -0
index abea91c..381ac38 100644
@@ -117,6 +117,7 @@ COBJS-$(CONFIG_CMD_MII) += miiphyutil.o
 COBJS-$(CONFIG_CMD_MII) += cmd_mii.o
 COBJS-$(CONFIG_CMD_MISC) += cmd_misc.o
 COBJS-$(CONFIG_CMD_MMC) += cmd_mmc.o
+COBJS-$(CONFIG_CMD_MMC_SPI) += cmd_mmc_spi.o
 COBJS-$(CONFIG_MP) += cmd_mp.o
 COBJS-$(CONFIG_CMD_MTDPARTS) += cmd_mtdparts.o
 COBJS-$(CONFIG_CMD_NAND) += cmd_nand.o
common/cmd_mmc_spi.c new file +88 -0

88 lines not on this page · raw message

drivers/mmc/Makefile +1 -0
index 68afd30..599105f 100644
@@ -30,6 +30,7 @@ COBJS-$(CONFIG_BFIN_SDH) += bfin_sdh.o
 COBJS-$(CONFIG_FSL_ESDHC) += fsl_esdhc.o
 COBJS-$(CONFIG_GENERIC_MMC) += mmc.o
 COBJS-$(CONFIG_GENERIC_ATMEL_MCI) += gen_atmel_mci.o
+COBJS-$(CONFIG_MMC_SPI) += mmc_spi.o
 COBJS-$(CONFIG_MXC_MMC) += mxcmmc.o
 COBJS-$(CONFIG_OMAP3_MMC) += omap3_mmc.o
 COBJS-$(CONFIG_OMAP_HSMMC) += omap_hsmmc.o
drivers/mmc/mmc.c +73 -20

158 lines not on this page · raw message

drivers/mmc/mmc_spi.c new file +280 -0

280 lines not on this page · raw message

include/mmc.h +5 -0
index 74c0b1d..0b1e064 100644
@@ -44,6 +44,7 @@
 #define MMC_MODE_HS_52MHz	0x010
 #define MMC_MODE_4BIT		0x100
 #define MMC_MODE_8BIT		0x200
+#define MMC_MODE_SPI		0x400
 
 #define SD_DATA_4BIT	0x00040000
 
@@ -75,6 +76,8 @@
 #define MMC_CMD_WRITE_SINGLE_BLOCK	24
 #define MMC_CMD_WRITE_MULTIPLE_BLOCK	25
 #define MMC_CMD_APP_CMD			55
+#define MMC_CMD_SPI_READ_OCR		58
+#define MMC_CMD_SPI_CRC_ON_OFF		59
 
 #define SD_CMD_SEND_RELATIVE_ADDR	3
 #define SD_CMD_SWITCH_FUNC		6
@@ -288,6 +291,8 @@ int board_mmc_getcd(u8 *cd, struct mmc *mmc);
 
 #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
 int mmc_legacy_init(int verbose);
 #endif
Signature · 1 line
1.7.3.4
#14 lore raw

cover generic mmc_spi driver

In reply to Thomas Chou
Quoted 7 lines · On Friday, December 24, 2010 02:16:05 Thomas Chou wrote:

This is the v9 update of the mmc_spi driver. Please enable DEBUG on the top of mmc_spi.c and help me perform the tests.

A new spi_set_speed() is added to meet the 400KHz clock requirement during mmc card initialization. An example update to bfin_spi is included. The altera_spi core does not support speed change, so I am going to post a new opencore ip for this.

this seems to work much nicer for me. only odd thing is that 'fatls' does not work if i dont 'mmcinfo' first. do you see the same ? maybe this is (currently) expected behavior ?

from cold boot:

bfin> mmc_spi 4
MMC_SPI: 0 at 0:4 hz 25000000 mode 0

bfin> fatls mmc 0:1
MMC: block number 0x1 exceeds max(0x0)
** Can't read from device 0 **

** Unable to use mmc 0:1 for fatls **

bfin> mmcinfo
Device: MMC_SPI
Manufacturer ID: 0
OEM: 2
Name: card
Tran Speed: 25000000
Rd Block Len: 512
SD version 1.0
High Capacity: No
Capacity: 31326208
Bus Width: 1-bit

bfin> fatls mmc 0:1

            private/
            bootmii/
     3041   installer.log
            apps/
     5213   readme-bootmii.txt
     7273   readme-hbc.txt
            config/

3 file(s), 4 dir(s)

-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20101224/511e161d/attachment.pgp

#15 lore raw

cover generic mmc_spi driver

Dear Mike Frysinger,

Quoted 3 lines

this seems to work much nicer for me. only odd thing is that 'fatls' does not work if i dont 'mmcinfo' first. do you see the same ? maybe this is (currently) expected behavior ?

Currently it is like that with the common MMC framework. Same behavior with gen_atmel_mci.

I'd think its normal that you have to "init" such a block device first, isn't it the same with USB?

Otherwise you'd have to implement automated init on first block read, and detection of removal and insertion of a new device to re-read the info.

Season's Greetings,
Reinhard

#16 lore raw

cover generic mmc_spi driver

Quoted 5 lines · On Friday, December 24, 2010 14:06:34 Reinhard Meyer wrote:

Dear Mike Frysinger,

Quoted 3 lines

this seems to work much nicer for me. only odd thing is that 'fatls' does not work if i dont 'mmcinfo' first. do you see the same ? maybe this is (currently) expected behavior ?

Quoted 8 lines

Currently it is like that with the common MMC framework. Same behavior with gen_atmel_mci.

I'd think its normal that you have to "init" such a block device first, isn't it the same with USB?

Otherwise you'd have to implement automated init on first block read, and detection of removal and insertion of a new device to re-read the info.

my gripe is that it's called "mmcinfo" and not "mmc init". if it were the latter, i wouldnt be surprised at all. but it seems odd that i have to "query the device and print its extended info" rather than "initialize the mmc card". perhaps i'm just whining semantics though.

if this is currently the standard/expected behavior for the generic mmc framework, then that's OK from the mmc_spi perspective. i'll merge this into the Blackfin tree and let our testers validate it with our regression tests. -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20101224/5b295a89/attachment.pgp

#17 lore raw

cover generic mmc_spi driver

Quoted 4 lines · Mike Frysinger

if this is currently the standard/expected behavior for the generic mmc framework, then that's OK from the mmc_spi perspective. i'll merge this into the Blackfin tree and let our testers validate it with our regression tests. -mike

Yes. It is the current behaviour. I just added an update to run the initialization clock at 400KHz which should improve compatibility. Please try out. Thank you very much.

Merry Xmas!

- Thomas

#18 lore raw

cover generic mmc_spi driver

In reply to Thomas Chou
Quoted 8 lines · On Friday, December 24, 2010 02:16:05 Thomas Chou wrote:

This is the v9 update of the mmc_spi driver. Please enable DEBUG on the top of mmc_spi.c and help me perform the tests.

A new spi_set_speed() is added to meet the 400KHz clock requirement during mmc card initialization. An example update to bfin_spi is included. The altera_spi core does not support speed change, so I am going to post a new opencore ip for this.

Quoted 8 lines

The driver now claims and releases the spi bus for each mmc command, as Mike suggested.

Thomas Chou (4):
lib: add crc7 from Linux
spi: add spi_set_speed func
bfin_spi: add spi_set_speed
mmc: add generic mmc spi driver

Andy: i think we've hit a fairly stable point. could you merge this now ? -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20110412/dd22131e/attachment.pgp

#19 lore raw

cover generic mmc_spi driver

Quoted 12 lines · Mike Frysinger
Quoted 11 lines · On Friday, December 24, 2010 02:16:05 Thomas Chou wrote:

This is the v9 update of the mmc_spi driver. Please enable DEBUG on the top of mmc_spi.c and help me perform the tests.

A new spi_set_speed() is added to meet the 400KHz clock requirement during mmc card initialization. An example update to bfin_spi is included. The altera_spi core does not support speed change, so I am going to post a new opencore ip for this.

The driver now claims and releases the spi bus for each mmc command, as Mike suggested.

Quoted 7 lines
Quoted 5 lines

Thomas Chou (4):
? lib: add crc7 from Linux
? spi: add spi_set_speed func
? bfin_spi: add spi_set_speed
? mmc: add generic mmc spi driver

Andy: i think we've hit a fairly stable point. ?could you merge this now ?

I'm going to merge this, but I'll note that the reason you had to run mmcinfo before this will work is because this code never invoks mmc_init(). If you look at the mmc command in common/cmd_mmc.c, and see how the various sub-commands operate (under GENERIC_MMC), all of them call mmc_init() before running the command. It's suboptimal in terms of performance, but has the advantage of being robust and actually detecting if you put a card in, or took one out. If someone could find the appropriate places to call mmc_init(mmc), I'll be happy to also merge in the follow-up patch.

Also, I'm assuming, at the moment, that this supersedes the legacy mmc_spi patch you submitted earlier? If not, I'll put that in, now, too.

Andy

#20 lore raw

cover generic mmc_spi driver

Quoted 22 lines · On Wednesday, April 13, 2011 06:17:43 Andy Fleming wrote:
Quoted 12 lines · Mike Frysinger
Quoted 11 lines · On Friday, December 24, 2010 02:16:05 Thomas Chou wrote:

This is the v9 update of the mmc_spi driver. Please enable DEBUG on the top of mmc_spi.c and help me perform the tests.

A new spi_set_speed() is added to meet the 400KHz clock requirement during mmc card initialization. An example update to bfin_spi is included. The altera_spi core does not support speed change, so I am going to post a new opencore ip for this.

The driver now claims and releases the spi bus for each mmc command, as Mike suggested.

Quoted 8 lines
Quoted 5 lines

Thomas Chou (4):
lib: add crc7 from Linux
spi: add spi_set_speed func
bfin_spi: add spi_set_speed
mmc: add generic mmc spi driver

Andy: i think we've hit a fairly stable point. could you merge this now ?

Quoted 9 lines

I'm going to merge this, but I'll note that the reason you had to run mmcinfo before this will work is because this code never invoks mmc_init(). If you look at the mmc command in common/cmd_mmc.c, and see how the various sub-commands operate (under GENERIC_MMC), all of them call mmc_init() before running the command. It's suboptimal in terms of performance, but has the advantage of being robust and actually detecting if you put a card in, or took one out. If someone could find the appropriate places to call mmc_init(mmc), I'll be happy to also merge in the follow-up patch.

i hope Thomas can do that :)

Quoted 3 lines

Also, I'm assuming, at the moment, that this supersedes the legacy mmc_spi patch you submitted earlier? If not, I'll put that in, now, too.

correct, the legacy mmc_spi code is hopefully no longer needed
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20110413/ea65099d/attachment.pgp

#21 lore raw

PATCH 1/1 mmc_spi: add mmc_init call

In reply to Andy Fleming

As Andy Fleming suggested, we can call mmc_init() in mmc_spi command. So that we don't need to run mmcinfo command next.

---
for u-boot.

 common/cmd_mmc_spi.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
common/cmd_mmc_spi.c +1 -0
index 63fe313..cfd0fb1 100644
@@ -74,6 +74,7 @@ static int do_mmc_spi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	}
 	printf("%s: %d at %u:%u hz %u mode %u\n", mmc->name, mmc->block_dev.dev,
 	       bus, cs, speed, mode);
+	mmc_init(mmc);
 	return 0;
 
 usage:
Signature · 1 line
1.7.1.86.g0e460