1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /*******************************************************************************
4 * Driver for OpenJTAG Project (www.openjtag.org) *
5 * Compatible with libftdi drivers. *
7 * Cypress CY7C65215 support *
8 * Copyright (C) 2015 Vianney le Clément de Saint-Marcq, Essensium NV *
9 * <vianney.leclement@essensium.com> *
11 * Copyright (C) 2010 by Ivan Meleca <mileca@gmail.com> *
13 * Copyright (C) 2013 by Ryan Corbin, GlueLogix Inc. <corbin.ryan@gmail.com> *
14 * Updated to work with OpenOCD v0.7.0. Fixed libftdi read speed issue. *
16 * Based on usb_blaster.c *
17 * Copyright (C) 2009 Catalin Patulea *
18 * Copyright (C) 2006 Kolja Waschk *
21 * Copyright (C) 2008 by Spencer Oliver *
22 * spen@spen-soft.co.uk *
23 ***************************************************************************/
25 /***************************************************************************
26 * Version 1.0 Tested on a MCBSTM32 board using a Cortex-M3 (stm32f103x), *
27 * GDB and Eclipse under Linux (Ubuntu 10.04) *
29 ***************************************************************************/
35 #include <jtag/interface.h>
36 #include <jtag/commands.h>
37 #include "libusb_helper.h"
40 OPENJTAG_VARIANT_STANDARD
,
41 OPENJTAG_VARIANT_CY7C65215
,
42 } openjtag_variant
= OPENJTAG_VARIANT_STANDARD
;
44 static const char * const openjtag_variant_names
[] = {
51 * OpenJTAG-OpenOCD state conversion
53 typedef enum openjtag_tap_state
{
54 OPENJTAG_TAP_INVALID
= -1,
55 OPENJTAG_TAP_RESET
= 0,
56 OPENJTAG_TAP_IDLE
= 1,
57 OPENJTAG_TAP_SELECT_DR
= 2,
58 OPENJTAG_TAP_CAPTURE_DR
= 3,
59 OPENJTAG_TAP_SHIFT_DR
= 4,
60 OPENJTAG_TAP_EXIT1_DR
= 5,
61 OPENJTAG_TAP_PAUSE_DR
= 6,
62 OPENJTAG_TAP_EXIT2_DR
= 7,
63 OPENJTAG_TAP_UPDATE_DR
= 8,
64 OPENJTAG_TAP_SELECT_IR
= 9,
65 OPENJTAG_TAP_CAPURE_IR
= 10,
66 OPENJTAG_TAP_SHIFT_IR
= 11,
67 OPENJTAG_TAP_EXIT1_IR
= 12,
68 OPENJTAG_TAP_PAUSE_IR
= 13,
69 OPENJTAG_TAP_EXIT2_IR
= 14,
70 OPENJTAG_TAP_UPDATE_IR
= 15,
71 } openjtag_tap_state_t
;
73 /* OPENJTAG access library includes */
74 #include "libftdi_helper.h"
76 /* OpenJTAG vid/pid */
77 static uint16_t openjtag_vid
= 0x0403;
78 static uint16_t openjtag_pid
= 0x6001;
80 static char *openjtag_device_desc
;
82 static struct ftdi_context ftdic
;
84 #define OPENJTAG_BUFFER_SIZE 504
85 #define OPENJTAG_MAX_PENDING_RESULTS 256
87 struct openjtag_scan_result
{
88 uint32_t bits
; /* Length in bits*/
89 struct scan_command
*command
; /* Corresponding scan command */
93 /* USB RX/TX buffers */
94 static int usb_tx_buf_offs
;
95 static uint8_t usb_tx_buf
[OPENJTAG_BUFFER_SIZE
];
96 static uint32_t usb_rx_buf_len
;
97 static uint8_t usb_rx_buf
[OPENJTAG_BUFFER_SIZE
];
99 /* Pending readings */
100 static struct openjtag_scan_result openjtag_scan_result_buffer
[OPENJTAG_MAX_PENDING_RESULTS
];
101 static int openjtag_scan_result_count
;
103 static struct libusb_device_handle
*usbh
;
105 /* CY7C65215 model only */
106 #define CY7C65215_JTAG_REQUEST 0x40 /* bmRequestType: vendor host-to-device */
107 #define CY7C65215_JTAG_ENABLE 0xD0 /* bRequest: enable JTAG */
108 #define CY7C65215_JTAG_DISABLE 0xD1 /* bRequest: disable JTAG */
109 #define CY7C65215_JTAG_READ 0xD2 /* bRequest: read buffer */
110 #define CY7C65215_JTAG_WRITE 0xD3 /* bRequest: write buffer */
112 #define CY7C65215_USB_TIMEOUT 100
114 static const uint16_t cy7c65215_vids
[] = {0x04b4, 0};
115 static const uint16_t cy7c65215_pids
[] = {0x0007, 0};
117 #define CY7C65215_JTAG_CLASS 0xff
118 #define CY7C65215_JTAG_SUBCLASS 0x04
120 static unsigned int ep_in
, ep_out
;
122 #ifdef _DEBUG_USB_COMMS_
124 #define DEBUG_TYPE_READ 0
125 #define DEBUG_TYPE_WRITE 1
126 #define DEBUG_TYPE_OCD_READ 2
127 #define DEBUG_TYPE_BUFFER 3
130 static void openjtag_debug_buffer(uint8_t *buffer
, int length
, uint8_t type
)
138 case DEBUG_TYPE_READ
:
139 sprintf(line
, "USB READ %d bytes", length
);
141 case DEBUG_TYPE_WRITE
:
142 sprintf(line
, "USB WRITE %d bytes", length
);
144 case DEBUG_TYPE_OCD_READ
:
145 sprintf(line
, "TO OpenOCD %d bytes", length
);
147 case DEBUG_TYPE_BUFFER
:
148 sprintf(line
, "Buffer %d bytes", length
);
152 LOG_DEBUG("%s", line
);
154 for (i
= 0; i
< length
; i
+= LINE_LEN
) {
156 case DEBUG_TYPE_READ
:
157 sprintf(line
, "USB READ: %04x", i
);
159 case DEBUG_TYPE_WRITE
:
160 sprintf(line
, "USB WRITE: %04x", i
);
162 case DEBUG_TYPE_OCD_READ
:
163 sprintf(line
, "TO OpenOCD: %04x", i
);
165 case DEBUG_TYPE_BUFFER
:
166 sprintf(line
, "BUFFER: %04x", i
);
170 for (j
= i
; j
< i
+ LINE_LEN
&& j
< length
; j
++) {
171 sprintf(s
, " %02x", buffer
[j
]);
174 LOG_DEBUG("%s", line
);
181 static int8_t openjtag_get_tap_state(int8_t state
)
185 case TAP_DREXIT2
: return OPENJTAG_TAP_EXIT2_DR
;
186 case TAP_DREXIT1
: return OPENJTAG_TAP_EXIT1_DR
;
187 case TAP_DRSHIFT
: return OPENJTAG_TAP_SHIFT_DR
;
188 case TAP_DRPAUSE
: return OPENJTAG_TAP_PAUSE_DR
;
189 case TAP_IRSELECT
: return OPENJTAG_TAP_SELECT_IR
;
190 case TAP_DRUPDATE
: return OPENJTAG_TAP_UPDATE_DR
;
191 case TAP_DRCAPTURE
: return OPENJTAG_TAP_CAPTURE_DR
;
192 case TAP_DRSELECT
: return OPENJTAG_TAP_SELECT_DR
;
193 case TAP_IREXIT2
: return OPENJTAG_TAP_EXIT2_IR
;
194 case TAP_IREXIT1
: return OPENJTAG_TAP_EXIT1_IR
;
195 case TAP_IRSHIFT
: return OPENJTAG_TAP_SHIFT_IR
;
196 case TAP_IRPAUSE
: return OPENJTAG_TAP_PAUSE_IR
;
197 case TAP_IDLE
: return OPENJTAG_TAP_IDLE
;
198 case TAP_IRUPDATE
: return OPENJTAG_TAP_UPDATE_IR
;
199 case TAP_IRCAPTURE
: return OPENJTAG_TAP_CAPURE_IR
;
200 case TAP_RESET
: return OPENJTAG_TAP_RESET
;
202 default: return OPENJTAG_TAP_INVALID
;
206 static int openjtag_buf_write_standard(
207 uint8_t *buf
, int size
, uint32_t *bytes_written
)
210 #ifdef _DEBUG_USB_COMMS_
211 openjtag_debug_buffer(buf
, size
, DEBUG_TYPE_WRITE
);
214 retval
= ftdi_write_data(&ftdic
, buf
, size
);
217 LOG_ERROR("ftdi_write_data: %s", ftdi_get_error_string(&ftdic
));
218 return ERROR_JTAG_DEVICE_ERROR
;
221 *bytes_written
= retval
;
226 static int openjtag_buf_write_cy7c65215(
227 uint8_t *buf
, int size
, uint32_t *bytes_written
)
231 #ifdef _DEBUG_USB_COMMS_
232 openjtag_debug_buffer(buf
, size
, DEBUG_TYPE_WRITE
);
240 ret
= jtag_libusb_control_transfer(usbh
, CY7C65215_JTAG_REQUEST
,
241 CY7C65215_JTAG_WRITE
, size
, 0,
242 NULL
, 0, CY7C65215_USB_TIMEOUT
, NULL
);
243 if (ret
!= ERROR_OK
) {
244 LOG_ERROR("vendor command failed");
248 if (jtag_libusb_bulk_write(usbh
, ep_out
, (char *)buf
, size
,
249 CY7C65215_USB_TIMEOUT
, &ret
)) {
250 LOG_ERROR("bulk write failed, error");
251 return ERROR_JTAG_DEVICE_ERROR
;
253 *bytes_written
= ret
;
258 static int openjtag_buf_write(
259 uint8_t *buf
, int size
, uint32_t *bytes_written
)
261 switch (openjtag_variant
) {
262 case OPENJTAG_VARIANT_CY7C65215
:
263 return openjtag_buf_write_cy7c65215(buf
, size
, bytes_written
);
265 return openjtag_buf_write_standard(buf
, size
, bytes_written
);
269 static int openjtag_buf_read_standard(
270 uint8_t *buf
, uint32_t qty
, uint32_t *bytes_read
)
278 while ((*bytes_read
< qty
) && timeout
--) {
279 retval
= ftdi_read_data(&ftdic
, buf
+ *bytes_read
,
283 LOG_DEBUG_IO("ftdi_read_data: %s",
284 ftdi_get_error_string(&ftdic
));
285 return ERROR_JTAG_DEVICE_ERROR
;
287 *bytes_read
+= retval
;
290 #ifdef _DEBUG_USB_COMMS_
291 openjtag_debug_buffer(buf
, *bytes_read
, DEBUG_TYPE_READ
);
297 static int openjtag_buf_read_cy7c65215(
298 uint8_t *buf
, uint32_t qty
, uint32_t *bytes_read
)
307 ret
= jtag_libusb_control_transfer(usbh
, CY7C65215_JTAG_REQUEST
,
308 CY7C65215_JTAG_READ
, qty
, 0,
309 NULL
, 0, CY7C65215_USB_TIMEOUT
, NULL
);
310 if (ret
!= ERROR_OK
) {
311 LOG_ERROR("vendor command failed");
315 if (jtag_libusb_bulk_read(usbh
, ep_in
, (char *)buf
, qty
,
316 CY7C65215_USB_TIMEOUT
, &ret
)) {
317 LOG_ERROR("bulk read failed, error");
318 return ERROR_JTAG_DEVICE_ERROR
;
323 #ifdef _DEBUG_USB_COMMS_
324 openjtag_debug_buffer(buf
, *bytes_read
, DEBUG_TYPE_READ
);
330 static int openjtag_buf_read(uint8_t *buf
, uint32_t qty
, uint32_t *bytes_read
)
332 switch (openjtag_variant
) {
333 case OPENJTAG_VARIANT_CY7C65215
:
334 return openjtag_buf_read_cy7c65215(buf
, qty
, bytes_read
);
336 return openjtag_buf_read_standard(buf
, qty
, bytes_read
);
340 static int openjtag_sendcommand(uint8_t cmd
)
343 return openjtag_buf_write(&cmd
, 1, &written
);
346 static int openjtag_speed(int speed
)
376 LOG_WARNING("adapter speed not recognized, reverting to 375 kHz");
379 openjtag_sendcommand(clockcmd
);
384 static int openjtag_init_standard(void)
386 uint8_t latency_timer
;
388 /* Open by device description */
389 if (!openjtag_device_desc
) {
390 LOG_WARNING("no openjtag device description specified, "
391 "using default 'Open JTAG Project'");
392 openjtag_device_desc
= "Open JTAG Project";
395 if (ftdi_init(&ftdic
) < 0)
396 return ERROR_JTAG_INIT_FAILED
;
398 /* context, vendor id, product id, description, serial id */
399 if (ftdi_usb_open_desc(&ftdic
, openjtag_vid
, openjtag_pid
, openjtag_device_desc
, NULL
) < 0) {
400 LOG_ERROR("unable to open ftdi device: %s", ftdic
.error_str
);
401 return ERROR_JTAG_INIT_FAILED
;
404 if (ftdi_usb_reset(&ftdic
) < 0) {
405 LOG_ERROR("unable to reset ftdi device");
406 return ERROR_JTAG_INIT_FAILED
;
409 if (ftdi_set_latency_timer(&ftdic
, 2) < 0) {
410 LOG_ERROR("unable to set latency timer");
411 return ERROR_JTAG_INIT_FAILED
;
414 if (ftdi_get_latency_timer(&ftdic
, &latency_timer
) < 0) {
415 LOG_ERROR("unable to get latency timer");
416 return ERROR_JTAG_INIT_FAILED
;
418 LOG_DEBUG("current latency timer: %u", latency_timer
);
420 ftdi_disable_bitbang(&ftdic
);
421 /* was (3000000 / 4) with a comment about a bug in libftdi when using high baudrate */
422 if (ftdi_set_baudrate(&ftdic
, 3000000) < 0) {
423 LOG_ERROR("Can't set baud rate to max: %s",
424 ftdi_get_error_string(&ftdic
));
425 return ERROR_JTAG_DEVICE_ERROR
;
428 if (ftdi_tcioflush(&ftdic
) < 0) {
429 LOG_ERROR("ftdi flush: %s", ftdic
.error_str
);
430 return ERROR_JTAG_INIT_FAILED
;
436 static int openjtag_init_cy7c65215(void)
441 ret
= jtag_libusb_open(cy7c65215_vids
, cy7c65215_pids
, NULL
, &usbh
, NULL
);
442 if (ret
!= ERROR_OK
) {
443 LOG_ERROR("unable to open cy7c65215 device");
447 ret
= jtag_libusb_choose_interface(usbh
, &ep_in
, &ep_out
,
448 CY7C65215_JTAG_CLASS
,
449 CY7C65215_JTAG_SUBCLASS
, -1, LIBUSB_TRANSFER_TYPE_BULK
);
450 if (ret
!= ERROR_OK
) {
451 LOG_ERROR("unable to claim JTAG interface");
455 ret
= jtag_libusb_control_transfer(usbh
,
456 CY7C65215_JTAG_REQUEST
,
457 CY7C65215_JTAG_ENABLE
,
458 0, 0, NULL
, 0, CY7C65215_USB_TIMEOUT
, NULL
);
459 if (ret
!= ERROR_OK
) {
460 LOG_ERROR("could not enable JTAG module");
468 jtag_libusb_close(usbh
);
472 static int openjtag_init(void)
478 openjtag_scan_result_count
= 0;
480 switch (openjtag_variant
) {
481 case OPENJTAG_VARIANT_CY7C65215
:
482 ret
= openjtag_init_cy7c65215();
485 ret
= openjtag_init_standard();
490 openjtag_speed(375); /* Start at slowest adapter speed */
491 openjtag_sendcommand(0x75); /* MSB */
496 static int openjtag_quit_standard(void)
498 ftdi_usb_close(&ftdic
);
504 static int openjtag_quit_cy7c65215(void)
508 ret
= jtag_libusb_control_transfer(usbh
,
509 CY7C65215_JTAG_REQUEST
,
510 CY7C65215_JTAG_DISABLE
,
511 0, 0, NULL
, 0, CY7C65215_USB_TIMEOUT
, NULL
);
513 LOG_WARNING("could not disable JTAG module");
515 jtag_libusb_close(usbh
);
520 static int openjtag_quit(void)
522 switch (openjtag_variant
) {
523 case OPENJTAG_VARIANT_CY7C65215
:
524 return openjtag_quit_cy7c65215();
526 return openjtag_quit_standard();
530 static void openjtag_write_tap_buffer(void)
533 uint32_t rx_expected
= 0;
535 /* calculate expected number of return bytes */
536 for (int tx_offs
= 0; tx_offs
< usb_tx_buf_offs
; tx_offs
++) {
537 if ((usb_tx_buf
[tx_offs
] & 0x0F) == 6) {
540 } else if ((usb_tx_buf
[tx_offs
] & 0x0F) == 2) {
545 openjtag_buf_write(usb_tx_buf
, usb_tx_buf_offs
, &written
);
546 openjtag_buf_read(usb_rx_buf
, rx_expected
, &usb_rx_buf_len
);
551 static int openjtag_execute_tap_queue(void)
553 openjtag_write_tap_buffer();
557 if (openjtag_scan_result_count
&& usb_rx_buf_len
) {
563 /* for every pending result */
564 while (res_count
< openjtag_scan_result_count
) {
567 len
= openjtag_scan_result_buffer
[res_count
].bits
;
571 uint8_t *buffer
= openjtag_scan_result_buffer
[res_count
].buffer
;
574 if (len
<= 8 && openjtag_variant
!= OPENJTAG_VARIANT_CY7C65215
) {
575 LOG_DEBUG_IO("bits < 8 buf = 0x%X, will be 0x%X",
576 usb_rx_buf
[rx_offs
], usb_rx_buf
[rx_offs
] >> (8 - len
));
577 buffer
[count
] = usb_rx_buf
[rx_offs
] >> (8 - len
);
580 buffer
[count
] = usb_rx_buf
[rx_offs
];
588 #ifdef _DEBUG_USB_COMMS_
589 openjtag_debug_buffer(buffer
,
590 DIV_ROUND_UP(openjtag_scan_result_buffer
[res_count
].bits
, 8), DEBUG_TYPE_OCD_READ
);
592 jtag_read_buffer(buffer
, openjtag_scan_result_buffer
[res_count
].command
);
594 free(openjtag_scan_result_buffer
[res_count
].buffer
);
600 openjtag_scan_result_count
= 0;
605 static void openjtag_add_byte(char buf
)
608 if (usb_tx_buf_offs
== OPENJTAG_BUFFER_SIZE
) {
609 LOG_DEBUG_IO("Forcing execute_tap_queue");
610 LOG_DEBUG_IO("TX Buff offs=%d", usb_tx_buf_offs
);
611 openjtag_execute_tap_queue();
614 usb_tx_buf
[usb_tx_buf_offs
] = buf
;
618 static void openjtag_add_scan(uint8_t *buffer
, int length
, struct scan_command
*scan_cmd
)
621 /* Ensure space to send long chains */
622 /* We add two byte for each eight (or less) bits, one for command, one for data */
623 if (usb_tx_buf_offs
+ (DIV_ROUND_UP(length
, 8) * 2) >= OPENJTAG_BUFFER_SIZE
) {
624 LOG_DEBUG_IO("Forcing execute_tap_queue from scan");
625 LOG_DEBUG_IO("TX Buff offs=%d len=%d", usb_tx_buf_offs
, DIV_ROUND_UP(length
, 8) * 2);
626 openjtag_execute_tap_queue();
629 openjtag_scan_result_buffer
[openjtag_scan_result_count
].bits
= length
;
630 openjtag_scan_result_buffer
[openjtag_scan_result_count
].command
= scan_cmd
;
631 openjtag_scan_result_buffer
[openjtag_scan_result_count
].buffer
= buffer
;
646 /* bits to transfer */
648 command
|= bits
<< 5;
653 /* bits to transfer */
658 openjtag_add_byte(command
);
659 openjtag_add_byte(buffer
[count
]);
663 openjtag_scan_result_count
++;
666 static void openjtag_execute_reset(struct jtag_command
*cmd
)
669 LOG_DEBUG_IO("reset trst: %i srst %i",
670 cmd
->cmd
.reset
->trst
, cmd
->cmd
.reset
->srst
);
674 /* Pull SRST low for 5 TCLK cycles */
675 if (cmd
->cmd
.reset
->srst
) {
678 openjtag_add_byte(buf
);
682 static void openjtag_execute_sleep(struct jtag_command
*cmd
)
684 jtag_sleep(cmd
->cmd
.sleep
->us
);
687 static void openjtag_set_state(uint8_t openocd_state
)
689 uint8_t state
= openjtag_get_tap_state(openocd_state
);
693 if (state
!= OPENJTAG_TAP_RESET
) {
697 /* Force software TLR */
701 openjtag_add_byte(buf
);
704 static void openjtag_execute_statemove(struct jtag_command
*cmd
)
706 LOG_DEBUG_IO("state move to %i", cmd
->cmd
.statemove
->end_state
);
708 tap_set_end_state(cmd
->cmd
.statemove
->end_state
);
710 openjtag_set_state(cmd
->cmd
.statemove
->end_state
);
712 tap_set_state(tap_get_end_state());
716 static void openjtag_execute_scan(struct jtag_command
*cmd
)
719 int scan_size
, old_state
;
722 LOG_DEBUG_IO("scan ends in %s", tap_state_name(cmd
->cmd
.scan
->end_state
));
725 tap_set_end_state(cmd
->cmd
.scan
->end_state
);
726 scan_size
= jtag_build_buffer(cmd
->cmd
.scan
, &buffer
);
728 #ifdef _DEBUG_USB_COMMS_
729 openjtag_debug_buffer(buffer
, (scan_size
+ 7) / 8, DEBUG_TYPE_BUFFER
);
732 old_state
= tap_get_end_state();
733 openjtag_set_state(cmd
->cmd
.scan
->ir_scan
? TAP_IRSHIFT
: TAP_DRSHIFT
);
734 tap_set_state(cmd
->cmd
.scan
->ir_scan
? TAP_IRSHIFT
: TAP_DRSHIFT
);
735 tap_set_end_state(old_state
);
737 openjtag_add_scan(buffer
, scan_size
, cmd
->cmd
.scan
);
739 openjtag_set_state(cmd
->cmd
.scan
->ir_scan
? TAP_IRPAUSE
: TAP_DRPAUSE
);
740 tap_set_state(cmd
->cmd
.scan
->ir_scan
? TAP_IRPAUSE
: TAP_DRPAUSE
);
742 if (tap_get_state() != tap_get_end_state()) {
743 openjtag_set_state(tap_get_end_state());
744 tap_set_state(tap_get_end_state());
748 static void openjtag_execute_runtest(struct jtag_command
*cmd
)
751 tap_state_t end_state
= cmd
->cmd
.runtest
->end_state
;
752 tap_set_end_state(end_state
);
754 /* only do a state_move when we're not already in IDLE */
755 if (tap_get_state() != TAP_IDLE
) {
756 openjtag_set_state(TAP_IDLE
);
757 tap_set_state(TAP_IDLE
);
760 if (openjtag_variant
!= OPENJTAG_VARIANT_CY7C65215
||
761 cmd
->cmd
.runtest
->num_cycles
) {
763 int cycles
= cmd
->cmd
.runtest
->num_cycles
;
767 command
|= (((cycles
> 16 ? 16 : cycles
) - 1) & 0x0F) << 4;
769 openjtag_add_byte(command
);
771 } while (cycles
> 0);
774 tap_set_end_state(end_state
);
775 if (tap_get_end_state() != tap_get_state()) {
776 openjtag_set_state(end_state
);
777 tap_set_state(end_state
);
781 static void openjtag_execute_command(struct jtag_command
*cmd
)
783 LOG_DEBUG_IO("openjtag_execute_command %i", cmd
->type
);
786 openjtag_execute_reset(cmd
);
789 openjtag_execute_sleep(cmd
);
792 openjtag_execute_statemove(cmd
);
795 openjtag_execute_scan(cmd
);
798 openjtag_execute_runtest(cmd
);
801 /* jlink_execute_pathmove(cmd); break; */
803 LOG_ERROR("BUG: unknown Open JTAG command type encountered");
808 static int openjtag_execute_queue(struct jtag_command
*cmd_queue
)
810 struct jtag_command
*cmd
= cmd_queue
;
813 openjtag_execute_command(cmd
);
817 return openjtag_execute_tap_queue();
820 static int openjtag_speed_div(int speed
, int *khz
)
827 static int openjtag_khz(int khz
, int *jtag_speed
)
832 else if (khz
>= 24000)
834 else if (khz
>= 12000)
836 else if (khz
>= 6000)
838 else if (khz
>= 3000)
840 else if (khz
>= 1500)
850 COMMAND_HANDLER(openjtag_handle_device_desc_command
)
853 openjtag_device_desc
= strdup(CMD_ARGV
[0]);
855 LOG_ERROR("require exactly one argument to "
856 "openjtag_device_desc <description>");
860 COMMAND_HANDLER(openjtag_handle_variant_command
)
863 const char * const *name
= openjtag_variant_names
;
865 for (; *name
; name
++, variant
++) {
866 if (strcasecmp(CMD_ARGV
[0], *name
) == 0) {
867 openjtag_variant
= variant
;
871 LOG_ERROR("unknown openjtag variant '%s'", CMD_ARGV
[0]);
873 LOG_ERROR("require exactly one argument to "
874 "openjtag_variant <variant>");
879 COMMAND_HANDLER(openjtag_handle_vid_pid_command
)
882 return ERROR_COMMAND_SYNTAX_ERROR
;
884 COMMAND_PARSE_NUMBER(u16
, CMD_ARGV
[0], openjtag_vid
);
885 COMMAND_PARSE_NUMBER(u16
, CMD_ARGV
[1], openjtag_pid
);
890 static const struct command_registration openjtag_subcommand_handlers
[] = {
892 .name
= "device_desc",
893 .handler
= openjtag_handle_device_desc_command
,
894 .mode
= COMMAND_CONFIG
,
895 .help
= "set the USB device description of the OpenJTAG",
896 .usage
= "description-string",
900 .handler
= openjtag_handle_variant_command
,
901 .mode
= COMMAND_CONFIG
,
902 .help
= "set the OpenJTAG variant",
903 .usage
= "variant-string",
907 .handler
= openjtag_handle_vid_pid_command
,
908 .mode
= COMMAND_CONFIG
,
909 .help
= "USB VID and PID of the adapter",
912 COMMAND_REGISTRATION_DONE
915 static const struct command_registration openjtag_command_handlers
[] = {
919 .help
= "perform openjtag management",
920 .chain
= openjtag_subcommand_handlers
,
923 COMMAND_REGISTRATION_DONE
926 static struct jtag_interface openjtag_interface
= {
927 .execute_queue
= openjtag_execute_queue
,
930 struct adapter_driver openjtag_adapter_driver
= {
932 .transports
= jtag_only
,
933 .commands
= openjtag_command_handlers
,
935 .init
= openjtag_init
,
936 .quit
= openjtag_quit
,
937 .speed
= openjtag_speed
,
939 .speed_div
= openjtag_speed_div
,
941 .jtag_ops
= &openjtag_interface
,