1 /*
2  * altera-jtag.h
3  *
4  * altera FPGA driver
5  *
6  * Copyright (C) Altera Corporation 1998-2001
7  * Copyright (C) 2010 NetUP Inc.
8  * Copyright (C) 2010 Igor M. Liplianin <liplianin@netup.ru>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 #ifndef ALTERA_JTAG_H
27 #define ALTERA_JTAG_H
28 
29 /* Function Prototypes */
30 enum altera_jtag_state {
31 	ILLEGAL_JTAG_STATE = -1,
32 	RESET = 0,
33 	IDLE = 1,
34 	DRSELECT = 2,
35 	DRCAPTURE = 3,
36 	DRSHIFT = 4,
37 	DREXIT1 = 5,
38 	DRPAUSE = 6,
39 	DREXIT2 = 7,
40 	DRUPDATE = 8,
41 	IRSELECT = 9,
42 	IRCAPTURE = 10,
43 	IRSHIFT = 11,
44 	IREXIT1 = 12,
45 	IRPAUSE = 13,
46 	IREXIT2 = 14,
47 	IRUPDATE = 15
48 
49 };
50 
51 struct altera_jtag {
52 	/* Global variable to store the current JTAG state */
53 	enum altera_jtag_state jtag_state;
54 
55 	/* Store current stop-state for DR and IR scan commands */
56 	enum altera_jtag_state drstop_state;
57 	enum altera_jtag_state irstop_state;
58 
59 	/* Store current padding values */
60 	u32 dr_pre;
61 	u32 dr_post;
62 	u32 ir_pre;
63 	u32 ir_post;
64 	u32 dr_length;
65 	u32 ir_length;
66 	u8 *dr_pre_data;
67 	u8 *dr_post_data;
68 	u8 *ir_pre_data;
69 	u8 *ir_post_data;
70 	u8 *dr_buffer;
71 	u8 *ir_buffer;
72 };
73 
74 #define ALTERA_STACK_SIZE 128
75 #define ALTERA_MESSAGE_LENGTH 1024
76 
77 struct altera_state {
78 	struct altera_config	*config;
79 	struct altera_jtag	js;
80 	char			msg_buff[ALTERA_MESSAGE_LENGTH + 1];
81 	long			stack[ALTERA_STACK_SIZE];
82 };
83 
84 int altera_jinit(struct altera_state *astate);
85 int altera_set_drstop(struct altera_jtag *js, enum altera_jtag_state state);
86 int altera_set_irstop(struct altera_jtag *js, enum altera_jtag_state state);
87 int altera_set_dr_pre(struct altera_jtag *js, u32 count, u32 start_index,
88 				u8 *preamble_data);
89 int altera_set_ir_pre(struct altera_jtag *js, u32 count, u32 start_index,
90 				u8 *preamble_data);
91 int altera_set_dr_post(struct altera_jtag *js, u32 count, u32 start_index,
92 				u8 *postamble_data);
93 int altera_set_ir_post(struct altera_jtag *js, u32 count, u32 start_index,
94 				u8 *postamble_data);
95 int altera_goto_jstate(struct altera_state *astate,
96 				enum altera_jtag_state state);
97 int altera_wait_cycles(struct altera_state *astate, s32 cycles,
98 				enum altera_jtag_state wait_state);
99 int altera_wait_msecs(struct altera_state *astate, s32 microseconds,
100 				enum altera_jtag_state wait_state);
101 int altera_irscan(struct altera_state *astate, u32 count,
102 				u8 *tdi_data, u32 start_index);
103 int altera_swap_ir(struct altera_state *astate,
104 				u32 count, u8 *in_data,
105 				u32 in_index, u8 *out_data,
106 				u32 out_index);
107 int altera_drscan(struct altera_state *astate, u32 count,
108 				u8 *tdi_data, u32 start_index);
109 int altera_swap_dr(struct altera_state *astate, u32 count,
110 				u8 *in_data, u32 in_index,
111 				u8 *out_data, u32 out_index);
112 void altera_free_buffers(struct altera_state *astate);
113 #endif /* ALTERA_JTAG_H */
114