This is an automated email from Gerrit.

"Daniel Anselmi <danse...@gmx.ch>" just uploaded a new patch set to Gerrit, 
which you can find at https://review.openocd.org/c/openocd/+/7823

-- gerrit

commit 8a473516bb2d75bfeda7e288d01c7fa76db2080a
Author: Daniel Anselmi <danse...@gmx.ch>
Date:   Mon Dec 12 16:47:16 2022 +0100

    jtagspi/pld: add support from lattice ecp2/ecp3 driver
    
    Change-Id: I39028aba47a74a0479be16d52d318f4bff7f2ed4
    Signed-off-by: Daniel Anselmi <danse...@gmx.ch>

diff --git a/src/pld/ecp2_3.c b/src/pld/ecp2_3.c
index b1c2833d53..a7b7580c72 100644
--- a/src/pld/ecp2_3.c
+++ b/src/pld/ecp2_3.c
@@ -21,6 +21,7 @@
 #define ISC_DISABLE          0x1E
 #define LSCC_READ_STATUS     0x53
 #define LSCC_BITSTREAM_BURST 0x02
+#define PROGRAM_SPI          0x3A
 
 #define STATUS_DONE_BIT        0x00020000
 #define STATUS_ERROR_BITS_ECP2 0x00040003
@@ -249,3 +250,57 @@ int lattice_ecp3_load(struct lattice_pld_device 
*lattice_device, struct lattice_
        const uint32_t expected = STATUS_DONE_BIT;
        return lattice_verify_status_register_u32(lattice_device, out, 
expected, mask, false);
 }
+
+int lattice_ecp2_3_connect_spi_to_jtag(struct lattice_pld_device 
*pld_device_info)
+{
+       if (!pld_device_info)
+               return ERROR_FAIL;
+
+       struct jtag_tap *tap = pld_device_info->tap;
+       if (!tap)
+               return ERROR_FAIL;
+
+       // erase configuration
+       int retval = lattice_set_instr(tap, ISC_ENABLE, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+       retval = lattice_set_instr(tap, ISC_ERASE, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+       retval = lattice_set_instr(tap, ISC_DISABLE, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+
+       // connect jtag to spi pins
+       retval = lattice_set_instr(tap, PROGRAM_SPI, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+
+       return jtag_execute_queue();
+}
+
+int lattice_ecp2_3_disconnect_spi_from_jtag(struct lattice_pld_device 
*pld_device_info)
+{
+       if (!pld_device_info)
+               return ERROR_FAIL;
+
+       struct jtag_tap *tap = pld_device_info->tap;
+       if (!tap)
+               return ERROR_FAIL;
+
+       int retval = lattice_set_instr(tap, BYPASS, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+
+       return jtag_execute_queue();
+}
+
+int lattice_ecp2_3_get_facing_read_bits(struct lattice_pld_device 
*pld_device_info, unsigned int *facing_read_bits)
+{
+       if (!pld_device_info)
+               return ERROR_FAIL;
+
+       *facing_read_bits = 1;
+
+       return ERROR_OK;
+}
diff --git a/src/pld/ecp2_3.h b/src/pld/ecp2_3.h
index 5f3e9e97b3..c5dec5693a 100644
--- a/src/pld/ecp2_3.h
+++ b/src/pld/ecp2_3.h
@@ -15,5 +15,8 @@ int lattice_ecp2_3_read_usercode(struct jtag_tap *tap, 
uint32_t *usercode, uint3
 int lattice_ecp2_3_write_usercode(struct lattice_pld_device *lattice_device, 
uint32_t usercode);
 int lattice_ecp2_load(struct lattice_pld_device *lattice_device, struct 
lattice_bit_file *bit_file);
 int lattice_ecp3_load(struct lattice_pld_device *lattice_device, struct 
lattice_bit_file *bit_file);
+int lattice_ecp2_3_connect_spi_to_jtag(struct lattice_pld_device 
*pld_device_info);
+int lattice_ecp2_3_disconnect_spi_from_jtag(struct lattice_pld_device 
*pld_device_info);
+int lattice_ecp2_3_get_facing_read_bits(struct lattice_pld_device 
*pld_device_info, unsigned int *facing_read_bits);
 
 #endif /* OPENOCD_PLD_ECP2_3_H */
diff --git a/src/pld/lattice.c b/src/pld/lattice.c
index 2075f4490d..ad7accc356 100644
--- a/src/pld/lattice.c
+++ b/src/pld/lattice.c
@@ -342,6 +342,67 @@ int lattice_get_ipdbg_hub(int user_num, struct pld_device 
*pld_device, struct pl
        return ERROR_OK;
 }
 
+static int lattice_connect_spi_to_jtag(struct pld_device *pld_device)
+{
+       if (!pld_device)
+               return ERROR_FAIL;
+
+       struct lattice_pld_device *pld_device_info = pld_device->driver_priv;
+
+       int retval = lattice_check_device_family(pld_device_info);
+       if (retval != ERROR_OK)
+               return retval;
+
+       if (pld_device_info->family == LATTICE_ECP2 || pld_device_info->family 
== LATTICE_ECP3)
+               return lattice_ecp2_3_connect_spi_to_jtag(pld_device_info);
+
+       return ERROR_FAIL;
+}
+
+static int lattice_disconnect_spi_from_jtag(struct pld_device *pld_device)
+{
+       if (!pld_device)
+               return ERROR_FAIL;
+
+       struct lattice_pld_device *pld_device_info = pld_device->driver_priv;
+
+       int retval = lattice_check_device_family(pld_device_info);
+       if (retval != ERROR_OK)
+               return retval;
+
+       if (pld_device_info->family == LATTICE_ECP2 || pld_device_info->family 
== LATTICE_ECP3)
+               return lattice_ecp2_3_disconnect_spi_from_jtag(pld_device_info);
+
+       return ERROR_FAIL;
+}
+
+static int lattice_get_facing_read_bits(struct pld_device *pld_device, 
unsigned int *facing_read_bits)
+{
+       if (!pld_device)
+               return ERROR_FAIL;
+
+       struct lattice_pld_device *pld_device_info = pld_device->driver_priv;
+
+       int retval = lattice_check_device_family(pld_device_info);
+       if (retval != ERROR_OK)
+               return retval;
+
+       if (pld_device_info->family == LATTICE_ECP2 || pld_device_info->family 
== LATTICE_ECP3)
+               return lattice_ecp2_3_get_facing_read_bits(pld_device_info, 
facing_read_bits);
+
+       return ERROR_FAIL;
+}
+
+static int lattice_get_jtagspi_info(struct pld_jtagspi *pld_jtagspi)
+{
+       pld_jtagspi->mode = JTAGSPI_MODE_SPECIFIC_INSTRUCTION;
+       pld_jtagspi->connect_spi_to_jtag = lattice_connect_spi_to_jtag;
+       pld_jtagspi->disconnect_spi_from_jtag = 
lattice_disconnect_spi_from_jtag;
+       pld_jtagspi->get_facing_read_bits = lattice_get_facing_read_bits;
+
+       return ERROR_OK;
+}
+
 PLD_CREATE_COMMAND_HANDLER(lattice_pld_create_command)
 {
        if (CMD_ARGC != 4 && CMD_ARGC != 6)
@@ -551,4 +612,5 @@ struct pld_driver lattice_pld = {
        .pld_create_command = &lattice_pld_create_command,
        .load = &lattice_load_command,
        .get_ipdbg_hub = lattice_get_ipdbg_hub,
+       .get_jtagspi_info = lattice_get_jtagspi_info,
 };

-- 

Reply via email to