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

2010-07-05 Thread Mike Frysinger
On Wednesday, May 19, 2010 00:37:47 Thomas Chou wrote:
 --- /dev/null
 +++ b/common/cmd_mmc_spi.c
 + printf(%s: %d at %u:%u %u %u\n, mmc-name, mmc-block_dev.dev,
 +bus, cs, speed, mode);

this is a bit terse.  how about prefixing the hz output with like hz: and 
the mode with like mode: ?

 +U_BOOT_CMD(
 + mmc_spi,4,  0,  do_mmc_spi,
 + mmc_spi setup,
 + [bus:]cs [hz] [mode]   - setup mmc_spi device on given\n
 +   SPI bus and chip select\n
 +);

there should be no newline at the end of the help string

 --- /dev/null
 +++ b/drivers/mmc/mmc_spi.c
 +struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode)
 +{
 + struct mmc *mmc;
 + mmc-b_max = MMC_SPI_MAX_BLOCKS;

do you have some local modification ?  i dont see b_max anywhere in 
include/mmc.h ...

unfortunately though, i tried this on my system and it doesnt seem to work.  
using a simple SPI-MMC card, the old mmc_spi driver works on my board, but 
booting the new u-boot and running the same things shows:

bfin mmc_spi 4 3000 3
MMC_SPI: 0 at 0:4 3000 3

bfin mmc list
MMC_SPI: 0

bfin mmcinfo
Card did not respond to voltage select!
Device: MMC_SPI
Manufacturer ID: 0
OEM: 0
Name: Tran Speed: 0
Rd Block Len: 0
MMC version 0.0
High Capacity: No
Capacity: 0
Bus Width: 1-bit

enabling debugging in the driver shows this:
bfin mmcinfo
mmc_spi_init_p: clock 0
mmc_spi_set_ios: clock 0
mmc_spi_set_ios: clock 40
mmc_spi_request:cmd0 0 0 0
mmc_spi_sendcmd:cmd0 resp6 1
mmc_spi_request:cmd8 15 1aa 0
mmc_spi_sendcmd:cmd8 resp8 ff
mmc_spi_request:cmd55 15 0 0
mmc_spi_sendcmd:cmd55 resp6 5
mmc_spi_request:cmd0 0 0 0
mmc_spi_sendcmd:cmd0 resp6 1
mmc_spi_request:cmd1 1 4030 0
mmc_spi_sendcmd:cmd1 resp6 1
mmc_spi_request:cmd1 1 4030 0
mmc_spi_sendcmd:cmd1 resp6 1
mmc_spi_request:cmd1 1 4030 0
mmc_spi_sendcmd:cmd1 resp4 1
mmc_spi_request:cmd1 1 4030 0
mmc_spi_sendcmd:cmd1 resp4 1
these last 2 lines repeat for a while
Card did not respond to voltage select!
...
-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 3/3 v8] mmc: add generic mmc spi driver

2010-07-05 Thread Thomas Chou
Hi Mike,

Thank you very much for the review and testing.


On 07/05/2010 03:40 PM, Mike Frysinger wrote:
 On Wednesday, May 19, 2010 00:37:47 Thomas Chou wrote:
 --- /dev/null
 +++ b/common/cmd_mmc_spi.c
 +printf(%s: %d at %u:%u %u %u\n, mmc-name, mmc-block_dev.dev,
 +   bus, cs, speed, mode);

 this is a bit terse.  how about prefixing the hz output with like hz: and
 the mode with like mode: ?

Yes, I will add them.


 +U_BOOT_CMD(
 +mmc_spi,4,  0,  do_mmc_spi,
 +mmc_spi setup,
 +[bus:]cs [hz] [mode]   - setup mmc_spi device on given\n
 +  SPI bus and chip select\n
 +);

 there should be no newline at the end of the help string

OK. I will remove the last newline.


 --- /dev/null
 +++ b/drivers/mmc/mmc_spi.c
 +struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode)
 +{
 +struct mmc *mmc;
 +mmc-b_max = MMC_SPI_MAX_BLOCKS;

 do you have some local modification ?  i dont see b_max anywhere in
 include/mmc.h ...

Please apply the multi-blocks patches (1,2,3/4) from Alagu on 05/12, as 
Andy said he had applied them.



 unfortunately though, i tried this on my system and it doesnt seem to work.
 using a simple SPI-MMC card, the old mmc_spi driver works on my board, but
 booting the new u-boot and running the same things shows:


 mmc_spi_request:cmd1 1 4030 0
 mmc_spi_sendcmd:cmd1 resp4 1
 these last 2 lines repeat for a while
 Card did not respond to voltage select!

It seems the mmc card was not initialized and timed out. Please try 
remove the OCR_HCS in mmc_send_op_cond() of mmc.c temporarily.

cmd.cmdarg = OCR_HCS | mmc-voltages;
-^

Best regards,
Thomas

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


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

2010-07-05 Thread Mike Frysinger
On Monday, July 05, 2010 10:22:45 Thomas Chou wrote:
 On 07/05/2010 03:40 PM, Mike Frysinger wrote:
  On Wednesday, May 19, 2010 00:37:47 Thomas Chou wrote:
  --- /dev/null
  +++ b/drivers/mmc/mmc_spi.c
  +struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode)
  +{
  +  struct mmc *mmc;
  +  mmc-b_max = MMC_SPI_MAX_BLOCKS;
  
  do you have some local modification ?  i dont see b_max anywhere in
  include/mmc.h ...
 
 Please apply the multi-blocks patches (1,2,3/4) from Alagu on 05/12, as
 Andy said he had applied them.

those arent required for basic probing functionality, right ?

  unfortunately though, i tried this on my system and it doesnt seem to
  work. using a simple SPI-MMC card, the old mmc_spi driver works on my
  board, but booting the new u-boot and running the same things shows:
  
  
  mmc_spi_request:cmd1 1 4030 0
  mmc_spi_sendcmd:cmd1 resp4 1
  these last 2 lines repeat for a while
  Card did not respond to voltage select!
 
 It seems the mmc card was not initialized and timed out. Please try
 remove the OCR_HCS in mmc_send_op_cond() of mmc.c temporarily.
 
   cmd.cmdarg = OCR_HCS | mmc-voltages;
 -^

that does fix the timeout/warning, but the card doesnt probe yet:
bfin mmcinfo
mmc_spi_init_p: clock 0
mmc_spi_set_ios: clock 0
mmc_spi_set_ios: clock 40
mmc_spi_request:cmd0 0 0 0
mmc_spi_sendcmd:cmd0 resp8 ff
Device: MMC_SPI
Manufacturer ID: 0
OEM: 0
Name: Tran Speed: 0
Rd Block Len: 0
MMC version 0.0
High Capacity: No
Capacity: 0
Bus Width: 1-bit

if i boot up the old u-boot and probe the card there, then load up the new u-
boot and try again, things get further:
bfin mmcinfo
mmc_spi_init_p: clock 0
mmc_spi_set_ios: clock 0
mmc_spi_set_ios: clock 40
mmc_spi_request:cmd0 0 0 0
mmc_spi_sendcmd:cmd0 resp6 1
mmc_spi_request:cmd8 15 1aa 0
mmc_spi_sendcmd:cmd8 resp8 ff
mmc_spi_request:cmd55 15 0 0
mmc_spi_sendcmd:cmd55 resp6 5
mmc_spi_request:cmd0 0 0 0
mmc_spi_sendcmd:cmd0 resp6 1
mmc_spi_request:cmd1 1 30 0
mmc_spi_sendcmd:cmd1 resp6 1
mmc_spi_request:cmd1 1 30 0
mmc_spi_sendcmd:cmd1 resp6 1
mmc_spi_request:cmd1 1 30 0
mmc_spi_sendcmd:cmd1 resp6 1
mmc_spi_request:cmd1 1 30 0
mmc_spi_sendcmd:cmd1 resp6 1
mmc_spi_request:cmd1 1 30 0
mmc_spi_sendcmd:cmd1 resp6 1
mmc_spi_request:cmd1 1 30 0
mmc_spi_sendcmd:cmd1 resp6 1
mmc_spi_request:cmd1 1 30 0
mmc_spi_sendcmd:cmd1 resp6 0
mmc_spi_request:cmd58 1 0 0
mmc_spi_sendcmd:cmd58 resp6 0
r32 
mmc_spi_request:cmd10 7 0 0
mmc_spi_sendcmd:cmd10 resp6 0
mmc_spi_readdata:tok0 80
r128 0 ff7a fdff 3831f903
mmc_spi_request:cmd9 7 0 0
mmc_spi_sendcmd:cmd9 resp6 0
mmc_spi_readdata:tok1 fe
r128 ff4900 263 61726420 1659810
mmc_spi_set_ios: clock 2000
mmc_spi_request:cmd16 15 1 0
mmc_spi_sendcmd:cmd16 resp6 0
mmc_spi_request:cmd17 15 0 0
mmc_spi_sendcmd:cmd17 resp8 ff
block read failed: -16
Device: MMC_SPI
Manufacturer ID: 0
OEM: 0
Name: Tran Speed: 0
Rd Block Len: 1
MMC version 1.2
High Capacity: Yes
Capacity: 2374355968
Bus Width: 1-bit

however, in poking the code, i see your mmc_spi_init_p() function calls 
spi_claim_bus(), but nowhere do i see spi_release_bus().
-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 3/3 v8] mmc: add generic mmc spi driver

2010-05-28 Thread Thomas Chou
Hi Andy,

Would you please review these patches?

05/03 [PATCH 1/3] lib: add crc7 from Linux
05/19 [PATCH 3/3 v8] mmc: add generic mmc spi driver

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


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

2010-05-18 Thread 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,
#define CONFIG_MMC_SPI_CRC_ON

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

Signed-off-by: Thomas Chou tho...@wytron.com.tw
---
v8: make mmc.c core aware of spi protocol, per Andy.
work with multi blocks read/write.
reduce cmd_mmc_spi.c, doesnt query to mmc dev list.
v7: use find_mmc_device(dev, verbose), per Wolfgang.
v6: add constant macros, crc check on data, per Andy.
v5: remove dev_num limit to search.
v4: change mmc_spi subcommand to search and create new mmc dev.
v3: add mmc_spi_init() proto to mmc_spi.h.
v2: add crc7, use cmd58 to read ocr, add subcommand mmc_spi.

 common/Makefile   |1 +
 common/cmd_mmc_spi.c  |   82 ++
 drivers/mmc/Makefile  |1 +
 drivers/mmc/mmc.c |   81 +++---
 drivers/mmc/mmc_spi.c |  296 +
 include/mmc.h |8 ++
 6 files changed, 451 insertions(+), 18 deletions(-)
 create mode 100644 common/cmd_mmc_spi.c
 create mode 100644 drivers/mmc/mmc_spi.c

diff --git a/common/Makefile b/common/Makefile
index 2c37073..55beac5 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -119,6 +119,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
diff --git a/common/cmd_mmc_spi.c b/common/cmd_mmc_spi.c
new file mode 100644
index 000..13933b0
--- /dev/null
+++ b/common/cmd_mmc_spi.c
@@ -0,0 +1,82 @@
+/*
+ * Command for mmc_spi setup.
+ *
+ * Copyright (C) 2010 Thomas Chou tho...@wytron.com.tw
+ * Licensed under the GPL-2 or later.
+ */
+
+#include common.h
+#include mmc.h
+#include spi.h
+
+#ifndef CONFIG_MMC_SPI_BUS
+# define CONFIG_MMC_SPI_BUS 0
+#endif
+#ifndef CONFIG_MMC_SPI_CS
+# define CONFIG_MMC_SPI_CS 1
+#endif
+#ifndef CONFIG_MMC_SPI_SPEED
+# define CONFIG_MMC_SPI_SPEED 2500
+#endif
+#ifndef CONFIG_MMC_SPI_MODE
+# define CONFIG_MMC_SPI_MODE SPI_MODE_3
+#endif
+
+static int do_mmc_spi(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+   uint bus = CONFIG_MMC_SPI_BUS;
+   uint cs = CONFIG_MMC_SPI_CS;
+   uint speed = CONFIG_MMC_SPI_SPEED;
+   uint mode = CONFIG_MMC_SPI_MODE;
+   char *endp;
+   struct mmc *mmc;
+
+   if (argc  2)
+   goto usage;
+
+   cs = simple_strtoul(argv[1], endp, 0);
+   if (*argv[1] == 0 || (*endp != 0  *endp != ':'))
+   goto usage;
+   if (*endp == ':') {
+   if (endp[1] == 0)
+   goto usage;
+   bus = cs;
+   cs = simple_strtoul(endp + 1, endp, 0);
+   if (*endp != 0)
+   goto usage;
+   }
+   if (argc = 3) {
+   speed = simple_strtoul(argv[2], endp, 0);
+   if (*argv[2] == 0 || *endp != 0)
+   goto usage;
+   }
+   if (argc = 4) {
+   mode = simple_strtoul(argv[3], endp, 16);
+   if (*argv[3] == 0 || *endp != 0)
+   goto usage;
+   }
+   if (!spi_cs_is_valid(bus, cs)) {
+   printf(Invalid SPI bus %u cs %u\n, bus, cs);
+   return 1;
+   }
+
+   mmc = mmc_spi_init(bus, cs, speed, mode);
+   if (!mmc) {
+   printf(Failed to create MMC Device\n);
+   return 1;
+   }
+   printf(%s: %d at %u:%u %u %u\n, mmc-name, mmc-block_dev.dev,
+  bus, cs, speed, mode);
+   return 0;
+
+usage:
+   cmd_usage(cmdtp);
+   return 1;
+}
+
+U_BOOT_CMD(
+   mmc_spi,4,  0,  do_mmc_spi,
+   mmc_spi setup,
+   [bus:]cs [hz] [mode]   - setup mmc_spi device on given\n
+ SPI bus and chip select\n
+);
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index 6fa04b8..02ed329 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -28,6 +28,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.c b/drivers/mmc/mmc.c
index aefd721..0e819f8 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -283,7 +283,10 @@ static int mmc_write_blocks(struct mmc *mmc, const char 
*src, uint start,
return err;
}
 
-   if (blkcnt  1) {
+   /* SPI multiblock writes terminate using a special
+* token, not a STOP_TRANSMISSION request.
+*/
+