1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
/* SPDX-License-Identifier: GPL-2.0 */
/***************************************************************************
* copyright : (C) 2004 by Frank Mori Hess
***************************************************************************/
#ifndef _NI_USB_GPIB_H
#define _NI_USB_GPIB_H
#include <linux/mutex.h>
#include <linux/semaphore.h>
#include <linux/usb.h>
#include <linux/timer.h>
#include "gpibP.h"
enum {
USB_VENDOR_ID_NI = 0x3923
};
enum {
USB_DEVICE_ID_NI_USB_B = 0x702a,
USB_DEVICE_ID_NI_USB_B_PREINIT = 0x702b, // device id before firmware is loaded
USB_DEVICE_ID_NI_USB_HS = 0x709b,
USB_DEVICE_ID_NI_USB_HS_PLUS = 0x7618,
USB_DEVICE_ID_KUSB_488A = 0x725c,
USB_DEVICE_ID_MC_USB_488 = 0x725d
};
enum ni_usb_device {
NIUSB_SUBDEV_TNT4882 = 1,
NIUSB_SUBDEV_UNKNOWN2 = 2,
NIUSB_SUBDEV_UNKNOWN3 = 3,
};
enum endpoint_addresses {
NIUSB_B_BULK_OUT_ENDPOINT = 0x2,
NIUSB_B_BULK_IN_ENDPOINT = 0x2,
NIUSB_B_BULK_IN_ALT_ENDPOINT = 0x6,
NIUSB_B_INTERRUPT_IN_ENDPOINT = 0x4,
};
enum hs_enpoint_addresses {
NIUSB_HS_BULK_OUT_ENDPOINT = 0x2,
NIUSB_HS_BULK_OUT_ALT_ENDPOINT = 0x6,
NIUSB_HS_BULK_IN_ENDPOINT = 0x4,
NIUSB_HS_BULK_IN_ALT_ENDPOINT = 0x8,
NIUSB_HS_INTERRUPT_IN_ENDPOINT = 0x1,
};
enum hs_plus_endpoint_addresses {
NIUSB_HS_PLUS_BULK_OUT_ENDPOINT = 0x1,
NIUSB_HS_PLUS_BULK_OUT_ALT_ENDPOINT = 0x4,
NIUSB_HS_PLUS_BULK_IN_ENDPOINT = 0x2,
NIUSB_HS_PLUS_BULK_IN_ALT_ENDPOINT = 0x5,
NIUSB_HS_PLUS_INTERRUPT_IN_ENDPOINT = 0x3,
};
struct ni_usb_urb_ctx {
struct completion complete;
unsigned timed_out : 1;
};
// struct which defines private_data for ni_usb devices
struct ni_usb_priv {
struct usb_interface *bus_interface;
int bulk_out_endpoint;
int bulk_in_endpoint;
int interrupt_in_endpoint;
u8 eos_char;
unsigned short eos_mode;
unsigned int monitored_ibsta_bits;
struct urb *bulk_urb;
struct urb *interrupt_urb;
u8 interrupt_buffer[0x11];
struct mutex addressed_transfer_lock; // protect transfer lock
struct mutex bulk_transfer_lock; // protect bulk message sends
struct mutex control_transfer_lock; // protect control messages
struct mutex interrupt_transfer_lock; // protect interrupt messages
struct timer_list bulk_timer;
struct ni_usb_urb_ctx context;
int product_id;
unsigned short ren_state;
};
struct ni_usb_status_block {
short id;
unsigned short ibsta;
short error_code;
unsigned short count;
};
struct ni_usb_register {
enum ni_usb_device device;
short address;
unsigned short value;
};
enum ni_usb_bulk_ids {
NIUSB_IBCAC_ID = 0x1,
NIUSB_UNKNOWN3_ID = 0x3, // device level function id?
NIUSB_TERM_ID = 0x4,
NIUSB_IBGTS_ID = 0x6,
NIUSB_IBRPP_ID = 0x7,
NIUSB_REG_READ_ID = 0x8,
NIUSB_REG_WRITE_ID = 0x9,
NIUSB_IBSIC_ID = 0xf,
NIUSB_REGISTER_READ_DATA_START_ID = 0x34,
NIUSB_REGISTER_READ_DATA_END_ID = 0x35,
NIUSB_IBRD_DATA_ID = 0x36,
NIUSB_IBRD_EXTENDED_DATA_ID = 0x37,
NIUSB_IBRD_STATUS_ID = 0x38
};
enum ni_usb_error_codes {
NIUSB_NO_ERROR = 0,
/*
* NIUSB_ABORTED_ERROR occurs when I/O is interrupted early by
* doing a NI_USB_STOP_REQUEST on the control endpoint.
*/
NIUSB_ABORTED_ERROR = 1,
/*
* NIUSB_READ_ATN_ERROR occurs when you do a board read while
* ATN is set
*/
NIUSB_ATN_STATE_ERROR = 2,
/*
* NIUSB_ADDRESSING_ERROR occurs when you do a board
* read/write as CIC but are not in LACS/TACS
*/
NIUSB_ADDRESSING_ERROR = 3,
/*
* NIUSB_EOSMODE_ERROR occurs on reads if any eos mode or char
* bits are set when REOS is not set.
* Have also seen error 4 if you try to send more than 16
* command bytes at once on a usb-b.
*/
NIUSB_EOSMODE_ERROR = 4,
/*
* NIUSB_NO_BUS_ERROR occurs when you try to write a command
* byte but there are no devices connected to the gpib bus
*/
NIUSB_NO_BUS_ERROR = 5,
/*
* NIUSB_NO_LISTENER_ERROR occurs when you do a board write as
* CIC with no listener
*/
NIUSB_NO_LISTENER_ERROR = 8,
/* get NIUSB_TIMEOUT_ERROR on board read/write timeout */
NIUSB_TIMEOUT_ERROR = 10,
};
enum ni_usb_control_requests {
NI_USB_STOP_REQUEST = 0x20,
NI_USB_WAIT_REQUEST = 0x21,
NI_USB_POLL_READY_REQUEST = 0x40,
NI_USB_SERIAL_NUMBER_REQUEST = 0x41,
NI_USB_HS_PLUS_0x48_REQUEST = 0x48,
NI_USB_HS_PLUS_LED_REQUEST = 0x4b,
NI_USB_HS_PLUS_0xf8_REQUEST = 0xf8
};
static const unsigned int ni_usb_ibsta_monitor_mask =
SRQI | LOK | REM | CIC | ATN | TACS | LACS | DTAS | DCAS;
static inline int nec7210_to_tnt4882_offset(int offset)
{
return 2 * offset;
};
static inline int ni_usb_bulk_termination(u8 *buffer)
{
int i = 0;
buffer[i++] = NIUSB_TERM_ID;
buffer[i++] = 0x0;
buffer[i++] = 0x0;
buffer[i++] = 0x0;
return i;
}
enum ni_usb_unknown3_register {
SERIAL_NUMBER_4_REG = 0x8,
SERIAL_NUMBER_3_REG = 0x9,
SERIAL_NUMBER_2_REG = 0xa,
SERIAL_NUMBER_1_REG = 0xb,
};
static inline int ni_usb_bulk_register_write_header(u8 *buffer, int num_writes)
{
int i = 0;
buffer[i++] = NIUSB_REG_WRITE_ID;
buffer[i++] = num_writes;
buffer[i++] = 0x0;
return i;
}
static inline int ni_usb_bulk_register_write(u8 *buffer, struct ni_usb_register reg)
{
int i = 0;
buffer[i++] = reg.device;
buffer[i++] = reg.address;
buffer[i++] = reg.value;
return i;
}
static inline int ni_usb_bulk_register_read_header(u8 *buffer, int num_reads)
{
int i = 0;
buffer[i++] = NIUSB_REG_READ_ID;
buffer[i++] = num_reads;
return i;
}
static inline int ni_usb_bulk_register_read(u8 *buffer, int device, int address)
{
int i = 0;
buffer[i++] = device;
buffer[i++] = address;
return i;
}
#endif // _NI_USB_GPIB_H
|