X-Git-Url: https://git.kernelconcepts.de/?a=blobdiff_plain;f=common%2Fcmd_spi.c;h=ab7aac780dbd85999ccf8cc65d01c226e7de247b;hb=d9c27253ce333e2086b2d758b42dc3ecb8b34c3d;hp=3118d279b97dcea25658f561b06d6b1bfde7ff29;hpb=375c2c9e57ea5b8d678475379378f4774aa9cb88;p=karo-tx-uboot.git diff --git a/common/cmd_spi.c b/common/cmd_spi.c index 3118d279b9..ab7aac780d 100644 --- a/common/cmd_spi.c +++ b/common/cmd_spi.c @@ -29,8 +29,6 @@ #include #include -#if defined(CONFIG_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; + } - if(spi_xfer(spi_chipsel[device], bitlen, dout, din) != 0) { + debug ("spi chipsel = %08X\n", device); + + 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