Added missing offsets for RTSI register on m-series
[comedi.git] / comedi / drivers / ni_stc.h
1 /*
2     module/ni_stc.h
3     Register descriptions for NI DAQ-STC chip
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 1998-9 David A. Schleef <ds@schleef.org>
7
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 */
23
24 /*
25         References:
26             DAQ-STC Technical Reference Manual
27 */
28
29 #ifndef _COMEDI_NI_STC_H
30 #define _COMEDI_NI_STC_H
31
32 #define _bit15          0x8000
33 #define _bit14          0x4000
34 #define _bit13          0x2000
35 #define _bit12          0x1000
36 #define _bit11          0x0800
37 #define _bit10          0x0400
38 #define _bit9           0x0200
39 #define _bit8           0x0100
40 #define _bit7           0x0080
41 #define _bit6           0x0040
42 #define _bit5           0x0020
43 #define _bit4           0x0010
44 #define _bit3           0x0008
45 #define _bit2           0x0004
46 #define _bit1           0x0002
47 #define _bit0           0x0001
48
49 /* Registers in the National Instruments DAQ-STC chip */
50
51 #define Interrupt_A_Ack_Register        2
52 #define G0_Gate_Interrupt_Ack                   _bit15
53 #define G0_TC_Interrupt_Ack                     _bit14
54 #define AI_Error_Interrupt_Ack                  _bit13
55 #define AI_STOP_Interrupt_Ack                   _bit12
56 #define AI_START_Interrupt_Ack                  _bit11
57 #define AI_START2_Interrupt_Ack                 _bit10
58 #define AI_START1_Interrupt_Ack                 _bit9
59 #define AI_SC_TC_Interrupt_Ack                  _bit8
60 #define AI_SC_TC_Error_Confirm                  _bit7
61 #define G0_TC_Error_Confirm                     _bit6
62 #define G0_Gate_Error_Confirm                   _bit5
63
64 #define AI_Status_1_Register            2
65 #define Interrupt_A_St                          0x8000
66 #define AI_FIFO_Full_St                         0x4000
67 #define AI_FIFO_Half_Full_St                    0x2000
68 #define AI_FIFO_Empty_St                        0x1000
69 #define AI_Overrun_St                           0x0800
70 #define AI_Overflow_St                          0x0400
71 #define AI_SC_TC_Error_St                       0x0200
72 #define AI_START2_St                            0x0100
73 #define AI_START1_St                            0x0080
74 #define AI_SC_TC_St                             0x0040
75 #define AI_START_St                             0x0020
76 #define AI_STOP_St                              0x0010
77 #define G0_TC_St                                0x0008
78 #define G0_Gate_Interrupt_St                    0x0004
79 #define AI_FIFO_Request_St                      0x0002
80 #define Pass_Thru_0_Interrupt_St                0x0001
81
82 #define AI_Status_2_Register            5
83
84 #define Interrupt_B_Ack_Register        3
85 enum Interrupt_B_Ack_Bits
86 {
87         AO_BC_TC_Interrupt_Ack = _bit8,
88         AO_Error_Interrupt_Ack = _bit13,
89 };
90
91 #define AO_Status_1_Register            3
92 #define Interrupt_B_St                          _bit15
93 #define AO_FIFO_Full_St                         _bit14
94 #define AO_FIFO_Half_Full_St                    _bit13
95 #define AO_FIFO_Empty_St                        _bit12
96 #define AO_BC_TC_Error_St                       _bit11
97 #define AO_START_St                             _bit10
98 #define AO_Overrun_St                           _bit9
99 #define AO_START1_St                            _bit8
100 #define AO_BC_TC_St                             _bit7
101 #define AO_UC_TC_St                             _bit6
102 #define AO_UPDATE_St                            _bit5
103 #define AO_UI2_TC_St                            _bit4
104 #define G1_TC_St                                _bit3
105 #define G1_Gate_Interrupt_St                    _bit2
106 #define AO_FIFO_Request_St                      _bit1
107 #define Pass_Thru_1_Interrupt_St                _bit0
108
109
110 #define AI_Command_2_Register           4
111 #define AI_End_On_SC_TC                         _bit15
112 #define AI_End_On_End_Of_Scan                   _bit14
113 #define AI_START1_Disable                       _bit11
114 #define AI_SC_Save_Trace                        _bit10
115 #define AI_SI_Switch_Load_On_SC_TC              _bit9
116 #define AI_SI_Switch_Load_On_STOP               _bit8
117 #define AI_SI_Switch_Load_On_TC                 _bit7
118 #define AI_SC_Switch_Load_On_TC                 _bit4
119 #define AI_STOP_Pulse                           _bit3
120 #define AI_START_Pulse                          _bit2
121 #define AI_START2_Pulse                         _bit1
122 #define AI_START1_Pulse                         _bit0
123
124 #define AO_Command_2_Register           5
125 #define AO_End_On_BC_TC(x)                      (((x) & 0x3) << 14)
126 #define AO_Start_Stop_Gate_Enable               _bit13
127 #define AO_UC_Save_Trace                        _bit12
128 #define AO_BC_Gate_Enable                       _bit11
129 #define AO_BC_Save_Trace                        _bit10
130 #define AO_UI_Switch_Load_On_BC_TC              _bit9
131 #define AO_UI_Switch_Load_On_Stop               _bit8
132 #define AO_UI_Switch_Load_On_TC                 _bit7
133 #define AO_UC_Switch_Load_On_BC_TC              _bit6
134 #define AO_UC_Switch_Load_On_TC                 _bit5
135 #define AO_BC_Switch_Load_On_TC                 _bit4
136 #define AO_Mute_B                               _bit3
137 #define AO_Mute_A                               _bit2
138 #define AO_UPDATE2_Pulse                        _bit1
139 #define AO_START1_Pulse                         _bit0
140
141 #define AO_Status_2_Register            6
142
143 #define DIO_Parallel_Input_Register     7
144
145 #define AI_Command_1_Register           8
146 #define AI_Analog_Trigger_Reset                 _bit14
147 #define AI_Disarm                               _bit13
148 #define AI_SI2_Arm                              _bit12
149 #define AI_SI2_Load                             _bit11
150 #define AI_SI_Arm                               _bit10
151 #define AI_SI_Load                              _bit9
152 #define AI_DIV_Arm                              _bit8
153 #define AI_DIV_Load                             _bit7
154 #define AI_SC_Arm                               _bit6
155 #define AI_SC_Load                              _bit5
156 #define AI_SCAN_IN_PROG_Pulse                   _bit4
157 #define AI_EXTMUX_CLK_Pulse                     _bit3
158 #define AI_LOCALMUX_CLK_Pulse                   _bit2
159 #define AI_SC_TC_Pulse                          _bit1
160 #define AI_CONVERT_Pulse                        _bit0
161
162 #define AO_Command_1_Register           9
163 #define AO_Analog_Trigger_Reset                 _bit15
164 #define AO_START_Pulse                          _bit14
165 #define AO_Disarm                               _bit13
166 #define AO_UI2_Arm_Disarm                       _bit12
167 #define AO_UI2_Load                             _bit11
168 #define AO_UI_Arm                               _bit10
169 #define AO_UI_Load                              _bit9
170 #define AO_UC_Arm                               _bit8
171 #define AO_UC_Load                              _bit7
172 #define AO_BC_Arm                               _bit6
173 #define AO_BC_Load                              _bit5
174 #define AO_DAC1_Update_Mode                     _bit4
175 #define AO_LDAC1_Source_Select                  _bit3
176 #define AO_DAC0_Update_Mode                     _bit2
177 #define AO_LDAC0_Source_Select                  _bit1
178 #define AO_UPDATE_Pulse                         _bit0
179
180
181 #define DIO_Output_Register             10
182 #define DIO_Parallel_Data_Out(a)                ((a)&0xff)
183 #define DIO_Parallel_Data_Mask                  0xff
184 #define DIO_SDOUT                               _bit0
185 #define DIO_SDIN                                _bit4
186 #define DIO_Serial_Data_Out(a)                  (((a)&0xff)<<8)
187 #define DIO_Serial_Data_Mask                    0xff00
188
189 #define DIO_Control_Register            11
190 #define DIO_Software_Serial_Control             _bit11
191 #define DIO_HW_Serial_Timebase                  _bit10
192 #define DIO_HW_Serial_Enable                    _bit9
193 #define DIO_HW_Serial_Start                     _bit8
194 #define DIO_Pins_Dir(a)                         ((a)&0xff)
195 #define DIO_Pins_Dir_Mask                       0xff
196
197 #define AI_Mode_1_Register              12
198 #define AI_CONVERT_Source_Select(a)             (((a) & 0x1f) << 11)
199 #define AI_SI_Source_select(a)                  (((a) & 0x1f) << 6)
200 #define AI_CONVERT_Source_Polarity              _bit5
201 #define AI_SI_Source_Polarity           _bit4
202 #define AI_Start_Stop                           _bit3
203 #define AI_Mode_1_Reserved                      _bit2
204 #define AI_Continuous                           _bit1
205 #define AI_Trigger_Once                         _bit0
206
207 #define AI_Mode_2_Register              13
208 #define AI_SC_Gate_Enable                       _bit15
209 #define AI_Start_Stop_Gate_Enable               _bit14
210 #define AI_Pre_Trigger                          _bit13
211 #define AI_External_MUX_Present                 _bit12
212 #define AI_SI2_Initial_Load_Source              _bit9
213 #define AI_SI2_Reload_Mode                      _bit8
214 #define AI_SI_Initial_Load_Source               _bit7
215 #define AI_SI_Reload_Mode(a)                    (((a) & 0x7)<<4)
216 #define AI_SI_Write_Switch                      _bit3
217 #define AI_SC_Initial_Load_Source               _bit2
218 #define AI_SC_Reload_Mode                       _bit1
219 #define AI_SC_Write_Switch                      _bit0
220
221 #define AI_SI_Load_A_Registers          14
222 #define AI_SI_Load_B_Registers          16
223 #define AI_SC_Load_A_Registers          18
224 #define AI_SC_Load_B_Registers          20
225 #define AI_SI_Save_Registers            64
226 #define AI_SC_Save_Registers            66
227
228 #define AI_SI2_Load_A_Register          23
229 #define AI_SI2_Load_B_Register          25
230
231 #define Joint_Status_1_Register         27
232 #define DIO_Serial_IO_In_Progress_St            _bit12
233
234 #define DIO_Serial_Input_Register       28
235 #define Joint_Status_2_Register         29
236 enum Joint_Status_2_Bits
237 {
238         AO_TMRDACWRs_In_Progress_St = 0x20,
239 };
240
241 #define AO_Mode_1_Register              38
242 #define AO_UPDATE_Source_Select(x)              (((x)&0x1f)<<11)
243 #define AO_UI_Source_Select(x)                  (((x)&0x1f)<<6)
244 #define AO_Multiple_Channels                    _bit5
245 #define AO_UPDATE_Source_Polarity               _bit4
246 #define AO_UI_Source_Polarity                   _bit3
247 #define AO_UC_Switch_Load_Every_TC              _bit2
248 #define AO_Continuous                           _bit1
249 #define AO_Trigger_Once                         _bit0
250
251 #define AO_Mode_2_Register              39
252 #define AO_FIFO_Mode_Mask ( 0x3 << 14 )
253 enum AO_FIFO_Mode_Bits
254 {
255         AO_FIFO_Mode_HF_to_F = (3<<14),
256         AO_FIFO_Mode_F = (2<<14),
257         AO_FIFO_Mode_HF = (1<<14),
258         AO_FIFO_Mode_E = (0<<14),
259 };
260 #define AO_FIFO_Retransmit_Enable               _bit13
261 #define AO_START1_Disable                       _bit12
262 #define AO_UC_Initial_Load_Source               _bit11
263 #define AO_UC_Write_Switch                      _bit10
264 #define AO_UI2_Initial_Load_Source              _bit9
265 #define AO_UI2_Reload_Mode                      _bit8
266 #define AO_UI_Initial_Load_Source               _bit7
267 #define AO_UI_Reload_Mode(x)                    (((x) & 0x7) << 4)
268 #define AO_UI_Write_Switch                      _bit3
269 #define AO_BC_Initial_Load_Source               _bit2
270 #define AO_BC_Reload_Mode                       _bit1
271 #define AO_BC_Write_Switch                      _bit0
272
273 #define AO_UI_Load_A_Register           40
274 #define AO_UI_Load_A_Register_High      40
275 #define AO_UI_Load_A_Register_Low       41
276 #define AO_UI_Load_B_Register           42
277 #define AO_UI_Save_Registers            16
278 #define AO_BC_Load_A_Register           44
279 #define AO_BC_Load_A_Register_High      44
280 #define AO_BC_Load_A_Register_Low       45
281 #define AO_BC_Load_B_Register           46
282 #define AO_BC_Load_B_Register_High      46
283 #define AO_BC_Load_B_Register_Low       47
284 #define AO_BC_Save_Registers            18
285 #define AO_UC_Load_A_Register           48
286 #define AO_UC_Load_A_Register_High      48
287 #define AO_UC_Load_A_Register_Low       49
288 #define AO_UC_Load_B_Register           50
289 #define AO_UC_Save_Registers            20
290
291 #define Clock_and_FOUT_Register         56
292 #define FOUT_Enable                             _bit15
293 #define FOUT_Timebase_Select                    _bit14
294 #define DIO_Serial_Out_Divide_By_2              _bit13
295 #define Slow_Internal_Time_Divide_By_2          _bit12
296 #define Slow_Internal_Timebase                  _bit11
297 #define G_Source_Divide_By_2                    _bit10
298 #define Clock_To_Board_Divide_By_2              _bit9
299 #define Clock_To_Board                          _bit8
300 #define AI_Output_Divide_By_2                   _bit7
301 #define AI_Source_Divide_By_2                   _bit6
302 #define AO_Output_Divide_By_2                   _bit5
303 #define AO_Source_Divide_By_2                   _bit4
304 #define FOUT_Divider(x)                         (((x) & 0xf) << 0)
305
306 #define IO_Bidirection_Pin_Register     57
307 #define RTSI_Trig_Direction_Register    58
308 enum RTSI_Trig_Direction_Bits
309 {
310         Drive_RTSI_Clock_Bit = 0x1,
311         Use_RTSI_Clock_Bit = 0x2,
312 };
313 static inline unsigned RTSI_Output_Bit(unsigned channel)
314 {
315         if(channel > 6)
316         {
317                 rt_printk("%s: bug, invalid RTSI_channel=%i\n", __FUNCTION__, channel);
318                 return 0;
319         }
320         return 1 << (9 + channel);
321 }
322
323 #define Interrupt_Control_Register      59
324 #define Interrupt_B_Enable                      _bit15
325 #define Interrupt_B_Output_Select(x)            ((x)<<12)
326 #define Interrupt_A_Enable                      _bit11
327 #define Interrupt_A_Output_Select(x)            ((x)<<8)
328 #define Pass_Thru_0_Interrupt_Polarity          _bit3
329 #define Pass_Thru_1_Interrupt_Polarity          _bit2
330 #define Interrupt_Output_On_3_Pins              _bit1
331 #define Interrupt_Output_Polarity               _bit0
332
333 #define AI_Output_Control_Register      60
334 #define AI_START_Output_Select                  _bit10
335 #define AI_SCAN_IN_PROG_Output_Select(x)        (((x) & 0x3) << 8)
336 #define AI_EXTMUX_CLK_Output_Select(x)          (((x) & 0x3) << 6)
337 #define AI_LOCALMUX_CLK_Output_Select(x)        ((x)<<4)
338 #define AI_SC_TC_Output_Select(x)               ((x)<<2)
339 #define AI_CONVERT_Output_Select(x)             (((x) & 0x3) << 0)
340
341 #define AI_START_STOP_Select_Register   62
342 #define AI_START_Polarity                       _bit15
343 #define AI_STOP_Polarity                        _bit14
344 #define AI_STOP_Sync                            _bit13
345 #define AI_STOP_Edge                            _bit12
346 #define AI_STOP_Select(a)                       (((a) & 0x1f)<<7)
347 #define AI_START_Sync                           _bit6
348 #define AI_START_Edge                           _bit5
349 #define AI_START_Select(a)                      ((a) & 0x1f)
350
351 #define AI_Trigger_Select_Register      63
352 #define AI_START1_Polarity                      _bit15
353 #define AI_START2_Polarity                      _bit14
354 #define AI_START2_Sync                          _bit13
355 #define AI_START2_Edge                          _bit12
356 #define AI_START2_Select(a)                     (((a) & 0x1f) << 7)
357 #define AI_START1_Sync                          _bit6
358 #define AI_START1_Edge                          _bit5
359 #define AI_START1_Select(a)                     ((a) & 0x1f)
360
361 #define AI_DIV_Load_A_Register  64
362
363 #define AO_Start_Select_Register        66
364 #define AO_UI2_Software_Gate                    _bit15
365 #define AO_UI2_External_Gate_Polarity           _bit14
366 #define AO_START_Polarity                       _bit13
367 #define AO_AOFREQ_Enable                        _bit12
368 #define AO_UI2_External_Gate_Select(a)          (((a) & 0x1f) << 7)
369 #define AO_START_Sync                           _bit6
370 #define AO_START_Edge                           _bit5
371 #define AO_START_Select(a)                      ((a) & 0x1f)
372
373 #define AO_Trigger_Select_Register      67
374 #define AO_UI2_External_Gate_Enable             _bit15
375 #define AO_Delayed_START1                       _bit14
376 #define AO_START1_Polarity                      _bit13
377 #define AO_UI2_Source_Polarity                  _bit12
378 #define AO_UI2_Source_Select(x)                 (((x)&0x1f)<<7)
379 #define AO_START1_Sync                          _bit6
380 #define AO_START1_Edge                          _bit5
381 #define AO_START1_Select(x)                     (((x)&0x1f)<<0)
382
383 #define AO_Mode_3_Register              70
384 #define AO_UI2_Switch_Load_Next_TC              _bit13
385 #define AO_UC_Switch_Load_Every_BC_TC           _bit12
386 #define AO_Trigger_Length                       _bit11
387 #define AO_Stop_On_Overrun_Error                _bit5
388 #define AO_Stop_On_BC_TC_Trigger_Error          _bit4
389 #define AO_Stop_On_BC_TC_Error                  _bit3
390 #define AO_Not_An_UPDATE                        _bit2
391 #define AO_Software_Gate                        _bit1
392 #define AO_Last_Gate_Disable            _bit0   /* M Series only */
393
394 #define Joint_Reset_Register            72
395 #define Software_Reset                  _bit11
396 #define AO_Configuration_End                    _bit9
397 #define AI_Configuration_End                    _bit8
398 #define AO_Configuration_Start                  _bit5
399 #define AI_Configuration_Start                  _bit4
400 #define G1_Reset                                _bit3
401 #define G0_Reset                                _bit2
402 #define AO_Reset                                _bit1
403 #define AI_Reset                                _bit0
404
405 #define Interrupt_A_Enable_Register     73
406 #define Pass_Thru_0_Interrupt_Enable            _bit9
407 #define G0_Gate_Interrupt_Enable                _bit8
408 #define AI_FIFO_Interrupt_Enable                _bit7
409 #define G0_TC_Interrupt_Enable                  _bit6
410 #define AI_Error_Interrupt_Enable               _bit5
411 #define AI_STOP_Interrupt_Enable                _bit4
412 #define AI_START_Interrupt_Enable               _bit3
413 #define AI_START2_Interrupt_Enable              _bit2
414 #define AI_START1_Interrupt_Enable              _bit1
415 #define AI_SC_TC_Interrupt_Enable               _bit0
416
417 #define Interrupt_B_Enable_Register     75
418 #define Pass_Thru_1_Interrupt_Enable            _bit11
419 #define G1_Gate_Interrupt_Enable                _bit10
420 #define G1_TC_Interrupt_Enable                  _bit9
421 #define AO_FIFO_Interrupt_Enable                _bit8
422 #define AO_UI2_TC_Interrupt_Enable              _bit7
423 #define AO_UC_TC_Interrupt_Enable               _bit6
424 #define AO_Error_Interrupt_Enable               _bit5
425 #define AO_STOP_Interrupt_Enable                _bit4
426 #define AO_START_Interrupt_Enable               _bit3
427 #define AO_UPDATE_Interrupt_Enable              _bit2
428 #define AO_START1_Interrupt_Enable              _bit1
429 #define AO_BC_TC_Interrupt_Enable               _bit0
430
431 #define Second_IRQ_B_Enable_Register    76
432 #define AI_Personal_Register            77
433 #define AI_SHIFTIN_Pulse_Width                  _bit15
434 #define AI_EOC_Polarity                         _bit14
435 #define AI_SOC_Polarity                         _bit13
436 #define AI_SHIFTIN_Polarity                     _bit12
437 #define AI_CONVERT_Pulse_Timebase               _bit11
438 #define AI_CONVERT_Pulse_Width                  _bit10
439 #define AI_CONVERT_Original_Pulse               _bit9
440 #define AI_FIFO_Flags_Polarity                  _bit8
441 #define AI_Overrun_Mode                         _bit7
442 #define AI_EXTMUX_CLK_Pulse_Width               _bit6
443 #define AI_LOCALMUX_CLK_Pulse_Width             _bit5
444 #define AI_AIFREQ_Polarity                      _bit4
445
446 #define AO_Personal_Register            78
447 enum AO_Personal_Bits
448 {
449         AO_Interval_Buffer_Mode = 1 << 3,
450         AO_BC_Source_Select = 1 << 4,
451         AO_UPDATE_Pulse_Width = 1 << 5,
452         AO_DMA_PIO_Control = 1 << 8,    /* M Series: reserved */
453         AO_AOFREQ_Polarity = 1 << 9,    /* M Series: reserved */
454         AO_FIFO_Enable = 1 << 10,
455         AO_TMRDACWR_Pulse_Width = 1 << 12,
456         AO_Number_Of_DAC_Packages = 1 << 14,    // 1 for "single" mode, 0 for "dual"
457 };
458 #define RTSI_Trig_A_Output_Register     79
459 #define RTSI_Trig_B_Output_Register     80
460 #define RTSI_Board_Register             81
461 #define Write_Strobe_0_Register         82
462 #define Write_Strobe_1_Register         83
463 #define Write_Strobe_2_Register         84
464 #define Write_Strobe_3_Register         85
465
466 #define AO_Output_Control_Register      86
467 #define AO_External_Gate_Enable                 _bit15
468 #define AO_External_Gate_Select(x)              (((x)&0x1f)<<10)
469 #define AO_Number_Of_Channels(x)                (((x)&0xf)<<6)
470 #define AO_UPDATE2_Output_Select(x)             (((x)&0x3)<<4)
471 #define AO_External_Gate_Polarity               _bit3
472 #define AO_UPDATE2_Output_Toggle                _bit2
473 #define AO_UPDATE_Output_Select(x)              (((x)&0x3)<<0)
474
475 #define AI_Mode_3_Register              87
476 #define AI_Trigger_Length                       _bit15
477 #define AI_Delay_START                          _bit14
478 #define AI_Software_Gate                        _bit13
479 #define AI_SI_Special_Trigger_Delay             _bit12
480 #define AI_SI2_Source_Select                    _bit11
481 #define AI_Delayed_START2                       _bit10
482 #define AI_Delayed_START1                       _bit9
483 #define AI_External_Gate_Mode                   _bit8
484 #define AI_FIFO_Mode_HF_to_E                    (3<<6)
485 #define AI_FIFO_Mode_F                          (2<<6)
486 #define AI_FIFO_Mode_HF                         (1<<6)
487 #define AI_FIFO_Mode_NE                         (0<<6)
488 #define AI_External_Gate_Polarity               _bit5
489 #define AI_External_Gate_Select(a)              ((a) & 0x1f)
490
491 #define G_Autoincrement_Register(a)     (68+(a))
492 #define G_Command_Register(a)           (6+(a))
493 #define G_HW_Save_Register(a)           (8+(a)*2)
494 #define G_HW_Save_Register_High(a)      (8+(a)*2)
495 #define G_HW_Save_Register_Low(a)       (9+(a)*2)
496 #define G_Input_Select_Register(a)      (36+(a))
497 #define G_Load_A_Register(a)            (28+(a)*4)
498 #define G_Load_A_Register_High(a)       (28+(a)*4)
499 #define G_Load_A_Register_Low(a)        (29+(a)*4)
500 #define G_Load_B_Register(a)            (30+(a)*4)
501 #define G_Load_B_Register_High(a)       (30+(a)*4)
502 #define G_Load_B_Register_Low(a)        (31+(a)*4)
503 #define G_Mode_Register(a)              (26+(a))
504 #define G_Save_Register(a)              (12+(a)*2)
505 #define G_Save_Register_High(a)         (12+(a)*2)
506 #define G_Save_Register_Low(a)          (13+(a)*2)
507 #define G_Status_Register               4
508 #define Analog_Trigger_Etc_Register     61
509
510 /* command register */
511 #define G_Disarm_Copy                   _bit15          /* strobe */
512 #define G_Save_Trace_Copy               _bit14
513 #define G_Arm_Copy                      _bit13          /* strobe */
514 #define G_Bank_Switch_Start             _bit10          /* strobe */
515 #define G_Little_Big_Endian             _bit9
516 #define G_Synchronized_Gate             _bit8
517 #define G_Write_Switch                  _bit7
518 #define G_Up_Down(a)                    (((a)&0x03)<<5)
519 #define G_Disarm                        _bit4           /* strobe */
520 #define G_Analog_Trigger_Reset          _bit3           /* strobe */
521 #define G_Save_Trace                    _bit1
522 #define G_Arm                           _bit0           /* strobe */
523
524 /*channel agnostic names for the command register #defines */
525 #define G_Bank_Switch_Enable            _bit12
526 #define G_Bank_Switch_Mode              _bit11
527 #define G_Load                          _bit2           /* strobe */
528
529
530 /* input select register */
531 #define G_Gate_Select(a)                (((a)&0x1f)<<7)
532 #define G_Source_Select(a)              (((a)&0x1f)<<2)
533 #define G_Write_Acknowledges_Irq        _bit1
534 #define G_Read_Acknowledges_Irq         _bit0
535
536 /* same input select register, but with channel agnostic names */
537 #define G_Source_Polarity               _bit15
538 #define G_Output_Polarity               _bit14
539 #define G_OR_Gate                       _bit13
540 #define G_Gate_Select_Load_Source       _bit12
541
542
543 /* mode register */
544 #define G_Loading_On_TC                 _bit12
545 #define G_Output_Mode(a)                (((a)&0x03)<<8)
546 #define G_Trigger_Mode_For_Edge_Gate(a) (((a)&0x03)<<3)
547 #define G_Gating_Mode(a)                (((a)&0x03)<<0)
548
549 /* same input mode register, but with channel agnostic names */
550 #define G_Load_Source_Select            _bit7
551 #define G_Reload_Source_Switching       _bit15
552 #define G_Loading_On_Gate               _bit14
553 #define G_Gate_Polarity                 _bit13
554
555 #define G_Counting_Once(a)              (((a)&0x03)<<10)
556 #define G_Stop_Mode(a)                  (((a)&0x03)<<5)
557 #define G_Gate_On_Both_Edges            _bit2
558
559 /* G_Status_Register */
560 #define G1_Gate_Error_St                _bit15
561 #define G0_Gate_Error_St                _bit14
562 #define G1_TC_Error_St                  _bit13
563 #define G0_TC_Error_St                  _bit12
564 #define G1_No_Load_Between_Gates_St     _bit11
565 #define G0_No_Load_Between_Gates_St     _bit10
566 #define G1_Armed_St                     _bit9
567 #define G0_Armed_St                     _bit8
568 #define G1_Stale_Data_St                _bit7
569 #define G0_Stale_Data_St                _bit6
570 #define G1_Next_Load_Source_St          _bit5
571 #define G0_Next_Load_Source_St          _bit4
572 #define G1_Counting_St                  _bit3
573 #define G0_Counting_St                  _bit2
574 #define G1_Save_St                      _bit1
575 #define G0_Save_St                      _bit0
576
577 /* general purpose counter timer */
578 #define G0_TC_Interrupt_Enable          _bit6
579 #define G1_TC_Interrupt_Enable          _bit9
580 #define G0_Gate_Interrupt_Enable        _bit8
581 #define G1_Gate_Interrupt_Enable        _bit10
582 #define G0_Synchronized_Gate            _bit8
583 #define G1_Synchronized_Gate            _bit8
584 #define G0_Gate_Error_Confirm           _bit5
585 #define G1_Gate_Error_Confirm           _bit1
586 #define G0_TC_Error_Confirm             _bit6
587 #define G1_TC_Error_Confirm             _bit2
588 #define G0_TC_Interrupt_Ack             _bit14
589 #define G1_TC_Interrupt_Ack             _bit14
590 #define G0_Gate_Interrupt_Ack           _bit15
591 #define G1_Gate_Interrupt_Ack           _bit15
592 #define G_Autoincrement(a)              ((a)<<0)
593 #define G_Autoincrement(a)              ((a)<<0)
594 #define G0_Arm                          _bit0
595 #define G1_Arm                          _bit0
596
597 /*Analog_Trigger_Etc_Register*/
598 #define Analog_Trigger_Mode(x) ((x) & 0x7)
599 #define Analog_Trigger_Enable _bit3
600 #define Analog_Trigger_Drive _bit4
601 #define GPFO_1_Output_Select            _bit7
602 #define GPFO_0_Output_Select(a)         ((a)<<11)
603 #define GPFO_0_Output_Enable            _bit14
604 #define GPFO_1_Output_Enable            _bit15
605
606 /* Additional windowed registers unique to E series */
607
608 /* 16 bit registers shadowed from DAQ-STC */
609 #define Window_Address                  0x00
610 #define Window_Data                     0x02
611
612 #define Configuration_Memory_Clear      82
613 #define ADC_FIFO_Clear                  83
614 #define DAC_FIFO_Clear                  84
615
616 /* i/o port offsets */
617
618 /* 8 bit registers */
619 #define XXX_Status                      0x01
620 enum XXX_Status_Bits
621 {
622         PROMOUT = 0x1,
623         AI_FIFO_LOWER_NOT_EMPTY = 0x8,
624 };
625 #define Serial_Command                  0x0d
626 #define Misc_Command                    0x0f
627 #define Port_A                          0x19
628 #define Port_B                          0x1b
629 #define Port_C                          0x1d
630 #define Configuration                   0x1f
631 #define Strobes                         0x01
632 #define Channel_A_Mode                  0x03
633 #define Channel_B_Mode                  0x05
634 #define Channel_C_Mode                  0x07
635 #define AI_AO_Select                    0x09
636 #define G0_G1_Select                    0x0b
637
638 /* 16 bit registers */
639
640 #define Configuration_Memory_Low        0x10
641 enum Configuration_Memory_Low_Bits
642 {
643         AI_DITHER       = 0x200,
644         AI_LAST_CHANNEL = 0x8000,
645 };
646 #define Configuration_Memory_High       0x12
647 enum Configuration_Memory_High_Bits
648 {
649         AI_AC_COUPLE    = 0x800,
650         AI_DIFFERENTIAL = 0x1000,
651         AI_COMMON = 0x2000,
652         AI_GROUND = 0x3000,
653 };
654 static inline unsigned int AI_CONFIG_CHANNEL( unsigned int channel )
655 {
656         return ( channel & 0x3f );
657 }
658
659 #define ADC_FIFO_Data_Register          0x1c
660
661 #define AO_Configuration                0x16
662 #define AO_Bipolar              _bit0
663 #define AO_Deglitch             _bit1
664 #define AO_Ext_Ref              _bit2
665 #define AO_Ground_Ref           _bit3
666 #define AO_Channel(x)           ((x) << 8)
667
668 #define DAC_FIFO_Data                   0x1e
669 #define DAC0_Direct_Data                0x18
670 #define DAC1_Direct_Data                0x1a
671
672
673 /* 611x registers (these boards differ from the e-series) */
674
675 #define Magic_611x                      0x19 /* w8 (new) */
676 #define Calibration_Channel_Select_611x 0x1a /* w16 (new) */
677 #define ADC_FIFO_Data_611x              0x1c /* r32 (incompatible) */
678 #define AI_FIFO_Offset_Load_611x        0x05 /* r8 (new) */
679 #define DAC_FIFO_Data_611x              0x14 /* w32 (incompatible) */
680 #define Cal_Gain_Select_611x            0x05 /* w8 (new) */
681
682 #define AO_Window_Address_611x          0x18
683 #define AO_Window_Data_611x             0x1e
684
685 /* 6143 registers */
686 #define Magic_6143                      0x19 /* w8 */
687 #define G0G1_DMA_Select_6143            0x0B /* w8 */
688 #define PipelineDelay_6143              0x1f /* w8 */
689 #define EOC_Set_6143                    0x1D /* w8 */
690 #define AIDMA_Select_6143               0x09 /* w8 */
691 #define AIFIFO_Data_6143                0x8C /* w32 */
692 #define AIFIFO_Flag_6143                0x84 /* w32 */
693 #define AIFIFO_Control_6143             0x88 /* w32 */
694 #define AIFIFO_Status_6143              0x88 /* w32 */
695 #define AIFIFO_DMAThreshold_6143        0x90 /* w32 */
696 #define AIFIFO_Words_Available_6143     0x94 /* w32 */
697
698 #define Calibration_Channel_6143        0x42 /* w16 */
699 #define Calibration_LowTime_6143        0x20 /* w16 */
700 #define Calibration_HighTime_6143       0x22 /* w16 */
701 #define Relay_Counter_Load_Val__6143    0x4C /* w32 */
702 #define Signature_6143                  0x50 /* w32 */
703 #define Release_Date_6143               0x54 /* w32 */
704 #define Release_Oldest_Date_6143        0x58 /* w32 */
705
706 #define Calibration_Channel_6143_RelayOn        0x8000  /* Calibration relay switch On */
707 #define Calibration_Channel_6143_RelayOff       0x4000  /* Calibration relay switch Off */
708 #define Calibration_Channel_Gnd_Gnd     0x00    /* Offset Calibration */
709 #define Calibration_Channel_2v5_Gnd     0x02    /* 2.5V Reference */
710 #define Calibration_Channel_Pwm_Gnd     0x05    /* +/- 5V Self Cal */
711 #define Calibration_Channel_2v5_Pwm     0x0a    /* PWM Calibration */
712 #define Calibration_Channel_Pwm_Pwm     0x0d    /* CMRR */
713 #define Calibration_Channel_Gnd_Pwm     0x0e    /* PWM Calibration */
714
715 /* 671x, 611x registers */
716
717 /* 671xi, 611x windowed ao registers */
718 enum windowed_regs_67xx_61xx
719 {
720         AO_Immediate_671x = 0x11, /* W 16 */
721         AO_Timed_611x = 0x10, /* W 16 */
722         AO_FIFO_Offset_Load_611x = 0x13, /* W32 */
723         AO_Later_Single_Point_Updates = 0x14, /* W 16 */
724         AO_Waveform_Generation_611x = 0x15, /* W 16 */
725         AO_Misc_611x = 0x16, /* W 16 */
726         AO_Calibration_Channel_Select_67xx = 0x17, /* W 16 */
727         AO_Configuration_2_67xx = 0x18, /* W 16 */
728         CAL_ADC_Command_67xx = 0x19, /* W 8 */
729         CAL_ADC_Status_67xx = 0x1a, /* R 8 */
730         CAL_ADC_Data_67xx = 0x1b, /* R 16 */
731         CAL_ADC_Config_Data_High_Word_67xx = 0x1c, /* RW 16 */
732         CAL_ADC_Config_Data_Low_Word_67xx = 0x1d, /* RW 16 */
733 };
734 static inline unsigned int DACx_Direct_Data_671x(int channel)
735 {
736         return channel;
737 }
738 enum AO_Misc_611x_Bits
739 {
740         CLEAR_WG = 1,
741 };
742 enum cs5529_configuration_bits
743 {
744         CSCFG_CAL_CONTROL_MASK = 0x7,
745         CSCFG_SELF_CAL_OFFSET = 0x1,
746         CSCFG_SELF_CAL_GAIN = 0x2,
747         CSCFG_SELF_CAL_OFFSET_GAIN = 0x3,
748         CSCFG_SYSTEM_CAL_OFFSET = 0x5,
749         CSCFG_SYSTEM_CAL_GAIN = 0x6,
750         CSCFG_DONE = 1 << 3,
751         CSCFG_POWER_SAVE_SELECT = 1 << 4,
752         CSCFG_PORT_MODE = 1 << 5,
753         CSCFG_RESET_VALID = 1 << 6,
754         CSCFG_RESET = 1 << 7,
755         CSCFG_UNIPOLAR = 1 << 12,
756         CSCFG_WORD_RATE_2180_CYCLES = 0x0 << 13,
757         CSCFG_WORD_RATE_1092_CYCLES = 0x1 << 13,
758         CSCFG_WORD_RATE_532_CYCLES = 0x2 << 13,
759         CSCFG_WORD_RATE_388_CYCLES = 0x3 << 13,
760         CSCFG_WORD_RATE_324_CYCLES = 0x4 << 13,
761         CSCFG_WORD_RATE_17444_CYCLES = 0x5 << 13,
762         CSCFG_WORD_RATE_8724_CYCLES = 0x6 << 13,
763         CSCFG_WORD_RATE_4364_CYCLES = 0x7 << 13,
764         CSCFG_WORD_RATE_MASK = 0x7 << 13,
765         CSCFG_LOW_POWER = 1 << 16,
766 };
767 static inline unsigned int CS5529_CONFIG_DOUT(int output)
768 {
769         return 1 << (18 + output);
770 }
771 static inline unsigned int CS5529_CONFIG_AOUT(int output)
772 {
773         return 1 << (22 + output);
774 }
775 enum cs5529_command_bits
776 {
777         CSCMD_POWER_SAVE = 0x1,
778         CSCMD_REGISTER_SELECT_MASK = 0xe,
779         CSCMD_OFFSET_REGISTER = 0x0,
780         CSCMD_GAIN_REGISTER = 0x2,
781         CSCMD_CONFIG_REGISTER = 0x4,
782         CSCMD_READ = 0x10,
783         CSCMD_CONTINUOUS_CONVERSIONS = 0x20,
784         CSCMD_SINGLE_CONVERSION = 0x40,
785         CSCMD_COMMAND = 0x80,
786 };
787 enum cs5529_status_bits
788 {
789         CSS_ADC_BUSY = 0x1,
790         CSS_OSC_DETECT = 0x2, /* indicates adc error */
791         CSS_OVERRANGE = 0x4,
792 };
793 #define SerDacLd(x)                     (0x08<<(x))
794
795 /*
796         This is stuff unique to the NI E series drivers,
797         but I thought I'd put it here anyway.
798 */
799
800 /* our default usage of mite channels */
801 enum mite_dma_channel{
802         AI_DMA_CHAN = 0,
803         AO_DMA_CHAN = 1,
804         GPC0_DMA_CHAN = 2,
805         GPC1_DMA_CHAN = 3,
806 };
807
808 enum{ ai_gain_16=0, ai_gain_8, ai_gain_14, ai_gain_4, ai_gain_611x, ai_gain_622x, ai_gain_628x,  ai_gain_6143};
809 enum caldac_enum { caldac_none=0, mb88341, dac8800, dac8043, ad8522,
810         ad8804, ad8842, ad8804_debug };
811 enum ni_reg_type {
812         ni_reg_normal = 0x0,
813         ni_reg_611x = 0x1,
814         ni_reg_6711 = 0x2,
815         ni_reg_6713 = 0x4,
816         ni_reg_67xx_mask = 0x6,
817         ni_reg_6xxx_mask = 0x7,
818         ni_reg_m_series = 0x8,
819         ni_reg_6143 = 0x10
820 };
821
822 static comedi_lrange range_ni_E_ao_ext;
823
824 enum m_series_register_offsets
825 {
826         M_Offset_CDIO_DMA_Select = 0x7, // write
827         M_Offset_SCXI_Status = 0x7,     // read
828         M_Offset_AI_AO_Select = 0x9,    // write
829         M_Offset_SCXI_Serial_Data_In = 0x9,     // read
830         M_Offset_G0_G1_Select = 0xb,
831         M_Offset_Misc_Command = 0xf,
832         M_Offset_SCXI_Serial_Data_Out = 0x11,
833         M_Offset_SCXI_Control = 0x13,
834         M_Offset_SCXI_Output_Enable = 0x15,
835         M_Offset_AI_FIFO_Data = 0x1c,
836         M_Offset_Static_Digital_Output = 0x24,  // write
837         M_Offset_Static_Digital_Input = 0x24,   // read
838         M_Offset_DIO_Direction = 0x28,
839         M_Offset_Cal_PWM = 0x40,
840         M_Offset_AI_Config_FIFO_Data = 0x5e,
841         M_Offset_Interrupt_C_Enable = 0x88,     // write
842         M_Offset_Interrupt_C_Status = 0x88,     // read
843         M_Offset_Analog_Trigger_Control = 0x8c,
844         M_Offset_AO_Serial_Interrupt_Enable = 0xa0,
845         M_Offset_AO_Serial_Interrupt_Ack = 0xa1,        // write
846         M_Offset_AO_Serial_Interrupt_Status = 0xa1,     // read
847         M_Offset_AO_Calibration = 0xa3,
848         M_Offset_AO_FIFO_Data = 0xa4,
849         M_Offset_PFI_Filter = 0xb0,
850         M_Offset_RTSI_Filter = 0xb4,
851         M_Offset_SCXI_Legacy_Compatibility = 0xbc,
852         M_Offset_Interrupt_A_Ack = 0x104,       // write
853         M_Offset_AI_Status_1 = 0x104,   // read
854         M_Offset_Interrupt_B_Ack = 0x106,       // write
855         M_Offset_AO_Status_1 = 0x106,   // read
856         M_Offset_AI_Command_2 = 0x108,  // write
857         M_Offset_G01_Status = 0x108,    // read
858         M_Offset_AO_Command_2 = 0x10a,
859         M_Offset_AO_Status_2 = 0x10c,   // read
860         M_Offset_G0_Command = 0x10c,    // write
861         M_Offset_G1_Command = 0x10e,    // write
862         M_Offset_G0_HW_Save = 0x110,
863         M_Offset_G0_HW_Save_High = 0x110,
864         M_Offset_AI_Command_1 = 0x110,
865         M_Offset_G0_HW_Save_Low = 0x112,
866         M_Offset_AO_Command_1 = 0x112,
867         M_Offset_G1_HW_Save = 0x114,
868         M_Offset_G1_HW_Save_High = 0x114,
869         M_Offset_G1_HW_Save_Low = 0x116,
870         M_Offset_AI_Mode_1 = 0x118,
871         M_Offset_G0_Save = 0x118,
872         M_Offset_G0_Save_High = 0x118,
873         M_Offset_AI_Mode_2 = 0x11a,
874         M_Offset_G0_Save_Low = 0x11a,
875         M_Offset_AI_SI_Load_A = 0x11c,
876         M_Offset_G1_Save = 0x11c,
877         M_Offset_G1_Save_High = 0x11c,
878         M_Offset_G1_Save_Low = 0x11e,
879         M_Offset_AI_SI_Load_B = 0x120,  // write
880         M_Offset_AO_UI_Save = 0x120,    // read
881         M_Offset_AI_SC_Load_A = 0x124,  // write
882         M_Offset_AO_BC_Save = 0x124,    // read
883         M_Offset_AI_SC_Load_B = 0x128,  // write
884         M_Offset_AO_UC_Save = 0x128,    //read
885         M_Offset_AI_SI2_Load_A = 0x12c,
886         M_Offset_AI_SI2_Load_B = 0x130,
887         M_Offset_G0_Mode = 0x134,
888         M_Offset_G1_Mode = 0x136,       // write
889         M_Offset_Joint_Status_1 = 0x136,        // read
890         M_Offset_G0_Load_A = 0x138,
891         M_Offset_Joint_Status_2 = 0x13a,
892         M_Offset_G0_Load_B = 0x13c,
893         M_Offset_G1_Load_A = 0x140,
894         M_Offset_G1_Load_B = 0x144,
895         M_Offset_G0_Input_Select = 0x148,
896         M_Offset_G1_Input_Select = 0x14a,
897         M_Offset_AO_Mode_1 = 0x14c,
898         M_Offset_AO_Mode_2 = 0x14e,
899         M_Offset_AO_UI_Load_A = 0x150,
900         M_Offset_AO_UI_Load_B = 0x154,
901         M_Offset_AO_BC_Load_A = 0x158,
902         M_Offset_AO_BC_Load_B = 0x15c,
903         M_Offset_AO_UC_Load_A = 0x160,
904         M_Offset_AO_UC_Load_B = 0x164,
905         M_Offset_Clock_and_FOUT = 0x170,
906         M_Offset_IO_Bidirection_Pin = 0x172,
907         M_Offset_RTSI_Trig_Direction = 0x174,
908         M_Offset_Interrupt_Control = 0x176,
909         M_Offset_AI_Output_Control = 0x178,
910         M_Offset_Analog_Trigger_Etc = 0x17a,
911         M_Offset_AI_START_STOP_Select = 0x17c,
912         M_Offset_AI_Trigger_Select = 0x17e,
913         M_Offset_AI_SI_Save = 0x180,    // read
914         M_Offset_AI_DIV_Load_A = 0x180, // write
915         M_Offset_AI_SC_Save = 0x184,    // read
916         M_Offset_AO_Start_Select = 0x184,       // write
917         M_Offset_AO_Trigger_Select = 0x186,
918         M_Offset_AO_Mode_3 = 0x18c,
919         M_Offset_G0_Autoincrement = 0x188,
920         M_Offset_G1_Autoincrement = 0x18a,
921         M_Offset_Joint_Reset = 0x190,
922         M_Offset_Interrupt_A_Enable = 0x192,
923         M_Offset_Interrupt_B_Enable = 0x196,
924         M_Offset_AI_Personal = 0x19a,
925         M_Offset_AO_Personal = 0x19c,
926         M_Offset_RTSI_Trig_A_Output = 0x19e,
927         M_Offset_RTSI_Trig_B_Output = 0x1a0,
928         M_Offset_RTSI_Shared_MUX = 0x1a2,
929         M_Offset_AO_Output_Control = 0x1ac,
930         M_Offset_AI_Mode_3 = 0x1ae,
931         M_Offset_Configuration_Memory_Clear = 0x1a4,
932         M_Offset_AI_FIFO_Clear = 0x1a6,
933         M_Offset_AO_FIFO_Clear = 0x1a8,
934         M_Offset_G0_Counting_Mode = 0x1b0,
935         M_Offset_G1_Counting_Mode = 0x1b2,
936         M_Offset_G0_Second_Gate = 0x1b4,
937         M_Offset_G1_Second_Gate = 0x1b6,
938         M_Offset_G0_DMA_Config = 0x1b8, // write
939         M_Offset_G0_DMA_Status = 0x1b8, // read
940         M_Offset_G1_DMA_Config = 0x1ba, // write
941         M_Offset_G1_DMA_Status = 0x1ba, // read
942         M_Offset_G0_MSeries_ABZ = 0x1c0,
943         M_Offset_G1_MSeries_ABZ = 0x1c2,
944         M_Offset_Clock_and_Fout2 = 0x1c4,
945         M_Offset_PLL_Control = 0x1c6,
946         M_Offset_PLL_Status = 0x1c8,
947         M_Offset_PFI_Output_Select_1 = 0x1d0,
948         M_Offset_PFI_Output_Select_2 = 0x1d2,
949         M_Offset_PFI_Output_Select_3 = 0x1d4,
950         M_Offset_PFI_Output_Select_4 = 0x1d6,
951         M_Offset_PFI_Output_Select_5 = 0x1d8,
952         M_Offset_PFI_Output_Select_6 = 0x1da,
953         M_Offset_PFI_DI = 0x1dc,
954         M_Offset_PFI_DO = 0x1de,
955         M_Offset_AI_Config_FIFO_Bypass = 0x218,
956         M_Offset_SCXI_DIO_Enable = 0x21c,
957         M_Offset_CDI_FIFO_Data = 0x220, // read
958         M_Offset_CDO_FIFO_Data = 0x220, // write
959         M_Offset_CDIO_Status = 0x224,   // read
960         M_Offset_CDIO_Command = 0x224,  // write
961         M_Offset_CDI_Mode = 0x228,
962         M_Offset_CDO_Mode = 0x22c,
963         M_Offset_CDI_Mask_Enable = 0x230,
964         M_Offset_CDO_Mask_Enable = 0x234,
965 };
966 static inline int M_Offset_AO_Waveform_Order(int channel)
967 {
968         return 0xc2 + 0x4 * channel;
969 };
970 static inline int M_Offset_AO_Config_Bank(int channel)
971 {
972         return 0xc3 + 0x4 * channel;
973 };
974 static inline int M_Offset_DAC_Direct_Data(int channel)
975 {
976         return 0xc0 + 0x4 * channel;
977 }
978 static inline int M_Offset_Gen_PWM(int channel)
979 {
980         return 0x44 + 0x2 * channel;
981 }
982 static inline int M_Offset_Static_AI_Control(int i)
983 {
984         int offset[] =
985         {
986                 0x64,
987                 0x261,
988                 0x262,
989                 0x263,
990         };
991         if(((unsigned)i) >= sizeof(offset) / sizeof(offset[0]))
992         {
993                 rt_printk("%s: invalid channel=%i\n", __FUNCTION__, i);
994                 return offset[0];
995         }
996         return offset[i];
997 };
998 static inline int M_Offset_AO_Reference_Attenuation(int channel)
999 {
1000         int offset[] =
1001         {
1002                 0x264,
1003                 0x265,
1004                 0x266,
1005                 0x267
1006         };
1007         if(((unsigned)channel) >= sizeof(offset) / sizeof(offset[0]))
1008         {
1009                 rt_printk("%s: invalid channel=%i\n", __FUNCTION__, channel);
1010                 return offset[0];
1011         }
1012         return offset[channel];
1013 };
1014
1015 enum MSeries_AI_Config_FIFO_Data_Bits
1016 {
1017         MSeries_AI_Config_Channel_Type_Mask = 0x7 << 6,
1018         MSeries_AI_Config_Channel_Type_Calibration_Bits = 0x0,
1019         MSeries_AI_Config_Channel_Type_Differential_Bits = 0x1 << 6,
1020         MSeries_AI_Config_Channel_Type_Common_Ref_Bits = 0x2 << 6,
1021         MSeries_AI_Config_Channel_Type_Ground_Ref_Bits = 0x3 << 6,
1022         MSeries_AI_Config_Channel_Type_Aux_Bits = 0x5 << 6,
1023         MSeries_AI_Config_Channel_Type_Ghost_Bits = 0x7 << 6,
1024         MSeries_AI_Config_Polarity_Bit = 0x1000,  // 0 for 2's complement encoding
1025         MSeries_AI_Config_Dither_Bit = 0x2000,
1026         MSeries_AI_Config_Last_Channel_Bit = 0x4000,
1027 };
1028 static inline unsigned MSeries_AI_Config_Channel_Bits(unsigned channel)
1029 {
1030         return channel & 0xf;
1031 }
1032 static inline unsigned MSeries_AI_Config_Bank_Bits(unsigned channel)
1033 {
1034         return channel & 0x30;
1035 }
1036 static inline unsigned MSeries_AI_Config_Gain_Bits(unsigned range)
1037 {
1038         return (range & 0x7) << 9;
1039 }
1040
1041 enum MSeries_Clock_and_Fout2_Bits
1042 {
1043         MSeries_PLL_In_Source_Select_RTSI0_Bits = 0xb,
1044         MSeries_PLL_In_Source_Select_Star_Trigger_Bits = 0x14,
1045         MSeries_PLL_In_Source_Select_RTSI7_Bits = 0x1b,
1046         MSeries_PLL_In_Source_Select_PXI_Clock10 = 0x1d,
1047         MSeries_PLL_In_Source_Select_Mask = 0x1f,
1048         MSeries_Timebase1_Select_Bit = 0x20,    // use PLL for timebase 1
1049         MSeries_Timebase3_Select_Bit = 0x40,    // use PLL for timebase 3
1050         MSeries_RTSI_10MHz_Bit = 0x80   // use 10MHz instead of 20MHz for RTSI clock frequency
1051 };
1052 static inline unsigned MSeries_PLL_In_Source_Select_RTSI_Bits(unsigned RTSI_channel)
1053 {
1054         if(RTSI_channel > 7)
1055         {
1056                 rt_printk("%s: bug, invalid RTSI_channel=%i\n", __FUNCTION__, RTSI_channel);
1057                 return 0;
1058         }
1059         if(RTSI_channel == 7) return MSeries_PLL_In_Source_Select_RTSI7_Bits;
1060         else return MSeries_PLL_In_Source_Select_RTSI0_Bits + RTSI_channel;
1061 }
1062
1063 enum MSeries_PLL_Control_Bits
1064 {
1065         MSeries_PLL_Enable_Bit = 0x1000,
1066         MSeries_PLL_VCO_Mode_200_325MHz_Bits = 0x0,
1067         MSeries_PLL_VCO_Mode_175_225MHz_Bits  = 0x2000,
1068         MSeries_PLL_VCO_Mode_100_225MHz_Bits  = 0x4000,
1069         MSeries_PLL_VCO_Mode_75_150MHz_Bits   = 0x7000,
1070 };
1071 static inline unsigned MSeries_PLL_Divisor_Bits(unsigned divisor)
1072 {
1073         static const unsigned max_divisor = 0x10;
1074         if(divisor < 1 || divisor > max_divisor)
1075         {
1076                 rt_printk("%s: bug, invalid divisor=%i\n", __FUNCTION__, divisor);
1077                 return 0;
1078         }
1079         return (divisor & 0xf) << 8;
1080 }
1081 static inline unsigned MSeries_PLL_Multiplier_Bits(unsigned multiplier)
1082 {
1083         static const unsigned max_multiplier = 0x100;
1084         if(multiplier < 1 || multiplier > max_multiplier)
1085         {
1086                 rt_printk("%s: bug, invalid multiplier=%i\n", __FUNCTION__, multiplier);
1087                 return 0;
1088         }
1089         return multiplier & 0xff;
1090 }
1091
1092 enum MSeries_PLL_Status
1093 {
1094         MSeries_PLL_Locked_Bit = 0x1
1095 };
1096
1097 enum MSeries_AI_Config_FIFO_Bypass_Bits
1098 {
1099         MSeries_AI_Bypass_Channel_Mask = 0x7,
1100         MSeries_AI_Bypass_Bank_Mask = 0x78,
1101         MSeries_AI_Bypass_Cal_Sel_Pos_Mask = 0x380,
1102         MSeries_AI_Bypass_Cal_Sel_Neg_Mask = 0x1c00,
1103         MSeries_AI_Bypass_Mode_Mux_Mask = 0x6000,
1104         MSeries_AO_Bypass_AO_Cal_Sel_Mask = 0x38000,
1105         MSeries_AI_Bypass_Gain_Mask = 0x1c0000,
1106         MSeries_AI_Bypass_Dither_Bit = 0x200000,
1107         MSeries_AI_Bypass_Polarity_Bit = 0x400000, // 0 for 2's complement encoding
1108         MSeries_AI_Bypass_Config_FIFO_Bit = 0x80000000
1109 };
1110 static inline unsigned MSeries_AI_Bypass_Cal_Sel_Pos_Bits(int calibration_source)
1111 {
1112         return (calibration_source << 7) & MSeries_AI_Bypass_Cal_Sel_Pos_Mask;
1113 }
1114 static inline unsigned MSeries_AI_Bypass_Cal_Sel_Neg_Bits(int calibration_source)
1115 {
1116         return (calibration_source << 10) & MSeries_AI_Bypass_Cal_Sel_Pos_Mask;
1117 }
1118 static inline unsigned MSeries_AI_Bypass_Gain_Bits(int gain)
1119 {
1120         return (gain << 18) & MSeries_AI_Bypass_Gain_Mask;
1121 }
1122
1123 enum MSeries_AO_Config_Bank_Bits
1124 {
1125         MSeries_AO_DAC_Offset_Select_Mask = 0x7,
1126         MSeries_AO_DAC_Offset_0V_Bits = 0x0,
1127         MSeries_AO_DAC_Offset_5V_Bits = 0x1,
1128         MSeries_AO_DAC_Reference_Mask = 0x38,
1129         MSeries_AO_DAC_Reference_10V_Internal_Bits = 0x0,
1130         MSeries_AO_DAC_Reference_5V_Internal_Bits = 0x8,
1131         MSeries_AO_Update_Timed_Bit = 0x40,
1132         MSeries_AO_Bipolar_Bit = 0x80   // turns on 2's complement encoding
1133 };
1134
1135 enum MSeries_AO_Reference_Attenuation_Bits
1136 {
1137         MSeries_Attenuate_x5_Bit = 0x1
1138 };
1139
1140 static inline unsigned MSeries_Cal_PWM_High_Time_Bits(unsigned count)
1141 {
1142         return (count << 16) & 0xffff0000;
1143 }
1144
1145 static inline unsigned MSeries_Cal_PWM_Low_Time_Bits(unsigned count)
1146 {
1147         return count & 0xffff;
1148 }
1149
1150
1151 #define M_SERIES_EEPROM_SIZE 1024
1152
1153 typedef struct ni_board_struct{
1154         int device_id;
1155         int isapnp_id;
1156         char *name;
1157
1158         int n_adchan;
1159         int adbits;
1160
1161         int ai_fifo_depth;
1162         unsigned int alwaysdither : 1;
1163         int gainlkup;
1164         int ai_speed;
1165
1166         int n_aochan;
1167         int aobits;
1168
1169         int ao_fifo_depth;
1170         comedi_lrange *ao_range_table;
1171
1172         int reg_type;
1173
1174         unsigned int ao_unipolar : 1;
1175         unsigned int has_8255 : 1;
1176         unsigned int has_analog_trig : 1;
1177
1178         enum caldac_enum caldac[3];
1179 }ni_board;
1180
1181 static ni_board ni_boards[];
1182 #define n_ni_boards  (sizeof(ni_boards)/sizeof(ni_board))
1183
1184 #define boardtype (*(ni_board *)dev->board_ptr)
1185
1186 #define MAX_N_AO_CHAN 8
1187
1188 #define NI_PRIVATE_COMMON                                       \
1189         uint16_t (*stc_readw)(comedi_device *dev, int register);        \
1190         void (*stc_writew)(comedi_device *dev, uint16_t value, int register);   \
1191         void (*stc_writel)(comedi_device *dev, uint32_t value, int register);   \
1192         \
1193         unsigned short dio_output;                              \
1194         unsigned short dio_control;                             \
1195         int ao0p,ao1p;                                          \
1196         int lastchan;                                           \
1197         int last_do;                                            \
1198         int rt_irq;                                             \
1199         int irqmask;                                            \
1200         int aimode;                                             \
1201         int ai_continuous;                                      \
1202         int blocksize;                                          \
1203         int n_left;                                             \
1204         unsigned int ai_calib_source;                           \
1205         unsigned int ai_calib_source_enabled;                   \
1206         spinlock_t window_lock; \
1207                                                                 \
1208         int changain_state;                                     \
1209         unsigned int changain_spec;                             \
1210                                                                 \
1211         unsigned int caldac_maxdata_list[MAX_N_CALDACS];        \
1212         unsigned short ao[MAX_N_AO_CHAN];                                       \
1213         unsigned short caldacs[MAX_N_CALDACS];                          \
1214                                                                 \
1215         volatile unsigned short ai_cmd2;        \
1216                                                                 \
1217         unsigned short ao_conf[MAX_N_AO_CHAN];                          \
1218         unsigned short ao_mode1;                                \
1219         unsigned short ao_mode2;                                \
1220         unsigned short ao_mode3;                                \
1221         unsigned short ao_cmd1;                                 \
1222         unsigned short ao_cmd2;                                 \
1223         unsigned short ao_cmd3;                                 \
1224         unsigned short ao_trigger_select;                       \
1225                                                                 \
1226         unsigned short gpct_mode[2];                            \
1227         unsigned short gpct_command[2];                         \
1228         unsigned short gpct_input_select[2];                    \
1229         int gpct_cur_operation[2];                              \
1230         unsigned short an_trig_etc_reg;                         \
1231                                                                 \
1232         unsigned ai_offset[512];                                \
1233                                                                 \
1234         unsigned long serial_interval_ns;                       \
1235         unsigned char serial_hw_mode;                           \
1236         unsigned short clock_and_fout;                          \
1237         unsigned short clock_and_fout2;                         \
1238                                                                 \
1239         volatile unsigned short int_a_enable_reg;                       \
1240         volatile unsigned short int_b_enable_reg;                       \
1241         unsigned short io_bidirection_pin_reg;                  \
1242         unsigned short rtsi_trig_direction_reg;                 \
1243                                                                 \
1244         unsigned clock_ns; \
1245         unsigned clock_source; \
1246         \
1247         unsigned short atrig_mode;                              \
1248         unsigned short atrig_high;                              \
1249         unsigned short atrig_low;                               \
1250         \
1251         unsigned short pwm_up_count;    \
1252         unsigned short pwm_down_count;  \
1253         \
1254         sampl_t ai_fifo_buffer[0x2000];                         \
1255         uint8_t eeprom_buffer[M_SERIES_EEPROM_SIZE];
1256
1257 #endif /* _COMEDI_NI_STC_H */
1258