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