1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * altera-jtag.h
4 *
5 * altera FPGA driver
6 *
7 * Copyright (C) Altera Corporation 1998-2001
8 * Copyright (C) 2010 NetUP Inc.
9 * Copyright (C) 2010 Igor M. Liplianin <liplianin@netup.ru>
10 */
11
12#ifndef ALTERA_JTAG_H
13#define ALTERA_JTAG_H
14
15/* Function Prototypes */
16enum altera_jtag_state {
17	ILLEGAL_JTAG_STATE = -1,
18	RESET = 0,
19	IDLE = 1,
20	DRSELECT = 2,
21	DRCAPTURE = 3,
22	DRSHIFT = 4,
23	DREXIT1 = 5,
24	DRPAUSE = 6,
25	DREXIT2 = 7,
26	DRUPDATE = 8,
27	IRSELECT = 9,
28	IRCAPTURE = 10,
29	IRSHIFT = 11,
30	IREXIT1 = 12,
31	IRPAUSE = 13,
32	IREXIT2 = 14,
33	IRUPDATE = 15
34
35};
36
37struct altera_jtag {
38	/* Global variable to store the current JTAG state */
39	enum altera_jtag_state jtag_state;
40
41	/* Store current stop-state for DR and IR scan commands */
42	enum altera_jtag_state drstop_state;
43	enum altera_jtag_state irstop_state;
44
45	/* Store current padding values */
46	u32 dr_pre;
47	u32 dr_post;
48	u32 ir_pre;
49	u32 ir_post;
50	u32 dr_length;
51	u32 ir_length;
52	u8 *dr_pre_data;
53	u8 *dr_post_data;
54	u8 *ir_pre_data;
55	u8 *ir_post_data;
56	u8 *dr_buffer;
57	u8 *ir_buffer;
58};
59
60#define ALTERA_STACK_SIZE 128
61#define ALTERA_MESSAGE_LENGTH 1024
62
63struct altera_state {
64	struct altera_config	*config;
65	struct altera_jtag	js;
66	char			msg_buff[ALTERA_MESSAGE_LENGTH + 1];
67	long			stack[ALTERA_STACK_SIZE];
68};
69
70int altera_jinit(struct altera_state *astate);
71int altera_set_drstop(struct altera_jtag *js, enum altera_jtag_state state);
72int altera_set_irstop(struct altera_jtag *js, enum altera_jtag_state state);
73int altera_set_dr_pre(struct altera_jtag *js, u32 count, u32 start_index,
74				u8 *preamble_data);
75int altera_set_ir_pre(struct altera_jtag *js, u32 count, u32 start_index,
76				u8 *preamble_data);
77int altera_set_dr_post(struct altera_jtag *js, u32 count, u32 start_index,
78				u8 *postamble_data);
79int altera_set_ir_post(struct altera_jtag *js, u32 count, u32 start_index,
80				u8 *postamble_data);
81int altera_goto_jstate(struct altera_state *astate,
82				enum altera_jtag_state state);
83int altera_wait_cycles(struct altera_state *astate, s32 cycles,
84				enum altera_jtag_state wait_state);
85int altera_wait_msecs(struct altera_state *astate, s32 microseconds,
86				enum altera_jtag_state wait_state);
87int altera_irscan(struct altera_state *astate, u32 count,
88				u8 *tdi_data, u32 start_index);
89int altera_swap_ir(struct altera_state *astate,
90				u32 count, u8 *in_data,
91				u32 in_index, u8 *out_data,
92				u32 out_index);
93int altera_drscan(struct altera_state *astate, u32 count,
94				u8 *tdi_data, u32 start_index);
95int altera_swap_dr(struct altera_state *astate, u32 count,
96				u8 *in_data, u32 in_index,
97				u8 *out_data, u32 out_index);
98void altera_free_buffers(struct altera_state *astate);
99#endif /* ALTERA_JTAG_H */
100