Altera Cyclone Passive Serial SPI FPGA Manager
Subsystems (4)
v5 cover Altera Cyclone Passive Serial SPI FPGA Manager
This series adds an FPGA manager for Altera cyclone FPGAs that can program them using an spi port and a couple of gpios, using Alteras passive serial protocol.
Still need an ACK from Russell King on the ARM specific portion of patch 1. Any comment/criticism on the addition of bitrev8x4() to bitrev.h would be welcome as well.
Changes from v4:
- Added the needed return statement to __arch_bitrev8x4()
- Added Rob Herrings ACK for and fix a typo in the commit log of patch 2
Changes from v3:
- Fixed up the state() function to return the state of the status pin reqested by Alan Tull
- Switched the pin to ACTIVE_LOW and coresponding logic level, and updated the corresponding documentation. Thanks Rob Herring for pointing out my mistake.
- Per Rob Herring, switched from "gpio" to "gpios" in dts
Changes from v2:
- Merged patch 3 and 4 as suggested in review by Moritz Fischer
- Changed FPGA_MIN_DELAY from 250 to 50 ms is the time advertized by Altera. This now works, as we don't assume it is done
Changes from v1:
- Changed the name from cyclone-spi-fpga-mgr to cyclone-ps-spi-fpga-mgr This name change was requested by Alan Tull, to be specific about which programming method is being employed on the fpga.
- Changed the name of the reset-gpio to config-gpio to closer match the way the pins are described in the Altera manual
- Moved MODULE_LICENCE, _AUTHOR, and _DESCRIPTION to the bottom
- Added a bitrev8x4() function to the bitrev headers and implemented ARM const, runtime, and ARM specific faster versions (This may end up needing to be a standalone patch)
- Moved the bitswapping into cyclonespi_write(), as requested. This falls short of my desired generic lsb first spi support, but is a step in that direction.
- Fixed whitespace problems introduced during refactoring
- Replaced magic number for initial delay with a descriptive macro
- Poll the fpga to see when it is ready rather than a fixed 1 ms sleep
Joshua Clayton (3):
lib: add bitrev8x4()
doc: dt: add cyclone-ps-spi binding document fpga manager: Add cyclone-ps-spi driver for Altera FPGAs
.../bindings/fpga/cyclone-ps-spi-fpga-mgr.txt | 25 +++ arch/arm/include/asm/bitrev.h | 6 + drivers/fpga/Kconfig | 7 + drivers/fpga/Makefile | 1 + drivers/fpga/cyclone-ps-spi.c | 181 +++++++++++++++++++++ include/linux/bitrev.h | 26 +++ 6 files changed, 246 insertions(+) create mode 100644 Documentation/devicetree/bindings/fpga/cyclone-ps-spi-fpga-mgr.txt create mode 100644 drivers/fpga/cyclone-ps-spi.c
Signature · 1 line
2.9.3
PATCH v5 1/3 lib: add bitrev8x4()
Add a function to reverse bytes within a 32 bit word. This function is more efficient than using the 8 bit version when iterating over an array
--- arch/arm/include/asm/bitrev.h | 6 ++++++ include/linux/bitrev.h | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
arch/arm/include/asm/bitrev.h +6 -0
@@ -17,4 +17,10 @@ static __always_inline __attribute_const__ u8 __arch_bitrev8(u8 x)return __arch_bitrev32 ((u32 )x) >>24 ; } +static __always_inline __attribute_const__ u32 __arch_bitrev8x4(u32 x) +{ + __asm__ ("rbit %0, %1; rev %0, %0" :"=r" (x) :"r" (x)); +return x; +} +#endif
include/linux/bitrev.h +26 -0
@@ -9,6 +9,7 @@#define __bitrev32 __arch_bitrev32#define __bitrev16 __arch_bitrev16#define __bitrev8 __arch_bitrev8 +#define __bitrev8x4 __arch_bitrev8x4#else extern u8 const byte_rev_table[256 ];
@@ -27,6 +28,14 @@ static inline u32 __bitrev32(u32 x) return (__bitrev16(x & 0xffff) << 16) | __bitrev16(x >> 16); } +static inline u32 __bitrev8x4 (u32 x) +{ +return (__bitrev8 (x &0xff ) | + (__bitrev8 ((x >>8 ) &0xff ) <<8 ) | + (__bitrev8 ((x >>16 ) &0xff ) <<16 ) | + (__bitrev8 ((x >>24 ) &0xff ) <<24 )); +} +#endif /* CONFIG_HAVE_ARCH_BITREVERSE */ #define __constant_bitrev32 (x) \
@@ -50,6 +59,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 +93,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.9.3
PATCH v5 2/3 doc: dt: add cyclone-ps-spi binding document
In reply to Joshua ClaytonDescribe a cyclone-ps-spi devicetree entry, required features
--- .../bindings/fpga/cyclone-ps-spi-fpga-mgr.txt | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Documentation/devicetree/bindings/fpga/cyclone-ps-spi-fpga-mgr.txt
Documentation/devicetree/bindings/fpga/cyclone-ps-spi-fpga-mgr.txt new file +25 -0
@@ -0,0 +1,25 @@ +Altera Cyclone Passive Serial SPI FPGA Manager + +Altera Cyclone 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 : should contain "altr,cyclone-ps-spi-fpga-mgr" +- reg : spi slave id of the fpga +- config-gpios : config pin (referred to as nCONFIG in the cyclone manual) +- status-gpios : status pin (referred to as nSTATUS in the cyclone manual) + +both gpios pins are normally active low open drain. + +Example: + fpga_spi: evi-fpga-spi at 0 { + compatible = "altr,cyclone-ps-spi-fpga-mgr"; + spi-max-frequency = <20000000>; + reg = <0>; + config-gpios = <&gpio4 9 GPIO_ACTIVE_LOW>; + status-gpios = <&gpio4 11 GPIO_ACTIVE_LOW>; + };
Signature · 1 line
2.9.3
PATCH v5 3/3 fpga manager: Add cyclone-ps-spi driver for Altera FPGAs
In reply to Joshua Claytoncyclone-ps-spi loads FPGA firmware over spi, using the "passive serial" interface on Altera Cyclone 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/cyclone-ps-spi.c | 181 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 drivers/fpga/cyclone-ps-spi.c
drivers/fpga/Kconfig +7 -0
@@ -13,6 +13,13 @@ config FPGA if FPGA +config FPGA_MGR_CYCLONE_PS_SPI + tristate "Altera Cyclone FPGA Passive Serial over SPI" + depends on SPI + help + FPGA manager driver support for Altera Cyclone using the + passive serial interface over SPI + config FPGA_MGR_SOCFPGA tristate "Altera SOCFPGA FPGA Manager" depends on ARCH_SOCFPGA
drivers/fpga/Makefile +1 -0
@@ -6,5 +6,6 @@ obj-$(CONFIG_FPGA) += fpga-mgr.o # FPGA Manager Drivers +obj-$(CONFIG_FPGA_MGR_CYCLONE_PS_SPI) += cyclone-ps-spi.o obj-$(CONFIG_FPGA_MGR_SOCFPGA) += socfpga.o obj-$(CONFIG_FPGA_MGR_ZYNQ_FPGA) += zynq-fpga.o
drivers/fpga/cyclone-ps-spi.c new file +181 -0
181 lines not on this page · raw message
Signature · 1 line
2.9.3
Re: [PATCH v5 3/3] fpga manager: Add cyclone-ps-spi driver for Altera FPGAs
On Wed, 7 Dec 2016 13:04:40 -0800
Joshua Clayton stillcompiling at gmail.com wrote:
...
drivers/fpga/cyclone-ps-spi.c line 49
Quoted 2 lines
drivers/fpga/cyclone-ps-spi.c new file +2
-0+static int cyclonespi_write_init (struct fpga_manager *mgr,u32 flags, +const char *buf,size_t count)
there is a minor API change in linux-next [1]. struct fpga_image_info * is passed instead of u32 flags. I assume this will be merged soon, so please prepare this driver accordingly.
...
Quoted 1 line
+static int
cyclonespi_write_complete(struct fpga_manager *mgr, u32 flags)
same here.
--
Anatolij
Re: [PATCH v5 3/3] fpga manager: Add cyclone-ps-spi driver for Altera FPGAs
Anatolij,
Thanks for the quick look and response.
I guess I should have rebased before submitting.
I just realized I also forgot to send this patch series to the newly minted FPGA Manager mailing list. V6 coming soon :)
Quoted 10 lines · Anatolij Gustschin
On Wed, 7 Dec 2016 13:04:40 -0800
Joshua Clayton stillcompiling at gmail.com wrote:
...drivers/fpga/cyclone-ps-spi.c line 49
Quoted 2 lines
drivers/fpga/cyclone-ps-spi.c new file +2
-0+static int cyclonespi_write_init (struct fpga_manager *mgr,u32 flags, +const char *buf,size_t count)there is a minor API change in linux-next [1]. struct
fpga_image_info* is passed instead of u32 flags. I assume this will be merged soon, so please prepare this driver accordingly....
Ah. Thanks.
Quoted 2 lines
Quoted 1 line
+static int
cyclonespi_write_complete(struct fpga_manager *mgr, u32 flags)same here.
OK.
Quoted 5 lines
--
Anatolij
Joshua
Re: [PATCH v5 3/3] fpga manager: Add cyclone-ps-spi driver for Altera FPGAs
Quoted 3 lines · On Wed, 7 Dec 2016 13:29:29 -0800 Joshua Clayton stillcompiling at gmail.com…
Anatolij,
Thanks for the quick look and response.
I guess I should have rebased before submitting.
yes, Makefile and Kconfig changes need rebasing, I think.
Quoted 2 lines
I just realized I also forgot to send this patch series to the newly minted FPGA Manager mailing list. V6 coming soon :)
okay, thanks.
--
Anatolij
kbuild test robot
build botRe: [PATCH v5 3/3] fpga manager: Add cyclone-ps-spi driver for Altera FPGAs
In reply to Joshua Claytonurl: https://github.com/0day-ci/linux/commits/Joshua-Clayton/lib-add-bitrev8x4/20161208-070638 config: arm64-allmodconfig (attached as .config) compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1…
Hi Joshua,
[auto build test ERROR on linus/master]
[also build test ERROR on v4.9-rc8]
[cannot apply to next-20161209]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Joshua-Clayton/lib-add-bitrev8x4/20161208-070638
config: arm64-allmodconfig (attached as .config)
compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64
All errors (new ones prefixed by >>):
In file included from drivers/fpga/cyclone-ps-spi.c:13:0:
drivers/fpga/cyclone-ps-spi.c: In function 'rev_buf':
>> include/linux/bitrev.h:12:21: error: implicit declaration of function '__arch_bitrev8x4' [-Werror=implicit-function-declaration]
#define __bitrev8x4 __arch_bitrev8x4
^
include/linux/bitrev.h:101:2: note: in expansion of macro '__bitrev8x4'
__bitrev8x4(__x); \
^~~~~~~~~~~
drivers/fpga/cyclone-ps-spi.c:84:11: note: in expansion of macro 'bitrev8x4'
*fw32 = bitrev8x4(*fw32);
^~~~~~~~~
In file included from include/linux/delay.h:10:0,
from drivers/fpga/cyclone-ps-spi.c:14:
drivers/fpga/cyclone-ps-spi.c: In function 'cyclonespi_write':
include/linux/kernel.h:739:16: warning: comparison of distinct pointer types lacks a cast
(void) (&min1 == &min2); \
^
include/linux/kernel.h:742:2: note: in expansion of macro '__min'
__min(typeof(x), typeof(y), \
^~~~~
drivers/fpga/cyclone-ps-spi.c:98:19: note: in expansion of macro 'min'
size_t stride = min(fw_data_end - fw_data, SZ_4K);
^~~cc1: some warnings being treated as errors
vim +/__arch_bitrev8x4 +12 include/linux/bitrev.h
556d2f05 Yalin Wang 2014-11-03 6 #ifdef CONFIG_HAVE_ARCH_BITREVERSE 556d2f05 Yalin Wang 2014-11-03 7 #include <asm/bitrev.h> 556d2f05 Yalin Wang 2014-11-03 8 556d2f05 Yalin Wang 2014-11-03 9 #define __bitrev32 __arch_bitrev32 556d2f05 Yalin Wang 2014-11-03 10 #define __bitrev16 __arch_bitrev16 556d2f05 Yalin Wang 2014-11-03 11 #define __bitrev8 __arch_bitrev8 533d0eab Joshua Clayton 2016-12-07 @12 #define __bitrev8x4 __arch_bitrev8x4 a5cfc1ec Akinobu Mita 2006-12-08 13 556d2f05 Yalin Wang 2014-11-03 14 #else 556d2f05 Yalin Wang 2014-11-03 15 extern u8 const byte_rev_table[256];
:::::: The code at line 12 was first introduced by commit :::::: 533d0eabff8f37edfdec7fdf6e705fdecb297daa lib: add bitrev8x4()
:::::: TO: Joshua Clayton <[email protected]> :::::: CC: 0day robot <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation