2 comedi/drivers/ni_pcimio.c
3 Hardware driver for NI PCI-MIO E series cards
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
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.
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.
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.
24 Description: National Instruments PCI-MIO-E series and M series (all boards)
25 Author: ds, John Hallen, Frank Mori Hess, Rolf Mueller, Herbert Peremans,
26 Herman Bruyninckx, Terry Barnaby
28 Devices: [National Instruments] PCI-MIO-16XE-50 (ni_pcimio),
29 PCI-MIO-16XE-10, PXI-6030E, PCI-MIO-16E-1, PCI-MIO-16E-4, PCI-6014, PCI-6040E,
30 PXI-6040E, PCI-6030E, PCI-6031E, PCI-6032E, PCI-6033E, PCI-6071E, PCI-6023E,
31 PCI-6024E, PCI-6025E, PXI-6025E, PCI-6034E, PCI-6035E, PCI-6052E,
32 PCI-6110, PCI-6111, PCI-6220, PCI-6221, PCI-6224, PXI-6224, PCI-6225, PXI-6225,
33 PCI-6229, PCI-6250, PCI-6251, PCIe-6251, PCI-6254, PCI-6259, PCIe-6259,
34 PCI-6280, PCI-6281, PXI-6281, PCI-6284, PCI-6289,
35 PCI-6711, PXI-6711, PCI-6713, PXI-6713,
36 PXI-6071E, PCI-6070E, PXI-6070E,
37 PXI-6052E, PCI-6036E, PCI-6731, PCI-6733, PXI-6733,
39 Updated: Wed, 03 Dec 2008 10:51:47 +0000
41 These boards are almost identical to the AT-MIO E series, except that
42 they use the PCI bus instead of ISA (i.e., AT). See the notes for
43 the ni_atmio.o driver for additional information about these boards.
45 Autocalibration is supported on many of the devices, using the
46 comedi_calibrate (or comedi_soft_calibrate for m-series) utility.
47 M-Series boards do analog input and analog output calibration entirely
48 in software. The software calibration corrects
49 the analog input for offset, gain and
50 nonlinearity. The analog outputs are corrected for offset and gain.
51 See the comedilib documentation on comedi_get_softcal_converter() for
54 By default, the driver uses DMA to transfer analog input data to
55 memory. When DMA is enabled, not all triggering features are
58 Digital I/O may not work on 673x.
60 Note that the PCI-6143 is a simultaineous sampling device with 8 convertors.
61 With this board all of the convertors perform one simultaineous sample during
62 a scan interval. The period for a scan is used for the convert time in a
63 Comedi cmd. The convert trigger source is normally set to TRIG_NOW by default.
65 The RTSI trigger bus is supported on these cards on
66 subdevice 10. See the comedilib documentation for details.
68 Information (number of channels, bits, etc.) for some devices may be
69 incorrect. Please check this and submit a bug if there are problems
72 SCXI is probably broken for m-series boards.
75 - When DMA is enabled, COMEDI_EV_CONVERT does
80 The PCI-MIO E series driver was originally written by
81 Tomasz Motylewski <...>, and ported to comedi by ds.
85 341079b.pdf PCI E Series Register-Level Programmer Manual
86 340934b.pdf DAQ-STC reference manual
88 322080b.pdf 6711/6713/6715 User Manual
90 320945c.pdf PCI E Series User Manual
91 322138a.pdf PCI-6052E and DAQPad-6052E User Manual
95 need to deal with external reference for DAC, and other DAC
96 properties in board properties
98 deal with at-mio-16de-10 revision D to N changes, etc.
100 need to add other CALDAC type
102 need to slow down DAC loading. I don't trust NI's claim that
103 two writes to the PCI bus slows IO enough. I would prefer to
104 use udelay(). Timing specs: (clock)
112 #include "../comedidev.h"
114 #include <asm/byteorder.h>
115 #include <linux/delay.h>
120 /* #define PCI_DEBUG */
127 #define MAX_N_CALDACS (16+16+2)
129 #define DRV_NAME "ni_pcimio"
131 /* The following two tables must be in the same order */
132 static DEFINE_PCI_DEVICE_TABLE(ni_pci_table
) = {
133 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x0162)},
134 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x1170)},
135 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x1180)},
136 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x1190)},
137 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x11b0)},
138 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x11c0)},
139 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x11d0)},
140 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x1270)},
141 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x1330)},
142 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x1340)},
143 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x1350)},
144 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x14e0)},
145 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x14f0)},
146 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x1580)},
147 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x15b0)},
148 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x1880)},
149 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x1870)},
150 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x18b0)},
151 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x18c0)},
152 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x2410)},
153 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x2420)},
154 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x2430)},
155 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x2890)},
156 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x28c0)},
157 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x2a60)},
158 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x2a70)},
159 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x2a80)},
160 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x2ab0)},
161 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x2b80)},
162 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x2b90)},
163 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x2c80)},
164 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x2ca0)},
165 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70aa)},
166 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70ab)},
167 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70ac)},
168 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70af)},
169 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70b0)},
170 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70b4)},
171 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70b6)},
172 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70b7)},
173 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70b8)},
174 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70bc)},
175 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70bd)},
176 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70bf)},
177 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70c0)},
178 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x70f2)},
179 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x710d)},
180 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x716c)},
181 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x716d)},
182 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x717f)},
183 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x71bc)},
184 {PCI_DEVICE(PCI_VENDOR_ID_NI
, 0x717d)},
188 MODULE_DEVICE_TABLE(pci
, ni_pci_table
);
190 /* These are not all the possible ao ranges for 628x boards.
191 They can do OFFSET +- REFERENCE where OFFSET can be
192 0V, 5V, APFI<0,1>, or AO<0...3> and RANGE can
193 be 10V, 5V, 2V, 1V, APFI<0,1>, AO<0...3>. That's
194 63 different possibilities. An AO channel
195 can not act as it's own OFFSET or REFERENCE.
197 static const struct comedi_lrange range_ni_M_628x_ao
= { 8, {
210 static const struct comedi_lrange range_ni_M_625x_ao
= { 3, {
217 static const struct comedi_lrange range_ni_M_622x_ao
= { 1, {
222 static const struct ni_board_struct ni_boards
[] = {
224 .device_id
= 0x0162, /* NI also says 0x1620. typo? */
225 .name
= "pci-mio-16xe-50",
228 .ai_fifo_depth
= 2048,
230 .gainlkup
= ai_gain_8
,
235 .ao_range_table
= &range_bipolar10
,
238 .num_p0_dio_channels
= 8,
239 .caldac
= {dac8800
, dac8043
},
244 .name
= "pci-mio-16xe-10", /* aka pci-6030E */
247 .ai_fifo_depth
= 512,
249 .gainlkup
= ai_gain_14
,
253 .ao_fifo_depth
= 2048,
254 .ao_range_table
= &range_ni_E_ao_ext
,
257 .num_p0_dio_channels
= 8,
258 .caldac
= {dac8800
, dac8043
, ad8522
},
266 .ai_fifo_depth
= 512,
268 .gainlkup
= ai_gain_4
,
273 .ao_range_table
= &range_bipolar10
,
276 .num_p0_dio_channels
= 8,
277 .caldac
= {ad8804_debug
},
285 .ai_fifo_depth
= 512,
287 .gainlkup
= ai_gain_14
,
291 .ao_fifo_depth
= 2048,
292 .ao_range_table
= &range_ni_E_ao_ext
,
295 .num_p0_dio_channels
= 8,
296 .caldac
= {dac8800
, dac8043
, ad8522
},
301 .name
= "pci-mio-16e-1", /* aka pci-6070e */
304 .ai_fifo_depth
= 512,
306 .gainlkup
= ai_gain_16
,
310 .ao_fifo_depth
= 2048,
311 .ao_range_table
= &range_ni_E_ao_ext
,
314 .num_p0_dio_channels
= 8,
320 .name
= "pci-mio-16e-4", /* aka pci-6040e */
323 .ai_fifo_depth
= 512,
325 .gainlkup
= ai_gain_16
,
326 /* .Note = there have been reported problems with full speed
331 .ao_fifo_depth
= 512,
332 .ao_range_table
= &range_ni_E_ao_ext
,
335 .num_p0_dio_channels
= 8,
336 .caldac
= {ad8804_debug
}, /* doc says mb88341 */
344 .ai_fifo_depth
= 512,
346 .gainlkup
= ai_gain_16
,
350 .ao_fifo_depth
= 512,
351 .ao_range_table
= &range_ni_E_ao_ext
,
354 .num_p0_dio_channels
= 8,
364 .ai_fifo_depth
= 512,
366 .gainlkup
= ai_gain_14
,
370 .ao_fifo_depth
= 2048,
371 .ao_range_table
= &range_ni_E_ao_ext
,
374 .num_p0_dio_channels
= 8,
375 .caldac
= {dac8800
, dac8043
, ad8522
},
383 .ai_fifo_depth
= 512,
385 .gainlkup
= ai_gain_14
,
391 .num_p0_dio_channels
= 8,
392 .caldac
= {dac8800
, dac8043
, ad8522
},
400 .ai_fifo_depth
= 512,
402 .gainlkup
= ai_gain_14
,
408 .num_p0_dio_channels
= 8,
409 .caldac
= {dac8800
, dac8043
, ad8522
},
417 .ai_fifo_depth
= 512,
419 .gainlkup
= ai_gain_16
,
423 .ao_fifo_depth
= 2048,
424 .ao_range_table
= &range_ni_E_ao_ext
,
427 .num_p0_dio_channels
= 8,
428 .caldac
= {ad8804_debug
},
436 .ai_fifo_depth
= 512,
438 .gainlkup
= ai_gain_4
,
443 .num_p0_dio_channels
= 8,
444 .caldac
= {ad8804_debug
}, /* manual is wrong */
452 .ai_fifo_depth
= 512,
454 .gainlkup
= ai_gain_4
,
459 .ao_range_table
= &range_bipolar10
,
462 .num_p0_dio_channels
= 8,
463 .caldac
= {ad8804_debug
}, /* manual is wrong */
471 .ai_fifo_depth
= 512,
473 .gainlkup
= ai_gain_4
,
478 .ao_range_table
= &range_bipolar10
,
481 .num_p0_dio_channels
= 8,
482 .caldac
= {ad8804_debug
}, /* manual is wrong */
490 .ai_fifo_depth
= 512,
492 .gainlkup
= ai_gain_4
,
497 .ao_range_table
= &range_ni_E_ao_ext
,
500 .num_p0_dio_channels
= 8,
501 .caldac
= {ad8804_debug
}, /* manual is wrong */
510 .ai_fifo_depth
= 512,
512 .gainlkup
= ai_gain_4
,
518 .num_p0_dio_channels
= 8,
519 .caldac
= {ad8804_debug
},
527 .ai_fifo_depth
= 512,
529 .gainlkup
= ai_gain_4
,
534 .ao_range_table
= &range_bipolar10
,
537 .num_p0_dio_channels
= 8,
538 .caldac
= {ad8804_debug
},
546 .ai_fifo_depth
= 512,
548 .gainlkup
= ai_gain_16
,
553 .ao_fifo_depth
= 2048,
554 .ao_range_table
= &range_ni_E_ao_ext
,
556 .num_p0_dio_channels
= 8,
557 .caldac
= {ad8804_debug
, ad8804_debug
, ad8522
}, /* manual is wrong */
559 {.device_id
= 0x14e0,
563 .ai_fifo_depth
= 8192,
565 .gainlkup
= ai_gain_611x
,
569 .reg_type
= ni_reg_611x
,
570 .ao_range_table
= &range_bipolar10
,
572 .ao_fifo_depth
= 2048,
574 .num_p0_dio_channels
= 8,
575 .caldac
= {ad8804
, ad8804
},
582 .ai_fifo_depth
= 8192,
584 .gainlkup
= ai_gain_611x
,
588 .reg_type
= ni_reg_611x
,
589 .ao_range_table
= &range_bipolar10
,
591 .ao_fifo_depth
= 2048,
593 .num_p0_dio_channels
= 8,
594 .caldac
= {ad8804
, ad8804
},
599 .n_adchan
= 0, /* no analog input */
603 .ao_fifo_depth
= 16384,
604 /* data sheet says 8192, but fifo really holds 16384 samples */
605 .ao_range_table
= &range_bipolar10
,
607 .num_p0_dio_channels
= 8,
608 .reg_type
= ni_reg_6711
,
609 .caldac
= {ad8804_debug
},
614 .n_adchan
= 0, /* no analog input */
618 .ao_fifo_depth
= 16384,
619 .ao_range_table
= &range_bipolar10
,
621 .num_p0_dio_channels
= 8,
622 .reg_type
= ni_reg_6711
,
623 .caldac
= {ad8804_debug
},
628 .n_adchan
= 0, /* no analog input */
632 .ao_fifo_depth
= 16384,
633 .ao_range_table
= &range_bipolar10
,
635 .num_p0_dio_channels
= 8,
636 .reg_type
= ni_reg_6713
,
637 .caldac
= {ad8804_debug
, ad8804_debug
},
642 .n_adchan
= 0, /* no analog input */
646 .ao_fifo_depth
= 16384,
647 .ao_range_table
= &range_bipolar10
,
649 .num_p0_dio_channels
= 8,
650 .reg_type
= ni_reg_6713
,
651 .caldac
= {ad8804_debug
, ad8804_debug
},
656 .n_adchan
= 0, /* no analog input */
660 .ao_fifo_depth
= 8192,
661 .ao_range_table
= &range_bipolar10
,
663 .num_p0_dio_channels
= 8,
664 .reg_type
= ni_reg_6711
,
665 .caldac
= {ad8804_debug
},
670 .n_adchan
= 0, /* no analog input */
674 .ao_fifo_depth
= 16384,
675 .ao_range_table
= &range_bipolar10
,
677 .num_p0_dio_channels
= 8,
678 .reg_type
= ni_reg_6713
,
679 .caldac
= {ad8804_debug
, ad8804_debug
},
684 .n_adchan
= 0, /* no analog input */
688 .ao_fifo_depth
= 16384,
689 .ao_range_table
= &range_bipolar10
,
691 .num_p0_dio_channels
= 8,
692 .reg_type
= ni_reg_6713
,
693 .caldac
= {ad8804_debug
, ad8804_debug
},
700 .ai_fifo_depth
= 512,
702 .gainlkup
= ai_gain_16
,
706 .ao_fifo_depth
= 2048,
707 .ao_range_table
= &range_ni_E_ao_ext
,
710 .num_p0_dio_channels
= 8,
711 .caldac
= {ad8804_debug
},
719 .ai_fifo_depth
= 512,
721 .gainlkup
= ai_gain_16
,
725 .ao_fifo_depth
= 2048,
726 .ao_range_table
= &range_ni_E_ao_ext
,
729 .num_p0_dio_channels
= 8,
730 .caldac
= {ad8804_debug
},
738 .ai_fifo_depth
= 512,
740 .gainlkup
= ai_gain_16
,
745 .ao_fifo_depth
= 2048,
746 .ao_range_table
= &range_ni_E_ao_ext
,
748 .num_p0_dio_channels
= 8,
749 .caldac
= {mb88341
, mb88341
, ad8522
},
756 .ai_fifo_depth
= 512,
758 .gainlkup
= ai_gain_14
,
762 .ao_fifo_depth
= 2048,
763 .ao_range_table
= &range_ni_E_ao_ext
,
766 .num_p0_dio_channels
= 8,
767 .caldac
= {dac8800
, dac8043
, ad8522
},
774 .ai_fifo_depth
= 512,
776 .gainlkup
= ai_gain_4
,
781 .ao_range_table
= &range_bipolar10
,
784 .num_p0_dio_channels
= 8,
785 .caldac
= {ad8804_debug
},
793 .ai_fifo_depth
= 512,
794 .gainlkup
= ai_gain_622x
,
799 .num_p0_dio_channels
= 8,
800 .reg_type
= ni_reg_622x
,
802 .caldac
= {caldac_none
},
810 .ai_fifo_depth
= 4095,
811 .gainlkup
= ai_gain_622x
,
815 .ao_fifo_depth
= 8191,
816 .ao_range_table
= &range_ni_M_622x_ao
,
817 .reg_type
= ni_reg_622x
,
820 .num_p0_dio_channels
= 8,
821 .caldac
= {caldac_none
},
826 .name
= "pci-6221_37pin",
829 .ai_fifo_depth
= 4095,
830 .gainlkup
= ai_gain_622x
,
834 .ao_fifo_depth
= 8191,
835 .ao_range_table
= &range_ni_M_622x_ao
,
836 .reg_type
= ni_reg_622x
,
839 .num_p0_dio_channels
= 8,
840 .caldac
= {caldac_none
},
848 .ai_fifo_depth
= 4095,
849 .gainlkup
= ai_gain_622x
,
854 .reg_type
= ni_reg_622x
,
856 .num_p0_dio_channels
= 32,
857 .caldac
= {caldac_none
},
865 .ai_fifo_depth
= 4095,
866 .gainlkup
= ai_gain_622x
,
871 .reg_type
= ni_reg_622x
,
873 .num_p0_dio_channels
= 32,
874 .caldac
= {caldac_none
},
882 .ai_fifo_depth
= 4095,
883 .gainlkup
= ai_gain_622x
,
887 .ao_fifo_depth
= 8191,
888 .ao_range_table
= &range_ni_M_622x_ao
,
889 .reg_type
= ni_reg_622x
,
892 .num_p0_dio_channels
= 32,
893 .caldac
= {caldac_none
},
901 .ai_fifo_depth
= 4095,
902 .gainlkup
= ai_gain_622x
,
906 .ao_fifo_depth
= 8191,
907 .ao_range_table
= &range_ni_M_622x_ao
,
908 .reg_type
= ni_reg_622x
,
911 .num_p0_dio_channels
= 32,
912 .caldac
= {caldac_none
},
920 .ai_fifo_depth
= 4095,
921 .gainlkup
= ai_gain_622x
,
925 .ao_fifo_depth
= 8191,
926 .ao_range_table
= &range_ni_M_622x_ao
,
927 .reg_type
= ni_reg_622x
,
930 .num_p0_dio_channels
= 32,
931 .caldac
= {caldac_none
},
939 .ai_fifo_depth
= 4095,
940 .gainlkup
= ai_gain_628x
,
945 .reg_type
= ni_reg_625x
,
947 .num_p0_dio_channels
= 8,
948 .caldac
= {caldac_none
},
956 .ai_fifo_depth
= 4095,
957 .gainlkup
= ai_gain_628x
,
961 .ao_fifo_depth
= 8191,
962 .ao_range_table
= &range_ni_M_625x_ao
,
963 .reg_type
= ni_reg_625x
,
966 .num_p0_dio_channels
= 8,
967 .caldac
= {caldac_none
},
975 .ai_fifo_depth
= 4095,
976 .gainlkup
= ai_gain_628x
,
980 .ao_fifo_depth
= 8191,
981 .ao_range_table
= &range_ni_M_625x_ao
,
982 .reg_type
= ni_reg_625x
,
985 .num_p0_dio_channels
= 8,
986 .caldac
= {caldac_none
},
994 .ai_fifo_depth
= 4095,
995 .gainlkup
= ai_gain_628x
,
1000 .reg_type
= ni_reg_625x
,
1002 .num_p0_dio_channels
= 32,
1003 .caldac
= {caldac_none
},
1007 .device_id
= 0x70ab,
1011 .ai_fifo_depth
= 4095,
1012 .gainlkup
= ai_gain_628x
,
1016 .ao_fifo_depth
= 8191,
1017 .ao_range_table
= &range_ni_M_625x_ao
,
1018 .reg_type
= ni_reg_625x
,
1021 .num_p0_dio_channels
= 32,
1022 .caldac
= {caldac_none
},
1026 .device_id
= 0x717f,
1027 .name
= "pcie-6259",
1030 .ai_fifo_depth
= 4095,
1031 .gainlkup
= ai_gain_628x
,
1035 .ao_fifo_depth
= 8191,
1036 .ao_range_table
= &range_ni_M_625x_ao
,
1037 .reg_type
= ni_reg_625x
,
1040 .num_p0_dio_channels
= 32,
1041 .caldac
= {caldac_none
},
1045 .device_id
= 0x70b6,
1049 .ai_fifo_depth
= 2047,
1050 .gainlkup
= ai_gain_628x
,
1054 .ao_fifo_depth
= 8191,
1055 .reg_type
= ni_reg_628x
,
1057 .num_p0_dio_channels
= 8,
1058 .caldac
= {caldac_none
},
1062 .device_id
= 0x70bd,
1066 .ai_fifo_depth
= 2047,
1067 .gainlkup
= ai_gain_628x
,
1071 .ao_fifo_depth
= 8191,
1072 .ao_range_table
= &range_ni_M_628x_ao
,
1073 .reg_type
= ni_reg_628x
,
1076 .num_p0_dio_channels
= 8,
1077 .caldac
= {caldac_none
},
1081 .device_id
= 0x70bf,
1085 .ai_fifo_depth
= 2047,
1086 .gainlkup
= ai_gain_628x
,
1090 .ao_fifo_depth
= 8191,
1091 .ao_range_table
= &range_ni_M_628x_ao
,
1092 .reg_type
= ni_reg_628x
,
1095 .num_p0_dio_channels
= 8,
1096 .caldac
= {caldac_none
},
1100 .device_id
= 0x70bc,
1104 .ai_fifo_depth
= 2047,
1105 .gainlkup
= ai_gain_628x
,
1110 .reg_type
= ni_reg_628x
,
1112 .num_p0_dio_channels
= 32,
1113 .caldac
= {caldac_none
},
1117 .device_id
= 0x70ac,
1121 .ai_fifo_depth
= 2047,
1122 .gainlkup
= ai_gain_628x
,
1126 .ao_fifo_depth
= 8191,
1127 .ao_range_table
= &range_ni_M_628x_ao
,
1128 .reg_type
= ni_reg_628x
,
1131 .num_p0_dio_channels
= 32,
1132 .caldac
= {caldac_none
},
1136 .device_id
= 0x70C0,
1140 .ai_fifo_depth
= 1024,
1142 .gainlkup
= ai_gain_6143
,
1146 .reg_type
= ni_reg_6143
,
1149 .num_p0_dio_channels
= 8,
1150 .caldac
= {ad8804_debug
, ad8804_debug
},
1153 .device_id
= 0x710D,
1157 .ai_fifo_depth
= 1024,
1159 .gainlkup
= ai_gain_6143
,
1163 .reg_type
= ni_reg_6143
,
1166 .num_p0_dio_channels
= 8,
1167 .caldac
= {ad8804_debug
, ad8804_debug
},
1171 #define n_pcimio_boards ARRAY_SIZE(ni_boards)
1173 static int pcimio_attach(struct comedi_device
*dev
,
1174 struct comedi_devconfig
*it
);
1175 static int pcimio_detach(struct comedi_device
*dev
);
1176 static struct comedi_driver driver_pcimio
= {
1177 .driver_name
= DRV_NAME
,
1178 .module
= THIS_MODULE
,
1179 .attach
= pcimio_attach
,
1180 .detach
= pcimio_detach
,
1183 static int __devinit
driver_pcimio_pci_probe(struct pci_dev
*dev
,
1184 const struct pci_device_id
*ent
)
1186 return comedi_pci_auto_config(dev
, driver_pcimio
.driver_name
);
1189 static void __devexit
driver_pcimio_pci_remove(struct pci_dev
*dev
)
1191 comedi_pci_auto_unconfig(dev
);
1194 static struct pci_driver driver_pcimio_pci_driver
= {
1195 .id_table
= ni_pci_table
,
1196 .probe
= &driver_pcimio_pci_probe
,
1197 .remove
= __devexit_p(&driver_pcimio_pci_remove
)
1200 static int __init
driver_pcimio_init_module(void)
1204 retval
= comedi_driver_register(&driver_pcimio
);
1208 driver_pcimio_pci_driver
.name
= (char *)driver_pcimio
.driver_name
;
1209 return pci_register_driver(&driver_pcimio_pci_driver
);
1212 static void __exit
driver_pcimio_cleanup_module(void)
1214 pci_unregister_driver(&driver_pcimio_pci_driver
);
1215 comedi_driver_unregister(&driver_pcimio
);
1218 module_init(driver_pcimio_init_module
);
1219 module_exit(driver_pcimio_cleanup_module
);
1223 #define devpriv ((struct ni_private *)dev->private)
1225 /* How we access registers */
1227 #define ni_writel(a, b) (writel((a), devpriv->mite->daq_io_addr + (b)))
1228 #define ni_readl(a) (readl(devpriv->mite->daq_io_addr + (a)))
1229 #define ni_writew(a, b) (writew((a), devpriv->mite->daq_io_addr + (b)))
1230 #define ni_readw(a) (readw(devpriv->mite->daq_io_addr + (a)))
1231 #define ni_writeb(a, b) (writeb((a), devpriv->mite->daq_io_addr + (b)))
1232 #define ni_readb(a) (readb(devpriv->mite->daq_io_addr + (a)))
1234 /* How we access STC registers */
1236 /* We automatically take advantage of STC registers that can be
1237 * read/written directly in the I/O space of the board. Most
1238 * PCIMIO devices map the low 8 STC registers to iobase+addr*2.
1239 * The 611x devices map the write registers to iobase+addr*2, and
1240 * the read registers to iobase+(addr-1)*2. */
1241 /* However, the 611x boards still aren't working, so I'm disabling
1242 * non-windowed STC access temporarily */
1244 static void e_series_win_out(struct comedi_device
*dev
, uint16_t data
, int reg
)
1246 unsigned long flags
;
1248 spin_lock_irqsave(&devpriv
->window_lock
, flags
);
1249 ni_writew(reg
, Window_Address
);
1250 ni_writew(data
, Window_Data
);
1251 spin_unlock_irqrestore(&devpriv
->window_lock
, flags
);
1254 static uint16_t e_series_win_in(struct comedi_device
*dev
, int reg
)
1256 unsigned long flags
;
1259 spin_lock_irqsave(&devpriv
->window_lock
, flags
);
1260 ni_writew(reg
, Window_Address
);
1261 ret
= ni_readw(Window_Data
);
1262 spin_unlock_irqrestore(&devpriv
->window_lock
, flags
);
1267 static void m_series_stc_writew(struct comedi_device
*dev
, uint16_t data
,
1272 case ADC_FIFO_Clear
:
1273 offset
= M_Offset_AI_FIFO_Clear
;
1275 case AI_Command_1_Register
:
1276 offset
= M_Offset_AI_Command_1
;
1278 case AI_Command_2_Register
:
1279 offset
= M_Offset_AI_Command_2
;
1281 case AI_Mode_1_Register
:
1282 offset
= M_Offset_AI_Mode_1
;
1284 case AI_Mode_2_Register
:
1285 offset
= M_Offset_AI_Mode_2
;
1287 case AI_Mode_3_Register
:
1288 offset
= M_Offset_AI_Mode_3
;
1290 case AI_Output_Control_Register
:
1291 offset
= M_Offset_AI_Output_Control
;
1293 case AI_Personal_Register
:
1294 offset
= M_Offset_AI_Personal
;
1296 case AI_SI2_Load_A_Register
:
1297 /* this is actually a 32 bit register on m series boards */
1298 ni_writel(data
, M_Offset_AI_SI2_Load_A
);
1301 case AI_SI2_Load_B_Register
:
1302 /* this is actually a 32 bit register on m series boards */
1303 ni_writel(data
, M_Offset_AI_SI2_Load_B
);
1306 case AI_START_STOP_Select_Register
:
1307 offset
= M_Offset_AI_START_STOP_Select
;
1309 case AI_Trigger_Select_Register
:
1310 offset
= M_Offset_AI_Trigger_Select
;
1312 case Analog_Trigger_Etc_Register
:
1313 offset
= M_Offset_Analog_Trigger_Etc
;
1315 case AO_Command_1_Register
:
1316 offset
= M_Offset_AO_Command_1
;
1318 case AO_Command_2_Register
:
1319 offset
= M_Offset_AO_Command_2
;
1321 case AO_Mode_1_Register
:
1322 offset
= M_Offset_AO_Mode_1
;
1324 case AO_Mode_2_Register
:
1325 offset
= M_Offset_AO_Mode_2
;
1327 case AO_Mode_3_Register
:
1328 offset
= M_Offset_AO_Mode_3
;
1330 case AO_Output_Control_Register
:
1331 offset
= M_Offset_AO_Output_Control
;
1333 case AO_Personal_Register
:
1334 offset
= M_Offset_AO_Personal
;
1336 case AO_Start_Select_Register
:
1337 offset
= M_Offset_AO_Start_Select
;
1339 case AO_Trigger_Select_Register
:
1340 offset
= M_Offset_AO_Trigger_Select
;
1342 case Clock_and_FOUT_Register
:
1343 offset
= M_Offset_Clock_and_FOUT
;
1345 case Configuration_Memory_Clear
:
1346 offset
= M_Offset_Configuration_Memory_Clear
;
1348 case DAC_FIFO_Clear
:
1349 offset
= M_Offset_AO_FIFO_Clear
;
1351 case DIO_Control_Register
:
1353 ("%s: FIXME: register 0x%x does not map cleanly on to m-series boards.\n",
1357 case G_Autoincrement_Register(0):
1358 offset
= M_Offset_G0_Autoincrement
;
1360 case G_Autoincrement_Register(1):
1361 offset
= M_Offset_G1_Autoincrement
;
1363 case G_Command_Register(0):
1364 offset
= M_Offset_G0_Command
;
1366 case G_Command_Register(1):
1367 offset
= M_Offset_G1_Command
;
1369 case G_Input_Select_Register(0):
1370 offset
= M_Offset_G0_Input_Select
;
1372 case G_Input_Select_Register(1):
1373 offset
= M_Offset_G1_Input_Select
;
1375 case G_Mode_Register(0):
1376 offset
= M_Offset_G0_Mode
;
1378 case G_Mode_Register(1):
1379 offset
= M_Offset_G1_Mode
;
1381 case Interrupt_A_Ack_Register
:
1382 offset
= M_Offset_Interrupt_A_Ack
;
1384 case Interrupt_A_Enable_Register
:
1385 offset
= M_Offset_Interrupt_A_Enable
;
1387 case Interrupt_B_Ack_Register
:
1388 offset
= M_Offset_Interrupt_B_Ack
;
1390 case Interrupt_B_Enable_Register
:
1391 offset
= M_Offset_Interrupt_B_Enable
;
1393 case Interrupt_Control_Register
:
1394 offset
= M_Offset_Interrupt_Control
;
1396 case IO_Bidirection_Pin_Register
:
1397 offset
= M_Offset_IO_Bidirection_Pin
;
1399 case Joint_Reset_Register
:
1400 offset
= M_Offset_Joint_Reset
;
1402 case RTSI_Trig_A_Output_Register
:
1403 offset
= M_Offset_RTSI_Trig_A_Output
;
1405 case RTSI_Trig_B_Output_Register
:
1406 offset
= M_Offset_RTSI_Trig_B_Output
;
1408 case RTSI_Trig_Direction_Register
:
1409 offset
= M_Offset_RTSI_Trig_Direction
;
1412 printk("%s: bug! unhandled register=0x%x in switch.\n",
1418 ni_writew(data
, offset
);
1421 static uint16_t m_series_stc_readw(struct comedi_device
*dev
, int reg
)
1425 case AI_Status_1_Register
:
1426 offset
= M_Offset_AI_Status_1
;
1428 case AO_Status_1_Register
:
1429 offset
= M_Offset_AO_Status_1
;
1431 case AO_Status_2_Register
:
1432 offset
= M_Offset_AO_Status_2
;
1434 case DIO_Serial_Input_Register
:
1435 return ni_readb(M_Offset_SCXI_Serial_Data_In
);
1437 case Joint_Status_1_Register
:
1438 offset
= M_Offset_Joint_Status_1
;
1440 case Joint_Status_2_Register
:
1441 offset
= M_Offset_Joint_Status_2
;
1443 case G_Status_Register
:
1444 offset
= M_Offset_G01_Status
;
1447 printk("%s: bug! unhandled register=0x%x in switch.\n",
1453 return ni_readw(offset
);
1456 static void m_series_stc_writel(struct comedi_device
*dev
, uint32_t data
,
1461 case AI_SC_Load_A_Registers
:
1462 offset
= M_Offset_AI_SC_Load_A
;
1464 case AI_SI_Load_A_Registers
:
1465 offset
= M_Offset_AI_SI_Load_A
;
1467 case AO_BC_Load_A_Register
:
1468 offset
= M_Offset_AO_BC_Load_A
;
1470 case AO_UC_Load_A_Register
:
1471 offset
= M_Offset_AO_UC_Load_A
;
1473 case AO_UI_Load_A_Register
:
1474 offset
= M_Offset_AO_UI_Load_A
;
1476 case G_Load_A_Register(0):
1477 offset
= M_Offset_G0_Load_A
;
1479 case G_Load_A_Register(1):
1480 offset
= M_Offset_G1_Load_A
;
1482 case G_Load_B_Register(0):
1483 offset
= M_Offset_G0_Load_B
;
1485 case G_Load_B_Register(1):
1486 offset
= M_Offset_G1_Load_B
;
1489 printk("%s: bug! unhandled register=0x%x in switch.\n",
1495 ni_writel(data
, offset
);
1498 static uint32_t m_series_stc_readl(struct comedi_device
*dev
, int reg
)
1502 case G_HW_Save_Register(0):
1503 offset
= M_Offset_G0_HW_Save
;
1505 case G_HW_Save_Register(1):
1506 offset
= M_Offset_G1_HW_Save
;
1508 case G_Save_Register(0):
1509 offset
= M_Offset_G0_Save
;
1511 case G_Save_Register(1):
1512 offset
= M_Offset_G1_Save
;
1515 printk("%s: bug! unhandled register=0x%x in switch.\n",
1521 return ni_readl(offset
);
1524 #define interrupt_pin(a) 0
1525 #define IRQ_POLARITY 1
1527 #define NI_E_IRQ_FLAGS IRQF_SHARED
1529 #include "ni_mio_common.c"
1531 static int pcimio_find_device(struct comedi_device
*dev
, int bus
, int slot
);
1532 static int pcimio_ai_change(struct comedi_device
*dev
,
1533 struct comedi_subdevice
*s
, unsigned long new_size
);
1534 static int pcimio_ao_change(struct comedi_device
*dev
,
1535 struct comedi_subdevice
*s
, unsigned long new_size
);
1536 static int pcimio_gpct0_change(struct comedi_device
*dev
,
1537 struct comedi_subdevice
*s
,
1538 unsigned long new_size
);
1539 static int pcimio_gpct1_change(struct comedi_device
*dev
,
1540 struct comedi_subdevice
*s
,
1541 unsigned long new_size
);
1542 static int pcimio_dio_change(struct comedi_device
*dev
,
1543 struct comedi_subdevice
*s
,
1544 unsigned long new_size
);
1546 static void m_series_init_eeprom_buffer(struct comedi_device
*dev
)
1548 static const int Start_Cal_EEPROM
= 0x400;
1549 static const unsigned window_size
= 10;
1550 static const int serial_number_eeprom_offset
= 0x4;
1551 static const int serial_number_eeprom_length
= 0x4;
1552 unsigned old_iodwbsr_bits
;
1553 unsigned old_iodwbsr1_bits
;
1554 unsigned old_iodwcr1_bits
;
1557 old_iodwbsr_bits
= readl(devpriv
->mite
->mite_io_addr
+ MITE_IODWBSR
);
1558 old_iodwbsr1_bits
= readl(devpriv
->mite
->mite_io_addr
+ MITE_IODWBSR_1
);
1559 old_iodwcr1_bits
= readl(devpriv
->mite
->mite_io_addr
+ MITE_IODWCR_1
);
1560 writel(0x0, devpriv
->mite
->mite_io_addr
+ MITE_IODWBSR
);
1561 writel(((0x80 | window_size
) | devpriv
->mite
->daq_phys_addr
),
1562 devpriv
->mite
->mite_io_addr
+ MITE_IODWBSR_1
);
1563 writel(0x1 | old_iodwcr1_bits
,
1564 devpriv
->mite
->mite_io_addr
+ MITE_IODWCR_1
);
1565 writel(0xf, devpriv
->mite
->mite_io_addr
+ 0x30);
1567 BUG_ON(serial_number_eeprom_length
> sizeof(devpriv
->serial_number
));
1568 for (i
= 0; i
< serial_number_eeprom_length
; ++i
) {
1569 char *byte_ptr
= (char *)&devpriv
->serial_number
+ i
;
1570 *byte_ptr
= ni_readb(serial_number_eeprom_offset
+ i
);
1572 devpriv
->serial_number
= be32_to_cpu(devpriv
->serial_number
);
1574 for (i
= 0; i
< M_SERIES_EEPROM_SIZE
; ++i
) {
1575 devpriv
->eeprom_buffer
[i
] = ni_readb(Start_Cal_EEPROM
+ i
);
1578 writel(old_iodwbsr1_bits
, devpriv
->mite
->mite_io_addr
+ MITE_IODWBSR_1
);
1579 writel(old_iodwbsr_bits
, devpriv
->mite
->mite_io_addr
+ MITE_IODWBSR
);
1580 writel(old_iodwcr1_bits
, devpriv
->mite
->mite_io_addr
+ MITE_IODWCR_1
);
1581 writel(0x0, devpriv
->mite
->mite_io_addr
+ 0x30);
1584 static void init_6143(struct comedi_device
*dev
)
1586 /* Disable interrupts */
1587 devpriv
->stc_writew(dev
, 0, Interrupt_Control_Register
);
1589 /* Initialise 6143 AI specific bits */
1590 ni_writeb(0x00, Magic_6143
); /* Set G0,G1 DMA mode to E series version */
1591 ni_writeb(0x80, PipelineDelay_6143
); /* Set EOCMode, ADCMode and pipelinedelay */
1592 ni_writeb(0x00, EOC_Set_6143
); /* Set EOC Delay */
1594 ni_writel(boardtype
.ai_fifo_depth
/ 2, AIFIFO_Flag_6143
); /* Set the FIFO half full level */
1596 /* Strobe Relay disable bit */
1597 devpriv
->ai_calib_source_enabled
= 0;
1598 ni_writew(devpriv
->ai_calib_source
| Calibration_Channel_6143_RelayOff
,
1599 Calibration_Channel_6143
);
1600 ni_writew(devpriv
->ai_calib_source
, Calibration_Channel_6143
);
1603 /* cleans up allocated resources */
1604 static int pcimio_detach(struct comedi_device
*dev
)
1606 mio_common_detach(dev
);
1608 free_irq(dev
->irq
, dev
);
1611 mite_free_ring(devpriv
->ai_mite_ring
);
1612 mite_free_ring(devpriv
->ao_mite_ring
);
1613 mite_free_ring(devpriv
->cdo_mite_ring
);
1614 mite_free_ring(devpriv
->gpct_mite_ring
[0]);
1615 mite_free_ring(devpriv
->gpct_mite_ring
[1]);
1617 mite_unsetup(devpriv
->mite
);
1623 static int pcimio_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
1627 printk("comedi%d: ni_pcimio:", dev
->minor
);
1629 ret
= ni_alloc_private(dev
);
1633 ret
= pcimio_find_device(dev
, it
->options
[0], it
->options
[1]);
1637 printk(" %s", boardtype
.name
);
1638 dev
->board_name
= boardtype
.name
;
1640 if (boardtype
.reg_type
& ni_reg_m_series_mask
) {
1641 devpriv
->stc_writew
= &m_series_stc_writew
;
1642 devpriv
->stc_readw
= &m_series_stc_readw
;
1643 devpriv
->stc_writel
= &m_series_stc_writel
;
1644 devpriv
->stc_readl
= &m_series_stc_readl
;
1646 devpriv
->stc_writew
= &e_series_win_out
;
1647 devpriv
->stc_readw
= &e_series_win_in
;
1648 devpriv
->stc_writel
= &win_out2
;
1649 devpriv
->stc_readl
= &win_in2
;
1652 ret
= mite_setup(devpriv
->mite
);
1654 printk(" error setting up mite\n");
1657 comedi_set_hw_dev(dev
, &devpriv
->mite
->pcidev
->dev
);
1658 devpriv
->ai_mite_ring
= mite_alloc_ring(devpriv
->mite
);
1659 if (devpriv
->ai_mite_ring
== NULL
)
1661 devpriv
->ao_mite_ring
= mite_alloc_ring(devpriv
->mite
);
1662 if (devpriv
->ao_mite_ring
== NULL
)
1664 devpriv
->cdo_mite_ring
= mite_alloc_ring(devpriv
->mite
);
1665 if (devpriv
->cdo_mite_ring
== NULL
)
1667 devpriv
->gpct_mite_ring
[0] = mite_alloc_ring(devpriv
->mite
);
1668 if (devpriv
->gpct_mite_ring
[0] == NULL
)
1670 devpriv
->gpct_mite_ring
[1] = mite_alloc_ring(devpriv
->mite
);
1671 if (devpriv
->gpct_mite_ring
[1] == NULL
)
1674 if (boardtype
.reg_type
& ni_reg_m_series_mask
)
1675 m_series_init_eeprom_buffer(dev
);
1676 if (boardtype
.reg_type
== ni_reg_6143
)
1679 dev
->irq
= mite_irq(devpriv
->mite
);
1681 if (dev
->irq
== 0) {
1682 printk(" unknown irq (bad)\n");
1684 printk(" ( irq = %u )", dev
->irq
);
1685 ret
= request_irq(dev
->irq
, ni_E_interrupt
, NI_E_IRQ_FLAGS
,
1688 printk(" irq not available\n");
1693 ret
= ni_E_init(dev
, it
);
1697 dev
->subdevices
[NI_AI_SUBDEV
].buf_change
= &pcimio_ai_change
;
1698 dev
->subdevices
[NI_AO_SUBDEV
].buf_change
= &pcimio_ao_change
;
1699 dev
->subdevices
[NI_GPCT_SUBDEV(0)].buf_change
= &pcimio_gpct0_change
;
1700 dev
->subdevices
[NI_GPCT_SUBDEV(1)].buf_change
= &pcimio_gpct1_change
;
1701 dev
->subdevices
[NI_DIO_SUBDEV
].buf_change
= &pcimio_dio_change
;
1706 static int pcimio_find_device(struct comedi_device
*dev
, int bus
, int slot
)
1708 struct mite_struct
*mite
;
1711 for (mite
= mite_devices
; mite
; mite
= mite
->next
) {
1715 if (bus
!= mite
->pcidev
->bus
->number
||
1716 slot
!= PCI_SLOT(mite
->pcidev
->devfn
))
1720 for (i
= 0; i
< n_pcimio_boards
; i
++) {
1721 if (mite_device_id(mite
) == ni_boards
[i
].device_id
) {
1722 dev
->board_ptr
= ni_boards
+ i
;
1723 devpriv
->mite
= mite
;
1729 printk("no device found\n");
1730 mite_list_devices();
1734 static int pcimio_ai_change(struct comedi_device
*dev
,
1735 struct comedi_subdevice
*s
, unsigned long new_size
)
1739 ret
= mite_buf_change(devpriv
->ai_mite_ring
, s
->async
);
1746 static int pcimio_ao_change(struct comedi_device
*dev
,
1747 struct comedi_subdevice
*s
, unsigned long new_size
)
1751 ret
= mite_buf_change(devpriv
->ao_mite_ring
, s
->async
);
1758 static int pcimio_gpct0_change(struct comedi_device
*dev
,
1759 struct comedi_subdevice
*s
,
1760 unsigned long new_size
)
1764 ret
= mite_buf_change(devpriv
->gpct_mite_ring
[0], s
->async
);
1771 static int pcimio_gpct1_change(struct comedi_device
*dev
,
1772 struct comedi_subdevice
*s
,
1773 unsigned long new_size
)
1777 ret
= mite_buf_change(devpriv
->gpct_mite_ring
[1], s
->async
);
1784 static int pcimio_dio_change(struct comedi_device
*dev
,
1785 struct comedi_subdevice
*s
, unsigned long new_size
)
1789 ret
= mite_buf_change(devpriv
->cdo_mite_ring
, s
->async
);