[PATCH v14 0/2] Lattice sysCONFIG SPI FPGA manager

From: Ivan Bornyakov
Date: Thu Oct 06 2022 - 04:13:11 EST

Add support to the FPGA manager for programming Lattice ECP5 FPGA over
slave SPI sysCONFIG interface.

v1 -> v2:
* remove "spi" from compatible string
* reword description in dt-bindings doc
* add reference to spi-peripheral-props.yaml in dt-binding doc
* fix DTS example in dt-bindings doc: 4-spaces indentations, no
undersores in node names.
v2 -> v3:
* fix typo "##size-cells" -> "#size-cells" in dt-bindings example
v3 -> v4:
* dt-bindings: reword description
* dt-bindings: revert props order
v4 -> v5:
* dt-bindings: remove trailing dot from title
* dt-bindings: reword description to avoid driver reference
* dt-bindings: add "Reviewed-by: Krzysztof Kozlowski" tag
v5 -> v6:
* ecp5-spi: lock SPI bus for exclusive usage in
ecp5_ops_write_init(), release in ecp5_ops_write_complete()
or on error
v6 -> v7:
* ecp5-spi.c -> lattice-sysconfig-spi.c. Reworked to represent
generalized sysCONFIG port with implementations for ECP5 and
* lattice,ecp5-fpga-mgr.yaml -> lattice,sysconfig.yaml. Reworked to
document both ECP5 and MachXO2 sysCONFIG.
* dt-bindings: remove "Reviewed-by: Krzysztof Kozlowski" tag as doc
was rewritten by a considerable amount.
v7 -> v8:
* dt-bindings: move "program-gpios", "init-gpios" and "done-gpios"
to top-level properties and disallow them for MachXO2 variant.
v8 -> v9:
* dt-bindings: "program-gpios", "init-gpios" and "done-gpios" are
now optional for both ECP5 and MachXO2
* lattice-sysconfig-spi.c -> sysconfig-spi.c + sysconfig.c +
** reworked to be one sysCONFIG FPGA Manager rather than two
distinct ECP5 and MachXO2 managers
** splitted to port type agnostic sysconfig.c and SPI-specific
** command transfer function moved to callback for ease of
adding another port type, such as I2C
v9 -> v10:
* split sysconfig_transfer() callback into separate command_write()
and command_write_then_read(). There are too many transfers
without readback.
* add command_write_with_data() callback which performs single
transfer of command + data. It's needed for better abstraction of
paged bitstream write routine.
* move sysconfig_lsc_burst_init() to bitstream_burst_write_init()
callback to break dependence of sysconfig.c from sysconfig-spi.c
* move sysconfig_lsc_burst_complete() to bitstream_burst_write_complete()
callback to break dependence of sysconfig.c from sysconfig-spi.c
* add bitstream_burst_write() to abstract fpga_manager_ops->write()
from bus type
* remove struct spi_device from struct sysconfig_priv, use
* move fpga_manager_ops initialization to sysconfig.c
v10 -> v11:
* rename sysconfig_lsc_burst_init() to sysconfig_spi_lsc_burst_init()
* rename sysconfig_bitstream_burst_write() to
* rename sysconfig_lsc_burst_complete() to
* rename "ecp5-fpga-mgr" to "sysconfig-ecp5"
* rename "machxo2-fpga-mgr" to "sysconfig-machxo2"
* move spi_max_speed_hz from struct sysconfig_fpga_priv to
struct sysconfig_spi_fpga_priv, which is local to sysconfig-spi.c
* remove SPI bus unlock on write error form
sysconfig_spi_bitstream_burst_write(), call
sysconfig_burst_write_complete() on error in
sysconfig_bitstream_burst_write() instead.
v11 -> v12:
* build sysconfig core as separate module to prevent duplication of
common code segments across different binaries
* rename sysconfig.c to lattice-sysconfig.c
* rename sysconfig.h to lattice-sysconfig.h
* rename sysconfig-spi.c to lattice-sysconfig-spi.c
* rename sysconfig_spi_cmd_write_then_read() to
* rename command_write_then_read() callback to command_read()
* rename sysconfig_cmd_write_then_read() to sysconfig_cmd_read()
* rename sysconfig_spi_lsc_burst_init() to
* rename sysconfig_spi_lsc_burst_complete() to
* remove excessive !spi check from sysconfig_spi_cmd_write(),
sysconfig_spi_cmd_read(), sysconfig_spi_bitstream_burst_init(),
sysconfig_spi_bitstream_burst_write() and
* drop MachXO2 support
** drop struct sysconfig_fpga_priv
** drop paged write
** drop command_write_with_data() and friends
** drop ISC_PROGRAM_DONE routine
** drop refresh from sysconfig_isc_finish()
** sysconfig_isc_erase() only erase SRAM
** drop MachXO2 mentions from DT bindings doc
v12 -> v13:
* use device_get_match_data() instead of of_device_get_match_data()
and drop of_device.h inclusion
* in polling routines use time_before(jiffies, timeout) instead of
retries count
* add usleep_range() to gpio polling routine
* check fail status of command in more pronounced way
* check definition of sysconfig_priv callbacks at probe
* (BIT(23) | BIT(24) | BIT(25)) -> GENMASK(25, 23)
v13 -> v14:
* return -ETIMEDOUT instead of -EBUSY from sysconfig_poll_busy() to
align with sysconfig_poll_gpio()

Ivan Bornyakov (2):
fpga: lattice-sysconfig-spi: add Lattice sysCONFIG FPGA manager
dt-bindings: fpga: document Lattice sysCONFIG FPGA manager

.../bindings/fpga/lattice,sysconfig.yaml | 81 ++++
drivers/fpga/Kconfig | 11 +
drivers/fpga/Makefile | 2 +
drivers/fpga/lattice-sysconfig-spi.c | 151 ++++++
drivers/fpga/lattice-sysconfig.c | 428 ++++++++++++++++++
drivers/fpga/lattice-sysconfig.h | 41 ++
6 files changed, 714 insertions(+)
create mode 100644 Documentation/devicetree/bindings/fpga/lattice,sysconfig.yaml
create mode 100644 drivers/fpga/lattice-sysconfig-spi.c
create mode 100644 drivers/fpga/lattice-sysconfig.c
create mode 100644 drivers/fpga/lattice-sysconfig.h