Skip to contentSkip to conversation

Add support for ARRI FPGA configuration

PATCH Superseded Anatolij Gustschin 3 participants 9 messages Nov 20, 2018 – Nov 28, 2018

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for ARRI FPGA configuration

This series adds drivers and FPGA manager support required for FT232H based ARRI FPGA configuration adapters.

Patch 1/3 adds FT232H interface driver (for ARRI USB PIDs) implementing commonly used FTDI USB transfer operations and ACBUS/MPSSE GPIO controllers. Depending on USB PIDs it creates platform devices for MPSSE SPI bus with attached SPI slaves or platform devices for ARRI FPP FPGA manager.

Patch 2/3 adds MPSSE SPI controller driver which registers an FTDI USB-SPI bus with attached SPI slaves from description in platform data, so existing SPI protocol drivers can be used for these slave devices (in our case altera-ps-spi). Via interface driver in patch 1/3 it is easily possible to add support for other slave devices using custom USB PIDs (e.g. spi-nor flash W25Q32 with m25p80 driver has beed used for testing MPSSE SPI controller driver).

Patch 3/3 adds FPGA manager driver for ARRI FPP adapters for FPGA configuration via Altera fast passive parallel interface.

Changes since v1:
Patch 1/3
- add myself as a maintainer for these drivers
- update copyright line to include 2018
- include required linux headers
- fix gcc 7.3.0 build warnings -Wunused-const-variable=
- make ftdi functions and spi_board_info struct static
- use KBUILD_MODNAME in drivers struct
- use dev_err() for error messages instead of dev_info()
- drop not needed output about number of used MPSSE pins since it is constant (not configurable)
- remove ftdi function prototypes from header ft232h-intf.h as these are not exported anymore
- update comments (don't use kernel-doc format as we do not export symbols anymore and functions are "static")

Patch 2/3
- fix build breakage when building with ARCH=i386 allmodconfig
- add checks for ops->lock/ops->unlock presence in pdata
- update copyright line to include 2018
- remove printing numbers in parentheses (%d)

Patch 3/3
- update copyright line to include 2018
- add sysfs ABI documentation

Changes since initial version (MFD based):
- don't use MFD framework
- don't use original FT232H USB PID (it is too generic and collides with existing ftdi_sio driver)
- don't add separate CBUS GPIO driver based on FT232H MFD device
- redesign/rework the drivers as described under [4]
- add basic FT232H interface driver under drivers/usb/misc/
- use custom reserved USB PIDs in the USB driver for adapter devices
- add notes about borrowed protocol code from libftdi to commit log and header file
- add MPSSE SPI controller driver supporting USB-SPI bus with dynamically added SPI slaves from description in platform data (the initial attempt didn't include USB SPI bus support for PS- SPI FPGA configuration via USB)
- rework FPP fpga manager driver based on new FT232H interface driver and extend it according to CPLD changes for additional support of new hardware revision B.

Anatolij Gustschin (3):
usb: misc: add driver for FT232H based FPGA configuration devices
spi: add FTDI MPSSE SPI controller driver
fpga: Add fpga manager driver for ARRI Altera FPP

 .../ABI/testing/sysfs-driver-ftdi-fifo-fpp    |    7 +
 MAINTAINERS                                   |    8 +
 drivers/fpga/Kconfig                          |    7 +
 drivers/fpga/Makefile                         |    1 +
 drivers/fpga/ftdi-fifo-fpp.c                  |  594 +++++++
 drivers/spi/Kconfig                           |    7 +
 drivers/spi/Makefile                          |    1 +
 drivers/spi/spi-ftdi-mpsse.c                  |  673 ++++++++
 drivers/usb/misc/Kconfig                      |    9 +
 drivers/usb/misc/Makefile                     |    1 +
 drivers/usb/misc/ft232h-intf.c                | 1464 +++++++++++++++++
 include/linux/usb/ft232h-intf.h               |  187 +++
 12 files changed, 2959 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-ftdi-fifo-fpp
 create mode 100644 drivers/fpga/ftdi-fifo-fpp.c
 create mode 100644 drivers/spi/spi-ftdi-mpsse.c
 create mode 100644 drivers/usb/misc/ft232h-intf.c
 create mode 100644 include/linux/usb/ft232h-intf.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/3 usb: misc: add driver for FT232H based FPGA configuration devices

Add USB interface driver for ARRI FPGA configuration devices based on FTDI FT232H chip. Depending on USB PID the driver registers different platform devices describing an FPGA configuration interface.

One FPGA configuration interface type is the usual SPI bus with additional control and status GPIOs. For this interface type the FTDI MPSSE mode is utilized to support SPI bus and GPIO-L/H pins for SPI bus chipselect and SPI slave device I/O. Subsequent patch adds an MPSSE SPI controller driver for USB-SPI bus support. The actual FPGA configuration driver for SPI bus is already available in the FPGA manager framework (altera-ps-spi module).

Another FPGA configuration interface type is the FT245 FIFO (connected via CPLD) with additional control and status GPIOs on FT232H ACBUS. This interface is used to configure FPGAs using Altera fast passive parallel (FPP) interface. Subsequent patch will add an FPP FPGA manager driver for it.

The FTDI protocol code and prototypes was borrowed from libftdi.

---
 MAINTAINERS                     |    8 +
 drivers/usb/misc/Kconfig        |    9 +
 drivers/usb/misc/Makefile       |    1 +
 drivers/usb/misc/ft232h-intf.c  | 1464 +++++++++++++++++++++++++++++++
 include/linux/usb/ft232h-intf.h |  187 ++++
 5 files changed, 1669 insertions(+)
 create mode 100644 drivers/usb/misc/ft232h-intf.c
 create mode 100644 include/linux/usb/ft232h-intf.h
MAINTAINERS +8 -0
index b755a89fa325..aaafa11f860f 100644
@@ -15388,6 +15388,14 @@ S:	Maintained
 F:	Documentation/usb/acm.txt
 F:	drivers/usb/class/cdc-acm.*
 
+USB ARRI FPGA CONFIGURATION ADAPTER DRIVER
+M:	Anatolij Gustschin <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/usb/misc/ft232h-intf.c
+F:	drivers/spi/spi-ftdi-mpsse.c
+F:	include/linux/usb/ft232h-intf.h
+
 USB AR5523 WIRELESS DRIVER
 M:	Pontus Fuchs <[email protected]>
 L:	[email protected]
drivers/usb/misc/Kconfig +9 -0
index 68d2f2cd17dd..41304ac7f0e3 100644
@@ -275,3 +275,12 @@ config USB_CHAOSKEY
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called chaoskey.
+
+config USB_FT232H_INTF
+	tristate "FTDI FT232H FPGA configuration interface driver"
+	help
+	  Enable driver support for the FT232H based USB-GPIO/SPI/FIFO
+	  interface adapter for FPGA configuration. Additional drivers
+	  such as spi-ftdi-mpsse, altera-ps-spi, ftdi-fifo-fpp and
+	  fpga-mgr must be enabled in order to use the functionality of
+	  the device.
drivers/usb/misc/Makefile +1 -0
index 109f54f5b9aa..3618d8c7bfdd 100644
@@ -31,3 +31,4 @@ obj-$(CONFIG_USB_CHAOSKEY)		+= chaoskey.o
 
 obj-$(CONFIG_USB_SISUSBVGA)		+= sisusbvga/
 obj-$(CONFIG_USB_LINK_LAYER_TEST)	+= lvstest.o
+obj-$(CONFIG_USB_FT232H_INTF)		+= ft232h-intf.o
drivers/usb/misc/ft232h-intf.c new file +1464 -0

1,464 lines not on this page · raw message

include/linux/usb/ft232h-intf.h new file +187 -0

187 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v2 1/3] usb: misc: add driver for FT232H based FPGA configuration devices

Quoted 3 lines · Anatolij Gustschin

Add USB interface driver for ARRI FPGA configuration devices based on FTDI FT232H chip. Depending on USB PID the driver registers different platform devices describing an FPGA configuration interface.

Is ARRI different than Arria?

drivers/usb/misc/ft232h-intf.c line 169

Quoted 2 lines
drivers/usb/misc/ft232h-intf.c new file +2 -0
+/* Use baudrate calculation borrowed from libftdi */
+static int ftdi_to_clkbits(int baudrate, unsigned int clk, int clk_div,

Linux uses unsigned values for clocks. Does it make any sense to mix the unsigned clk with signed values? Seems like baudrate and clk_div should also be unsigned.

drivers/usb/misc/ft232h-intf.c line 170

Quoted 1 line
drivers/usb/misc/ft232h-intf.c new file +1 -0
+			   unsigned long *encoded_divisor)

unsigned long is an odd choice here. Is there any to reason to use an unsigned long to store the result of right shifting a signed int (best_div)? It can't be longer than a int, but it can be negative.

Quoted 15 lines
drivers/usb/misc/ft232h-intf.c new file +15 -0
+{
+	static const char frac_code[8] = { 0, 3, 2, 4, 1, 5, 6, 7 };
+	int best_baud = 0;
+	int div, best_div;
+
+	if (baudrate >= clk / clk_div) {
+		*encoded_divisor = 0;
+		best_baud = clk / clk_div;
+	} else if (baudrate >= clk / (clk_div + clk_div / 2)) {
+		*encoded_divisor = 1;
+		best_baud = clk / (clk_div + clk_div / 2);
+	} else if (baudrate >= clk / (2 * clk_div)) {
+		*encoded_divisor = 2;
+		best_baud = clk / (2 * clk_div);
+	} else {

drivers/usb/misc/ft232h-intf.c line 194

Quoted 10 lines
drivers/usb/misc/ft232h-intf.c new file +9 -0
+		/*
+		 * Divide by 16 to have 3 fractional bits and
+		 * one bit for rounding
+		 */
+		div = clk * 16 / clk_div / baudrate;
 
+		if (div & 1)	/* Decide if to round up or down */
+			best_div = div / 2 + 1;
+		else
+			best_div = div / 2;

In Linux we would write:

best_div = DIV_ROUND_UP(div, 2);

Though I think you can combine that with the above to get:

best_div = DIV_ROUND_CLOSEST(clk * 8 / clk_div, baudrate);

That what the above is trying to accomplish in a round about way

drivers/usb/misc/ft232h-intf.c line 196

Quoted 2 lines
drivers/usb/misc/ft232h-intf.c new file +2 -0
+		if (best_div > 0x20000)
+			best_div = 0x1ffff;

Looks like the above was probably supposed to be >=

drivers/usb/misc/ft232h-intf.c line 201

Quoted 5 lines
drivers/usb/misc/ft232h-intf.c new file +5 -0
+		best_baud = clk * 16 / clk_div / best_div;
+		if (best_baud & 1)	/* Decide if to round up or down */
+			best_baud = best_baud / 2 + 1;
+		else
+			best_baud = best_baud / 2;

Again, looks like a complicated way to round to the nearest.

Quoted 5 lines
drivers/usb/misc/ft232h-intf.c new file +4 -0
+		*encoded_divisor = (best_div >> 3) |
+				   (frac_code[best_div & 0x7] << 14);
+	}
+	return best_baud;
#3 lore raw

Re: [PATCH v2 1/3] usb: misc: add driver for FT232H based FPGA configuration devices

Quoted 6 lines · On Tue, 20 Nov 2018 00:56:13 +0000 Trent Piepho [email protected] wrote:
Quoted 3 lines · Anatolij Gustschin

Add USB interface driver for ARRI FPGA configuration devices based on FTDI FT232H chip. Depending on USB PID the driver registers different platform devices describing an FPGA configuration interface.

Is ARRI different than Arria?

yes, ARRI is a company name.

Quoted 6 lines

drivers/usb/misc/ft232h-intf.c line 169

Quoted 2 lines
drivers/usb/misc/ft232h-intf.c new file +2 -0
+/* Use baudrate calculation borrowed from libftdi */
+static int ftdi_to_clkbits(int baudrate, unsigned int clk, int clk_div,  

Linux uses unsigned values for clocks. Does it make any sense to mix the unsigned clk with signed values? Seems like baudrate and clk_div should also be unsigned.

okay, will fix to unsigned.

Quoted 5 lines

drivers/usb/misc/ft232h-intf.c line 170

Quoted 1 line
drivers/usb/misc/ft232h-intf.c new file +1 -0
+			   unsigned long *encoded_divisor)  

unsigned long is an odd choice here. Is there any to reason to use an unsigned long to store the result of right shifting a signed int (best_div)? It can't be longer than a int, but it can be negative.

okay, I'll change that to unsigned int.

Quoted 28 lines
Quoted 15 lines
drivers/usb/misc/ft232h-intf.c new file +15 -0
+{
+	static const char frac_code[8] = { 0, 3, 2, 4, 1, 5, 6, 7 };
+	int best_baud = 0;
+	int div, best_div;
+
+	if (baudrate >= clk / clk_div) {
+		*encoded_divisor = 0;
+		best_baud = clk / clk_div;
+	} else if (baudrate >= clk / (clk_div + clk_div / 2)) {
+		*encoded_divisor = 1;
+		best_baud = clk / (clk_div + clk_div / 2);
+	} else if (baudrate >= clk / (2 * clk_div)) {
+		*encoded_divisor = 2;
+		best_baud = clk / (2 * clk_div);
+	} else {

drivers/usb/misc/ft232h-intf.c line 194

Quoted 10 lines
drivers/usb/misc/ft232h-intf.c new file +9 -0
+		/*
+		 * Divide by 16 to have 3 fractional bits and
+		 * one bit for rounding
+		 */
+		div = clk * 16 / clk_div / baudrate;
 
+		if (div & 1)	/* Decide if to round up or down */
+			best_div = div / 2 + 1;
+		else
+			best_div = div / 2;  

In Linux we would write:

Quoted 7 lines

best_div = DIV_ROUND_UP(div, 2);

Though I think you can combine that with the above to get:

best_div = DIV_ROUND_CLOSEST(clk * 8 / clk_div, baudrate);

That what the above is trying to accomplish in a round about way

will rework this, too. Thanks for suggestions.

Quoted 4 lines

drivers/usb/misc/ft232h-intf.c line 196

Quoted 2 lines
drivers/usb/misc/ft232h-intf.c new file +2 -0
+		if (best_div > 0x20000)
+			best_div = 0x1ffff;

Looks like the above was probably supposed to be >=

I'll check it.

Quoted 7 lines

drivers/usb/misc/ft232h-intf.c line 201

Quoted 5 lines
drivers/usb/misc/ft232h-intf.c new file +5 -0
+		best_baud = clk * 16 / clk_div / best_div;
+		if (best_baud & 1)	/* Decide if to round up or down */
+			best_baud = best_baud / 2 + 1;
+		else
+			best_baud = best_baud / 2;  

Again, looks like a complicated way to round to the nearest.

will change this, too.

Thanks,
Anatolij

#4 lore raw

PATCH v2 2/3 spi: add FTDI MPSSE SPI controller driver

In reply to Anatolij Gustschin

Add SPI bus controller driver for FTDI MPSSE mode. This driver is supposed to be used together with the FT232H interface driver for FPGA configuration in drivers/usb/misc/ft232h-intf.c which adds an mpsse spi platform device describing USB SPI bus with attached SPI slave devices.

---
 drivers/spi/Kconfig          |   7 +
 drivers/spi/Makefile         |   1 +
 drivers/spi/spi-ftdi-mpsse.c | 673 +++++++++++++++++++++++++++++++++++
 3 files changed, 681 insertions(+)
 create mode 100644 drivers/spi/spi-ftdi-mpsse.c
drivers/spi/Kconfig +7 -0
index 7d3a5c94727e..2cb24e28c485 100644
@@ -259,6 +259,13 @@ config SPI_FSL_LPSPI
 	help
 	  This enables Freescale i.MX LPSPI controllers in master mode.
 
+config SPI_FTDI_MPSSE
+	tristate "FTDI MPSSE SPI controller"
+	depends on USB_FT232H_INTF || COMPILE_TEST
+	help
+	  FT232H supports SPI in MPSSE mode. This driver provides MPSSE
+	  SPI controller in master mode.
+
 config SPI_GPIO
 	tristate "GPIO-based bitbanging SPI Master"
 	depends on GPIOLIB || COMPILE_TEST
drivers/spi/Makefile +1 -0
index 3575205c5c27..268c42c502e2 100644
@@ -113,6 +113,7 @@ obj-$(CONFIG_SPI_XILINX)		+= spi-xilinx.o
 obj-$(CONFIG_SPI_XLP)			+= spi-xlp.o
 obj-$(CONFIG_SPI_XTENSA_XTFPGA)		+= spi-xtensa-xtfpga.o
 obj-$(CONFIG_SPI_ZYNQMP_GQSPI)		+= spi-zynqmp-gqspi.o
+obj-$(CONFIG_SPI_FTDI_MPSSE)		+= spi-ftdi-mpsse.o
 
 # SPI slave protocol handlers
 obj-$(CONFIG_SPI_SLAVE_TIME)		+= spi-slave-time.o
drivers/spi/spi-ftdi-mpsse.c new file +673 -0

673 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#5 lore raw

Re: [PATCH v2 2/3] spi: add FTDI MPSSE SPI controller driver

drivers/spi/Makefile obj-$(CONFIG_SPI_XILINX) += spi-xilinx.o · line 119

Quoted 10 lines · Anatolij Gustschin
drivers/spi/Makefile +1 -0
@@ -113,6 +113,7 @@ obj-$(CONFIG_SPI_XILINX)		+= spi-xilinx.o
 obj-$(CONFIG_SPI_XLP)			+= spi-xlp.o
 obj-$(CONFIG_SPI_XTENSA_XTFPGA)		+= spi-xtensa-xtfpga.o
 obj-$(CONFIG_SPI_ZYNQMP_GQSPI)		+= spi-zynqmp-gqspi.o
+obj-$(CONFIG_SPI_FTDI_MPSSE)		+= spi-ftdi-mpsse.o
 
 # SPI slave protocol handlers
 obj-$(CONFIG_SPI_SLAVE_TIME)		+= spi-slave-time.o

Please keep the Makefile sorted.

drivers/spi/Makefile line 3

Quoted 5 lines

+++ b/drivers/spi/spi-ftdi-mpsse.c

drivers/spi/Makefile +3 -0
@@ -0,0 +1,673 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * FTDI FT232H MPSSE SPI controller driver

Please make the entire comment block here a C++ one so it looks more consistent.

drivers/spi/Makefile line 4

Quoted 1 line
drivers/spi/Makefile +1 -0
+	struct gpiod_lookup_table *lookup[13];

This magic number for the size of the lookup table is not good.

drivers/spi/Makefile line 14

Quoted 10 lines
drivers/spi/Makefile +10 -0
+static void ftdi_spi_chipselect(struct ftdi_spi *priv, struct spi_device *spi,
+				bool value)
+{
+	int cs = spi->chip_select;
+
+	dev_dbg(&priv->master->dev, "%s: CS %d, cs mode %d, val %d\n",
+		__func__, cs, (spi->mode & SPI_CS_HIGH), value);
+
+	gpiod_set_raw_value_cansleep(priv->cs_gpios[cs], value);
+}

This is just a gpio chip select - can't it be handled by the core chip select code?

drivers/spi/Makefile line 17

Quoted 3 lines
drivers/spi/Makefile +3 -0
+	remaining = len;
+	do {
+		stride = min_t(size_t, remaining, SZ_64K - 3);

Rather than having a magic number for the buffer size it would be better to either have a driver specific constant that's used consistently or just use sizeof() when it's referenced in the code. That way if the buffer size is changed nothing will get missed.

drivers/spi/Makefile line 25

Quoted 8 lines
drivers/spi/Makefile +8 -0
+		/* Last transfer with cs_change set, stop keeping CS */
+		if (list_is_last(&t->transfer_list, &msg->transfers)) {
+			keep_cs = true;
+			break;
+		}
+		ftdi_spi_chipselect(priv, spi, !(spi->mode & SPI_CS_HIGH));
+		usleep_range(10, 15);
+		ftdi_spi_chipselect(priv, spi, spi->mode & SPI_CS_HIGH);

I'm not clear what this is intended to do? It's overall not clear to me that the driver needs to use transfer_one_message and not transfer_one, the latter keeps more of the code in common code.

drivers/spi/Makefile line 38

Quoted 13 lines
drivers/spi/Makefile +13 -0
+	/* Find max. slave chipselect number */
+	num_cs = pd->spi_info_len;
+	for (i = 0; i < num_cs; i++) {
+		if (max_cs < pd->spi_info[i].chip_select)
+			max_cs = pd->spi_info[i].chip_select;
+	}
+
+	if (max_cs > 12) {
+		dev_err(dev, "Invalid max CS in platform data: %d\n", max_cs);
+		return -EINVAL;
+	}
+	dev_dbg(dev, "CS count %d, max CS %d\n", num_cs, max_cs);
+	max_cs += 1; /* including CS0 */

Why not just size the array based on the platform data?

#6 lore raw

Re: [PATCH v2 2/3] spi: add FTDI MPSSE SPI controller driver

On Wed, 21 Nov 2018 12:42:37 +0000
Mark Brown [email protected] wrote:
...

Quoted 7 lines
Quoted 5 lines

obj-$(CONFIG_SPI_ZYNQMP_GQSPI) += spi-zynqmp-gqspi.o
+obj-$(CONFIG_SPI_FTDI_MPSSE) += spi-ftdi-mpsse.o

# SPI slave protocol handlers
obj-$(CONFIG_SPI_SLAVE_TIME) += spi-slave-time.o

Please keep the Makefile sorted.

Will fix it in v3.

Quoted 8 lines

drivers/spi/spi-ftdi-mpsse.c line 3

Quoted 5 lines

+++ b/drivers/spi/spi-ftdi-mpsse.c

drivers/spi/spi-ftdi-mpsse.c new file +3 -0
@@ -0,0 +1,673 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * FTDI FT232H MPSSE SPI controller driver  

Please make the entire comment block here a C++ one so it looks more consistent.

Okay.

Quoted 3 lines

drivers/spi/spi-ftdi-mpsse.c line 35

Quoted 1 line
drivers/spi/spi-ftdi-mpsse.c new file +1 -0
+	struct gpiod_lookup_table *lookup[13];  

This magic number for the size of the lookup table is not good.

Will fix it in v3.

Quoted 5 lines
Quoted 5 lines
drivers/spi/spi-ftdi-mpsse.c new file +5 -0
+static void ftdi_spi_chipselect(struct ftdi_spi *priv, struct spi_device *spi,
+				bool value)
+{
+	int cs = spi->chip_select;
+
Quoted 8 lines

drivers/spi/spi-ftdi-mpsse.c line 54

Quoted 5 lines
drivers/spi/spi-ftdi-mpsse.c new file +5 -0
+	dev_dbg(&priv->master->dev, "%s: CS %d, cs mode %d, val %d\n",
+		__func__, cs, (spi->mode & SPI_CS_HIGH), value);
+
+	gpiod_set_raw_value_cansleep(priv->cs_gpios[cs], value);
+}  

This is just a gpio chip select - can't it be handled by the core chip select code?

spi core chip select code doesn't use gpio_desc based API yet. But it can be handled using .set_cs(), I'll convert the driver to use .set_cs().

Quoted 8 lines

drivers/spi/spi-ftdi-mpsse.c line 199

Quoted 3 lines
drivers/spi/spi-ftdi-mpsse.c new file +3 -0
+	remaining = len;
+	do {
+		stride = min_t(size_t, remaining, SZ_64K - 3);  

Rather than having a magic number for the buffer size it would be better to either have a driver specific constant that's used consistently or just use sizeof() when it's referenced in the code. That way if the buffer size is changed nothing will get missed.

sizeof() is better choice here, will use it in v3.

Quoted 4 lines
Quoted 4 lines
drivers/spi/spi-ftdi-mpsse.c new file +4 -0
+		/* Last transfer with cs_change set, stop keeping CS */
+		if (list_is_last(&t->transfer_list, &msg->transfers)) {
+			keep_cs = true;
+			break;
Quoted 8 lines

drivers/spi/spi-ftdi-mpsse.c line 396

Quoted 4 lines
drivers/spi/spi-ftdi-mpsse.c new file +4 -0
+		}
+		ftdi_spi_chipselect(priv, spi, !(spi->mode & SPI_CS_HIGH));
+		usleep_range(10, 15);
+		ftdi_spi_chipselect(priv, spi, spi->mode & SPI_CS_HIGH);  

I'm not clear what this is intended to do? It's overall not clear to me that the driver needs to use transfer_one_message and not transfer_one, the latter keeps more of the code in common code.

It has been a while since I started with this driver, I don't remember the intention of this chip select toggling here. I'll convert the driver to use .transfer_one().

Quoted 7 lines
Quoted 7 lines
drivers/spi/spi-ftdi-mpsse.c new file +7 -0
+	/* Find max. slave chipselect number */
+	num_cs = pd->spi_info_len;
+	for (i = 0; i < num_cs; i++) {
+		if (max_cs < pd->spi_info[i].chip_select)
+			max_cs = pd->spi_info[i].chip_select;
+	}
+
Quoted 8 lines

drivers/spi/spi-ftdi-mpsse.c line 539

Quoted 6 lines
drivers/spi/spi-ftdi-mpsse.c new file +6 -0
+	if (max_cs > 12) {
+		dev_err(dev, "Invalid max CS in platform data: %d\n", max_cs);
+		return -EINVAL;
+	}
+	dev_dbg(dev, "CS count %d, max CS %d\n", num_cs, max_cs);
+	max_cs += 1; /* including CS0 */  

Why not just size the array based on the platform data?

The driver must also support multiple SPI slaves with additional control pins (besides SPI chip-select gpios). There are devices with not adjacent chip-select gpios or devices with single chip-select gpio starting at some offset. The array size is not always the number of chip-selects or the max. chip-select, e.g.:

$ tree /sys/bus/spi/devices/
/sys/bus/spi/devices/
├── spi0.4 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2.4/2-1.2.4:1.0/ftdi-mpsse-spi.0/spi_master/spi0/spi0.4
├── spi1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2.3/2-1.2.3:1.0/ftdi-mpsse-spi.1/spi_master/spi1/spi1.0
├── spi1.12 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2.3/2-1.2.3:1.0/ftdi-mpsse-spi.1/spi_master/spi1/spi1.12
├── spi1.4 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2.3/2-1.2.3:1.0/ftdi-mpsse-spi.1/spi_master/spi1/spi1.4
└── spi1.8 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2.3/2-1.2.3:1.0/ftdi-mpsse-spi.1/spi_master/spi1/spi1.8
$ sudo cat /sys/kernel/debug/gpio
gpiochip1: GPIOs 486-498, parent: usb/2-1.2.3:1.0, ftdi-mpsse-gpio.1, can sleep:
 gpio-486 (mpsse.1-CS          |spi-cs              ) out hi ACTIVE LOW
 gpio-487 (mpsse.1-GPIOL0      |confd               ) in  hi 
 gpio-488 (mpsse.1-GPIOL1      |nstat               ) in  hi ACTIVE LOW
 gpio-489 (mpsse.1-GPIOL2      |nconfig             ) out hi ACTIVE LOW
 gpio-490 (mpsse.1-GPIOL3      |spi-cs              ) out hi ACTIVE LOW
 gpio-491 (mpsse.1-GPIOH0      |confd               ) in  hi 
 gpio-492 (mpsse.1-GPIOH1      |nstat               ) in  hi ACTIVE LOW
 gpio-493 (mpsse.1-GPIOH2      |nconfig             ) out hi ACTIVE LOW
 gpio-494 (mpsse.1-GPIOH3      |spi-cs              ) out hi ACTIVE LOW
 gpio-495 (mpsse.1-GPIOH4      |confd               ) in  hi 
 gpio-496 (mpsse.1-GPIOH5      |nstat               ) in  hi ACTIVE LOW
 gpio-497 (mpsse.1-GPIOH6      |nconfig             ) out hi ACTIVE LOW
 gpio-498 (mpsse.1-GPIOH7      |spi-cs              ) out hi 

gpiochip0: GPIOs 499-511, parent: usb/2-1.2.4:1.0, ftdi-mpsse-gpio.0, can sleep:

 gpio-499 (mpsse.0-CS          )
 gpio-500 (mpsse.0-GPIOL0      )
 gpio-501 (mpsse.0-GPIOL1      )
 gpio-502 (mpsse.0-GPIOL2      )
 gpio-503 (mpsse.0-GPIOL3      |spi-cs              ) out hi ACTIVE LOW
 gpio-504 (mpsse.0-GPIOH0      |confd               ) in  hi 
 gpio-505 (mpsse.0-GPIOH1      |nstat               ) in  hi ACTIVE LOW
 gpio-506 (mpsse.0-GPIOH2      |nconfig             ) out hi ACTIVE LOW
 gpio-507 (mpsse.0-GPIOH3      )
 gpio-508 (mpsse.0-GPIOH4      )
 gpio-509 (mpsse.0-GPIOH5      )
 gpio-510 (mpsse.0-GPIOH6      )
 gpio-511 (mpsse.0-GPIOH7      )

Thanks,
Anatolij

maintainer
#7 lore raw

Re: [PATCH v2 2/3] spi: add FTDI MPSSE SPI controller driver

Quoted 11 lines · Anatolij Gustschin
Quoted 8 lines · Mark Brown [email protected] wrote:

drivers/spi/spi-ftdi-mpsse.c line 539

Quoted 6 lines
drivers/spi/spi-ftdi-mpsse.c new file +6 -0
+	if (max_cs > 12) {
+		dev_err(dev, "Invalid max CS in platform data: %d\n", max_cs);
+		return -EINVAL;
+	}
+	dev_dbg(dev, "CS count %d, max CS %d\n", num_cs, max_cs);
+	max_cs += 1; /* including CS0 */  

Why not just size the array based on the platform data?

Quoted 5 lines

The driver must also support multiple SPI slaves with additional control pins (besides SPI chip-select gpios). There are devices with not adjacent chip-select gpios or devices with single chip-select gpio starting at some offset. The array size is not always the number of chip-selects or the max. chip-select, e.g.:

A few unused entries really won't matter.

#8 lore raw

PATCH v2 3/3 fpga: Add fpga manager driver for ARRI Altera FPP

In reply to Anatolij Gustschin

Add FPGA manager driver for loading ARRI Altera FPGAs via fast passive parallel (FPP) interface using FTDI FT232H chip.

---
 .../ABI/testing/sysfs-driver-ftdi-fifo-fpp    |   7 +
 drivers/fpga/Kconfig                          |   7 +
 drivers/fpga/Makefile                         |   1 +
 drivers/fpga/ftdi-fifo-fpp.c                  | 594 ++++++++++++++++++
 4 files changed, 609 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-ftdi-fifo-fpp
 create mode 100644 drivers/fpga/ftdi-fifo-fpp.c
Documentation/ABI/testing/sysfs-driver-ftdi-fifo-fpp new file +7 -0
new file mode 100644
index 000000000000..084e691d0983
@@ -0,0 +1,7 @@
+What:		/sys/bus/platform/devices/ftdi-fifo-fpp-mgr.N/cfg_mode
+Date:		Nov 2018
+Kernel Version:	4.21
+Contact:	Anatolij Gustschin <[email protected]>
+Description:
+		Contains either "fifo" or "bitbang" and controls if fifo
+		of bitbang configuration mode is used in the driver.
drivers/fpga/Kconfig +7 -0
index 205042b441ea..584866a27c35 100644
@@ -59,6 +59,13 @@ config FPGA_MGR_ALTERA_CVP
 	  FPGA manager driver support for Arria-V, Cyclone-V, Stratix-V
 	  and Arria 10 Altera FPGAs using the CvP interface over PCIe.
 
+config FPGA_MGR_FTDI_FIFO_FPP
+	tristate "Altera FPP over FT232H FIFO"
+	depends on USB_FT232H_INTF
+	help
+	  FPGA manager driver support for Altera fast passive parallel
+	  interface (FPP) over FT232H FT245 FIFO.
+
 config FPGA_MGR_ZYNQ_FPGA
 	tristate "Xilinx Zynq FPGA"
 	depends on ARCH_ZYNQ || COMPILE_TEST
drivers/fpga/Makefile +1 -0
index 7a2d73ba7122..8c1d714bd440 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_FPGA)			+= fpga-mgr.o
 # FPGA Manager Drivers
 obj-$(CONFIG_FPGA_MGR_ALTERA_CVP)	+= altera-cvp.o
 obj-$(CONFIG_FPGA_MGR_ALTERA_PS_SPI)	+= altera-ps-spi.o
+obj-$(CONFIG_FPGA_MGR_FTDI_FIFO_FPP)	+= ftdi-fifo-fpp.o
 obj-$(CONFIG_FPGA_MGR_ICE40_SPI)	+= ice40-spi.o
 obj-$(CONFIG_FPGA_MGR_MACHXO2_SPI)	+= machxo2-spi.o
 obj-$(CONFIG_FPGA_MGR_SOCFPGA)		+= socfpga.o
drivers/fpga/ftdi-fifo-fpp.c new file +594 -0

594 lines not on this page · raw message

Signature · 1 line
2.17.1