Skip to contentSkip to conversation

add spi command

PATCH Superseded Jean-Christophe PLAGNIOL-VILLARD 3 participants 8 messages Nov 2, 2012 – Nov 3, 2012 SPI

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover add spi command

HI,

while debugging a spi issue I found we have a i2c commands but no spi command

So introduce one

The following changes since commit 56371f4e8446d04d2a5608dd5890fd87a50f888e:

iomux-imx35: add missing comma in pad definition (2012-11-01 16:32:12 +0100)

are available in the git repository at:

git://git.jcrosoft.org/barebox.git delivery/command_spi

for you to fetch changes up to 3d6660a40aa5a51215a1909fd2fb5702f0e6558b:

introduce spi command (2012-11-02 08:55:11 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (2):
spi: introduce spi_get_master
introduce spi command

 commands/Kconfig  |    6 ++++++
 commands/Makefile |    1 +
 commands/spi.c    |  126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/spi/spi.c |   12 ++++++++++++
 include/spi/spi.h |    2 ++
 5 files changed, 147 insertions(+)
 create mode 100644 commands/spi.c

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH 1/2 spi: introduce spi_get_master

so we can request a master usefull for the spi command

---
 drivers/spi/spi.c |   12 ++++++++++++
 include/spi/spi.h |    2 ++
 2 files changed, 14 insertions(+)
drivers/spi/spi.c +12 -0
index 44040e5..6a5bd6d 100644
@@ -219,6 +219,18 @@ int spi_register_master(struct spi_master *master)
 }
 EXPORT_SYMBOL(spi_register_master);
 
+struct spi_master *spi_get_master(int bus)
+{
+	struct spi_master* m;
+
+	list_for_each_entry(m, &spi_master_list, list) {
+		if (m->bus_num == bus)
+			return m;
+	}
+
+	return NULL;
+}
+
 int spi_sync(struct spi_device *spi, struct spi_message *message)
 {
 	return spi->master->transfer(spi, message);
include/spi/spi.h +2 -0
index 1773ca2..d6570a4 100644
@@ -432,6 +432,8 @@ static inline ssize_t spi_w8r8(struct spi_device *spi, u8 cmd)
 
 extern struct bus_type spi_bus;
 
+struct spi_master *spi_get_master(int bus);
+
 static inline int spi_register_driver(struct driver_d *drv)
 {
 	drv->bus = &spi_bus;
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/2 introduce spi command

usefull to debug spi

The command allow to read/write on a spi device

Usage: spi [OPTION] [data to write 0xXX]
write/read spi device.

  -b <bus_num>  spi bus number (default = 0)
  -r <count>    to read
  -c <cs>       chip select (default = 0)
  -m <mode>     spi mode (default = 0)
  -f <hz>       max_speed_hz (default = 1MHz)
  -w <bit>      bits_per_word (default = 8)
  -v            verbose
---
 commands/Kconfig  |    6 +++
 commands/Makefile |    1 +
 commands/spi.c    |  126 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 commands/spi.c
commands/Kconfig +6 -0
index 16706d3..f7cbd67 100644
@@ -597,6 +597,12 @@ config CMD_I2C
 	  include i2c_probe, i2c_read and i2c_write commands to communicate
 	  on i2c bus.
 
+config CMD_SPI
+	bool
+	depends on SPI
+	prompt "spi command"
+	help
+
 config CMD_LED
 	bool
 	depends on LED
commands/Makefile +1 -0
index 610be55..19d496e 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_USB_GADGET_SERIAL)	+= usbserial.o
 obj-$(CONFIG_CMD_GPIO)		+= gpio.o
 obj-$(CONFIG_CMD_UNCOMPRESS)	+= uncompress.o
 obj-$(CONFIG_CMD_I2C)		+= i2c.o
+obj-$(CONFIG_CMD_SPI)		+= spi.o
 obj-$(CONFIG_CMD_UBI)		+= ubi.o
 obj-$(CONFIG_CMD_MENU)		+= menu.o
 obj-$(CONFIG_CMD_PASSWD)	+= passwd.o
commands/spi.c new file +126 -0

126 lines not on this page · raw message

Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Re: [PATCH 2/2] introduce spi command

Fri, 2 Nov 2012 17:17:40 +0100 от Jean-Christophe PLAGNIOL-VILLARD <[email protected]>:

Quoted 13 lines

usefull to debug spi

The command allow to read/write on a spi device

Usage: spi [OPTION] [data to write 0xXX]
write/read spi device.

  -b <bus_num>  spi bus number (default = 0)
  -r <count>    to read
  -c <cs>       chip select (default = 0)
  -m <mode>     spi mode (default = 0)
  -f <hz>       max_speed_hz (default = 1MHz)
  -w <bit>      bits_per_word (default = 8)
  -v            verbose

...

Quoted 4 lines
commands/spi.c new file +4 -0
+static int do_spi(int argc, char *argv[])
+{
+	struct spi_device spi;
+	int bus = 0;

commands/spi.c line 28

Quoted 10 lines
commands/spi.c new file +10 -0
+	int read = 0;
+	int verbose = 0;
+	int opt, count, i, ret;
+
+	u8 *tx_buf, *rx_buf;
+
+	memset(&spi, 0, sizeof(struct spi_device));
+
+	spi.max_speed_hz = 1 * 1000 * 1000;
+	spi.bits_per_word = 8;

I suggest using the default data from master for these parameters.

---
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw

Re: [PATCH 2/2] introduce spi command

Quoted 15 lines · Alexander Shiyan

Fri, 2 Nov 2012 17:17:40 +0100 от Jean-Christophe PLAGNIOL-VILLARD <[email protected]>:

Quoted 13 lines

usefull to debug spi

The command allow to read/write on a spi device

Usage: spi [OPTION] [data to write 0xXX]
write/read spi device.

  -b <bus_num>  spi bus number (default = 0)
  -r <count>    to read
  -c <cs>       chip select (default = 0)
  -m <mode>     spi mode (default = 0)
  -f <hz>       max_speed_hz (default = 1MHz)
  -w <bit>      bits_per_word (default = 8)
  -v            verbose

...

Quoted 16 lines
Quoted 4 lines
commands/spi.c new file +4 -0
+static int do_spi(int argc, char *argv[])
+{
+	struct spi_device spi;
+	int bus = 0;

commands/spi.c line 28

Quoted 10 lines
commands/spi.c new file +10 -0
+	int read = 0;
+	int verbose = 0;
+	int opt, count, i, ret;
+
+	u8 *tx_buf, *rx_buf;
+
+	memset(&spi, 0, sizeof(struct spi_device));
+
+	spi.max_speed_hz = 1 * 1000 * 1000;
+	spi.bits_per_word = 8;

I suggest using the default data from master for these parameters.

no otherwise we can not write the help and bits_et_word it's default value at spi framework level is 8

and thh max_speed_hz is slow already

and it has always been the device to control it no the master

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#6 lore raw
In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 9 lines · Jean-Christophe PLAGNIOL-VILLARD

HI,

while debugging a spi issue I found we have a i2c commands but no spi command

So introduce one

The following changes since commit 56371f4e8446d04d2a5608dd5890fd87a50f888e:

Quoted 8 lines

iomux-imx35: add missing comma in pad definition (2012-11-01 16:32:12 +0100)

are available in the git repository at:

git://git.jcrosoft.org/barebox.git delivery/command_spi

for you to fetch changes up to 3d6660a40aa5a51215a1909fd2fb5702f0e6558b:

I recently used the i2c_* commands and thought it would be a good idea to introduce regmap for barebox. This way we could add a regmap command which just maps arbitrary i2c/spi devices as a cdev. Also we could replace several drivers in drivers/mfd/ with nearly one-liners.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw
Quoted 16 lines · Sascha Hauer
Quoted 15 lines · Jean-Christophe PLAGNIOL-VILLARD

HI,

while debugging a spi issue I found we have a i2c commands but no spi command

So introduce one

The following changes since commit 56371f4e8446d04d2a5608dd5890fd87a50f888e:

iomux-imx35: add missing comma in pad definition (2012-11-01 16:32:12 +0100)

are available in the git repository at:

git://git.jcrosoft.org/barebox.git delivery/command_spi

Quoted 7 lines
Quoted 2 lines

for you to fetch changes up to 3d6660a40aa5a51215a1909fd2fb5702f0e6558b:

I recently used the i2c_* commands and thought it would be a good idea to introduce regmap for barebox. This way we could add a regmap command which just maps arbitrary i2c/spi devices as a cdev. Also we could replace several drivers in drivers/mfd/ with nearly one-liners.

why not but how to pass all the parameter to this cdev

on SPI we need some on i2c it's more simple

If this will be for the next release ok otherwise can we have this command until then

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#5 lore raw

Re: [PATCH 2/2] introduce spi command

In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 99 lines · Jean-Christophe PLAGNIOL-VILLARD

usefull to debug spi

The command allow to read/write on a spi device

Usage: spi [OPTION] [data to write 0xXX]
write/read spi device.

  -b <bus_num>  spi bus number (default = 0)
  -r <count>    to read
  -c <cs>       chip select (default = 0)
  -m <mode>     spi mode (default = 0)
  -f <hz>       max_speed_hz (default = 1MHz)
  -w <bit>      bits_per_word (default = 8)
  -v            verbose
---
 commands/Kconfig  |    6 +++
 commands/Makefile |    1 +
 commands/spi.c    |  126 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 commands/spi.c
commands/Kconfig +6 -0
index 16706d3..f7cbd67 100644
@@ -597,6 +597,12 @@ config CMD_I2C
 	  include i2c_probe, i2c_read and i2c_write commands to communicate
 	  on i2c bus.
 
+config CMD_SPI
+	bool
+	depends on SPI
+	prompt "spi command"
+	help
+
 config CMD_LED
 	bool
 	depends on LED
commands/Makefile +1 -0
index 610be55..19d496e 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_USB_GADGET_SERIAL)	+= usbserial.o
 obj-$(CONFIG_CMD_GPIO)		+= gpio.o
 obj-$(CONFIG_CMD_UNCOMPRESS)	+= uncompress.o
 obj-$(CONFIG_CMD_I2C)		+= i2c.o
+obj-$(CONFIG_CMD_SPI)		+= spi.o
 obj-$(CONFIG_CMD_UBI)		+= ubi.o
 obj-$(CONFIG_CMD_MENU)		+= menu.o
 obj-$(CONFIG_CMD_PASSWD)	+= passwd.o
commands/spi.c new file +42 -0
new file mode 100644
index 0000000..599637c
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
+ *
+ * Under GPLv2 only
+ *
+ */
+
+#include <common.h>
+#include <command.h>
+#include <errno.h>
+#include <malloc.h>
+#include <getopt.h>
+#include <spi/spi.h>
+
+static int do_spi(int argc, char *argv[])
+{
+	struct spi_device spi;
+	int bus = 0;
+	int read = 0;
+	int verbose = 0;
+	int opt, count, i, ret;
+
+	u8 *tx_buf, *rx_buf;
+
+	memset(&spi, 0, sizeof(struct spi_device));
+
+	spi.max_speed_hz = 1 * 1000 * 1000;
+	spi.bits_per_word = 8;
+
+	while ((opt = getopt(argc, argv, "b:c:r:m:f:w:v")) > 0) {
+		switch (opt) {
+		case 'b':
+			bus = simple_strtol(optarg, NULL, 0);
+			break;
+		case 'r':
+			read = simple_strtol(optarg, NULL, 0);
+			break;
+		case 'c':
+			spi.chip_select = simple_strtoul(optarg, NULL, 0);
+			break;
+		case 'm':
+			spi.mode = simple_strtoul(optarg, NULL, 0);

commands/spi.c line 52

Quoted 10 lines
commands/spi.c new file +10 -0
+			break;
+		case 'f':
+			spi.max_speed_hz = simple_strtoul(optarg, NULL, 0);
+			break;
+		case 'w':
+			spi.bits_per_word = simple_strtoul(optarg, NULL, 0);
+			break;
+		case 'v':
+			verbose = 1;
+			break;
		default:
			return COMMAND_ERROR_USAGE;

I still didn't find the time to fix the other commands, but for new ones we should get used to it.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox