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 #include <sys/mman.h>
24 
25 static uint8_t output_value;
26 static int dev_mem_fd;
27 static uint8_t *gpio_controller;
28 static volatile uint8_t *gpio_data_register;
29 static volatile uint8_t *gpio_data_direction_register;
30 
31 /* low level command set
32  */
33 static enum bb_value ep93xx_read(void);
34 static int ep93xx_write(int tck, int tms, int tdi);
35 static int ep93xx_reset(int trst, int srst);
36 
37 static int ep93xx_init(void);
38 static int ep93xx_quit(void);
39 
40 static struct timespec ep93xx_zzzz;
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  nanosleep(&ep93xx_zzzz, NULL);
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  nanosleep(&ep93xx_zzzz, NULL);
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  ep93xx_zzzz.tv_sec = 0;
137  ep93xx_zzzz.tv_nsec = 10000000;
138 
139  dev_mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
140  if (dev_mem_fd < 0) {
141  LOG_ERROR("open: %s", strerror(errno));
142  return ERROR_JTAG_INIT_FAILED;
143  }
144 
145  gpio_controller = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
146  MAP_SHARED, dev_mem_fd, 0x80840000);
147  if (gpio_controller == MAP_FAILED) {
148  LOG_ERROR("mmap: %s", strerror(errno));
149  close(dev_mem_fd);
150  return ERROR_JTAG_INIT_FAILED;
151  }
152 
153  ret = set_gonk_mode();
154  if (ret != ERROR_OK) {
155  munmap(gpio_controller, 4096);
156  close(dev_mem_fd);
157  return ret;
158  }
159 
160 #if 0
161  /* Use GPIO port A. */
164 
165 
166  /* Use GPIO port B. */
169 
170  /* Use GPIO port C. */
173 
174  /* Use GPIO port D. */
177 #endif
178 
179  /* Use GPIO port C. */
182 
183  LOG_INFO("gpio_data_register = %p", gpio_data_register);
184  LOG_INFO("gpio_data_direction_reg = %p", gpio_data_direction_register);
185  /*
186  * Configure bit 0 (TDO) as an input, and bits 1-5 (TDI, TCK
187  * TMS, TRST, SRST) as outputs. Drive TDI and TCK low, and
188  * TMS/TRST/SRST high.
189  */
192  nanosleep(&ep93xx_zzzz, NULL);
193 
194  /*
195  * Configure the direction register. 1 = output, 0 = input.
196  */
199 
200  nanosleep(&ep93xx_zzzz, NULL);
201  return ERROR_OK;
202 }
203 
204 static int ep93xx_quit(void)
205 {
206 
207  return ERROR_OK;
208 }
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
static enum bb_value ep93xx_read(void)
Definition: ep93xx.c:65
static uint8_t output_value
Definition: ep93xx.c:25
static struct timespec ep93xx_zzzz
Definition: ep93xx.c:40
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:27
static int ep93xx_quit(void)
Definition: ep93xx.c:204
static int dev_mem_fd
Definition: ep93xx.c:26
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:28
#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:29
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:133
#define LOG_INFO(expr ...)
Definition: log.h:127
#define ERROR_OK
Definition: log.h:168
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