xref: /linux/drivers/staging/gpib/include/gpib_cmd.h (revision 1641684528815bb7e85737d5d2bceb551c55d5a8)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef _GPIB_CMD_H
4 #define _GPIB_CMD_H
5 
6 #include <linux/types.h>
7 
8 /* Command byte definitions tests and functions */
9 
10 /* mask of bits that actually matter in a command byte */
11 enum {
12 	gpib_command_mask = 0x7f,
13 };
14 
15 /* Possible GPIB command messages */
16 
17 enum cmd_byte {
18 	GTL = 0x1,	/* go to local			*/
19 	SDC = 0x4,	/* selected device clear	*/
20 	PP_CONFIG = 0x5,
21 	GET = 0x8,	/* group execute trigger	*/
22 	TCT = 0x9,	/* take control			*/
23 	LLO = 0x11,	/* local lockout		*/
24 	DCL = 0x14,	/* device clear			*/
25 	PPU = 0x15,	/* parallel poll unconfigure	*/
26 	SPE = 0x18,	/* serial poll enable		*/
27 	SPD = 0x19,	/* serial poll disable		*/
28 	CFE = 0x1f,     /* configure enable */
29 	LAD = 0x20,	/* value to be 'ored' in to obtain listen address */
30 	UNL = 0x3F,	/* unlisten			*/
31 	TAD = 0x40,	/* value to be 'ored' in to obtain talk address	  */
32 	UNT = 0x5F,	/* untalk			*/
33 	SAD = 0x60,	/* my secondary address (base) */
34 	PPE = 0x60,	/* parallel poll enable (base)	*/
35 	PPD = 0x70	/* parallel poll disable	*/
36 };
37 
38 /* confine address to range 0 to 30. */
gpib_address_restrict(u32 addr)39 static inline unsigned int gpib_address_restrict(u32 addr)
40 {
41 	addr &= 0x1f;
42 	if (addr == 0x1f)
43 		addr = 0;
44 	return addr;
45 }
46 
MLA(u32 addr)47 static inline u8 MLA(u32 addr)
48 {
49 	return gpib_address_restrict(addr) | LAD;
50 }
51 
MTA(u32 addr)52 static inline u8 MTA(u32 addr)
53 {
54 	return gpib_address_restrict(addr) | TAD;
55 }
56 
MSA(u32 addr)57 static inline u8 MSA(u32 addr)
58 {
59 	return (addr & 0x1f) | SAD;
60 }
61 
gpib_address_equal(u32 pad1,s32 sad1,u32 pad2,s32 sad2)62 static inline s32 gpib_address_equal(u32 pad1, s32 sad1, u32 pad2, s32 sad2)
63 {
64 	if (pad1 == pad2) {
65 		if (sad1 == sad2)
66 			return 1;
67 		if (sad1 < 0 && sad2 < 0)
68 			return 1;
69 	}
70 
71 	return 0;
72 }
73 
is_PPE(u8 command)74 static inline s32 is_PPE(u8 command)
75 {
76 	return (command & 0x70) == 0x60;
77 }
78 
is_PPD(u8 command)79 static inline s32 is_PPD(u8 command)
80 {
81 	return (command & 0x70) == 0x70;
82 }
83 
in_addressed_command_group(u8 command)84 static inline s32 in_addressed_command_group(u8 command)
85 {
86 	return (command & 0x70) == 0x0;
87 }
88 
in_universal_command_group(u8 command)89 static inline s32 in_universal_command_group(u8 command)
90 {
91 	return (command & 0x70) == 0x10;
92 }
93 
in_listen_address_group(u8 command)94 static inline s32 in_listen_address_group(u8 command)
95 {
96 	return (command & 0x60) == 0x20;
97 }
98 
in_talk_address_group(u8 command)99 static inline s32 in_talk_address_group(u8 command)
100 {
101 	return (command & 0x60) == 0x40;
102 }
103 
in_primary_command_group(u8 command)104 static inline s32 in_primary_command_group(u8 command)
105 {
106 	return in_addressed_command_group(command) ||
107 		in_universal_command_group(command) ||
108 		in_listen_address_group(command) ||
109 		in_talk_address_group(command);
110 }
111 
112 #endif /* _GPIB_CMD_H */
113