X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=cmd%2Fspi.c;h=aec912167c675a0dd56cbf2ad358024ea97c120a;hb=2843444a6eaf1bf287aa00ad46ccfac54fac26b0;hp=64c3ffcf423b35fc1b0a65daccb99d490a053c5f;hpb=9c3193f8d03d4074fa6ca6b783246b97d8dc2ff5;p=oweals%2Fu-boot.git diff --git a/cmd/spi.c b/cmd/spi.c index 64c3ffcf42..aec912167c 100644 --- a/cmd/spi.c +++ b/cmd/spi.c @@ -1,8 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2002 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com - * - * SPDX-License-Identifier: GPL-2.0+ */ /* @@ -23,19 +22,13 @@ # define MAX_SPI_BYTES 32 /* Maximum number of bytes we can handle */ #endif -#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 unsigned int bus; static unsigned int cs; static unsigned int mode; +static unsigned int freq; static int bitlen; static uchar dout[MAX_SPI_BYTES]; static uchar din[MAX_SPI_BYTES]; @@ -51,12 +44,14 @@ static int do_spi_xfer(int bus, int cs) snprintf(name, sizeof(name), "generic_%d:%d", bus, cs); str = strdup(name); - ret = spi_get_bus_and_cs(bus, cs, 1000000, mode, "spi_generic_drv", + if (!str) + return -ENOMEM; + ret = spi_get_bus_and_cs(bus, cs, freq, mode, "spi_generic_drv", str, &dev, &slave); if (ret) return ret; #else - slave = spi_setup_slave(bus, cs, 1000000, mode); + slave = spi_setup_slave(bus, cs, freq, mode); if (!slave) { printf("Invalid device %d:%d\n", bus, cs); return -EINVAL; @@ -102,7 +97,7 @@ done: * The command prints out the hexadecimal string received via SPI. */ -int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +int do_spi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { char *cp = 0; uchar tmp; @@ -112,6 +107,8 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * We use the last specified parameters, unless new ones are * entered. */ + if (freq == 0) + freq = 1000000; if ((flag & CMD_FLAG_REPEAT) == 0) { @@ -125,7 +122,9 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) bus = CONFIG_DEFAULT_SPI_BUS; } if (*cp == '.') - mode = simple_strtoul(cp+1, NULL, 10); + mode = simple_strtoul(cp+1, &cp, 10); + if (*cp == '@') + freq = simple_strtoul(cp+1, &cp, 10); } if (argc >= 3) bitlen = simple_strtoul(argv[2], NULL, 10); @@ -165,10 +164,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 command", - "[:][.] - Send and receive bits\n" + "[:][.][@] - Send and receive bits\n" " - Identifies the SPI bus\n" " - Identifies the chip select\n" " - Identifies the SPI mode to use\n" + " - Identifies the SPI bus frequency in Hz\n" " - Number of bits to send (base 10)\n" " - Hexadecimal string that gets sent" );