lattice.h 9.0 KB

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