lattice.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. * Porting to U-Boot:
  3. *
  4. * (C) Copyright 2010
  5. * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
  6. *
  7. * Lattice's ispVME Embedded Tool to load Lattice's FPGA:
  8. *
  9. * Lattice Semiconductor Corp. Copyright 2009
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. *
  29. */
  30. #ifndef _VME_OPCODE_H
  31. #define _VME_OPCODE_H
  32. #define VME_VERSION_NUMBER "12.1"
  33. /* Maximum declarations. */
  34. #define VMEHEXMAX 60000L /* The hex file is split 60K per file. */
  35. #define SCANMAX 64000L /* The maximum SDR/SIR burst. */
  36. /*
  37. *
  38. * Supported JTAG state transitions.
  39. *
  40. */
  41. #define RESET 0x00
  42. #define IDLE 0x01
  43. #define IRPAUSE 0x02
  44. #define DRPAUSE 0x03
  45. #define SHIFTIR 0x04
  46. #define SHIFTDR 0x05
  47. /* 11/15/05 Nguyen changed to support DRCAPTURE*/
  48. #define DRCAPTURE 0x06
  49. /*
  50. * Flow control register bit definitions. A set bit indicates
  51. * that the register currently exhibits the corresponding mode.
  52. */
  53. #define INTEL_PRGM 0x0001 /* Intelligent programming is in effect. */
  54. #define CASCADE 0x0002 /* Currently splitting large SDR. */
  55. #define REPEATLOOP 0x0008 /* Currently executing a repeat loop. */
  56. #define SHIFTRIGHT 0x0080 /* The next data stream needs a right shift. */
  57. #define SHIFTLEFT 0x0100 /* The next data stream needs a left shift. */
  58. #define VERIFYUES 0x0200 /* Continue if fail is in effect. */
  59. /*
  60. * DataType register bit definitions. A set bit indicates
  61. * that the register currently holds the corresponding type of data.
  62. */
  63. #define EXPRESS 0x0001 /* Simultaneous program and verify. */
  64. #define SIR_DATA 0x0002 /* SIR is the active SVF command. */
  65. #define SDR_DATA 0x0004 /* SDR is the active SVF command. */
  66. #define COMPRESS 0x0008 /* Data is compressed. */
  67. #define TDI_DATA 0x0010 /* TDI data is present. */
  68. #define TDO_DATA 0x0020 /* TDO data is present. */
  69. #define MASK_DATA 0x0040 /* MASK data is present. */
  70. #define HEAP_IN 0x0080 /* Data is from the heap. */
  71. #define LHEAP_IN 0x0200 /* Data is from intel data buffer. */
  72. #define VARIABLE 0x0400 /* Data is from a declared variable. */
  73. #define CRC_DATA 0x0800 /* CRC data is pressent. */
  74. #define CMASK_DATA 0x1000 /* CMASK data is pressent. */
  75. #define RMASK_DATA 0x2000 /* RMASK data is pressent. */
  76. #define READ_DATA 0x4000 /* READ data is pressent. */
  77. #define DMASK_DATA 0x8000 /* DMASK data is pressent. */
  78. /*
  79. *
  80. * Pin opcodes.
  81. *
  82. */
  83. #define signalENABLE 0x1C /* ispENABLE pin. */
  84. #define signalTMS 0x1D /* TMS pin. */
  85. #define signalTCK 0x1E /* TCK pin. */
  86. #define signalTDI 0x1F /* TDI pin. */
  87. #define signalTRST 0x20 /* TRST pin. */
  88. /*
  89. *
  90. * Supported vendors.
  91. *
  92. */
  93. #define VENDOR 0x56
  94. #define LATTICE 0x01
  95. #define ALTERA 0x02
  96. #define XILINX 0x03
  97. /*
  98. * Opcode definitions.
  99. *
  100. * Note: opcodes must be unique.
  101. */
  102. #define ENDDATA 0x00 /* The end of the current SDR data stream. */
  103. #define RUNTEST 0x01 /* The duration to stay at the stable state. */
  104. #define ENDDR 0x02 /* The stable state after SDR. */
  105. #define ENDIR 0x03 /* The stable state after SIR. */
  106. #define ENDSTATE 0x04 /* The stable state after RUNTEST. */
  107. #define TRST 0x05 /* Assert the TRST pin. */
  108. #define HIR 0x06 /*
  109. * The sum of the IR bits of the
  110. * leading devices.
  111. */
  112. #define TIR 0x07 /*
  113. * The sum of the IR bits of the trailing
  114. * devices.
  115. */
  116. #define HDR 0x08 /* The number of leading devices. */
  117. #define TDR 0x09 /* The number of trailing devices. */
  118. #define ispEN 0x0A /* Assert the ispEN pin. */
  119. #define FREQUENCY 0x0B /*
  120. * The maximum clock rate to run the JTAG state
  121. * machine.
  122. */
  123. #define STATE 0x10 /* Move to the next stable state. */
  124. #define SIR 0x11 /* The instruction stream follows. */
  125. #define SDR 0x12 /* The data stream follows. */
  126. #define TDI 0x13 /* The following data stream feeds into
  127. the device. */
  128. #define TDO 0x14 /*
  129. * The following data stream is compared against
  130. * the device.
  131. */
  132. #define MASK 0x15 /* The following data stream is used as mask. */
  133. #define XSDR 0x16 /*
  134. * The following data stream is for simultaneous
  135. * program and verify.
  136. */
  137. #define XTDI 0x17 /* The following data stream is for shift in
  138. * only. It must be stored for the next
  139. * XSDR.
  140. */
  141. #define XTDO 0x18 /*
  142. * There is not data stream. The data stream
  143. * was stored from the previous XTDI.
  144. */
  145. #define MEM 0x19 /*
  146. * The maximum memory needed to allocate in
  147. * order hold one row of data.
  148. */
  149. #define WAIT 0x1A /* The duration of delay to observe. */
  150. #define TCK 0x1B /* The number of TCK pulses. */
  151. #define SHR 0x23 /*
  152. * Set the flow control register for
  153. * right shift
  154. */
  155. #define SHL 0x24 /*
  156. * Set the flow control register for left shift.
  157. */
  158. #define HEAP 0x32 /* The memory size needed to hold one loop. */
  159. #define REPEAT 0x33 /* The beginning of the loop. */
  160. #define LEFTPAREN 0x35 /* The beginning of data following the loop. */
  161. #define VAR 0x55 /* Plac holder for loop data. */
  162. #define SEC 0x1C /*
  163. * The delay time in seconds that must be
  164. * observed.
  165. */
  166. #define SMASK 0x1D /* The mask for TDI data. */
  167. #define MAX_WAIT 0x1E /* The absolute maximum wait time. */
  168. #define ON 0x1F /* Assert the targeted pin. */
  169. #define OFF 0x20 /* Dis-assert the targeted pin. */
  170. #define SETFLOW 0x30 /* Change the flow control register. */
  171. #define RESETFLOW 0x31 /* Clear the flow control register. */
  172. #define CRC 0x47 /*
  173. * The following data stream is used for CRC
  174. * calculation.
  175. */
  176. #define CMASK 0x48 /*
  177. * The following data stream is used as mask
  178. * for CRC calculation.
  179. */
  180. #define RMASK 0x49 /*
  181. * The following data stream is used as mask
  182. * for read and save.
  183. */
  184. #define READ 0x50 /*
  185. * The following data stream is used for read
  186. * and save.
  187. */
  188. #define ENDLOOP 0x59 /* The end of the repeat loop. */
  189. #define SECUREHEAP 0x60 /* Used to secure the HEAP opcode. */
  190. #define VUES 0x61 /* Support continue if fail. */
  191. #define DMASK 0x62 /*
  192. * The following data stream is used for dynamic
  193. * I/O.
  194. */
  195. #define COMMENT 0x63 /* Support SVF comments in the VME file. */
  196. #define HEADER 0x64 /* Support header in VME file. */
  197. #define FILE_CRC 0x65 /* Support crc-protected VME file. */
  198. #define LCOUNT 0x66 /* Support intelligent programming. */
  199. #define LDELAY 0x67 /* Support intelligent programming. */
  200. #define LSDR 0x68 /* Support intelligent programming. */
  201. #define LHEAP 0x69 /*
  202. * Memory needed to hold intelligent data
  203. * buffer
  204. */
  205. #define CONTINUE 0x70 /* Allow continuation. */
  206. #define LVDS 0x71 /* Support LVDS. */
  207. #define ENDVME 0x7F /* End of the VME file. */
  208. #define ENDFILE 0xFF /* End of file. */
  209. /*
  210. *
  211. * ispVM Embedded Return Codes.
  212. *
  213. */
  214. #define VME_VERIFICATION_FAILURE -1
  215. #define VME_FILE_READ_FAILURE -2
  216. #define VME_VERSION_FAILURE -3
  217. #define VME_INVALID_FILE -4
  218. #define VME_ARGUMENT_FAILURE -5
  219. #define VME_CRC_FAILURE -6
  220. #define g_ucPinTDI 0x01
  221. #define g_ucPinTCK 0x02
  222. #define g_ucPinTMS 0x04
  223. #define g_ucPinENABLE 0x08
  224. #define g_ucPinTRST 0x10
  225. /*
  226. *
  227. * Type definitions.
  228. *
  229. */
  230. /* Support LVDS */
  231. typedef struct {
  232. unsigned short usPositiveIndex;
  233. unsigned short usNegativeIndex;
  234. unsigned char ucUpdate;
  235. } LVDSPair;
  236. typedef enum {
  237. min_lattice_iface_type, /* insert all new types after this */
  238. lattice_jtag_mode, /* jtag/tap */
  239. max_lattice_iface_type /* insert all new types before this */
  240. } Lattice_iface;
  241. typedef enum {
  242. min_lattice_type,
  243. Lattice_XP2, /* Lattice XP2 Family */
  244. max_lattice_type /* insert all new types before this */
  245. } Lattice_Family;
  246. typedef struct {
  247. Lattice_Family family; /* part type */
  248. Lattice_iface iface; /* interface type */
  249. size_t size; /* bytes of data part can accept */
  250. void *iface_fns; /* interface function table */
  251. void *base; /* base interface address */
  252. int cookie; /* implementation specific cookie */
  253. char *desc; /* description string */
  254. } Lattice_desc; /* end, typedef Altera_desc */
  255. /* Lattice Model Type */
  256. #define CONFIG_SYS_XP2 CONFIG_SYS_FPGA_DEV(0x1)
  257. /* Board specific implementation specific function types */
  258. typedef void (*Lattice_jtag_init)(void);
  259. typedef void (*Lattice_jtag_set_tdi)(int v);
  260. typedef void (*Lattice_jtag_set_tms)(int v);
  261. typedef void (*Lattice_jtag_set_tck)(int v);
  262. typedef int (*Lattice_jtag_get_tdo)(void);
  263. typedef struct {
  264. Lattice_jtag_init jtag_init;
  265. Lattice_jtag_set_tdi jtag_set_tdi;
  266. Lattice_jtag_set_tms jtag_set_tms;
  267. Lattice_jtag_set_tck jtag_set_tck;
  268. Lattice_jtag_get_tdo jtag_get_tdo;
  269. } lattice_board_specific_func;
  270. void writePort(unsigned char pins, unsigned char value);
  271. unsigned char readPort(void);
  272. void sclock(void);
  273. void ispVMDelay(unsigned short int a_usMicroSecondDelay);
  274. void calibration(void);
  275. int lattice_load(Lattice_desc *desc, void *buf, size_t bsize);
  276. int lattice_dump(Lattice_desc *desc, void *buf, size_t bsize);
  277. int lattice_info(Lattice_desc *desc);
  278. void ispVMStart(void);
  279. void ispVMEnd(void);
  280. extern void ispVMFreeMem(void);
  281. signed char ispVMCode(void);
  282. void ispVMDelay(unsigned short int a_usMicroSecondDelay);
  283. void ispVMCalculateCRC32(unsigned char a_ucData);
  284. unsigned char GetByte(void);
  285. void writePort(unsigned char pins, unsigned char value);
  286. unsigned char readPort(void);
  287. void sclock(void);
  288. #endif