OpenOCD
ep93xx.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2005 by Dominic Rath *
5  * Dominic.Rath@gmx.de *
6  ***************************************************************************/
7 
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11 
12 #include <jtag/interface.h>
13 #include "bitbang.h"
14 
15 #define TDO_BIT 1
16 #define TDI_BIT 2
17 #define TCK_BIT 4
18 #define TMS_BIT 8
19 #define TRST_BIT 16
20 #define SRST_BIT 32
21 #define VCC_BIT 64
22 
23 #define EP93XX_DELAY_US 10000
24 
25 #include <sys/mman.h>
26 
27 static uint8_t output_value;
28 static int dev_mem_fd;
29 static uint8_t *gpio_controller;
30 static volatile uint8_t *gpio_data_register;
31 static volatile uint8_t *gpio_data_direction_register;
32 
33 /* low level command set
34  */
35 static enum bb_value ep93xx_read(void);
36 static int ep93xx_write(int tck, int tms, int tdi);
37 static int ep93xx_reset(int trst, int srst);
38 
39 static int ep93xx_init(void);
40 static int ep93xx_quit(void);
41 
42 static struct jtag_interface ep93xx_interface = {
44  .execute_queue = bitbang_execute_queue,
45 };
46 
48  .name = "ep93xx",
49  .transport_ids = TRANSPORT_JTAG,
50  .transport_preferred_id = TRANSPORT_JTAG,
51 
52  .init = ep93xx_init,
53  .quit = ep93xx_quit,
54  .reset = ep93xx_reset,
55 
56  .jtag_ops = &ep93xx_interface,
57 };
58 
59 static const struct bitbang_interface ep93xx_bitbang = {
60  .read = ep93xx_read,
61  .write = ep93xx_write,
62  .blink = NULL,
63 };
64 
65 static enum bb_value ep93xx_read(void)
66 {
67  return (*gpio_data_register & TDO_BIT) ? BB_HIGH : BB_LOW;
68 }
69 
70 static int ep93xx_write(int tck, int tms, int tdi)
71 {
72  if (tck)
74  else
76 
77  if (tms)
79  else
81 
82  if (tdi)
84  else
86 
88  usleep(EP93XX_DELAY_US);
89 
90  return ERROR_OK;
91 }
92 
93 /* (1) assert or (0) deassert reset lines */
94 static int ep93xx_reset(int trst, int srst)
95 {
96  if (trst == 0)
98  else if (trst == 1)
100 
101  if (srst == 0)
103  else if (srst == 1)
105 
107  usleep(EP93XX_DELAY_US);
108 
109  return ERROR_OK;
110 }
111 
112 static int set_gonk_mode(void)
113 {
114  void *syscon = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
115  MAP_SHARED, dev_mem_fd, 0x80930000);
116  if (syscon == MAP_FAILED) {
117  LOG_ERROR("mmap: %s", strerror(errno));
118  return ERROR_JTAG_INIT_FAILED;
119  }
120 
121  uint32_t devicecfg = *((volatile uint32_t *)((uintptr_t)syscon + 0x80));
122  *((volatile uint32_t *)((uintptr_t)syscon + 0xc0)) = 0xaa;
123  *((volatile uint32_t *)((uintptr_t)syscon + 0x80)) = devicecfg | 0x08000000;
124 
125  munmap(syscon, 4096);
126 
127  return ERROR_OK;
128 }
129 
130 static int ep93xx_init(void)
131 {
132  int ret;
133 
135 
136  dev_mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
137  if (dev_mem_fd < 0) {
138  LOG_ERROR("open: %s", strerror(errno));
139  return ERROR_JTAG_INIT_FAILED;
140  }
141 
142  gpio_controller = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
143  MAP_SHARED, dev_mem_fd, 0x80840000);
144  if (gpio_controller == MAP_FAILED) {
145  LOG_ERROR("mmap: %s", strerror(errno));
146  close(dev_mem_fd);
147  return ERROR_JTAG_INIT_FAILED;
148  }
149 
150  ret = set_gonk_mode();
151  if (ret != ERROR_OK) {
152  munmap(gpio_controller, 4096);
153  close(dev_mem_fd);
154  return ret;
155  }
156 
157 #if 0
158  /* Use GPIO port A. */
161 
162 
163  /* Use GPIO port B. */
166 
167  /* Use GPIO port C. */
170 
171  /* Use GPIO port D. */
174 #endif
175 
176  /* Use GPIO port C. */
179 
180  LOG_INFO("gpio_data_register = %p", gpio_data_register);
181  LOG_INFO("gpio_data_direction_reg = %p", gpio_data_direction_register);
182  /*
183  * Configure bit 0 (TDO) as an input, and bits 1-5 (TDI, TCK
184  * TMS, TRST, SRST) as outputs. Drive TDI and TCK low, and
185  * TMS/TRST/SRST high.
186  */
189  usleep(EP93XX_DELAY_US);
190 
191  /*
192  * Configure the direction register. 1 = output, 0 = input.
193  */
196 
197  usleep(EP93XX_DELAY_US);
198  return ERROR_OK;
199 }
200 
201 static int ep93xx_quit(void)
202 {
203 
204  return ERROR_OK;
205 }
int bitbang_execute_queue(struct jtag_command *cmd_queue)
Definition: bitbang.c:293
bb_value
Definition: bitbang.h:17
@ BB_LOW
Definition: bitbang.h:18
@ BB_HIGH
Definition: bitbang.h:19
#define EP93XX_DELAY_US
Definition: ep93xx.c:23
static enum bb_value ep93xx_read(void)
Definition: ep93xx.c:65
static uint8_t output_value
Definition: ep93xx.c:27
struct adapter_driver ep93xx_adapter_driver
Definition: ep93xx.c:47
static int set_gonk_mode(void)
Definition: ep93xx.c:112
#define TRST_BIT
Definition: ep93xx.c:19
#define TDI_BIT
Definition: ep93xx.c:16
#define VCC_BIT
Definition: ep93xx.c:21
static uint8_t * gpio_controller
Definition: ep93xx.c:29
static int ep93xx_quit(void)
Definition: ep93xx.c:201
static int dev_mem_fd
Definition: ep93xx.c:28
static const struct bitbang_interface ep93xx_bitbang
Definition: ep93xx.c:59
static struct jtag_interface ep93xx_interface
Definition: ep93xx.c:42
static int ep93xx_reset(int trst, int srst)
Definition: ep93xx.c:94
#define TDO_BIT
Definition: ep93xx.c:15
static volatile uint8_t * gpio_data_register
Definition: ep93xx.c:30
#define SRST_BIT
Definition: ep93xx.c:20
#define TMS_BIT
Definition: ep93xx.c:18
static volatile uint8_t * gpio_data_direction_register
Definition: ep93xx.c:31
static int ep93xx_write(int tck, int tms, int tdi)
Definition: ep93xx.c:70
static int ep93xx_init(void)
Definition: ep93xx.c:130
#define TCK_BIT
Definition: ep93xx.c:17
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:188
#define ERROR_JTAG_INIT_FAILED
Definition: jtag.h:552
#define LOG_ERROR(expr ...)
Definition: log.h:147
#define LOG_INFO(expr ...)
Definition: log.h:141
#define ERROR_OK
Definition: log.h:182
Represents a driver for a debugging interface.
Definition: interface.h:208
const char *const name
The name of the interface driver.
Definition: interface.h:210
Low level callbacks (for bitbang).
Definition: bitbang.h:30
enum bb_value(* read)(void)
Sample TDO and return the value.
Definition: bitbang.h:32
Represents a driver for a debugging interface.
Definition: interface.h:183
unsigned int supported
Bit vector listing capabilities exposed by this driver.
Definition: interface.h:187
#define TRANSPORT_JTAG
Definition: transport.h:19
#define NULL
Definition: usb.h:16