* [PATCH] cmd: spi: Permit setting bus frequency
@ 2019-12-20 11:44 Marek Vasut
2019-12-20 11:48 ` Lukasz Majewski
2020-01-26 13:26 ` Jagan Teki
0 siblings, 2 replies; 3+ messages in thread
From: Marek Vasut @ 2019-12-20 11:44 UTC (permalink / raw)
To: u-boot
The 'sspi' command hard-coded 1 MHz bus frequency for all transmissions.
Allow changing that at runtime by specifying '@freq' bus frequency in Hz.
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Tom Rini <trini@konsulko.com>
---
cmd/spi.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/cmd/spi.c b/cmd/spi.c
index 75226fd368..bfa185b6ae 100644
--- a/cmd/spi.c
+++ b/cmd/spi.c
@@ -28,6 +28,7 @@
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];
@@ -45,12 +46,12 @@ static int do_spi_xfer(int bus, int cs)
str = strdup(name);
if (!str)
return -ENOMEM;
- ret = spi_get_bus_and_cs(bus, cs, 1000000, mode, "spi_generic_drv",
+ 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;
@@ -106,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)
{
@@ -119,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);
@@ -159,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",
- "[<bus>:]<cs>[.<mode>] <bit_len> <dout> - Send and receive bits\n"
+ "[<bus>:]<cs>[.<mode>][@<freq>] <bit_len> <dout> - Send and receive bits\n"
"<bus> - Identifies the SPI bus\n"
"<cs> - Identifies the chip select\n"
"<mode> - Identifies the SPI mode to use\n"
+ "<freq> - Identifies the SPI bus frequency in Hz\n"
"<bit_len> - Number of bits to send (base 10)\n"
"<dout> - Hexadecimal string that gets sent"
);
--
2.24.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] cmd: spi: Permit setting bus frequency
2019-12-20 11:44 [PATCH] cmd: spi: Permit setting bus frequency Marek Vasut
@ 2019-12-20 11:48 ` Lukasz Majewski
2020-01-26 13:26 ` Jagan Teki
1 sibling, 0 replies; 3+ messages in thread
From: Lukasz Majewski @ 2019-12-20 11:48 UTC (permalink / raw)
To: u-boot
On Fri, 20 Dec 2019 12:44:57 +0100
Marek Vasut <marex@denx.de> wrote:
> The 'sspi' command hard-coded 1 MHz bus frequency for all
> transmissions. Allow changing that at runtime by specifying '@freq'
> bus frequency in Hz.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Tom Rini <trini@konsulko.com>
> ---
> cmd/spi.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/cmd/spi.c b/cmd/spi.c
> index 75226fd368..bfa185b6ae 100644
> --- a/cmd/spi.c
> +++ b/cmd/spi.c
> @@ -28,6 +28,7 @@
> 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];
> @@ -45,12 +46,12 @@ static int do_spi_xfer(int bus, int cs)
> str = strdup(name);
> if (!str)
> return -ENOMEM;
> - ret = spi_get_bus_and_cs(bus, cs, 1000000, mode,
> "spi_generic_drv",
> + 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;
> @@ -106,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)
> {
> @@ -119,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);
> @@ -159,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",
> - "[<bus>:]<cs>[.<mode>] <bit_len> <dout> - Send and receive
> bits\n"
> + "[<bus>:]<cs>[.<mode>][@<freq>] <bit_len> <dout> - Send and
> receive bits\n" "<bus> - Identifies the SPI bus\n"
> "<cs> - Identifies the chip select\n"
> "<mode> Lukasz Majewski <lukma@denx.de> - Identifies the
> SPI mode to use\n"
> + "<freq> - Identifies the SPI bus frequency in Hz\n"
> "<bit_len> - Number of bits to send (base 10)\n"
> "<dout> - Hexadecimal string that gets sent"
> );
Reviewed-by: Lukasz Majewski <lukma@denx.de>
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191220/e35b876b/attachment.sig>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] cmd: spi: Permit setting bus frequency
2019-12-20 11:44 [PATCH] cmd: spi: Permit setting bus frequency Marek Vasut
2019-12-20 11:48 ` Lukasz Majewski
@ 2020-01-26 13:26 ` Jagan Teki
1 sibling, 0 replies; 3+ messages in thread
From: Jagan Teki @ 2020-01-26 13:26 UTC (permalink / raw)
To: u-boot
On Fri, Dec 20, 2019 at 5:15 PM Marek Vasut <marex@denx.de> wrote:
>
> The 'sspi' command hard-coded 1 MHz bus frequency for all transmissions.
> Allow changing that at runtime by specifying '@freq' bus frequency in Hz.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Tom Rini <trini@konsulko.com>
> ---
Applied to u-boot-spi/master
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-26 13:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-20 11:44 [PATCH] cmd: spi: Permit setting bus frequency Marek Vasut
2019-12-20 11:48 ` Lukasz Majewski
2020-01-26 13:26 ` Jagan Teki
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.