X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=common%2Fcmd_spi.c;h=ab7aac780dbd85999ccf8cc65d01c226e7de247b;hb=91b469c95faf92435e3d5d78292ba78075a3c5ca;hp=d544b27018889ff2cad5e5bc3b4611a2dbb3e9f5;hpb=eb9401e3ebfa6a1550522be28895af461137f797;p=oweals%2Fu-boot.git diff --git a/common/cmd_spi.c b/common/cmd_spi.c index d544b27018..ab7aac780d 100644 --- a/common/cmd_spi.c +++ b/common/cmd_spi.c @@ -28,9 +28,6 @@ #include #include #include -#include - -#if (CONFIG_COMMANDS & CFG_CMD_SPI) /*----------------------------------------------------------------------- * Definitions @@ -40,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 @@ -68,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; @@ -104,30 +102,45 @@ 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; - } + } + + /* 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[%d] = %08X\n", - device, (uint)spi_chipsel[device]); + 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 = 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; } -#endif /* CFG_CMD_SPI */ +/***************************************************/ + +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" + " - Number of bits to send (base 10)\n" + " - Hexadecimal string that gets sent" +);