X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fcmd_spi.c;h=ab7aac780dbd85999ccf8cc65d01c226e7de247b;hb=7b5ae460c34fa43261fe1ded71dc9c33d3ffd8e5;hp=a6fdf7fddbd0924e7d10c0a9171df35ec88b98c9;hpb=ea1fba136a4778b8f55e6b94a76a548cfad9f522;p=u-boot diff --git a/common/cmd_spi.c b/common/cmd_spi.c index a6fdf7fddb..ab7aac780d 100644 --- a/common/cmd_spi.c +++ b/common/cmd_spi.c @@ -29,8 +29,6 @@ #include #include -#if (CONFIG_COMMANDS & CFG_CMD_SPI) - /*----------------------------------------------------------------------- * Definitions */ @@ -39,20 +37,20 @@ # define MAX_SPI_BYTES 32 /* Maximum number of bytes we can handle */ #endif -/* - * External table of chip select functions (see the appropriate board - * support for the actual definition of the table). - */ -extern spi_chipsel_type spi_chipsel[]; -extern int spi_chipsel_cnt; +#ifndef CONFIG_DEFAULT_SPI_BUS +# define CONFIG_DEFAULT_SPI_BUS 0 +#endif +#ifndef CONFIG_DEFAULT_SPI_MODE +# define CONFIG_DEFAULT_SPI_MODE SPI_MODE_0 +#endif /* * Values from last command. */ -static int device; -static int bitlen; -static uchar dout[MAX_SPI_BYTES]; -static uchar din[MAX_SPI_BYTES]; +static unsigned int device; +static int bitlen; +static uchar dout[MAX_SPI_BYTES]; +static uchar din[MAX_SPI_BYTES]; /* * SPI read/write @@ -67,6 +65,7 @@ static uchar din[MAX_SPI_BYTES]; int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { + struct spi_slave *slave; char *cp = 0; uchar tmp; int j; @@ -103,28 +102,34 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } } - if ((device < 0) || (device >= spi_chipsel_cnt)) { - printf("Invalid device %d, giving up.\n", device); - return 1; - } if ((bitlen < 0) || (bitlen > (MAX_SPI_BYTES * 8))) { printf("Invalid bitlen %d, giving up.\n", bitlen); return 1; } - debug ("spi_chipsel[%d] = %08X\n", - device, (uint)spi_chipsel[device]); + /* FIXME: Make these parameters run-time configurable */ + slave = spi_setup_slave(CONFIG_DEFAULT_SPI_BUS, device, 1000000, + CONFIG_DEFAULT_SPI_MODE); + if (!slave) { + printf("Invalid device %d, giving up.\n", device); + return 1; + } + + debug ("spi chipsel = %08X\n", device); - if(spi_xfer(spi_chipsel[device], bitlen, dout, din) != 0) { + spi_claim_bus(slave); + if(spi_xfer(slave, bitlen, dout, din, + SPI_XFER_BEGIN | SPI_XFER_END) != 0) { printf("Error with the SPI transaction.\n"); rcode = 1; } else { - cp = (char *)din; for(j = 0; j < ((bitlen + 7) / 8); j++) { - printf("%02X", *cp++); + printf("%02X", din[j]); } printf("\n"); } + spi_release_bus(slave); + spi_free_slave(slave); return rcode; } @@ -133,11 +138,9 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) U_BOOT_CMD( sspi, 5, 1, do_spi, - "sspi - SPI utility commands\n", + "SPI utility commands", " - Send bits from out the SPI\n" " - Identifies the chip select of the device\n" " - Number of bits to send (base 10)\n" - " - Hexadecimal string that gets sent\n" + " - Hexadecimal string that gets sent" ); - -#endif /* CFG_CMD_SPI */