[U-Boot] [PATCH] SPI: cmd_spi.c: add option to specify bus and mode

Reinhard Meyer u-boot at emk-elektronik.de
Mon Aug 9 18:21:47 CEST 2010


To facilitate better testing of SPI peripherals, add
the possibility to specify bus and SPI mode to the
"sspi" command

Signed-off-by: Reinhard Meyer <u-boot at emk-elektronik.de>
---
 common/cmd_spi.c |   33 +++++++++++++++++++++++----------
 1 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/common/cmd_spi.c b/common/cmd_spi.c
index bafa217..fd1b1f5 100644
--- a/common/cmd_spi.c
+++ b/common/cmd_spi.c
@@ -47,7 +47,9 @@
 /*
  * Values from last command.
  */
-static unsigned int	device;
+static unsigned int	bus;
+static unsigned int	cs;
+static unsigned int	mode;
 static int   		bitlen;
 static uchar 		dout[MAX_SPI_BYTES];
 static uchar 		din[MAX_SPI_BYTES];
@@ -78,8 +80,18 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	if ((flag & CMD_FLAG_REPEAT) == 0)
 	{
-		if (argc >= 2)
-			device = simple_strtoul(argv[1], NULL, 10);
+		if (argc >= 2) {
+			mode = CONFIG_DEFAULT_SPI_MODE;
+			bus = simple_strtoul(argv[1], &cp, 10);
+			if (*cp == ':') {
+				cs = simple_strtoul(cp+1, &cp, 10);
+				if (*cp == '.');
+					mode = simple_strtoul(cp+1, NULL, 10);
+			} else {
+				cs = bus;
+				bus = CONFIG_DEFAULT_SPI_BUS;
+			}
+		}
 		if (argc >= 3)
 			bitlen = simple_strtoul(argv[2], NULL, 10);
 		if (argc >= 4) {
@@ -107,15 +119,13 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		return 1;
 	}
 
-	/* FIXME: Make these parameters run-time configurable */
-	slave = spi_setup_slave(CONFIG_DEFAULT_SPI_BUS, device, 1000000,
-			CONFIG_DEFAULT_SPI_MODE);
+	slave = spi_setup_slave(bus, cs, 1000000, mode);
 	if (!slave) {
-		printf("Invalid device %d, giving up.\n", device);
+		printf("Invalid bus %d cs %d, giving up.\n", bus, cs);
 		return 1;
 	}
 
-	debug ("spi chipsel = %08X\n", device);
+	debug ("spi bus=%02x cs=%02x\n", bus, cs);
 
 	spi_claim_bus(slave);
 	if(spi_xfer(slave, bitlen, dout, din,
@@ -139,8 +149,11 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 U_BOOT_CMD(
 	sspi,	5,	1,	do_spi,
 	"SPI utility commands",
-	"<device> <bit_len> <dout> - Send <bit_len> bits from <dout> out the SPI\n"
-	"<device>  - Identifies the chip select of the device\n"
+	"<cs> <bit_len> <dout> - Send <bit_len> bits from <dout> out the SPI\n"
+	"<bus>:<cs>[.<mode>] - extended form\n"
+	"<bus>     - Identifies the SPI bus of the device\n"
+	"<cs>      - Identifies the chip select of the device\n"
+	"<mode>    - Identifies the SPI mode to use for the transfer\n"
 	"<bit_len> - Number of bits to send (base 10)\n"
 	"<dout>    - Hexadecimal string that gets sent"
 );
-- 
1.5.6.5




More information about the U-Boot mailing list