xref: /linux/drivers/staging/gpib/uapi/gpib.h (revision a100922a3855eb35ecd465f1d558546b1e144445)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 /***************************************************************************
4  *    copyright		   : (C) 2002 by Frank Mori Hess
5  ***************************************************************************/
6 
7 #ifndef _GPIB_H
8 #define _GPIB_H
9 
10 #define GPIB_MAX_NUM_BOARDS 16
11 #define GPIB_MAX_NUM_DESCRIPTORS 0x1000
12 
13 enum ibsta_bit_numbers {
14 	DCAS_NUM = 0,
15 	DTAS_NUM = 1,
16 	LACS_NUM = 2,
17 	TACS_NUM = 3,
18 	ATN_NUM = 4,
19 	CIC_NUM = 5,
20 	REM_NUM = 6,
21 	LOK_NUM = 7,
22 	CMPL_NUM = 8,
23 	EVENT_NUM = 9,
24 	SPOLL_NUM = 10,
25 	RQS_NUM = 11,
26 	SRQI_NUM = 12,
27 	END_NUM = 13,
28 	TIMO_NUM = 14,
29 	ERR_NUM = 15
30 };
31 
32 /* IBSTA status bits (returned by all functions) */
33 enum ibsta_bits {
34 	DCAS = (1 << DCAS_NUM),	/* device clear state */
35 	DTAS = (1 << DTAS_NUM),	/* device trigger state */
36 	LACS = (1 <<  LACS_NUM),	/* GPIB interface is addressed as Listener */
37 	TACS = (1 <<  TACS_NUM),	/* GPIB interface is addressed as Talker */
38 	ATN = (1 <<  ATN_NUM),	/* Attention is asserted */
39 	CIC = (1 <<  CIC_NUM),	/* GPIB interface is Controller-in-Charge */
40 	REM = (1 << REM_NUM),	/* remote state */
41 	LOK = (1 << LOK_NUM),	/* lockout state */
42 	CMPL = (1 <<  CMPL_NUM),	/* I/O is complete  */
43 	EVENT = (1 << EVENT_NUM),	/* DCAS, DTAS, or IFC has occurred */
44 	SPOLL = (1 << SPOLL_NUM),	/* board serial polled by busmaster */
45 	RQS = (1 <<  RQS_NUM),	/* Device requesting service  */
46 	SRQI = (1 << SRQI_NUM),	/* SRQ is asserted */
47 	END = (1 << END_NUM),	/* EOI or EOS encountered */
48 	TIMO = (1 << TIMO_NUM),	/* Time limit on I/O or wait function exceeded */
49 	ERR = (1 << ERR_NUM),	/* Function call terminated on error */
50 
51 	device_status_mask = ERR | TIMO | END | CMPL | RQS,
52 	board_status_mask = ERR | TIMO | END | CMPL | SPOLL |
53 		EVENT | LOK | REM | CIC | ATN | TACS | LACS | DTAS | DCAS | SRQI,
54 };
55 
56 /* End-of-string (EOS) modes for use with ibeos */
57 
58 enum eos_flags {
59 	EOS_MASK = 0x1c00,
60 	REOS = 0x0400,		/* Terminate reads on EOS	*/
61 	XEOS = 0x800,	/* assert EOI when EOS char is sent */
62 	BIN = 0x1000		/* Do 8-bit compare on EOS	*/
63 };
64 
65 /* GPIB Bus Control Lines bit vector */
66 enum bus_control_line {
67 	VALID_DAV = 0x01,
68 	VALID_NDAC = 0x02,
69 	VALID_NRFD = 0x04,
70 	VALID_IFC = 0x08,
71 	VALID_REN = 0x10,
72 	VALID_SRQ = 0x20,
73 	VALID_ATN = 0x40,
74 	VALID_EOI = 0x80,
75 	VALID_ALL = 0xff,
76 	BUS_DAV = 0x0100,		/* DAV	line status bit */
77 	BUS_NDAC = 0x0200,		/* NDAC line status bit */
78 	BUS_NRFD = 0x0400,		/* NRFD line status bit */
79 	BUS_IFC = 0x0800,		/* IFC	line status bit */
80 	BUS_REN = 0x1000,		/* REN	line status bit */
81 	BUS_SRQ = 0x2000,		/* SRQ	line status bit */
82 	BUS_ATN = 0x4000,		/* ATN	line status bit */
83 	BUS_EOI = 0x8000		/* EOI	line status bit */
84 };
85 
86 /* Possible GPIB command messages */
87 
88 enum cmd_byte {
89 	GTL = 0x1,	/* go to local			*/
90 	SDC = 0x4,	/* selected device clear	*/
91 	PP_CONFIG = 0x5,
92 #ifndef PPC
93 	PPC = PP_CONFIG, /* parallel poll configure	*/
94 #endif
95 	GET = 0x8,	/* group execute trigger	*/
96 	TCT = 0x9,	/* take control			*/
97 	LLO = 0x11,	/* local lockout		*/
98 	DCL = 0x14,	/* device clear			*/
99 	PPU = 0x15,	/* parallel poll unconfigure	*/
100 	SPE = 0x18,	/* serial poll enable		*/
101 	SPD = 0x19,	/* serial poll disable		*/
102 	CFE = 0x1f, /* configure enable */
103 	LAD = 0x20,	/* value to be 'ored' in to obtain listen address */
104 	UNL = 0x3F,	/* unlisten			*/
105 	TAD = 0x40,	/* value to be 'ored' in to obtain talk address	  */
106 	UNT = 0x5F,	/* untalk			*/
107 	SAD = 0x60,	/* my secondary address (base) */
108 	PPE = 0x60,	/* parallel poll enable (base)	*/
109 	PPD = 0x70	/* parallel poll disable	*/
110 };
111 
112 enum ppe_bits {
113 	PPC_DISABLE = 0x10,
114 	PPC_SENSE = 0x8,	/* parallel poll sense bit	*/
115 	PPC_DIO_MASK = 0x7
116 };
117 
118 /* confine address to range 0 to 30. */
gpib_address_restrict(unsigned int addr)119 static inline unsigned int gpib_address_restrict(unsigned int addr)
120 {
121 	addr &= 0x1f;
122 	if (addr == 0x1f)
123 		addr = 0;
124 	return addr;
125 }
126 
MLA(unsigned int addr)127 static inline __u8 MLA(unsigned int addr)
128 {
129 	return gpib_address_restrict(addr) | LAD;
130 }
131 
MTA(unsigned int addr)132 static inline __u8 MTA(unsigned int addr)
133 {
134 	return gpib_address_restrict(addr) | TAD;
135 }
136 
MSA(unsigned int addr)137 static inline __u8 MSA(unsigned int addr)
138 {
139 	return (addr & 0x1f) | SAD;
140 }
141 
PPE_byte(unsigned int dio_line,int sense)142 static inline __u8 PPE_byte(unsigned int dio_line, int sense)
143 {
144 	__u8 cmd;
145 
146 	cmd = PPE;
147 	if (sense)
148 		cmd |= PPC_SENSE;
149 	cmd |= (dio_line - 1) & 0x7;
150 	return cmd;
151 }
152 
153 /* mask of bits that actually matter in a command byte */
154 enum {
155 	gpib_command_mask = 0x7f,
156 };
157 
is_PPE(__u8 command)158 static inline int is_PPE(__u8 command)
159 {
160 	return (command & 0x70) == 0x60;
161 }
162 
is_PPD(__u8 command)163 static inline int is_PPD(__u8 command)
164 {
165 	return (command & 0x70) == 0x70;
166 }
167 
in_addressed_command_group(__u8 command)168 static inline int in_addressed_command_group(__u8 command)
169 {
170 	return (command & 0x70) == 0x0;
171 }
172 
in_universal_command_group(__u8 command)173 static inline int in_universal_command_group(__u8 command)
174 {
175 	return (command & 0x70) == 0x10;
176 }
177 
in_listen_address_group(__u8 command)178 static inline int in_listen_address_group(__u8 command)
179 {
180 	return (command & 0x60) == 0x20;
181 }
182 
in_talk_address_group(__u8 command)183 static inline int in_talk_address_group(__u8 command)
184 {
185 	return (command & 0x60) == 0x40;
186 }
187 
in_primary_command_group(__u8 command)188 static inline int in_primary_command_group(__u8 command)
189 {
190 	return in_addressed_command_group(command) ||
191 		in_universal_command_group(command) ||
192 		in_listen_address_group(command) ||
193 		in_talk_address_group(command);
194 }
195 
gpib_address_equal(unsigned int pad1,int sad1,unsigned int pad2,int sad2)196 static inline int gpib_address_equal(unsigned int pad1, int sad1, unsigned int pad2, int sad2)
197 {
198 	if (pad1 == pad2) {
199 		if (sad1 == sad2)
200 			return 1;
201 		if (sad1 < 0 && sad2 < 0)
202 			return 1;
203 	}
204 
205 	return 0;
206 }
207 
208 enum ibask_option {
209 	IBA_PAD = 0x1,
210 	IBA_SAD = 0x2,
211 	IBA_TMO = 0x3,
212 	IBA_EOT = 0x4,
213 	IBA_PPC = 0x5,	/* board only */
214 	IBA_READ_DR = 0x6,	/* device only */
215 	IBA_AUTOPOLL = 0x7,	/* board only */
216 	IBA_CICPROT = 0x8,	/* board only */
217 	IBA_IRQ = 0x9,	/* board only */
218 	IBA_SC = 0xa,	/* board only */
219 	IBA_SRE = 0xb,	/* board only */
220 	IBA_EOS_RD = 0xc,
221 	IBA_EOS_WRT = 0xd,
222 	IBA_EOS_CMP = 0xe,
223 	IBA_EOS_CHAR = 0xf,
224 	IBA_PP2 = 0x10,	/* board only */
225 	IBA_TIMING = 0x11,	/* board only */
226 	IBA_DMA = 0x12,	/* board only */
227 	IBA_READ_ADJUST = 0x13,
228 	IBA_WRITE_ADJUST = 0x14,
229 	IBA_EVENT_QUEUE = 0x15,	/* board only */
230 	IBA_SPOLL_BIT = 0x16,	/* board only */
231 	IBA_SEND_LLO = 0x17,	/* board only */
232 	IBA_SPOLL_TIME = 0x18,	/* device only */
233 	IBA_PPOLL_TIME = 0x19,	/* board only */
234 	IBA_END_BIT_IS_NORMAL = 0x1a,
235 	IBA_UN_ADDR = 0x1b,	/* device only */
236 	IBA_HS_CABLE_LENGTH = 0x1f,	/* board only */
237 	IBA_IST = 0x20,	/* board only */
238 	IBA_RSV = 0x21,	/* board only */
239 	IBA_BNA = 0x200,	/* device only */
240 	/* linux-gpib extensions */
241 	IBA_7_BIT_EOS = 0x1000	/* board only. Returns 1 if board supports 7 bit eos compares*/
242 };
243 
244 enum ibconfig_option {
245 	IBC_PAD = 0x1,
246 	IBC_SAD = 0x2,
247 	IBC_TMO = 0x3,
248 	IBC_EOT = 0x4,
249 	IBC_PPC = 0x5,	/* board only */
250 	IBC_READDR = 0x6,	/* device only */
251 	IBC_AUTOPOLL = 0x7,	/* board only */
252 	IBC_CICPROT = 0x8,	/* board only */
253 	IBC_IRQ = 0x9,	/* board only */
254 	IBC_SC = 0xa,	/* board only */
255 	IBC_SRE = 0xb,	/* board only */
256 	IBC_EOS_RD = 0xc,
257 	IBC_EOS_WRT = 0xd,
258 	IBC_EOS_CMP = 0xe,
259 	IBC_EOS_CHAR = 0xf,
260 	IBC_PP2 = 0x10,	/* board only */
261 	IBC_TIMING = 0x11,	/* board only */
262 	IBC_DMA = 0x12,	/* board only */
263 	IBC_READ_ADJUST = 0x13,
264 	IBC_WRITE_ADJUST = 0x14,
265 	IBC_EVENT_QUEUE = 0x15,	/* board only */
266 	IBC_SPOLL_BIT = 0x16,	/* board only */
267 	IBC_SEND_LLO = 0x17,	/* board only */
268 	IBC_SPOLL_TIME = 0x18,	/* device only */
269 	IBC_PPOLL_TIME = 0x19,	/* board only */
270 	IBC_END_BIT_IS_NORMAL = 0x1a,
271 	IBC_UN_ADDR = 0x1b,	/* device only */
272 	IBC_HS_CABLE_LENGTH = 0x1f,	/* board only */
273 	IBC_IST = 0x20,	/* board only */
274 	IBC_RSV = 0x21,	/* board only */
275 	IBC_BNA = 0x200	/* device only */
276 };
277 
278 enum t1_delays {
279 	T1_DELAY_2000ns = 1,
280 	T1_DELAY_500ns = 2,
281 	T1_DELAY_350ns = 3
282 };
283 
284 enum {
285 	request_service_bit = 0x40,
286 };
287 
288 enum gpib_events {
289 	EVENT_NONE = 0,
290 	EVENT_DEV_TRG = 1,
291 	EVENT_DEV_CLR = 2,
292 	EVENT_IFC = 3
293 };
294 
295 enum gpib_stb {
296 	IB_STB_RQS = 0x40, /* IEEE 488.1 & 2  */
297 	IB_STB_ESB = 0x20, /* IEEE 488.2 only */
298 	IB_STB_MAV = 0x10	 /* IEEE 488.2 only */
299 };
300 
301 #endif	/* _GPIB_H */
302 
303