All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] SPI: cmd_spi.c: add option to specify bus and mode
@ 2010-08-09 16:21 Reinhard Meyer
  2010-08-09 17:05 ` Mike Frysinger
  0 siblings, 1 reply; 8+ messages in thread
From: Reinhard Meyer @ 2010-08-09 16:21 UTC (permalink / raw)
  To: u-boot

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@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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-08-26  5:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-09 16:21 [U-Boot] [PATCH] SPI: cmd_spi.c: add option to specify bus and mode Reinhard Meyer
2010-08-09 17:05 ` Mike Frysinger
2010-08-23 22:15   ` Mike Frysinger
2010-08-24  8:05     ` Reinhard Meyer
2010-08-24 21:07       ` Mike Frysinger
2010-08-24 10:53   ` Reinhard Meyer
2010-08-26  2:04     ` Mike Frysinger
2010-08-26  5:26       ` Reinhard Meyer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.