FPGA Manager support for altera passive serial
v11 cover FPGA Manager support for altera passive serial
FPGA Manager passive serial can now support Stratix, Cyclone and Arria FPGAs.
Thanks to Bastian and Anatolij for helping to extend support beyond Cyclone
changes from v10
- Rebase on v4.12-rc2
- Remove an erroneous cyclone-ps-spi.o reference from drivers/fpga/Makefile
- Change FPGA_MGR_SPI_BITSTREAM_LSB_FIRST tp FPGA_MGR_BITSTREAM_LSB_FIRST
- Change CONF_DONE "low" to "inactive" in an error message
- Add a MODULE_DEVICE_TABLE for SPI
- Patches 1-4 can be merged without 5 and 6
- Patches 5, and 6 Add back in the bitrev8x4 speed up code newly with support for any size buffer.
Anatolij Gustschin (1):
fpga: Add flag to indicate SPI bitstream is bit-reversed
Joshua Clayton (4):
doc: dt: add altera-ps-spi binding document fpga manager: Add altera-ps-spi driver for Altera FPGAs
ARM: dts: imx6q-evi: support altera-ps-spi
lib: add bitrev8x4()
fpga-manager: altera-ps-spi: use bitrev8x4
.../bindings/fpga/altera-passive-serial.txt | 29 ++ arch/arm/boot/dts/imx6q-evi.dts | 16 ++ drivers/fpga/Kconfig | 7 + drivers/fpga/Makefile | 1 + drivers/fpga/altera-ps-spi.c | 307 +++++++++++++++++++++ include/linux/bitrev.h | 19 ++ include/linux/fpga/fpga-mgr.h | 2 + 7 files changed, 381 insertions(+) create mode 100644 Documentation/devicetree/bindings/fpga/altera-passive-serial.txt create mode 100644 drivers/fpga/altera-ps-spi.c
Signature · 1 line
2.11.0
PATCH v11 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.
--- 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 v11 2/6 doc: dt: add altera-ps-spi binding document
In reply to Joshua ClaytonDescribe an altera-ps-spi 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_spi: evi-fpga-spi 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 v11 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 | 296 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 304 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 || COMPILE_TEST + 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 v11 4/6 ARM: dts: imx6q-evi: support altera-ps-spi
In reply to Joshua ClaytonAdd support for Altera V 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_spi: cyclonespi 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 v11 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 v11 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
Hi Alan,
Quoted 2 lines · On Thu, 25 May 2017 10:29:05 -0700 Joshua Clayton stillcompiling at gmail.com…
FPGA Manager passive serial can now support Stratix, Cyclone and Arria FPGAs.
can this series be queued for merging in v4.13 or are there any issues with it?
Thanks,
Anatolij
Re: [PATCH v11 4/6] ARM: dts: imx6q-evi: support altera-ps-spi
In reply to Joshua ClaytonHi,
Am 25.05.2017 um 19:29 schrieb Joshua Clayton:
Quoted 1 line
Add support for Altera V FPGA connected to an spi port
Did you mean "Altera Cyclone V"?
Quoted 12 lines
to the evi devicetree file
Signed-off-by Joshua Clayton <[email protected]>--- arch/arm/boot/dts/imx6q-evi.dts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)arch/arm/boot/dts/imx6q-evi.dts +0
-0
arch/arm/boot/dts/imx6q-evi.dts line 86
Quoted 5 lines
arch/arm/boot/dts/imx6q-evi.dts +2
-0@@ -82,6 +82,15 @@ pinctrl-names = "default"; pinctrl-0 = <&pinctrl_ecspi1 &pinctrl_ecspi1cs>; status = "okay"; + + fpga_spi: cyclonespi at 0 {
"cyclonespi" does not strike me as the best node name.
I am guessing this is a sub-node of a SPI controller node, so no need to repeat "spi", and Cyclone seems more or less implied by "altr,fpga-".
Note that the example in the bindings doc uses "evi-fpga-spi". Nodes don't need to be (shouldn't be?) prefixed with the board. Note that bindings examples tend to get copied a lot.
Any reason not to just use "fpga at 0" in both places for simplicity?
arch/arm/boot/dts/imx6q-evi.dts line 96
Quoted 10 lines
arch/arm/boot/dts/imx6q-evi.dts +7
-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 {
[snip]
Regards,
Andreas
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany GF: Felix Imend?rffer, Jane Smithard, Graham Norton HRB 21284 (AG N?rnberg)
Re: [PATCH v11 4/6] ARM: dts: imx6q-evi: support altera-ps-spi
Quoted 6 lines · PDT Andreas F?rber
Hi,
Am 25.05.2017 um 19:29 schrieb Joshua Clayton:
Quoted 1 line
Add support for Altera V FPGA connected to an spi port
Did you mean "Altera Cyclone V"?
I meant to shorten it from Altera Cyclone V to Altera FPGA. Didn't quite make it. Will fix and resubmit today.
Quoted 19 lines
Quoted 19 lines
to the evi devicetree file
Signed-off-by Joshua Clayton <[email protected]>---
arch/arm/boot/dts/imx6q-evi.dts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)(quoted diff) +0
-0
b/arch/arm/boot/dts/imx6q-evi.dtsindex24fe093a66db..a0cbb2d84803100644arch/arm/boot/dts/imx6q-evi.dts +0
-0@@ -82,6 +82,15 @@ pinctrl-names = "default"; pinctrl-0 = <&pinctrl_ecspi1 &pinctrl_ecspi1cs>; status = "okay";
Quoted 7 lines
arch/arm/boot/dts/imx6q-evi.dts line 86
Quoted 2 lines
arch/arm/boot/dts/imx6q-evi.dts +2
-0+ + fpga_spi: cyclonespi at 0 {"cyclonespi" does not strike me as the best node name.
I am guessing this is a sub-node of a SPI controller node, so no need to repeat "spi", and Cyclone seems more or less implied by "altr,fpga-".
True.
Quoted 6 lines
Note that the example in the bindings doc uses "evi-fpga-spi". Nodes don't need to be (shouldn't be?) prefixed with the board. Note that bindings examples tend to get copied a lot.
Any reason not to just use "fpga at 0" in both places for simplicity?
Sure. fpga: fpga at 0 is probably better. I'll change it in both the dts and the binding doc.
Quoted 17 lines
Quoted 11 lines
arch/arm/boot/dts/imx6q-evi.dts +7
-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>; + };};
Quoted 1 line
&ecspi3 {
[snip]
Regards,
Andreas
Signature · 1 line
~Joshua A Clayton
Re: [PATCH v11 4/6] ARM: dts: imx6q-evi: support altera-ps-spi
Am 02.06.2017 um 21:39 schrieb stillcompiling at gmail.com:
Quoted 19 lines · PDT Andreas F?rber
Quoted 11 lines
Am 25.05.2017 um 19:29 schrieb Joshua Clayton:
Quoted 10 lines
(quoted diff) +0
-0
b/arch/arm/boot/dts/imx6q-evi.dtsindex24fe093a66db..a0cbb2d84803100644arch/arm/boot/dts/imx6q-evi.dts +0
-0@@ -82,6 +82,15 @@ pinctrl-names = "default"; pinctrl-0 = <&pinctrl_ecspi1 &pinctrl_ecspi1cs>; status = "okay";Quoted 7 lines
arch/arm/boot/dts/imx6q-evi.dts line 86
Quoted 2 lines
arch/arm/boot/dts/imx6q-evi.dts +2
-0+ + fpga_spi: cyclonespi at 0 {"cyclonespi" does not strike me as the best node name.
I am guessing this is a sub-node of a SPI controller node, so no need to repeat "spi", and Cyclone seems more or less implied by "altr,fpga-".
Quoted 8 lines
True.
Quoted 6 lines
Note that the example in the bindings doc uses "evi-fpga-spi". Nodes don't need to be (shouldn't be?) prefixed with the board. Note that bindings examples tend to get copied a lot.
Any reason not to just use "fpga at 0" in both places for simplicity?
Sure. fpga: fpga at 0 is probably better.
Note that I was only commenting on the node name, the latter part.
I'm not aware of any rules for the label, so that could remain unchanged or adopt cyclone_spi from the old node name or whatever is unique and syntactically valid.
Quoted 1 line
I'll change it in both the dts and the binding doc.
Thanks. Maybe double-check if there's any conventions Xilinx/Lattice DTs are using.
Cheers,
Andreas
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany GF: Felix Imend?rffer, Jane Smithard, Graham Norton HRB 21284 (AG N?rnberg)
PATCH v12 1/6 fpga: Add flag to indicate SPI bitstream is bit-reversed
In reply to Joshua ClaytonFrom: 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 from v11 (all in patch 4/4)
- Change "Altera V FPGA" to simply "Altera FPGA"
- Change the devicetree name to a generic "fpga: fpga at 0" from "fpga_spi: cyclonespi at 0"
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 v12 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 v12 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 || COMPILE_TEST + 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 v12 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 v12 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 v12 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 v11 4/6] ARM: dts: imx6q-evi: support altera-ps-spi
In reply to Andreas FärberQuoted 30 lines · PDT Andreas F?rber
Am 02.06.2017 um 21:39 schrieb stillcompiling at gmail.com:
Quoted 29 lines · PDT Andreas F?rber
Quoted 12 lines
Am 25.05.2017 um 19:29 schrieb Joshua Clayton:
Quoted 11 lines
(quoted diff) +0
-0
b/arch/arm/boot/dts/imx6q-evi.dtsindex24fe093a66db..a0cbb2d84803100644arch/arm/boot/dts/imx6q-evi.dts +0
-0@@ -82,6 +82,15 @@ pinctrl-names = "default"; pinctrl-0 = <&pinctrl_ecspi1 &pinctrl_ecspi1cs>; status = "okay";Quoted 7 lines
arch/arm/boot/dts/imx6q-evi.dts line 86
Quoted 2 lines
arch/arm/boot/dts/imx6q-evi.dts +2
-0+ + fpga_spi: cyclonespi at 0 {"cyclonespi" does not strike me as the best node name.
I am guessing this is a sub-node of a SPI controller node, so no need to repeat "spi", and Cyclone seems more or less implied by "altr,fpga-".
True.
Quoted 5 lines
Note that the example in the bindings doc uses "evi-fpga-spi". Nodes don't need to be (shouldn't be?) prefixed with the board. Note that bindings examples tend to get copied a lot.
Any reason not to just use "fpga at 0" in both places for simplicity?
Quoted 7 lines
Quoted 1 line
Sure. fpga: fpga at 0 is probably better.
Note that I was only commenting on the node name, the latter part.
I'm not aware of any rules for the label, so that could remain unchanged or adopt
cyclone_spifrom the old node name or whatever is unique and syntactically valid.
Too late! Patches posted.
Oh, well, I'm not changing it back.
Quoted 6 lines
Quoted 2 lines
I'll change it in both the dts and the binding doc.
Thanks. Maybe double-check if there's any conventions Xilinx/Lattice DTs are using.
Of the conventions I found, fpga seemed the most "hardware descriptive" for a plain FPGA.
The other one several binding doc examples are using is "fpga-mgr".
Quoted 2 lines
Cheers,
Andreas
Signature · 1 line
~Joshua A Clayton
Re: [PATCH v11 4/6] ARM: dts: imx6q-evi: support altera-ps-spi
Quoted 33 lines · On Fri, Jun 2, 2017 at 4:10 PM, <[email protected]> wrote:
Quoted 32 lines · PDT Andreas F?rber
Am 02.06.2017 um 21:39 schrieb stillcompiling at gmail.com:
Quoted 30 lines · PDT Andreas F?rber
Quoted 12 lines
Am 25.05.2017 um 19:29 schrieb Joshua Clayton:
Quoted 11 lines
(quoted diff) +0
-0
b/arch/arm/boot/dts/imx6q-evi.dtsindex24fe093a66db..a0cbb2d84803100644arch/arm/boot/dts/imx6q-evi.dts +0
-0@@ -82,6 +82,15 @@ pinctrl-names = "default"; pinctrl-0 = <&pinctrl_ecspi1 &pinctrl_ecspi1cs>; status = "okay";Quoted 7 lines
arch/arm/boot/dts/imx6q-evi.dts line 86
Quoted 2 lines
arch/arm/boot/dts/imx6q-evi.dts +2
-0+ + fpga_spi: cyclonespi at 0 {"cyclonespi" does not strike me as the best node name.
I am guessing this is a sub-node of a SPI controller node, so no need to repeat "spi", and Cyclone seems more or less implied by "altr,fpga-".
True.
Quoted 5 lines
Note that the example in the bindings doc uses "evi-fpga-spi". Nodes don't need to be (shouldn't be?) prefixed with the board. Note that bindings examples tend to get copied a lot.
Any reason not to just use "fpga at 0" in both places for simplicity?
Sure. fpga: fpga at 0 is probably better.
Quoted 7 lines
Quoted 5 lines
Note that I was only commenting on the node name, the latter part.
I'm not aware of any rules for the label, so that could remain unchanged or adopt
cyclone_spifrom the old node name or whatever is unique and syntactically valid.Too late! Patches posted.
Oh, well, I'm not changing it back.
It's fine as it is in v12.
fpga_mgr: fpga-mgr at 0 is what I've been using most recently. It distinguishes the one block that is used to program the fpga from the fpga and hardware in the fpga. But no need to respin this.
Alan
Quoted 16 lines
Quoted 6 lines
Quoted 2 lines
I'll change it in both the dts and the binding doc.
Thanks. Maybe double-check if there's any conventions Xilinx/Lattice DTs are using.
Of the conventions I found, fpga seemed the most "hardware descriptive" for a plain FPGA.
The other one several binding doc examples are using is "fpga-mgr".Quoted 2 lines
Cheers,
Andreas--
~Joshua A Clayton
Re: [PATCH v12 1/6] fpga: Add flag to indicate SPI bitstream is bit-reversed
In reply to Joshua ClaytonQuoted 8 lines · Joshua Clayton
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.
Quoted 7 lines
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.
Signed-off-by Anatolij Gustschin <[email protected]>Signed-off-by Joshua Clayton <[email protected]>
Quoted 30 lines
---
Changes from v11 (all in patch 4/4)
- Change "Altera V FPGA" to simply "Altera FPGA"
- Change the devicetree name to a generic "fpga: fpga at 0" from "fpga_spi: cyclonespi at 0"include/linux/fpga/fpga-mgr.h | 2 ++ 1 file changed, 2 insertions(+)include/linux/fpga/fpga-mgr.h +2
-1@@ -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 -- 2.11.0
Re: [PATCH v12 2/6] doc: dt: document altera-passive-serial binding
In reply to Joshua ClaytonQuoted 4 lines · Joshua Clayton
Describe an altera-passive-serial devicetree entry, required features
Signed-off-by Joshua Clayton <[email protected]>Acked-by Rob Herring <[email protected]>
Quoted 43 lines
--- .../bindings/fpga/altera-passive-serial.txt | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/fpga/altera-passive-serial.txtDocumentation/devicetree/bindings/fpga/altera-passive-serial.txt new file +29
-1@@ -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>; + }; --2.11.0
Re: [PATCH v12 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]>
Quoted 343 lines
--- 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.cdrivers/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 || COMPILE_TEST + 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_TESTdrivers/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.odrivers/fpga/altera-ps-spi.c new file +297
-1@@ -0,0 +1,297 @@ +/* +* Altera Passive Serial SPI Driver +* +* Copyright (c) 2017 United Western Technologies, Corporation +* +* Joshua Clayton <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* Manage Altera FPGA firmware that is loaded over SPI using the passive +* serial configuration method. +* Firmware must be in binary "rbf" format. +* Works on Arria 10, Cyclone V and Stratix V. Should work on Cyclone series. +* May work on other Altera FPGAs. +*/ + +#include <linux/bitrev.h> +#include <linux/delay.h> +#include <linux/fpga/fpga-mgr.h> +#include <linux/gpio/consumer.h> +#include <linux/module.h> +#include <linux/of_gpio.h> +#include <linux/of_device.h> +#include <linux/spi/spi.h> +#include <linux/sizes.h> + +enum altera_ps_devtype { +CYCLONE5 , +ARRIA10 , +}; + +struct altera_ps_data { +enum altera_ps_devtype devtype; +int status_wait_min_us; +int status_wait_max_us; +int t_cfg_us; +int t_st2ck_us; +}; + +struct altera_ps_conf { +struct gpio_desc *config; +struct gpio_desc *confd; +struct gpio_desc *status; +struct spi_device *spi; +const struct altera_ps_data *data; +u32 info_flags; +char mgr_name[64 ]; +}; + +/* | Arria 10 | Cyclone5 | Stratix5 | +* t_CF2ST0 | [; 600] | [; 600] | [; 600] |ns +* t_CFG | [2;] | [2;] | [2;] |?s +* t_STATUS | [268; 3000] | [268; 1506] | [268; 1506] |?s +* t_CF2ST1 | [; 3000] | [; 1506] | [; 1506] |?s +* t_CF2CK | [3010;] | [1506;] | [1506;] |?s +* t_ST2CK | [10;] | [2;] | [2;] |?s +* t_CD2UM | [175; 830] | [175; 437] | [175; 437] |?s +*/ +static struct altera_ps_data c5_data = { +/* these values for Cyclone5 are compatible with Stratix5 */ + .devtype =CYCLONE5 , + .status_wait_min_us =268 , + .status_wait_max_us =1506 , + .t_cfg_us =2 , + .t_st2ck_us =2 , +}; + +static struct altera_ps_data a10_data = { + .devtype =ARRIA10 , + .status_wait_min_us =268 ,/* min(t_STATUS) */ + .status_wait_max_us =3000 ,/* max(t_CF2ST1) */ + .t_cfg_us =2 ,/* max { min(t_CFG), max(tCF2ST0) } */ + .t_st2ck_us =10 ,/* min(t_ST2CK) */ +}; + +static const struct of_device_id of_ef_match[] = { + { .compatible ="altr,fpga-passive-serial" , .data = &c5_data }, + { .compatible ="altr,fpga-arria10-passive-serial" , .data = &a10_data }, + {} +}; +MODULE_DEVICE_TABLE (of, of_ef_match); + +static enum fpga_mgr_states altera_ps_state (struct fpga_manager *mgr) +{ +struct altera_ps_conf *conf = mgr->priv; + +if (gpiod_get_value_cansleep (conf->status)) +return FPGA_MGR_STATE_RESET ; + +return FPGA_MGR_STATE_UNKNOWN ; +} + +static inline void altera_ps_delay (int delay_us) +{ +if (delay_us >10 ) +usleep_range (delay_us, delay_us +5 ); +else +udelay (delay_us); +} + +static int altera_ps_write_init (struct fpga_manager *mgr, +struct fpga_image_info *info, +const char *buf,size_t count) +{ +struct altera_ps_conf *conf = mgr->priv; +int min, max, waits; +int i; + + conf->info_flags = info->flags; + +if (info->flags &FPGA_MGR_PARTIAL_RECONFIG ) { +dev_err (&mgr->dev,"Partial reconfiguration not supported.\n" ); +return -EINVAL ; + } + +gpiod_set_value_cansleep (conf->config,1 ); + +/* wait min reset pulse time */ +altera_ps_delay (conf->data->t_cfg_us); + +if (!gpiod_get_value_cansleep (conf->status)) { +dev_err (&mgr->dev,"Status pin failed to show a reset\n" ); +return -EIO ; + } + +gpiod_set_value_cansleep (conf->config,0 ); + + min = conf->data->status_wait_min_us; + max = conf->data->status_wait_max_us; + waits = max / min; +if (max % min) + waits++; + +/* wait for max { max(t_STATUS), max(t_CF2ST1) } */ +for (i =0 ; i < waits; i++) { +usleep_range (min, min +10 ); +if (!gpiod_get_value_cansleep (conf->status)) { +/* wait for min(t_ST2CK)*/ +altera_ps_delay (conf->data->t_st2ck_us); +return 0 ; + } + } + +dev_err (&mgr->dev,"Status pin not ready.\n" ); +return -EIO ; +} + +static void rev_buf (char *buf,size_t len) +{ +const char *fw_end = (buf + len); + +/* set buffer to lsb first */ +while (buf < fw_end) { + *buf =bitrev8 (*buf); + buf++; + } +} + +static int altera_ps_write (struct fpga_manager *mgr,const char *buf, +size_t count) +{ +struct altera_ps_conf *conf = mgr->priv; +const char *fw_data = buf; +const char *fw_data_end = fw_data + count; + +while (fw_data < fw_data_end) { +int ret; +size_t stride =min_t (size_t, fw_data_end - fw_data,SZ_4K ); + +if (!(conf->info_flags &FPGA_MGR_BITSTREAM_LSB_FIRST )) +rev_buf ((char *)fw_data, stride); + + ret =spi_write (conf->spi, fw_data, stride); +if (ret) { +dev_err (&mgr->dev,"spi error in firmware write: %d\n" , + ret); +return ret; + } + fw_data += stride; + } + +return 0 ; +} + +static int altera_ps_write_complete (struct fpga_manager *mgr, +struct fpga_image_info *info) +{ +struct altera_ps_conf *conf = mgr->priv; +const char dummy[] = {0 }; +int ret; + +if (gpiod_get_value_cansleep (conf->status)) { +dev_err (&mgr->dev,"Error during configuration.\n" ); +return -EIO ; + } + +if (!IS_ERR (conf->confd)) { +if (!gpiod_get_raw_value_cansleep (conf->confd)) { +dev_err (&mgr->dev,"CONF_DONE is inactive!\n" ); +return -EIO ; + } + } + +/* +* After CONF_DONE goes high, send two additional falling edges on DCLK +* to begin initialization and enter user mode +*/ + ret =spi_write (conf->spi, dummy,1 ); +if (ret) { +dev_err (&mgr->dev,"spi error during end sequence: %d\n" , ret); +return ret; + } + +return 0 ; +} + +static const struct fpga_manager_ops altera_ps_ops = { + .state = altera_ps_state, + .write_init = altera_ps_write_init, + .write = altera_ps_write, + .write_complete = altera_ps_write_complete, +}; + +static int altera_ps_probe (struct spi_device *spi) +{ +struct altera_ps_conf *conf; +const struct of_device_id *of_id; + + conf =devm_kzalloc (&spi->dev,sizeof (*conf),GFP_KERNEL ); +if (!conf) +return -ENOMEM ; + + of_id =of_match_device (of_ef_match, &spi->dev); +if (!of_id) +return -ENODEV ; + + conf->data = of_id->data; + conf->spi = spi; + conf->config =devm_gpiod_get (&spi->dev,"nconfig" ,GPIOD_OUT_HIGH ); +if (IS_ERR (conf->config)) { +dev_err (&spi->dev,"Failed to get config gpio: %ld\n" , +PTR_ERR (conf->config)); +return PTR_ERR (conf->config); + } + + conf->status =devm_gpiod_get (&spi->dev,"nstat" ,GPIOD_IN ); +if (IS_ERR (conf->status)) { +dev_err (&spi->dev,"Failed to get status gpio: %ld\n" , +PTR_ERR (conf->status)); +return PTR_ERR (conf->status); + } + + conf->confd =devm_gpiod_get (&spi->dev,"confd" ,GPIOD_IN ); +if (IS_ERR (conf->confd)) { +dev_warn (&spi->dev,"Not using confd gpio: %ld\n" , +PTR_ERR (conf->confd)); + } + +/* Register manager with unique name */ +snprintf (conf->mgr_name,sizeof (conf->mgr_name),"%s %s" , +dev_driver_string (&spi->dev),dev_name (&spi->dev)); + +return fpga_mgr_register (&spi->dev, conf->mgr_name, + &altera_ps_ops, conf); +} + +static int altera_ps_remove (struct spi_device *spi) +{ +fpga_mgr_unregister (&spi->dev); + +return 0 ; +} + +static const struct spi_device_id altera_ps_spi_ids[] = { + {"cyclone-ps-spi" ,0 }, + {} +}; +MODULE_DEVICE_TABLE (spi, altera_ps_spi_ids); + +static struct spi_driver altera_ps_driver = { + .driver = { + .name ="altera-ps-spi" , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (of_ef_match), + }, + .id_table = altera_ps_spi_ids, + .probe = altera_ps_probe, + .remove = altera_ps_remove, +}; + +module_spi_driver(altera_ps_driver) + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR ("Joshua Clayton <[email protected]>" ); +MODULE_DESCRIPTION ("Module to load Altera FPGA firmware over SPI" ); --2.11.0
Re: [PATCH v12 4/6] ARM: dts: imx6q-evi: support altera-ps-spi
In reply to Joshua ClaytonQuoted 4 lines · Joshua Clayton
Add support for Altera FPGA connected to an spi port to the evi devicetree file
Signed-off-by Joshua Clayton <[email protected]>
Quoted 41 lines
--- arch/arm/boot/dts/imx6q-evi.dts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)arch/arm/boot/dts/imx6q-evi.dts +16
-1@@ -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 --2.11.0
Re: [PATCH v12 5/6] lib: add bitrev8x4()
In reply to Joshua ClaytonQuoted 4 lines · Joshua Clayton
Add a function to reverse bytes within a 32 bit word. Operate on a u32 rather than individual bytes.
Signed-off-by Joshua Clayton <[email protected]>
Quoted 51 lines
--- include/linux/bitrev.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)include/linux/bitrev.h +19
-1@@ -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; \ --2.11.0
Re: [PATCH v12 6/6] fpga-manager: altera-ps-spi: use bitrev8x4
In reply to Joshua ClaytonOn Fri, Jun 2, 2017 at 3:30 PM, Joshua Clayton <[email protected]> wrote:
Hi Joshua,
Thanks for your work on this!
Alan
Quoted 4 lines
Speed up bit reversal by using hardware bit reversal Add extra code to handle less than 4byte remnants, if any
Signed-off-by Joshua Clayton <[email protected]>
Quoted 39 lines
--- drivers/fpga/altera-ps-spi.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)drivers/fpga/altera-ps-spi.c +15
-5@@ -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--; + } } } --2.11.0