aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Anselmi <danselmi@gmx.ch>2023-02-24 15:57:30 +0100
committerAntonio Borneo <borneo.antonio@gmail.com>2023-09-23 14:33:59 +0000
commit2b99846ab67dd53540a18ed43fc9394c94f940ff (patch)
tree37dd288c4a02125daf9033288fad9ee3e234a77d
parentfe5ed48f40e4f1b36d74900d0d9b410affea6bdb (diff)
downloadriscv-openocd-2b99846ab67dd53540a18ed43fc9394c94f940ff.zip
riscv-openocd-2b99846ab67dd53540a18ed43fc9394c94f940ff.tar.gz
riscv-openocd-2b99846ab67dd53540a18ed43fc9394c94f940ff.tar.bz2
jtagspi/pld: add support from lattice ecp2/ecp3 driver
Provide jtagspi with specific procedures to be able to use jtagspi for programming spi-flash devices on lattice ecp2 and ecp3 devices. Change-Id: I39028aba47a74a0479be16d52d318f4bff7f2ed4 Signed-off-by: Daniel Anselmi <danselmi@gmx.ch> Reviewed-on: https://review.openocd.org/c/openocd/+/7823 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
-rw-r--r--src/pld/ecp2_3.c55
-rw-r--r--src/pld/ecp2_3.h3
-rw-r--r--src/pld/lattice.c62
3 files changed, 120 insertions, 0 deletions
diff --git a/src/pld/ecp2_3.c b/src/pld/ecp2_3.c
index b1c2833..a7b7580 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 5f3e9e97..c5dec56 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 0cd08dd..4085ec1 100644
--- a/src/pld/lattice.c
+++ b/src/pld/lattice.c
@@ -342,6 +342,64 @@ static int lattice_get_ipdbg_hub(int user_num, struct pld_device *pld_device, st
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_stuff_bits(struct pld_device *pld_device, unsigned int *facing_read_bits,
+ unsigned int *trailing_write_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_has_jtagspi_instruction(struct pld_device *device, bool *has_instruction)
+{
+ *has_instruction = true;
+ return ERROR_OK;
+}
+
PLD_CREATE_COMMAND_HANDLER(lattice_pld_create_command)
{
if (CMD_ARGC != 4 && CMD_ARGC != 6)
@@ -551,4 +609,8 @@ struct pld_driver lattice_pld = {
.pld_create_command = &lattice_pld_create_command,
.load = &lattice_load_command,
.get_ipdbg_hub = lattice_get_ipdbg_hub,
+ .has_jtagspi_instruction = lattice_has_jtagspi_instruction,
+ .connect_spi_to_jtag = lattice_connect_spi_to_jtag,
+ .disconnect_spi_from_jtag = lattice_disconnect_spi_from_jtag,
+ .get_stuff_bits = lattice_get_stuff_bits,
};