From mboxrd@z Thu Jan 1 00:00:00 1970 From: Reinhard Meyer Date: Mon, 09 Aug 2010 18:21:47 +0200 Subject: [U-Boot] [PATCH] SPI: cmd_spi.c: add option to specify bus and mode Message-ID: <4C602B1B.7050800@emk-elektronik.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 --- 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", - " - Send bits from out the SPI\n" - " - Identifies the chip select of the device\n" + " - Send bits from out the SPI\n" + ":[.] - extended form\n" + " - Identifies the SPI bus of the device\n" + " - Identifies the chip select of the device\n" + " - Identifies the SPI mode to use for the transfer\n" " - Number of bits to send (base 10)\n" " - Hexadecimal string that gets sent" ); -- 1.5.6.5