This is an automated email from Gerrit.

"Conor Paxton <conor.pax...@microchip.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8553

-- gerrit

commit 39698effd618c4b1282b3f34d303d82e08918bf4
Author: Conor Paxton <conor.pax...@microchip.com>
Date:   Wed May 22 00:13:00 2024 +0100

    jtag: drivers: add microchip flashpro5 support
    
    This patch adds support for Microchip's FlashPro5 debug probe.
    
    Change-Id: Ic4a718180165048f42cbe5e25c2992d491cc5e4c
    Signed-off-by: Tommy Murphy <tommy_mur...@hotmail.com>
    Signed-off-by: Anton Krug <anton.k...@gmail.com>
    Signed-off-by: Daire McNamara <daire.mcnam...@microchip.com>
    Signed-off-by: Matteo Bonicolini <matteo.bonicol...@microchip.com>
    Signed-off-by: Conor Paxton <conor.pax...@microchip.com>

diff --git a/configure.ac b/configure.ac
index cbd2ecedb2..e1c974520a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -355,6 +355,10 @@ AC_ARG_ENABLE([microchip_efp6],
   AS_HELP_STRING([--enable-microchip-efp6], [Enable building support for 
Microchip embedded FlashPro6 Programmer]),
   [build_microchip_efp6=$enableval], [build_microchip_efp6=no])
 
+AC_ARG_ENABLE([microchip_fp5],
+  AS_HELP_STRING([--enable-microchip-fp5], [Enable building support for 
Microchip FlashPro5 Programmer]),
+  [build_microchip_fp5=$enableval], [build_microchip_fp5=no])
+
 AS_CASE([$host_os],
   [linux*], [
     is_linux=yes
@@ -642,6 +646,13 @@ AS_IF([test "x$build_microchip_efp6" = "xyes"], [
   AC_DEFINE([BUILD_MICROCHIP_EFP6], [0], [0 if you don't the Microchip 
embedded FlashPro6 driver.])
 ])
 
+AS_IF([test "x$build_microchip_fp5" = "xyes"], [
+  build_microchip_fp5=yes
+  AC_DEFINE([BUILD_MICROCHIP_FP5], [1], [1 if you want the Microchip FlashPro5 
driver.])
+], [
+  AC_DEFINE([BUILD_MICROCHIP_FP5], [0], [0 if you don't want the Microchip 
FlashPro5 driver.])
+])
+
 PKG_CHECK_MODULES([LIBUSB1], [libusb-1.0], [
        use_libusb1=yes
        AC_DEFINE([HAVE_LIBUSB1], [1], [Define if you have libusb-1.x])
@@ -806,6 +817,7 @@ AM_CONDITIONAL([DMEM], [test "x$build_dmem" = "xyes"])
 AM_CONDITIONAL([HAVE_CAPSTONE], [test "x$enable_capstone" != "xno"])
 AM_CONDITIONAL([MICROCHIP_FP6], [test "x$build_microchip_fp6" = "xyes"])
 AM_CONDITIONAL([MICROCHIP_EFP6], [test "x$build_microchip_efp6" = "xyes"])
+AM_CONDITIONAL([MICROCHIP_FP5], [test "x$build_microchip_fp5" = "xyes"])
 
 AM_CONDITIONAL([INTERNAL_JIMTCL], [test "x$use_internal_jimtcl" = "xyes"])
 AM_CONDITIONAL([HAVE_JIMTCL_PKG_CONFIG], [test "x$have_jimtcl_pkg_config" = 
"xyes"])
diff --git a/src/jtag/drivers/Makefile.am b/src/jtag/drivers/Makefile.am
index 3ef4d4f6c3..20fdd67cef 100644
--- a/src/jtag/drivers/Makefile.am
+++ b/src/jtag/drivers/Makefile.am
@@ -210,6 +210,9 @@ endif
 if MICROCHIP_EFP6
 DRIVERFILES += %D%/mchp_efp6.c
 endif
+if MICROCHIP_FP5
+DRIVERFILES += %D%/mchp_ftdi.c
+endif
 
 DRIVERHEADERS = \
        %D%/bitbang.h \
diff --git a/src/jtag/drivers/ftdi.c b/src/jtag/drivers/ftdi.c
index 42ecda117b..7c9d380b19 100644
--- a/src/jtag/drivers/ftdi.c
+++ b/src/jtag/drivers/ftdi.c
@@ -917,6 +917,13 @@ COMMAND_HANDLER(ftdi_handle_tdo_sample_edge_command)
        return ERROR_OK;
 }
 
+COMMAND_HANDLER(ftdi_init_bank_d_command)
+{
+       extern void interface_d_init(void);
+       interface_d_init();
+       return ERROR_OK;
+}
+
 static const struct command_registration ftdi_subcommand_handlers[] = {
        {
                .name = "device_desc",
@@ -978,6 +985,13 @@ static const struct command_registration 
ftdi_subcommand_handlers[] = {
                        "allow signalling speed increase)",
                .usage = "(rising|falling)",
        },
+       {
+               .name = "init_bank_d",
+               .handler = &ftdi_init_bank_d_command,
+               .mode = COMMAND_CONFIG,
+               .help = "for some devices, you may need to initialize bank d",
+               .usage = "init_bank_d"
+       },
        COMMAND_REGISTRATION_DONE
 };
 
diff --git a/src/jtag/drivers/mchp_ftdi.c b/src/jtag/drivers/mchp_ftdi.c
new file mode 100644
index 0000000000..dfd129a847
--- /dev/null
+++ b/src/jtag/drivers/mchp_ftdi.c
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/***************************************************************************
+ *   Copyright (C) 2024 by Microchip Inc.                                  *
+ *   matteo.bonicol...@microchip.com                                       *
+ ***************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "config.h"
+#include "libftdi_helper.h"
+#include "helper/log.h"
+
+#define MCHP_FP5_VID (0x1514)
+#define MCHP_FP5_PID (0x2008)
+
+#define DD0_CTRL0                      (1)
+#define DD1_CTRL1                      (2)
+#define DD2_CTRL2                      (4)
+#define DD3_CTRL3                      (8)
+#define DD4_PROG_MODE                  (0x10)
+#define DD5_VJTAG_SPI_PWR_ENB_OFF      (0x20) /* (Low - on, High - Off */
+#define DD6_VJTAG_DEBUG_PWR_ENB_OFF    (0x40) /* (Low - on, High - Off */
+#define DD7_VPUMP_PWR_ENB_OFF          (0x80) /* (Low - on, High - Off */
+
+int interface_d_init(void)
+{
+       struct ftdi_device_list *devlist, *curdev;
+       struct ftdi_context ftdic;
+       unsigned char pins = DD0_CTRL0 | DD1_CTRL1 | DD2_CTRL2 | DD3_CTRL3 |
+                       DD6_VJTAG_DEBUG_PWR_ENB_OFF;
+       uint16_t ftdi_vid = MCHP_FP5_VID;
+       uint16_t ftdi_pid = MCHP_FP5_PID;
+       int err;
+
+       err = ftdi_init(&ftdic);
+       if (err) {
+               LOG_ERROR("ftdi_init() failed: %d (%s)", err, 
ftdi_get_error_string(&ftdic));
+               return err;
+       }
+
+       err = ftdi_usb_find_all(&ftdic, &devlist, ftdi_vid, ftdi_pid);
+       if (err < 0) {
+               LOG_ERROR("ftdi_usb_find_all() failed: %d (%s)", err, 
ftdi_get_error_string(&ftdic));
+               return err;
+       }
+
+       if (err == 0) {
+               LOG_INFO("Found no FP5 devices");
+               return err;
+       }
+
+       LOG_INFO("Found %d FP5 device%s\n", err, err > 1 ? "s" : "");
+       curdev = devlist;
+       while (curdev) {
+               err = ftdi_set_interface(&ftdic, INTERFACE_D);
+               if (err < 0) {
+                       LOG_ERROR("ftdi_set_interface failed: %d (%s)", err, 
ftdi_get_error_string(&ftdic));
+                       exit(0);
+               }
+
+               err = ftdi_usb_open_dev(&ftdic, curdev->dev);
+               if (err < 0) {
+                       LOG_ERROR("ftdi_usb_open_dev failed: %d (%s)", err, 
ftdi_get_error_string(&ftdic));
+                       exit(0);
+               }
+               LOG_DEBUG("Opened FP5's interface D");
+
+               err = ftdi_set_bitmode(&ftdic, 0xff, 0x01);
+               if (err) {
+                       LOG_ERROR("ftdi_set_bitmode failed: %d (%s)", err, 
ftdi_get_error_string(&ftdic));
+                       exit(0);
+               }
+
+               err = ftdi_write_data(&ftdic, &pins, sizeof(pins));
+               if (err != sizeof(pins)) {
+                       LOG_ERROR("ftdi_write_data failed: %d (%s)", err, 
ftdi_get_error_string(&ftdic));
+                       exit(0);
+               }
+
+               err = ftdi_read_data(&ftdic, &pins, sizeof(pins));
+               if (err != sizeof(pins)) {
+                       LOG_ERROR("ftdi_read_data failed: %d (%s)", err, 
ftdi_get_error_string(&ftdic));
+                       exit(0);
+               }
+               LOG_DEBUG("Set pins on interface D to 0x%x", pins);
+
+               err = ftdi_usb_close(&ftdic);
+               if (err) {
+                       LOG_ERROR("ftdi_usb_close failed: %d (%s)", err, 
ftdi_get_error_string(&ftdic));
+                       exit(0);
+               }
+               LOG_DEBUG("Closed FP5's interface D");
+
+               curdev = curdev->next;
+       }
+       ftdi_list_free(&devlist);
+
+       return ERROR_OK;
+}
diff --git a/tcl/board/microchip_riscv_fp5.cfg 
b/tcl/board/microchip_riscv_fp5.cfg
new file mode 100644
index 0000000000..0c708e43b2
--- /dev/null
+++ b/tcl/board/microchip_riscv_fp5.cfg
@@ -0,0 +1,31 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#**************************************************************************
+#   Copyright (C) 2015-2018 by Microchip Technology Inc.                  *
+#   http://www.microchip.com/support                                      *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
+#**************************************************************************
+
+#------------------------------------------------------------------------------
+# Microchip RISC-V board
+#------------------------------------------------------------------------------
+
+# Device
+source [find interface/flashpro5.cfg]
+source [find target/microchip_riscv.cfg]
+
+# Board specific initialization
+proc do_board_reset_init {} {
+       # doesn't appear to be called
+}
diff --git a/tcl/interface/flashpro5.cfg b/tcl/interface/flashpro5.cfg
new file mode 100644
index 0000000000..8d3de51a60
--- /dev/null
+++ b/tcl/interface/flashpro5.cfg
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+#
+# FlashPro5
+#
+
+adapter speed 6000
+
+adapter driver ftdi
+ftdi device_desc "FlashPro5"
+ftdi vid_pid 0x1514 0x2008
+ftdi init_bank_d
+
+# That FTDI has 4 channels (channel 0 and 1 are MPSSE-capable, 2 and 3 are 
bitbang
+ftdi channel 0
+
+# Initial Layout - data[0..15] direction[0..15]
+ftdi layout_init 0xff78 0xff7b
+#     Signal        Data    Direction       Notes
+# AD0 TCK           0       1 (out)         Port A TCK
+# AD1 TDI           0       1 (out)         Port A TDI
+# AD2 TDO           0       0 (in)          PORT A TDO
+# AD3 TMS           1       1 (out)         Port A TMS
+# AD4 GPIOL0        1       1 (out)         Port A TRST
+# AD5 GPIOL1        1       1 (out)         Enable Buff Prog
+# AD6 GPIOL2        1       1 (out)         Mux Sel Prog ADC
+# AD7 GPIOL3        0       0 (in)          GPIO Spare (Unused)
+
+# BD0 TCK           1       1 (out)         Port B TCK
+# BD1 TDI           1       1 (out)         Port B TDI
+# BD2 TDO           1       1 (out)         Port B TDO (unused)
+# BD3 TMS           1       1 (out)         Port B TMS
+# BD4 GPIOL0        1       1 (out)         Port B TRST
+# BD5 GPIOL1        1       1 (out)         Enable Buff SD
+# BD6 GPIOL2        1       1 (out)         Status LED B1
+# BD7 GPIOL2        1       1 (out)         Status LED B0
+
+# Signals definition
+ftdi layout_signal nTRST -data 0x0010

-- 

Reply via email to