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.
 
 
 
 
 
 

239 lines
5.8 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, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include "log.h"
  24. #include "jtag.h"
  25. #include "bitbang.h"
  26. #define TDO_BIT 1
  27. #define TDI_BIT 2
  28. #define TCK_BIT 4
  29. #define TMS_BIT 8
  30. #define TRST_BIT 16
  31. #define SRST_BIT 32
  32. #define VCC_BIT 64
  33. /* system includes */
  34. #include <string.h>
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37. #include <time.h>
  38. #include <sys/mman.h>
  39. #include <unistd.h>
  40. #include <fcntl.h>
  41. static u8 output_value = 0x0;
  42. static int dev_mem_fd;
  43. static void *gpio_controller;
  44. static volatile u8 *gpio_data_register;
  45. static volatile u8 *gpio_data_direction_register;
  46. /* low level command set
  47. */
  48. int ep93xx_read(void);
  49. void ep93xx_write(int tck, int tms, int tdi);
  50. void ep93xx_reset(int trst, int srst);
  51. int ep93xx_speed(int speed);
  52. int ep93xx_register_commands(struct command_context_s *cmd_ctx);
  53. int ep93xx_init(void);
  54. int ep93xx_quit(void);
  55. struct timespec ep93xx_zzzz;
  56. jtag_interface_t ep93xx_interface =
  57. {
  58. .name = "ep93xx",
  59. .execute_queue = bitbang_execute_queue,
  60. .speed = ep93xx_speed,
  61. .register_commands = ep93xx_register_commands,
  62. .init = ep93xx_init,
  63. .quit = ep93xx_quit,
  64. };
  65. bitbang_interface_t ep93xx_bitbang =
  66. {
  67. .read = ep93xx_read,
  68. .write = ep93xx_write,
  69. .reset = ep93xx_reset,
  70. .blink = 0,
  71. };
  72. int ep93xx_read(void)
  73. {
  74. return !!(*gpio_data_register & TDO_BIT);
  75. }
  76. void ep93xx_write(int tck, int tms, int tdi)
  77. {
  78. if (tck)
  79. output_value |= TCK_BIT;
  80. else
  81. output_value &= ~TCK_BIT;
  82. if (tms)
  83. output_value |= TMS_BIT;
  84. else
  85. output_value &= ~TMS_BIT;
  86. if (tdi)
  87. output_value |= TDI_BIT;
  88. else
  89. output_value &= ~TDI_BIT;
  90. *gpio_data_register = output_value;
  91. nanosleep(&ep93xx_zzzz, NULL);
  92. }
  93. /* (1) assert or (0) deassert reset lines */
  94. void ep93xx_reset(int trst, int srst)
  95. {
  96. if (trst == 0)
  97. output_value |= TRST_BIT;
  98. else if (trst == 1)
  99. output_value &= ~TRST_BIT;
  100. if (srst == 0)
  101. output_value |= SRST_BIT;
  102. else if (srst == 1)
  103. output_value &= ~SRST_BIT;
  104. *gpio_data_register = output_value;
  105. nanosleep(&ep93xx_zzzz, NULL);
  106. }
  107. int ep93xx_speed(int speed)
  108. {
  109. return ERROR_OK;
  110. }
  111. int ep93xx_register_commands(struct command_context_s *cmd_ctx)
  112. {
  113. return ERROR_OK;
  114. }
  115. static int set_gonk_mode(void)
  116. {
  117. void *syscon;
  118. u32 devicecfg;
  119. syscon = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
  120. MAP_SHARED, dev_mem_fd, 0x80930000);
  121. if (syscon == MAP_FAILED) {
  122. perror("mmap");
  123. return ERROR_JTAG_INIT_FAILED;
  124. }
  125. devicecfg = *((volatile int *)(syscon + 0x80));
  126. *((volatile int *)(syscon + 0xc0)) = 0xaa;
  127. *((volatile int *)(syscon + 0x80)) = devicecfg | 0x08000000;
  128. munmap(syscon, 4096);
  129. return ERROR_OK;
  130. }
  131. int ep93xx_init(void)
  132. {
  133. int ret;
  134. bitbang_interface = &ep93xx_bitbang;
  135. ep93xx_zzzz.tv_sec = 0;
  136. ep93xx_zzzz.tv_nsec = 10000000;
  137. dev_mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
  138. if (dev_mem_fd < 0) {
  139. perror("open");
  140. return ERROR_JTAG_INIT_FAILED;
  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. perror("mmap");
  146. close(dev_mem_fd);
  147. return ERROR_JTAG_INIT_FAILED;
  148. }
  149. ret = set_gonk_mode();
  150. if (ret != ERROR_OK) {
  151. munmap(gpio_controller, 4096);
  152. close(dev_mem_fd);
  153. return ret;
  154. }
  155. #if 0
  156. /* Use GPIO port A. */
  157. gpio_data_register = gpio_controller + 0x00;
  158. gpio_data_direction_register = gpio_controller + 0x10;
  159. /* Use GPIO port B. */
  160. gpio_data_register = gpio_controller + 0x04;
  161. gpio_data_direction_register = gpio_controller + 0x14;
  162. /* Use GPIO port C. */
  163. gpio_data_register = gpio_controller + 0x08;
  164. gpio_data_direction_register = gpio_controller + 0x18;
  165. /* Use GPIO port D. */
  166. gpio_data_register = gpio_controller + 0x0c;
  167. gpio_data_direction_register = gpio_controller + 0x1c;
  168. #endif
  169. /* Use GPIO port C. */
  170. gpio_data_register = gpio_controller + 0x08;
  171. gpio_data_direction_register = gpio_controller + 0x18;
  172. LOG_INFO("gpio_data_register = %p\n", gpio_data_register);
  173. LOG_INFO("gpio_data_direction_reg = %p\n", gpio_data_direction_register);
  174. /*
  175. * Configure bit 0 (TDO) as an input, and bits 1-5 (TDI, TCK
  176. * TMS, TRST, SRST) as outputs. Drive TDI and TCK low, and
  177. * TMS/TRST/SRST high.
  178. */
  179. output_value = TMS_BIT | TRST_BIT | SRST_BIT | VCC_BIT;
  180. *gpio_data_register = output_value;
  181. nanosleep(&ep93xx_zzzz, NULL);
  182. /*
  183. * Configure the direction register. 1 = output, 0 = input.
  184. */
  185. *gpio_data_direction_register =
  186. TDI_BIT | TCK_BIT | TMS_BIT | TRST_BIT | SRST_BIT | VCC_BIT;
  187. nanosleep(&ep93xx_zzzz, NULL);
  188. return ERROR_OK;
  189. }
  190. int ep93xx_quit(void)
  191. {
  192. return ERROR_OK;
  193. }