Lattice MachXO2 Slave SPI FPGA Manager support
Subsystems (2)
v7 cover Lattice MachXO2 Slave SPI FPGA Manager support
Hi all,
this series adds support for the Lattice MachXO2 FPGA chip, programmed over Slave SPI.
Tested on a raspberry pi3, beaglebone black (little endian mode) and imx6 hummingboard (big endian mode) + bugblat's pif2 fpga hat (machxo2 7000HC) or tinyfpga A1/A2 (machxo2 256HC / 1200HC), in SPI slave mode with varying bus speed.
Changes since v6:
* added the SPDX boilerplate
* switched to pr_debug() and renamed MACHXO2_DEBUG to DEBUG
Paolo Pisati (2):
dt: bindings: fpga: add lattice machxo2 slave spi binding description
fpga: lattice machxo2: Add Lattice MachXO2 support
.../bindings/fpga/lattice-machxo2-spi.txt | 29 ++ drivers/fpga/Kconfig | 8 + drivers/fpga/Makefile | 1 + drivers/fpga/machxo2-spi.c | 405 +++++++++++++++++++++ 4 files changed, 443 insertions(+) create mode 100644 Documentation/devicetree/bindings/fpga/lattice-machxo2-spi.txt create mode 100644 drivers/fpga/machxo2-spi.c
Signature · 1 line
2.7.4
PATCH v7 1/2 dt: bindings: fpga: add lattice machxo2 slave spi binding description
Add dt binding documentation details for Lattice MachXO2 FPGA configuration over Slave SPI interface.
--- .../bindings/fpga/lattice-machxo2-spi.txt | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/fpga/lattice-machxo2-spi.txt
Documentation/devicetree/bindings/fpga/lattice-machxo2-spi.txt new file +29 -0
@@ -0,0 +1,29 @@ +Lattice MachXO2 Slave SPI FPGA Manager + +Lattice MachXO2 FPGAs support a method of loading the bitstream over +a 'slave SPI' interface. + +See 'MachXO2ProgrammingandConfigurationUsageGuide.pdf' on www.latticesemi.com + +Required properties: +- compatible: should contain "lattice,machxo2-slave-spi" +- reg: spi chip select of the FPGA + +Example for full FPGA configuration: + + fpga-region0 { + compatible = "fpga-region"; + fpga-mgr = <&fpga_mgr_spi>; + #address-cells = <0x1>; + #size-cells = <0x1>; + }; + + spi1: spi@2000 { + ... + + fpga_mgr_spi: fpga-mgr@0 { + compatible = "lattice,machxo2-slave-spi"; + spi-max-frequency = <8000000>; + reg = <0>; + }; + };
Signature · 1 line
2.7.4
PATCH v7 2/2 fpga: lattice machxo2: Add Lattice MachXO2 support
In reply to Paolo PisatiThis patch adds support to the FPGA manager for programming MachXO2 device’s internal flash memory, via slave SPI.
--- drivers/fpga/Kconfig | 8 + drivers/fpga/Makefile | 1 + drivers/fpga/machxo2-spi.c | 405 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 414 insertions(+) create mode 100644 drivers/fpga/machxo2-spi.c
drivers/fpga/Kconfig +8 -0
@@ -38,6 +38,14 @@ config FPGA_MGR_ALTERA_PS_SPI FPGA manager driver support for Altera Arria/Cyclone/Stratix using the passive serial interface over SPI. +config FPGA_MGR_MACHXO2_SPI + tristate "Lattice MachXO2 SPI" + depends on SPI + help + FPGA manager driver support for Lattice MachXO2 configuration + over slave SPI interface. + + config FPGA_MGR_SOCFPGA tristate "Altera SOCFPGA FPGA Manager" depends on ARCH_SOCFPGA || COMPILE_TEST
drivers/fpga/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-$(CONFIG_FPGA) += fpga-mgr.o obj-$(CONFIG_FPGA_MGR_ALTERA_CVP) += altera-cvp.o obj-$(CONFIG_FPGA_MGR_ALTERA_PS_SPI) += altera-ps-spi.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 obj-$(CONFIG_FPGA_MGR_SOCFPGA_A10) += socfpga-a10.o obj-$(CONFIG_FPGA_MGR_TS73XX) += ts73xx-fpga.o
drivers/fpga/machxo2-spi.c new file +405 -0
405 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH 2/2] fpga: lattice machxo2: Add Lattice MachXO2 support
Quoted 2 lines · Paolo Pisati
This patch adds support to the FPGA manager for programming MachXO2 device’s internal flash memory, via slave SPI.
style trivia:
drivers/fpga/machxo2-spi.c
Quoted 1 line
drivers/fpga/machxo2-spi.c +0
-0
[]
drivers/fpga/machxo2-spi.c line 70
Quoted 5 lines
drivers/fpga/machxo2-spi.c +5
-0+static int get_status (struct spi_device *spi,unsigned long *status) +{ +struct spi_message msg; +struct spi_transfer rx, tx; +u8 cmd[] =LSC_READ_STATUS ;
static const u8 cmd[]
here and everywhere else as all the tx_buf assignments of cmd are to const void *
drivers/fpga/machxo2-spi.c line 75
Quoted 5 lines
drivers/fpga/machxo2-spi.c +5
-0+int ret; + +memset (&rx,0 ,sizeof (rx)); +memset (&tx,0 ,sizeof (tx)); + tx.tx_buf = cmd;
[]
drivers/fpga/machxo2-spi.c line 92
Quoted 3 lines
drivers/fpga/machxo2-spi.c +3
-0+#ifdef DEBUG +static void dump_status_reg (unsigned long *status) +{
Instead of multiple declarations of dump_status_reg it's frequently nicer to use a style like
static void debug_func(args...)
{
#ifdef DEBUG [code...]
#endif
}
so if function arguments ever need to be changed it's only required to be changed in one spot and not multiply compilation tested with and without the DEBUG definition
Quoted 20 lines
drivers/fpga/machxo2-spi.c +20
-0+char *ferr; + +switch (get_err (status)) { +case ENOERR : + ferr ="No Error" ; +break ; +case EID : + ferr ="ID ERR" ; +break ; +case ECMD : + ferr ="CMD ERR" ; +break ; +case ECRC : + ferr ="CRC ERR" ; +break ; +case EPREAM : + ferr ="Preamble ERR" ; +break ; +case EABRT : + ferr ="Abort ERR" ;
drivers/fpga/machxo2-spi.c line 122
Quoted 10 lines
drivers/fpga/machxo2-spi.c +10
-0+break ; +case EOVERFL : + ferr ="Overflow ERR" ; +break ; +case ESDMEOF : + ferr ="SDM EOF" ; +break ; +default : + ferr ="Default switch case" ; + }
It's frequently nicer to use a static function for these enum -> string conversions like:
static const char *get_err_string(unsigned long err)
{
switch (err) {
case ENOERR: return "No Error";
case EID: return "ID ERR";
case ECMD: return "CMD ERR";
[...]
}
return "default switch case";
}drivers/fpga/machxo2-spi.c line 126
Quoted 4 lines
drivers/fpga/machxo2-spi.c +4
-0+pr_debug ("machxo2 status: 0x%08lX - done=%d, cfgena=%d, busy=%d, fail=%d, devver=%d, err=%s\n" , + *status,test_bit (DONE , status),test_bit (ENAB , status), +test_bit (BUSY , status),test_bit (FAIL , status), +test_bit (DVER , status), ferr);
So instead of ferr, this could use
get_err_string(*status)
And please try to keep a consistent alignment for indentation of multiple line statements
Quoted 12 lines
drivers/fpga/machxo2-spi.c +12
-0+} +#else +static void dump_status_reg (unsigned long *status) {} +#endif + +static int wait_until_not_busy (struct spi_device *spi) +{ +unsigned long status; +int ret, loop =0 ; + + do { + ret = get_status(spi, &status);
drivers/fpga/machxo2-spi.c line 148
Quoted 10 lines
drivers/fpga/machxo2-spi.c +10
-0+if (ret) +break ; +if (++loop >=MACHXO2_MAX_BUSY_LOOP ) { + ret = -EBUSY ; +break ; + } + }while (test_bit (BUSY , &status)); + +return ret; +}
Direct returns are OK and would shorten the function line count.
Re: [PATCH 2/2] fpga: lattice machxo2: Add Lattice MachXO2 support
Quoted 4 lines · Joe Perches
static const u8 cmd[]
here and everywhere else as all thetx_bufassignments of cmd are to const void *
Ok
Quoted 7 lines
Instead of multiple declarations of
dump_status_regit's frequently nicer to use a style likestatic void
debug_func(args...)
{#ifdef DEBUG [code...]
Quoted 7 lines
#endif
}so if function arguments ever need to be changed it's only required to be changed in one spot and not multiply compilation tested with and without the DEBUG definition
Ok
Quoted 4 lines
It's frequently nicer to use a static function for these enum -> string conversions like:
static const char *get_err_string(unsigned long err)
Quoted 9 lines
{
switch (err) {
case ENOERR: return "No Error";
case EID: return "ID ERR";
case ECMD: return "CMD ERR";
[...]
}
return "default switch case";
}Ok - checkpatch complained when i put the "case ...: return ...;" on the same line as you did here, that is why i ended up with the ugly "case...: $string; break" all on different lines
Quoted 10 lines
drivers/fpga/machxo2-spi.c line 126
Quoted 4 lines
drivers/fpga/machxo2-spi.c new file +4
-0+pr_debug ("machxo2 status: 0x%08lX - done=%d, cfgena=%d, busy=%d, fail=%d, devver=%d, err=%s\n" , + *status,test_bit (DONE , status),test_bit (ENAB , status), +test_bit (BUSY , status),test_bit (FAIL , status), +test_bit (DVER , status), ferr);So instead of ferr, this could use
get_err_string(*status)And please try to keep a consistent alignment for indentation of multiple line statements
I tried, but then checkpatch complained again about the indentation of the above block and i literally had to guess...
Anyhow, thanks, i'll send a v8 with all these style fixes.
Signature · 2 lines
bye, p.
Re: [PATCH 2/2] fpga: lattice machxo2: Add Lattice MachXO2 support
Quoted 14 lines · Paolo Pisati
Quoted 4 lines
It's frequently nicer to use a static function
for these enum -> string conversions like:static const char *get_err_string(unsigned long err)
Quoted 9 lines
{ switch (err) { case ENOERR: return "No Error"; case EID: return "ID ERR"; case ECMD: return "CMD ERR"; [...] } return "default switch case"; }
Quoted 3 lines
Ok - checkpatch complained when i put the "case ...: return ...;" on the same line as you did here, that is why i ended up with the ugly "case...: $string; break" all on different lines
checkpatch is brainless and stupid and if it recommends stupid consistency over readability, ignore it.
Quoted 8 lines
Quoted 8 lines
drivers/fpga/machxo2-spi.c line 126
Quoted 4 lines
drivers/fpga/machxo2-spi.c new file +4
-0+pr_debug ("machxo2 status: 0x%08lX - done=%d, cfgena=%d, busy=%d, fail=%d, devver=%d, err=%s\n" , + *status,test_bit (DONE , status),test_bit (ENAB , status), +test_bit (BUSY , status),test_bit (FAIL , status), +test_bit (DVER , status), ferr);So instead of ferr, this could use
get_err_string(*status)
Quoted 5 lines
Quoted 2 lines
And please try to keep a consistent alignment for
indentation of multiple line statementsI tried, but then checkpatch complained again about the indentation of the above block and i literally had to guess...
I think it only complained about the 2nd line that starts *status because it doesn't align with the open parenthesis of pr_debug
Re: [PATCH 2/2] fpga: lattice machxo2: Add Lattice MachXO2 support
In reply to Joe PerchesQuoted 8 lines · Joe Perches
Quoted 2 lines · Paolo Pisati
This patch adds support to the FPGA manager for programming MachXO2 device’s internal flash memory, via slave SPI.
style trivia:
drivers/fpga/machxo2-spi.c
Quoted 1 line
drivers/fpga/machxo2-spi.c +0
-0[]
Quoted 9 lines
drivers/fpga/machxo2-spi.c line 70
Quoted 5 lines
drivers/fpga/machxo2-spi.c +5
-0+static int get_status (struct spi_device *spi,unsigned long *status) +{ +struct spi_message msg; +struct spi_transfer rx, tx; +u8 cmd[] =LSC_READ_STATUS ;static const u8 cmd[]
here and everywhere else as all thetx_bufassignments of cmd are to const void *
Why *static* const u8 cmd[]?
Alan
Quoted 110 lines
drivers/fpga/machxo2-spi.c line 75
Quoted 6 lines
drivers/fpga/machxo2-spi.c +5
-0+int ret; + +memset (&rx,0 ,sizeof (rx)); +memset (&tx,0 ,sizeof (tx)); + tx.tx_buf = cmd;[]
drivers/fpga/machxo2-spi.c line 92
Quoted 3 lines
drivers/fpga/machxo2-spi.c +3
-0+#ifdef DEBUG +static void dump_status_reg (unsigned long *status) +{Instead of multiple declarations of
dump_status_regit's frequently nicer to use a style likestatic void
debug_func(args...)
{#ifdef DEBUG [code...]#endif
}so if function arguments ever need to be changed it's only required to be changed in one spot and not multiply compilation tested with and without the DEBUG definition
Quoted 20 lines
drivers/fpga/machxo2-spi.c +20
-0+char *ferr; + +switch (get_err (status)) { +case ENOERR : + ferr ="No Error" ; +break ; +case EID : + ferr ="ID ERR" ; +break ; +case ECMD : + ferr ="CMD ERR" ; +break ; +case ECRC : + ferr ="CRC ERR" ; +break ; +case EPREAM : + ferr ="Preamble ERR" ; +break ; +case EABRT : + ferr ="Abort ERR" ;drivers/fpga/machxo2-spi.c line 122
Quoted 10 lines
drivers/fpga/machxo2-spi.c +10
-0+break ; +case EOVERFL : + ferr ="Overflow ERR" ; +break ; +case ESDMEOF : + ferr ="SDM EOF" ; +break ; +default : + ferr ="Default switch case" ; + }It's frequently nicer to use a static function for these enum -> string conversions like:
static const char *get_err_string(unsigned long err)
{ switch (err) { case ENOERR: return "No Error"; case EID: return "ID ERR"; case ECMD: return "CMD ERR"; [...] } return "default switch case"; }drivers/fpga/machxo2-spi.c line 126
Quoted 4 lines
drivers/fpga/machxo2-spi.c +4
-0+pr_debug ("machxo2 status: 0x%08lX - done=%d, cfgena=%d, busy=%d, fail=%d, devver=%d, err=%s\n" , + *status,test_bit (DONE , status),test_bit (ENAB , status), +test_bit (BUSY , status),test_bit (FAIL , status), +test_bit (DVER , status), ferr);So instead of ferr, this could use
get_err_string(*status)And please try to keep a consistent alignment for indentation of multiple line statements
Quoted 12 lines
drivers/fpga/machxo2-spi.c +12
-0+} +#else +static void dump_status_reg (unsigned long *status) {} +#endif + +static int wait_until_not_busy (struct spi_device *spi) +{ +unsigned long status; +int ret, loop =0 ; + + do { + ret = get_status(spi, &status);drivers/fpga/machxo2-spi.c line 148
Quoted 10 lines
drivers/fpga/machxo2-spi.c +10
-0+if (ret) +break ; +if (++loop >=MACHXO2_MAX_BUSY_LOOP ) { + ret = -EBUSY ; +break ; + } + }while (test_bit (BUSY , &status)); + +return ret; +}Direct returns are OK and would shorten the function line count.
Re: [PATCH 2/2] fpga: lattice machxo2: Add Lattice MachXO2 support
Quoted 20 lines · Alan Tull
Quoted 9 lines · Joe Perches
Quoted 2 lines · Paolo Pisati
This patch adds support to the FPGA manager for programming MachXO2 device’s internal flash memory, via slave SPI.
style trivia:
drivers/fpga/machxo2-spi.c
Quoted 1 line
drivers/fpga/machxo2-spi.c +0
-0[]
Quoted 9 lines
drivers/fpga/machxo2-spi.c line 70
Quoted 5 lines
drivers/fpga/machxo2-spi.c +5
-0+static int get_status (struct spi_device *spi,unsigned long *status) +{ +struct spi_message msg; +struct spi_transfer rx, tx; +u8 cmd[] =LSC_READ_STATUS ;static const u8 cmd[]
here and everywhere else as all thetx_bufassignments of cmd are to const void *
Quoted 1 line
Why *static* const u8 cmd[]?
So various compilers don't reload it on each call.