Re: [U-Boot] [PATCH] mmc: add generic mmc spi driver

2010-04-26 Thread Thomas Chou
On 04/25/2010 02:56 PM, Mike Frysinger wrote:
 On Friday 23 April 2010 01:55:11 Thomas Chou wrote:

 On 04/23/2010 12:04 PM, Thomas Chou wrote:
  
 it's too bad the new framework doesnt allow for dynamic probing like
 the spi layer.  makes it a pain to work with a SPI/MMC card that can have
 the CS changed on the fly.
  
 Second thought.
 With generic mmc framework, we can instance multiple mmc devices. Then
 we can probe one of them when we want.
  
 i dont think that's a scalable solution.  what if you have multiple spi busses
 or 10's of GPIO CS's ?  only way to scale is to have a new subcommand so
 people can do it themselves.  a simple CONFIG_CMD_MMC_SPI command which
 forwards along calls to mmc_spi_init() on the fly would work.
 -mike

Hi Mike,

I have resolved the SDHC issue and have tested various MMC/SD cards, 
including writing. I will submit the patch tomorrow.

I have moved spi slave setup so that we can change the cs on the fly. We 
could add a subcommand, like,

mmc_spi [bus:]cs

Where should I place this command? in a new file in common dir or inside 
the mmc_spi driver?

Cheers,
Thomas


___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] mmc: add generic mmc spi driver

2010-04-26 Thread Mike Frysinger
On Monday 26 April 2010 10:37:07 Thomas Chou wrote:
 I have moved spi slave setup so that we can change the cs on the fly. We
 could add a subcommand, like,
 
 mmc_spi [bus:]cs
 
 Where should I place this command? in a new file in common dir or inside
 the mmc_spi driver?

i would keep the current board init hook you have currently so that the boards 
which do have static settings can leverage that, and have the mmc_spi command 
simply call that.  i'd have the syntax be:
mmc_spi [bus:]cs [hz [mode]]

i'd have it be a dedicated command in common/ so that people can disable it if 
they dont want it.
-mike


signature.asc
Description: This is a digitally signed message part.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] mmc: add generic mmc spi driver

2010-04-25 Thread Mike Frysinger
On Friday 23 April 2010 00:04:51 Thomas Chou wrote:
 Do you mean parity as crc? Crc is not supported, but can be added. I
 make some command set translation when spi doesn't support.

i mean functionality wrt card/spec support
-mike


signature.asc
Description: This is a digitally signed message part.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] mmc: add generic mmc spi driver

2010-04-25 Thread Mike Frysinger
On Friday 23 April 2010 01:55:11 Thomas Chou wrote:
 On 04/23/2010 12:04 PM, Thomas Chou wrote:
  it's too bad the new framework doesnt allow for dynamic probing like
  the spi layer.  makes it a pain to work with a SPI/MMC card that can have
  the CS changed on the fly.
 
 Second thought.
 With generic mmc framework, we can instance multiple mmc devices. Then
 we can probe one of them when we want.

i dont think that's a scalable solution.  what if you have multiple spi busses 
or 10's of GPIO CS's ?  only way to scale is to have a new subcommand so 
people can do it themselves.  a simple CONFIG_CMD_MMC_SPI command which 
forwards along calls to mmc_spi_init() on the fly would work.
-mike


signature.asc
Description: This is a digitally signed message part.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] mmc: add generic mmc spi driver

2010-04-22 Thread Thomas Chou
This patch supports mmc/sd card with spi interface.
I have tested with sd and mmc cards. But there is still ocr issue
with SDHC.

Signed-off-by: Thomas Chou tho...@wytron.com.tw
---
 drivers/mmc/Makefile  |1 +
 drivers/mmc/mmc_spi.c |  252 +
 2 files changed, 253 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mmc/mmc_spi.c

diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index 1b8f5bd..d03eb47 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -31,6 +31,7 @@ LIB   := $(obj)libmmc.a
 COBJS-$(CONFIG_GENERIC_MMC) += mmc.o
 COBJS-$(CONFIG_ATMEL_MCI) += atmel_mci.o
 COBJS-$(CONFIG_BFIN_SDH) += bfin_sdh.o
+COBJS-$(CONFIG_MMC_SPI) += mmc_spi.o
 COBJS-$(CONFIG_OMAP3_MMC) += omap3_mmc.o
 COBJS-$(CONFIG_FSL_ESDHC) += fsl_esdhc.o
 COBJS-$(CONFIG_MXC_MMC) += mxcmmc.o
diff --git a/drivers/mmc/mmc_spi.c b/drivers/mmc/mmc_spi.c
new file mode 100644
index 000..76c5977
--- /dev/null
+++ b/drivers/mmc/mmc_spi.c
@@ -0,0 +1,252 @@
+/*
+ * generic mmc spi driver
+ *
+ * Copyright (C) 2010 Thomas Chou tho...@wytron.com.tw
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include common.h
+#include malloc.h
+#include part.h
+#include mmc.h
+#include spi.h
+#include asm/errno.h
+
+#define CTOUT 0x10
+#define RTOUT 0x1
+#define WTOUT 0x1
+
+static uint mmc_spi_sendcmd(struct mmc *mmc, u8 cmdidx, u32 cmdarg)
+{
+   u8 cmdo[6];
+   u8 r1;
+   int i;
+   cmdo[0] = 0x40 + cmdidx;
+   cmdo[1] = cmdarg  24;
+   cmdo[2] = cmdarg  16;
+   cmdo[3] = cmdarg  8;
+   cmdo[4] = cmdarg;
+   cmdo[5] = 0x95; /* crc valid only for cmd00 */
+   spi_xfer(mmc-priv, 6 * 8, cmdo, NULL, SPI_XFER_BEGIN);
+   for (i = 0; i  CTOUT; i++) {
+   spi_xfer(mmc-priv, 1 * 8, NULL, r1, 0);
+   if ((r1  0x80) == 0)
+   break;
+   }
+   debug(%s:cmd%d resp%d %x\n, __func__, cmdidx, i, r1);
+   return r1;
+}
+
+static uint mmc_spi_readdata(struct mmc *mmc, char *buf,
+   u32 bcnt, u32 bsize)
+{
+   u8 r1;
+   u8 crc[2];
+   int i;
+   while (bcnt--) {
+   for (i = 0; i  RTOUT; i++) {
+   spi_xfer(mmc-priv, 1 * 8, NULL, r1, 0);
+   if (r1 != 0xff)
+   break;
+   }
+   debug(%s:tok%d %x\n, __func__, i, r1);
+   if (r1 == 0xfe) {
+   spi_xfer(mmc-priv, bsize * 8, NULL, buf, 0);
+   buf += bsize;
+   spi_xfer(mmc-priv, 2 * 8, NULL, crc, 0);
+   r1 = 0;
+   } else
+   break;
+   }
+   return r1;
+}
+
+static uint mmc_spi_writedata(struct mmc *mmc, const char *buf,
+   u32 bcnt, u32 bsize)
+{
+   u8 r1;
+   u8 tok[2] = { 0xff, 0xfe };
+   u8 crc[2];
+   int i;
+   while (bcnt--) {
+   spi_xfer(mmc-priv, 2 * 8, tok, NULL, 0);
+   spi_xfer(mmc-priv, bsize * 8, buf, NULL, 0);
+   buf += bsize;
+   spi_xfer(mmc-priv, 2 * 8, crc, NULL, 0);
+   spi_xfer(mmc-priv, 1 * 8, NULL, r1, 0);
+   if (r1 == 0x05) {
+   for (i = 0; i  WTOUT; i++) {
+   spi_xfer(mmc-priv, 1 * 8, NULL, r1, 0);
+   if (r1 == 0xff) {
+   r1 = 0;
+   break;
+   }
+   }
+   if (i == WTOUT) {
+   debug(%s:wtout %x\n, __func__, r1);
+   r1 = 0x04;
+   break;
+   }
+   } else
+   break;
+   }
+   return r1;
+}
+
+static uint mmc_spi_writeblock(struct mmc *mmc, const char *buf,
+   u32 bcnt, u32 bsize)
+{
+   u8 r1;
+   u8 tok[2] = { 0xff, 0xfc };
+   u8 stop[2] = { 0xff, 0xfd };
+   u8 crc[2];
+   int i;
+   while (bcnt--) {
+   spi_xfer(mmc-priv, 2 * 8, tok, NULL, 0);
+   spi_xfer(mmc-priv, bsize * 8, buf, NULL, 0);
+   buf += bsize;
+   spi_xfer(mmc-priv, 2 * 8, crc, NULL, 0);
+   spi_xfer(mmc-priv, 1 * 8, NULL, r1, 0);
+   if (r1 == 0x05) {
+   for (i = 0; i  WTOUT; i++) {
+   spi_xfer(mmc-priv, 1 * 8, NULL, r1, 0);
+   if (r1 == 0xff) {
+   r1 = 0;
+   break;
+   }
+   }
+   if (i == WTOUT) {
+   debug(%s:wtout %x\n, __func__, r1);
+   r1 = 0x04;
+   

Re: [U-Boot] [PATCH] mmc: add generic mmc spi driver

2010-04-22 Thread Mike Frysinger
On Thursday 22 April 2010 22:53:34 Thomas Chou wrote:
 This patch supports mmc/sd card with spi interface.
 I have tested with sd and mmc cards. But there is still ocr issue
 with SDHC.

now the semi-obvious question ... how does this differ from the old spi_mmc.c 
driver ?  i see this doesnt rely on the legacy mmc framework, but what about 
device/commandset support parity ?

it's too bad the new framework doesnt allow for dynamic probing like the spi 
layer.  makes it a pain to work with a SPI/MMC card that can have the CS 
changed on the fly.
-mike


signature.asc
Description: This is a digitally signed message part.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] mmc: add generic mmc spi driver

2010-04-22 Thread Thomas Chou
On 04/23/2010 11:35 AM, Mike Frysinger wrote:
 On Thursday 22 April 2010 22:53:34 Thomas Chou wrote:

 This patch supports mmc/sd card with spi interface.
 I have tested with sd and mmc cards. But there is still ocr issue
 with SDHC.
  
 now the semi-obvious question ... how does this differ from the old spi_mmc.c
 driver ?  i see this doesnt rely on the legacy mmc framework, but what about
 device/commandset support parity ?


Hi Mike,

Right after playing your spi_mmc.c, I started this one based on generic 
mmc framework last night. I tried hard to recall my memory about mmc/sd, 
and hoped to catch up the merge window.

Do you mean parity as crc? Crc is not supported, but can be added. I 
make some command set translation when spi doesn't support.

 it's too bad the new framework doesnt allow for dynamic probing like the spi
 layer.  makes it a pain to work with a SPI/MMC card that can have the CS
 changed on the fly.
 -mike

Maybe we can move spi_setup_slave to the mmc-init() and  do probing. Or 
shall we add a subcommand?

Cheers,
Thomas


___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] mmc: add generic mmc spi driver

2010-04-22 Thread Thomas Chou
On 04/23/2010 12:04 PM, Thomas Chou wrote:
 it's too bad the new framework doesnt allow for dynamic probing like 
 the spi
 layer.  makes it a pain to work with a SPI/MMC card that can have the CS
 changed on the fly.
 -mike

  

Second thought.
With generic mmc framework, we can instance multiple mmc devices. Then 
we can probe one of them when we want.

#ifdef CONFIG_GENERIC_MMC
int board_mmc_init(bd_t *bis)
{
 int rc = 0;
#ifdef CONFIG_MMC_SPI
 extern int mmc_spi_init(uint bus, uint cs, uint speed, uint mode);
 mmc_spi_init(CONFIG_MMC_SPI_BUS,
   CONFIG_MMC_SPI_CS_0,
   CONFIG_MMC_SPI_SPEED,
   CONFIG_MMC_SPI_MODE);
 mmc_spi_init(CONFIG_MMC_SPI_BUS,
   CONFIG_MMC_SPI_CS_1,
   CONFIG_MMC_SPI_SPEED,
   CONFIG_MMC_SPI_MODE);
#endif
 return rc;
}
#endif

Cheers,
Thomas
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot