On Mon, 2009-06-01 at 22:09 -0700, Rick Altherr wrote:
> On May 23, 2009, at 7:28 PM, Zach Welch wrote:
> 
> > On Wed, 2009-05-20 at 22:59 -0700, Zach Welch wrote:
> >> On Wed, 2009-05-20 at 22:54 -0700, Rick Altherr wrote:
> >>> On May 20, 2009, at 10:31 PM, Zach Welch wrote:
> >>>
> >>>> On Wed, 2009-05-20 at 22:23 -0700, Rick Altherr wrote:
> >>>>> On Mar 25, 2009, at 2:54 PM, joern kaipf wrote:
> >>>>>
> >>>>>> * autodetection if FS or HS device attachted -> adapt tck max
> >>>>>> * enable adaptive clocking if HS device attached and jtag_khz =  
> >>>>>> 0 in
> >>>>>> cfg (not
> >>>>>> tested yet)
> >>>>>>
> >>>>>> Note:
> >>>>>> The HS devices are currently only support by the drivers from  
> >>>>>> FTDI
> >>>>>> and not
> >>>>>> from the libftdi. So using libftdi and RTCK support will cause a
> >>>>>> error
> >>>>>> message.
> >>>>>> <ft2232.patch>_______________________________________________
> >>>>>> Openocd-development mailing list
> >>>>>> Openocd-development@lists.berlios.de
> >>>>>> https://lists.berlios.de/mailman/listinfo/openocd-development
> >>>>>
> >>>>>
> >>>>> This doesn't appear to have been applied, but doesn't apply  
> >>>>> cleanly
> >>>>> to
> >>>>> HEAD.  Is there an updated version available?
> >>>>
> >>>> I cleaned it up and posted it here:
> >>>>
> >>>>  
> >>>> https://lists.berlios.de/pipermail/openocd-development/2009-April/005479.html
> >>>>
> >>>> It probably needs a little more work.
> >>>>
> >>>> Cheers,
> >>>>
> >>>> Zach
> >>>>
> >>>>
> >>>
> >>>
> >>> It looks like even _that_ version doesn't apply cleanly since the  
> >>> last
> >>> batch of updates to the ft2232 driver.
> >>
> >> Bummer, but that is where I would start development.  I recommend
> >> applying it to the old revision ('svn up -r${PATCH_REV}') then  
> >> letting
> >> SVN help with the merge through an 'svn up'.  You are probably more
> >> familiar with the code and can figure out what to do better than I.
> >
> > Whoops... looks like this patch almost slipped through the cracks.
> > I will take a stab at it shortly and repost it, unless you started it.
> >
> > --Z
> 
> 
> I didn't even get a chance to respond, let alone try to update the  
> patch.  Are you going to give it a whirl?

I spun a new one and reposted it.  Attached again for our convenience.

--Z
Index: configure.in
===================================================================
--- configure.in	(revision 1942)
+++ configure.in	(working copy)
@@ -310,6 +310,10 @@
 AC_ARG_ENABLE(ft2232_ftd2xx,
   AS_HELP_STRING([--enable-ft2232_ftd2xx], [Enable building support for FT2232 based devices using the FTD2XX driver from ftdichip.com]), 
   [build_ft2232_ftd2xx=$enableval], [build_ft2232_ftd2xx=no])
+
+AC_ARG_ENABLE(ftd2xx_highspeed,
+  AS_HELP_STRING([--enable-ftd2xx-highspeed], [Enable building support for FT2232H and FT4232H-based devices (requires >=libftd2xx-0.4.16)]), 
+  [want_ftd2xx_highspeed=$enableval], [want_ftd2xx_highspeed=maybe])
  
 AC_ARG_ENABLE(amtjtagaccel,
   AS_HELP_STRING([--enable-amtjtagaccel], [Enable building the Amontec JTAG-Accelerator driver]), 
@@ -737,6 +741,32 @@
 	return 0;
 }
 ], [ AC_MSG_RESULT([Success!])] , [ AC_MSG_ERROR([Cannot build & run test program using ftd2xx.lib]) ] )
+
+AC_MSG_CHECKING([whether to build ftd2xx device support])
+AC_MSG_RESULT([$want_ftd2xx_highspeed])
+if test $want_ftd2xx_highspeed != no; then
+AC_MSG_CHECKING([for ftd2xx highspeed device support])
+AC_COMPILE_IFELSE([
+#include "confdefs.h"
+#if IS_WIN32
+#include "windows.h"
+#endif
+#include <stdio.h>
+#include <ftd2xx.h>
+DWORD x = FT_DEVICE_4232H;
+], [
+ AC_DEFINE(BUILD_FTD2XX_HIGHSPEED, [1], [Support FT2232H/FT4232HS with FTD2XX.])
+ build_ftd2xx_highspeed=yes
+], [
+ build_ftd2xx_highspeed=no
+] )
+AC_MSG_RESULT([$build_ftd2xx_highspeed])
+
+if test $want_ftd2xx_highspeed = yes -a $build_ftd2xx_highspeed = no; then
+   AC_MSG_ERROR([You need a newer FTD2XX driver (version 0.4.16 or later).])
+ fi
+fi
+
 LDFLAGS=$LDFLAGS_SAVE
 CFLAGS=$CFLAGS_SAVE
 fi
Index: src/jtag/ft2232.c
===================================================================
--- src/jtag/ft2232.c	(revision 1942)
+++ src/jtag/ft2232.c	(working copy)
@@ -91,6 +91,8 @@
  */
 static int ft2232_stableclocks(int num_cycles, jtag_command_t* cmd);
 
+/* max TCK for the high speed devices 30000 kHz */
+#define	FTDI_2232H_4232H_MAX_TCK	30000
 
 static char *       ft2232_device_desc_A = NULL;
 static char*        ft2232_device_desc = NULL;
@@ -173,6 +175,7 @@
 
 #if BUILD_FT2232_FTD2XX == 1
 static FT_HANDLE 	ftdih = NULL;
+static FT_DEVICE 	ftdi_device = 0;
 #elif BUILD_FT2232_LIBFTDI == 1
 static struct ftdi_context ftdic;
 #endif
@@ -410,13 +413,55 @@
 	return ERROR_OK;
 }
 
+#ifdef BUILD_FTD2XX_HIGHSPEED
+static bool ft2232_device_is_highspeed(void)
+{
+	return (ftdi_device == FT_DEVICE_2232H) || (ftdi_device == FT_DEVICE_4232H);
+}
 
+static int ft2232_adaptive_clocking(int speed)
+{
+	bool use_adaptive_clocking = FALSE;
+	if (0 == speed)
+	{
+		if (ft2232_device_is_highspeed())
+			use_adaptive_clocking = TRUE;
+		else
+		{
+			LOG_ERROR("ft2232 device %lu does not support RTCK", ftdi_device);
+			return ERROR_OK;
+		}
+	}
+
+	u8  buf = use_adaptive_clocking ? 0x96 : 0x97;
+	LOG_DEBUG("%2.2x", buf);
+
+	u32 bytes_written;
+	int retval = ft2232_write(&buf, 1, &bytes_written);
+	if (ERROR_OK != retval || bytes_written != 1)
+	{
+		LOG_ERROR("unable to set adative clocking: %d", retval);
+		return retval;
+	}
+
+	return ERROR_OK;
+}
+#else
+static int ft2232_adaptive_clocking(int speed)
+{
+	// not implemented on low-speed devices
+	return speed ? ERROR_OK : -1234;
+}
+#endif
+
 static int ft2232_speed(int speed)
 {
 	u8  buf[3];
 	int retval;
 	u32 bytes_written;
 
+	ft2232_adaptive_clocking(speed);
+
 	buf[0] = 0x86;                  	/* command "set divisor" */
 	buf[1] = speed & 0xff;          /* valueL (0=6MHz, 1=3MHz, 2=2.0MHz, ...*/
 	buf[2] = (speed >> 8) & 0xff;   /* valueH */
@@ -448,8 +493,15 @@
 {
 	if (khz==0)
 	{
-		LOG_DEBUG("RTCK not supported");
+#ifdef BUILD_FTD2XX_HIGHSPEED
+		*jtag_speed = 0;
+		return ERROR_OK;
+#else
+		LOG_DEBUG("RCLK not supported");
+		LOG_DEBUG("If you have a high-speed FTDI device, then "
+			"OpenOCD may be built with --enable-ftd2xx-highspeed.");
 		return ERROR_FAIL;
+#endif
 	}
 
 	/* Take a look in the FT2232 manual,
@@ -1743,6 +1795,9 @@
 static int ft2232_init_ftd2xx(u16 vid, u16 pid, int more, int* try_more)
 {
 	FT_STATUS 	status;
+	DWORD		deviceID;
+	char		SerialNumber[16];
+	char		Description[64]; 
 	DWORD     	openex_flags  = 0;
 	char*     	openex_string = NULL;
 	u8        	latency_timer;
@@ -1873,6 +1928,27 @@
 		return ERROR_JTAG_INIT_FAILED;
 	}
 
+	if ( ( status = FT_GetDeviceInfo(ftdih, &ftdi_device, &deviceID, SerialNumber, Description, NULL) ) != FT_OK )
+	{
+		LOG_ERROR("unable to get FT_GetDeviceInfo: %lu", status);
+		return ERROR_JTAG_INIT_FAILED;
+	}
+	else
+	{
+		LOG_INFO("device: %lu", ftdi_device);
+		LOG_INFO("deviceID: %lu", deviceID);
+		LOG_INFO("SerialNumber: %s", SerialNumber);
+		LOG_INFO("Description: %s", Description);
+
+#ifdef BUILD_FTD2XX_HIGHSPEED
+		if (ft2232_device_is_highspeed())
+		{
+			ft2232_max_tck = FTDI_2232H_4232H_MAX_TCK;
+			LOG_INFO("max TCK change to: %u kHz", ft2232_max_tck);
+		}
+#endif
+	}
+
 	return ERROR_OK;
 }
 
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to