fpga: Add flag to indicate SPI bitstream is bit-reversed
PATCH v13 1/6 fpga: Add flag to indicate SPI bitstream is bit-reversed
From: Anatolij Gustschin <[email protected]>
Add a flag that is passed to the write_init() callback, indicating that the SPI bitstream starts with LSB first. SPI controllers usually send data with MSB first. If an FPGA expects bitstream data as LSB first, the data must be reversed either by the SPI controller or by the driver.
Alternatively the bitstream could be prepared as bit-reversed to avoid the bit-swapping while sending. This flag indicates such bit-reversed SPI bitstream. The low-level driver will deal with the flag and perform bit-reversing if needed.
---
Changes since v12:
- Change "depends on SPI || COMPILE_TEST" to "depends on SPI" in patch 3
include/linux/fpga/fpga-mgr.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/fpga/fpga-mgr.h +2 -0
@@ -67,10 +67,12 @@ enum fpga_mgr_states {* FPGA Manager flags * FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported * FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting +* FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first */ #define FPGA_MGR_PARTIAL_RECONFIG BIT(0)#define FPGA_MGR_EXTERNAL_CONFIG BIT(1)#define FPGA_MGR_ENCRYPTED_BITSTREAM BIT(2) +#define FPGA_MGR_BITSTREAM_LSB_FIRST BIT(3)/** * struct fpga_image_info - information specific to a FPGA image
Signature · 1 line
2.11.0
PATCH v13 2/6 doc: dt: document altera-passive-serial binding
Describe an altera-passive-serial devicetree entry, required features
--- .../bindings/fpga/altera-passive-serial.txt | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/fpga/altera-passive-serial.txt
Documentation/devicetree/bindings/fpga/altera-passive-serial.txt new file +29 -0
@@ -0,0 +1,29 @@ +Altera Passive Serial SPI FPGA Manager + +Altera FPGAs support a method of loading the bitstream over what is +referred to as "passive serial". +The passive serial link is not technically SPI, and might require extra +circuits in order to play nicely with other SPI slaves on the same bus. + +See https://www.altera.com/literature/hb/cyc/cyc_c51013.pdf + +Required properties: +- compatible: Must be one of the following: + "altr,fpga-passive-serial", + "altr,fpga-arria10-passive-serial" +- reg: SPI chip select of the FPGA +- nconfig-gpios: config pin (referred to as nCONFIG in the manual) +- nstat-gpios: status pin (referred to as nSTATUS in the manual) + +Optional properties: +- confd-gpios: confd pin (referred to as CONF_DONE in the manual) + +Example: + fpga: fpga at 0 { + compatible = "altr,fpga-passive-serial"; + spi-max-frequency = <20000000>; + reg = <0>; + nconfig-gpios = <&gpio4 9 GPIO_ACTIVE_LOW>; + nstat-gpios = <&gpio4 11 GPIO_ACTIVE_LOW>; + confd-gpios = <&gpio4 12 GPIO_ACTIVE_LOW>; + };
Signature · 1 line
2.11.0
PATCH v13 3/6 fpga manager: Add altera-ps-spi driver for Altera FPGAs
In reply to Joshua Claytonaltera-ps-spi loads FPGA firmware over SPI, using the "passive serial" interface on Altera Arria 10, Cyclone V or Stratix V FPGAs.
This is one of the simpler ways to set up an FPGA at runtime. The signal interface is close to unidirectional SPI with lsb first.
--- drivers/fpga/Kconfig | 7 + drivers/fpga/Makefile | 1 + drivers/fpga/altera-ps-spi.c | 297 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 305 insertions(+) create mode 100644 drivers/fpga/altera-ps-spi.c
drivers/fpga/Kconfig +7 -0
@@ -26,6 +26,13 @@ config FPGA_MGR_ICE40_SPI help FPGA manager driver support for Lattice iCE40 FPGAs over SPI. +config FPGA_MGR_ALTERA_PS_SPI + tristate "Altera FPGA Passive Serial over SPI" + depends on SPI + help + FPGA manager driver support for Altera Arria/Cyclone/Stratix + using the passive serial interface over SPI. + config FPGA_MGR_SOCFPGA tristate "Altera SOCFPGA FPGA Manager" depends on ARCH_SOCFPGA || COMPILE_TEST
drivers/fpga/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_FPGA) += fpga-mgr.o # FPGA Manager Drivers +obj-$(CONFIG_FPGA_MGR_ALTERA_PS_SPI) += altera-ps-spi.o obj-$(CONFIG_FPGA_MGR_ICE40_SPI) += ice40-spi.o obj-$(CONFIG_FPGA_MGR_SOCFPGA) += socfpga.o obj-$(CONFIG_FPGA_MGR_SOCFPGA_A10) += socfpga-a10.o
drivers/fpga/altera-ps-spi.c new file +297 -0
297 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v13 4/6 ARM: dts: imx6q-evi: support altera-ps-spi
In reply to Joshua ClaytonAdd support for Altera FPGA connected to an spi port to the evi devicetree file
--- arch/arm/boot/dts/imx6q-evi.dts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/arm/boot/dts/imx6q-evi.dts +16 -0
@@ -82,6 +82,15 @@ pinctrl-names = "default"; pinctrl-0 = <&pinctrl_ecspi1 &pinctrl_ecspi1cs>; status = "okay"; + + fpga: fpga at 0 { + compatible = "altr,fpga-passive-serial"; + spi-max-frequency = <20000000>; + reg = <0>; + pinctrl-0 = <&pinctrl_fpgaspi>; + nconfig-gpios = <&gpio4 9 GPIO_ACTIVE_LOW>; + nstat-gpios = <&gpio4 11 GPIO_ACTIVE_LOW>; + }; }; &ecspi3 {
@@ -313,6 +322,13 @@ >; }; + pinctrl_fpgaspi: fpgaspigrp { + fsl,pins = < + MX6QDL_PAD_KEY_ROW1__GPIO4_IO09 0x1b0b0 + MX6QDL_PAD_KEY_ROW2__GPIO4_IO11 0x1b0b0 + >; + }; + pinctrl_gpminand: gpminandgrp { fsl,pins = < MX6QDL_PAD_NANDF_CLE__NAND_CLE 0xb0b1
Signature · 1 line
2.11.0
PATCH v13 5/6 lib: add bitrev8x4()
In reply to Joshua ClaytonAdd a function to reverse bytes within a 32 bit word. Operate on a u32 rather than individual bytes.
--- include/linux/bitrev.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
include/linux/bitrev.h +19 -0
@@ -29,6 +29,8 @@ static inline u32 __bitrev32(u32 x)#endif /* CONFIG_HAVE_ARCH_BITREVERSE */ +#define __bitrev8x4 (x) (__bitrev32(swab32(x))) +#define __constant_bitrev32 (x) \ ({ \ u32 __x = x; \
@@ -50,6 +52,15 @@ static inline u32 __bitrev32(u32 x) __x; \ }) +#define __constant_bitrev8x4 (x) \ +({ \ + u32 __x = x; \ + __x = ((__x & (u32)0xF0F0F0F0UL) >> 4) | ((__x & (u32)0x0F0F0F0FUL) << 4); \ + __x = ((__x & (u32)0xCCCCCCCCUL) >> 2) | ((__x & (u32)0x33333333UL) << 2); \ + __x = ((__x & (u32)0xAAAAAAAAUL) >> 1) | ((__x & (u32)0x55555555UL) << 1); \ + __x; \ +}) +#define __constant_bitrev8 (x) \ ({ \ u8 __x = x; \
@@ -75,6 +86,14 @@ static inline u32 __bitrev32(u32 x)__bitrev16 (__x); \ }) +#define bitrev8x4 (x) \ +({ \ + u32 __x = x; \ + __builtin_constant_p(__x) ? \ + __constant_bitrev8x4(__x) : \ + __bitrev8x4(__x); \ + }) +#define bitrev8 (x) \ ({ \ u8 __x = x; \
Signature · 1 line
2.11.0
PATCH v13 6/6 fpga-manager: altera-ps-spi: use bitrev8x4
In reply to Joshua ClaytonSpeed up bit reversal by using hardware bit reversal Add extra code to handle less than 4byte remnants, if any
--- drivers/fpga/altera-ps-spi.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/fpga/altera-ps-spi.c +15 -4
@@ -149,12 +149,23 @@ static int altera_ps_write_init(struct fpga_manager *mgr,static void rev_buf (char *buf,size_t len) { -const char *fw_end = (buf + len); +u32 *fw32 = (u32 *)buf; +size_t extra_bytes = (len &0x03 ); +const u32 *fw_end = (u32 *)(buf + len - extra_bytes);/* set buffer to lsb first */ -while (buf < fw_end) { - *buf =bitrev8 (*buf); - buf++; +while (fw32 < fw_end) { + *fw32 =bitrev8x4 (*fw32); + fw32++; + } + +if (extra_bytes) { + buf = (char *)fw_end; +while (extra_bytes) { + *buf =bitrev8 (*buf); + buf++; + extra_bytes--; + } } }
Signature · 1 line
2.11.0
Re: [PATCH v13 3/6] fpga manager: Add altera-ps-spi driver for Altera FPGAs
In reply to Joshua ClaytonQuoted 8 lines · Joshua Clayton
altera-ps-spi loads FPGA firmware over SPI, using the "passive serial" interface on Altera Arria 10, Cyclone V or Stratix V FPGAs.
This is one of the simpler ways to set up an FPGA at runtime. The signal interface is close to unidirectional SPI with lsb first.
Signed-off-by Joshua Clayton <[email protected]>Signed-off-by Anatolij Gustschin <[email protected]>
I tested the whole series with an Altera Arria 10 and it's working as expected. Thanks again!
Bastian
Signature · 5 lines
Pengutronix e.K. Industrial Linux Solutions http://www.pengutronix.de/ Peiner Str. 6-8, 31137 Hildesheim, Germany Amtsgericht Hildesheim, HRA 2686
Re: [PATCH v13 3/6] fpga manager: Add altera-ps-spi driver for Altera FPGAs
Quoted 8 lines · Bastian Stender
Quoted 7 lines · Joshua Clayton
altera-ps-spi loads FPGA firmware over SPI, using the "passive serial" interface on Altera Arria 10, Cyclone V or Stratix V FPGAs.
This is one of the simpler ways to set up an FPGA at runtime. The signal interface is close to unidirectional SPI with lsb first.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Joshua Clayton <[email protected]>Signed-off-by Anatolij Gustschin <[email protected]>Tested-by Bastian Stender <[email protected]>I tested the whole series with an Altera Arria 10 and it's working as expected. Thanks again!
Thanks for the testing! This patchset is already in linux-next for 4.13.
Alan
Quoted 9 lines
Bastian
--
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686