Skip to contentSkip to conversation

sandbox: add gpio support with libftdi1

RFC In review Antony Pavlov 3 participants 7 messages Feb 15, 2017 – Feb 16, 2017 GPIO

lore
Share & tools
lore
#0 lore raw

cover sandbox: add gpio support with libftdi1

This patch series makes it possible to use FT2232H ACBUS[7:0] pins as gpio pins from sandbox barebox.

I have tested output gpio functionality by connecting a LED to ACBUS[0] and lightening it with gpio_direction_output and gpio_set_value barebox commands.

Also I have performed input test with ACBUS[0] -> ACBUS[1] loopback.

The main goal of adding gpio functionality to sandbox barebox is using it for connecting real i2c and spi devices to sandbox barebox (not tested yet).

Antony Pavlov (2):
sandbox: avoid symbol conflict for {open,read,close}dir
sandbox: add gpio support with libftdi1

 arch/sandbox/Kconfig                           |   1 +
 arch/sandbox/Makefile                          |  10 +-
 arch/sandbox/board/board.c                     |   7 ++
 arch/sandbox/mach-sandbox/include/mach/linux.h |  11 ++
 arch/sandbox/os/Makefile                       |   3 +
 arch/sandbox/os/ftdi.c                         | 167 +++++++++++++++++++++++++
 drivers/gpio/Kconfig                           |   4 +
 drivers/gpio/Makefile                          |   1 +
 drivers/gpio/gpio-libftdi1.c                   | 116 +++++++++++++++++
 9 files changed, 318 insertions(+), 2 deletions(-)
 create mode 100644 arch/sandbox/os/ftdi.c
 create mode 100644 drivers/gpio/gpio-libftdi1.c
Signature · 7 lines
2.11.0


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

RFC 1/2 sandbox: avoid symbol conflict for {open,read,close}dir

This fixes libusb's /dev/bus/usb directory scan.

---
 arch/sandbox/Makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/sandbox/Makefile +3 -1
index 8155a790e..9d545c3b7 100644
@@ -21,7 +21,9 @@ CFLAGS += -Dmalloc=barebox_malloc -Dcalloc=barebox_calloc \
 		-Dfputs=barebox_fputs -Dsetenv=barebox_setenv \
 		-Dgetenv=barebox_getenv -Dprintf=barebox_printf \
 		-Dglob=barebox_glob -Dglobfree=barebox_globfree \
-		-Dioctl=barebox_ioctl -Dfstat=barebox_fstat
+		-Dioctl=barebox_ioctl -Dfstat=barebox_fstat \
+		-Dopendir=barebox_opendir -Dreaddir=barebox_readdir \
+		-Dclosedir=barebox_closedir
 
 machdirs := $(patsubst %,arch/sandbox/mach-%/,$(machine-y))
 
Signature · 7 lines
2.11.0


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

RFC 2/2 sandbox: add gpio support with libftdi1

In reply to Antony Pavlov
---
 arch/sandbox/Kconfig                           |   1 +
 arch/sandbox/Makefile                          |   6 +-
 arch/sandbox/board/board.c                     |   7 ++
 arch/sandbox/mach-sandbox/include/mach/linux.h |  11 ++
 arch/sandbox/os/Makefile                       |   3 +
 arch/sandbox/os/ftdi.c                         | 167 +++++++++++++++++++++++++
 drivers/gpio/Kconfig                           |   4 +
 drivers/gpio/Makefile                          |   1 +
 drivers/gpio/gpio-libftdi1.c                   | 116 +++++++++++++++++
 9 files changed, 315 insertions(+), 1 deletion(-)
arch/sandbox/Kconfig +1 -0
index 9c72673bd..3f1cefb83 100644
@@ -1,6 +1,7 @@
 config SANDBOX
 	bool
 	select OFTREE
+	select GPIOLIB
 	default y
 
 config ARCH_TEXT_BASE
arch/sandbox/Makefile +5 -1
index 9d545c3b7..85c70b5e8 100644
@@ -41,9 +41,13 @@ ifeq ($(CONFIG_DRIVER_VIDEO_SDL),y)
 SDL_LIBS := $(shell pkg-config sdl --libs)
 endif
 
+ifeq ($(CONFIG_GPIO_LIBFTDI1),y)
+FTDI1_LIBS := $(shell pkg-config libftdi1 --libs)
+endif
+
 cmd_barebox__ = $(CC) -o $@ -Wl,-T,$(barebox-lds) \
 	-Wl,--start-group $(barebox-common) -Wl,--end-group \
-	-lrt -lpthread $(SDL_LIBS)
+	-lrt -lpthread $(SDL_LIBS) $(FTDI1_LIBS)
 
 common-y += $(BOARD) arch/sandbox/os/
 
arch/sandbox/board/board.c +7 -0
index dcad3c249..5ab47e21c 100644
@@ -42,6 +42,11 @@ static struct device_d sdl_device = {
 	.platform_data = &mode,
 };
 
+static struct device_d libftdi1_device = {
+	.id	  = DEVICE_ID_DYNAMIC,
+	.name     = "libftdi1-gpio",
+};
+
 static int devices_init(void)
 {
 	platform_device_register(&tap_device);
@@ -54,6 +59,8 @@ static int devices_init(void)
 
 	platform_device_register(&sdl_device);
 
+	platform_device_register(&libftdi1_device);
+
 	return 0;
 }
 
arch/sandbox/mach-sandbox/include/mach/linux.h +11 -0
index 1f11ed449..e52180ae4 100644
@@ -38,4 +38,15 @@ void sdl_get_bitfield_rgba(struct fb_bitfield *r, struct fb_bitfield *g,
 			    struct fb_bitfield *b, struct fb_bitfield *a);
 void sdl_setpixel(int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
 
+struct ft2232_bitbang;
+struct ft2232_bitbang *barebox_libftdi1_open(void);
+void barebox_libftdi1_gpio_direction(struct ft2232_bitbang *ftbb,
+						unsigned off, unsigned dir);
+int barebox_libftdi1_gpio_get_value(struct ft2232_bitbang *ftbb,
+						unsigned off);
+void barebox_libftdi1_gpio_set_value(struct ft2232_bitbang *ftbb,
+						unsigned off, unsigned val);
+int barebox_libftdi1_update(struct ft2232_bitbang *ftbb);
+void barebox_libftdi1_close(void);
+
 #endif /* __ASM_ARCH_LINUX_H */
arch/sandbox/os/Makefile +3 -0
index 537f848e0..75baa34a8 100644
@@ -17,3 +17,6 @@ obj-y = common.o tap.o
 
 CFLAGS_sdl.o = $(shell pkg-config sdl --cflags)
 obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o
+
+CFLAGS_ftdi.o = $(shell pkg-config libftdi1 --cflags)
+obj-$(CONFIG_GPIO_LIBFTDI1) += ftdi.o
arch/sandbox/os/ftdi.c new file +167 -0

167 lines not on this page · raw message

drivers/gpio/Kconfig +4 -0
index 434c5688b..ed93e868a 100644
@@ -132,6 +132,10 @@ config GPIO_SX150X
 	  Say Y here to build support for the Semtec Sx150x I2C GPIO
 	  expander chip.
 
+config GPIO_LIBFTDI1
+	bool "libftdi1 driver"
+	depends on SANDBOX
+
 endmenu
 
 endif
drivers/gpio/Makefile +1 -0
index f37dd08f1..f5ed876d5 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_GPIO_CLPS711X)	+= gpio-clps711x.o
 obj-$(CONFIG_GPIO_DIGIC)	+= gpio-digic.o
 obj-$(CONFIG_GPIO_GENERIC)	+= gpio-generic.o
 obj-$(CONFIG_GPIO_IMX)		+= gpio-imx.o
+obj-$(CONFIG_GPIO_LIBFTDI1)	+= gpio-libftdi1.o
 obj-$(CONFIG_GPIO_MXS)		+= gpio-mxs.o
 obj-$(CONFIG_GPIO_JZ4740)	+= gpio-jz4740.o
 obj-$(CONFIG_GPIO_MALTA_FPGA_I2C) += gpio-malta-fpga-i2c.o
drivers/gpio/gpio-libftdi1.c new file +116 -0

116 lines not on this page · raw message

Signature · 7 lines
2.11.0


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

Hi Antony,

Quoted 7 lines · Antony Pavlov

This patch series makes it possible to use FT2232H ACBUS[7:0] pins as gpio pins from sandbox barebox.

I have tested output gpio functionality by connecting a LED to ACBUS[0] and lightening it with gpio_direction_output and gpio_set_value barebox commands.

Quoted 5 lines

Also I have performed input test with ACBUS[0] -> ACBUS[1] loopback.

The main goal of adding gpio functionality to sandbox barebox is using it for connecting real i2c and spi devices to sandbox barebox (not tested yet).

I just read that the FT2232H can even do native I2C and SPI, so no gpio bitbanging would be necessary. Would it be possible to use this mode instead?

Otherwise I think there should be a possibility to specify which, if any, FT2232H chip barebox uses.

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
#4 lore raw
Quoted 10 lines · On Thu, 16 Feb 2017 08:34:30 +0100 Sascha Hauer <[email protected]> wrote:

Hi Antony,

Quoted 7 lines · Antony Pavlov

This patch series makes it possible to use FT2232H ACBUS[7:0] pins as gpio pins from sandbox barebox.

I have tested output gpio functionality by connecting a LED to ACBUS[0] and lightening it with gpio_direction_output and gpio_set_value barebox commands.

Quoted 8 lines
Quoted 5 lines

Also I have performed input test with ACBUS[0] -> ACBUS[1] loopback.

The main goal of adding gpio functionality to sandbox barebox is using it for connecting real i2c and spi devices to sandbox barebox (not tested yet).

I just read that the FT2232H can even do native I2C and SPI, so no gpio bitbanging would be necessary.

I suppose that gpio support itself is valuable.

Quoted 1 line

Would it be possible to use this mode instead?

Yes, FT2232H has MPSSE acellerator.
Using MPSSE one can increase FT2232 I2C/SPI performance dramatically.
I have compared two FT2232 I2C realizations (bitbang and libmpsse,
see https://github.com/frantony/mprog/tree/master/i2c_access).
on reading of 8 KiB data block from I2C eeprom. libmpsse's bandwidth is 6 KiB per second, bitbang's bandwidth is only 73 bytes per second (nearly 100 times worse).

Alas, I have no time to realize ftdi fast i2c/spi support for barebox in the nearest future

Quoted 2 lines

Otherwise I think there should be a possibility to specify which, if any, FT2232H chip barebox uses.

I'll add cmdline options to select FT2232H chips on USB bus in v2 patchseries. Also I'll check i2c bitbang support. I can connect ds1307 rtc or at24 eeprom).

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw
Quoted 26 lines · Antony Pavlov
Quoted 10 lines · On Thu, 16 Feb 2017 08:34:30 +0100 Sascha Hauer <[email protected]> wrote:

Hi Antony,

Quoted 7 lines · Antony Pavlov

This patch series makes it possible to use FT2232H ACBUS[7:0] pins as gpio pins from sandbox barebox.

I have tested output gpio functionality by connecting a LED to ACBUS[0] and lightening it with gpio_direction_output and gpio_set_value barebox commands.

Quoted 8 lines
Quoted 5 lines

Also I have performed input test with ACBUS[0] -> ACBUS[1] loopback.

The main goal of adding gpio functionality to sandbox barebox is using it for connecting real i2c and spi devices to sandbox barebox (not tested yet).

I just read that the FT2232H can even do native I2C and SPI, so no gpio bitbanging would be necessary.

I suppose that gpio support itself is valuable.

Quoted 1 line

Would it be possible to use this mode instead?

Quoted 8 lines

Yes, FT2232H has MPSSE acellerator.
Using MPSSE one can increase FT2232 I2C/SPI performance dramatically.
I have compared two FT2232 I2C realizations (bitbang and libmpsse,
see https://github.com/frantony/mprog/tree/master/i2c_access).
on reading of 8 KiB data block from I2C eeprom. libmpsse's bandwidth is 6 KiB per second, bitbang's bandwidth is only 73 bytes per second (nearly 100 times worse).

Alas, I have no time to realize ftdi fast i2c/spi support for barebox in the nearest future

Don't worry, I was only curious.

Quoted 6 lines
Quoted 3 lines

Otherwise I think there should be a possibility to specify which, if any, FT2232H chip barebox uses.

I'll add cmdline options to select FT2232H chips on USB bus in v2 patchseries. Also I'll check i2c bitbang support. I can connect ds1307 rtc or at24 eeprom).

Ok.

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
#6 lore raw
In reply to Sascha Hauer
Quoted 16 lines · Sascha Hauer

Hi Antony,

Quoted 7 lines · Antony Pavlov

This patch series makes it possible to use FT2232H ACBUS[7:0] pins as gpio pins from sandbox barebox.

I have tested output gpio functionality by connecting a LED to ACBUS[0] and lightening it with gpio_direction_output and gpio_set_value barebox commands.

Quoted 5 lines

Also I have performed input test with ACBUS[0] -> ACBUS[1] loopback.

The main goal of adding gpio functionality to sandbox barebox is using it for connecting real i2c and spi devices to sandbox barebox (not tested yet).

Quoted 6 lines

I just read that the FT2232H can even do native I2C and SPI, so no gpio bitbanging would be necessary. Would it be possible to use this mode instead?

Otherwise I think there should be a possibility to specify which, if any, FT2232H chip barebox uses.

The MPSSE mode of the FT2232H can sort of do native I2C, but not in a strictly conforming way. The I2C SDA needs to be connected to two pins on the FT2232H, one for output and one for input, and there is a "Drive-Only-Zero" option for the output to ensure it is only driven low, and tri-stated high. However, the I2C SCL is only connected to an output pin on the FT2232H, and is always driven in both directions. Therefore, it does not support "clock-stretching" by I2C slaves (where a slave pulls the SCL line low until it is ready), because it cannot read back the state of the SCL line. Worse, if an I2C slave is doing clock-stretching by driving SCL low, this will contend with the FT2232H driving SCL high at the same time.

Signature · 7 lines
-=( Ian Abbott @ MEV Ltd.    E-mail: <[email protected]> )=-
-=(                          Web: http://www.mev.co.uk/  )=-

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