You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

213 lines
5.4 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  17. ***************************************************************************/
  18. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif
  21. #include <jtag/interface.h>
  22. #include "bitbang.h"
  23. #define TDO_BIT 1
  24. #define TDI_BIT 2
  25. #define TCK_BIT 4
  26. #define TMS_BIT 8
  27. #define TRST_BIT 16
  28. #define SRST_BIT 32
  29. #define VCC_BIT 64
  30. #include <sys/mman.h>
  31. static uint8_t output_value;
  32. static int dev_mem_fd;
  33. static void *gpio_controller;
  34. static volatile uint8_t *gpio_data_register;
  35. static volatile uint8_t *gpio_data_direction_register;
  36. /* low level command set
  37. */
  38. static int ep93xx_read(void);
  39. static void ep93xx_write(int tck, int tms, int tdi);
  40. static void ep93xx_reset(int trst, int srst);
  41. static int ep93xx_init(void);
  42. static int ep93xx_quit(void);
  43. struct timespec ep93xx_zzzz;
  44. struct jtag_interface ep93xx_interface = {
  45. .name = "ep93xx",
  46. .supported = DEBUG_CAP_TMS_SEQ,
  47. .execute_queue = bitbang_execute_queue,
  48. .init = ep93xx_init,
  49. .quit = ep93xx_quit,
  50. };
  51. static struct bitbang_interface ep93xx_bitbang = {
  52. .read = ep93xx_read,
  53. .write = ep93xx_write,
  54. .reset = ep93xx_reset,
  55. .blink = 0,
  56. };
  57. static int ep93xx_read(void)
  58. {
  59. return !!(*gpio_data_register & TDO_BIT);
  60. }
  61. static void ep93xx_write(int tck, int tms, int tdi)
  62. {
  63. if (tck)
  64. output_value |= TCK_BIT;
  65. else
  66. output_value &= ~TCK_BIT;
  67. if (tms)
  68. output_value |= TMS_BIT;
  69. else
  70. output_value &= ~TMS_BIT;
  71. if (tdi)
  72. output_value |= TDI_BIT;
  73. else
  74. output_value &= ~TDI_BIT;
  75. *gpio_data_register = output_value;
  76. nanosleep(&ep93xx_zzzz, NULL);
  77. }
  78. /* (1) assert or (0) deassert reset lines */
  79. static void ep93xx_reset(int trst, int srst)
  80. {
  81. if (trst == 0)
  82. output_value |= TRST_BIT;
  83. else if (trst == 1)
  84. output_value &= ~TRST_BIT;
  85. if (srst == 0)
  86. output_value |= SRST_BIT;
  87. else if (srst == 1)
  88. output_value &= ~SRST_BIT;
  89. *gpio_data_register = output_value;
  90. nanosleep(&ep93xx_zzzz, NULL);
  91. }
  92. static int set_gonk_mode(void)
  93. {
  94. void *syscon;
  95. uint32_t devicecfg;
  96. syscon = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
  97. MAP_SHARED, dev_mem_fd, 0x80930000);
  98. if (syscon == MAP_FAILED) {
  99. perror("mmap");
  100. return ERROR_JTAG_INIT_FAILED;
  101. }
  102. devicecfg = *((volatile int *)(syscon + 0x80));
  103. *((volatile int *)(syscon + 0xc0)) = 0xaa;
  104. *((volatile int *)(syscon + 0x80)) = devicecfg | 0x08000000;
  105. munmap(syscon, 4096);
  106. return ERROR_OK;
  107. }
  108. static int ep93xx_init(void)
  109. {
  110. int ret;
  111. bitbang_interface = &ep93xx_bitbang;
  112. ep93xx_zzzz.tv_sec = 0;
  113. ep93xx_zzzz.tv_nsec = 10000000;
  114. dev_mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
  115. if (dev_mem_fd < 0) {
  116. perror("open");
  117. return ERROR_JTAG_INIT_FAILED;
  118. }
  119. gpio_controller = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
  120. MAP_SHARED, dev_mem_fd, 0x80840000);
  121. if (gpio_controller == MAP_FAILED) {
  122. perror("mmap");
  123. close(dev_mem_fd);
  124. return ERROR_JTAG_INIT_FAILED;
  125. }
  126. ret = set_gonk_mode();
  127. if (ret != ERROR_OK) {
  128. munmap(gpio_controller, 4096);
  129. close(dev_mem_fd);
  130. return ret;
  131. }
  132. #if 0
  133. /* Use GPIO port A. */
  134. gpio_data_register = gpio_controller + 0x00;
  135. gpio_data_direction_register = gpio_controller + 0x10;
  136. /* Use GPIO port B. */
  137. gpio_data_register = gpio_controller + 0x04;
  138. gpio_data_direction_register = gpio_controller + 0x14;
  139. /* Use GPIO port C. */
  140. gpio_data_register = gpio_controller + 0x08;
  141. gpio_data_direction_register = gpio_controller + 0x18;
  142. /* Use GPIO port D. */
  143. gpio_data_register = gpio_controller + 0x0c;
  144. gpio_data_direction_register = gpio_controller + 0x1c;
  145. #endif
  146. /* Use GPIO port C. */
  147. gpio_data_register = gpio_controller + 0x08;
  148. gpio_data_direction_register = gpio_controller + 0x18;
  149. LOG_INFO("gpio_data_register = %p", gpio_data_register);
  150. LOG_INFO("gpio_data_direction_reg = %p", gpio_data_direction_register);
  151. /*
  152. * Configure bit 0 (TDO) as an input, and bits 1-5 (TDI, TCK
  153. * TMS, TRST, SRST) as outputs. Drive TDI and TCK low, and
  154. * TMS/TRST/SRST high.
  155. */
  156. output_value = TMS_BIT | TRST_BIT | SRST_BIT | VCC_BIT;
  157. *gpio_data_register = output_value;
  158. nanosleep(&ep93xx_zzzz, NULL);
  159. /*
  160. * Configure the direction register. 1 = output, 0 = input.
  161. */
  162. *gpio_data_direction_register =
  163. TDI_BIT | TCK_BIT | TMS_BIT | TRST_BIT | SRST_BIT | VCC_BIT;
  164. nanosleep(&ep93xx_zzzz, NULL);
  165. return ERROR_OK;
  166. }
  167. static int ep93xx_quit(void)
  168. {
  169. return ERROR_OK;
  170. }