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,
33 PCI-6225, PXI-6225, PCI-6229, PCI-6250, PCI-6251, PCIe-6251, PXIe-6251,
34 PCI-6254, PCI-6259, PCIe-6259,
35 PCI-6280, PCI-6281, PXI-6281, PCI-6284, PCI-6289,
36 PCI-6711, PXI-6711, PCI-6713, PXI-6713,
37 PXI-6071E, PCI-6070E, PXI-6070E,
38 PXI-6052E, PCI-6036E, PCI-6731, PCI-6733, PXI-6733,
40 Updated: Mon, 09 Jan 2012 14:52:48 +0000
42 These boards are almost identical to the AT-MIO E series, except that
43 they use the PCI bus instead of ISA (i.e., AT). See the notes for
44 the ni_atmio.o driver for additional information about these boards.
46 Autocalibration is supported on many of the devices, using the
47 comedi_calibrate (or comedi_soft_calibrate for m-series) utility.
48 M-Series boards do analog input and analog output calibration entirely
49 in software. The software calibration corrects
50 the analog input for offset, gain and
51 nonlinearity. The analog outputs are corrected for offset and gain.
52 See the comedilib documentation on comedi_get_softcal_converter() for
55 By default, the driver uses DMA to transfer analog input data to
56 memory. When DMA is enabled, not all triggering features are
59 Digital I/O may not work on 673x.
61 Note that the PCI-6143 is a simultaineous sampling device with 8 convertors.
62 With this board all of the convertors perform one simultaineous sample during
63 a scan interval. The period for a scan is used for the convert time in a
64 Comedi cmd. The convert trigger source is normally set to TRIG_NOW by default.
66 The RTSI trigger bus is supported on these cards on
67 subdevice 10. See the comedilib documentation for details.
69 Information (number of channels, bits, etc.) for some devices may be
70 incorrect. Please check this and submit a bug if there are problems
73 SCXI is probably broken for m-series boards.
76 - When DMA is enabled, COMEDI_EV_CONVERT does
81 The PCI-MIO E series driver was originally written by
82 Tomasz Motylewski <...>, and ported to comedi by ds.
86 341079b.pdf PCI E Series Register-Level Programmer Manual
87 340934b.pdf DAQ-STC reference manual
89 322080b.pdf 6711/6713/6715 User Manual
91 320945c.pdf PCI E Series User Manual
92 322138a.pdf PCI-6052E and DAQPad-6052E User Manual
96 need to deal with external reference for DAC, and other DAC
97 properties in board properties
99 deal with at-mio-16de-10 revision D to N changes, etc.
101 need to add other CALDAC type
103 need to slow down DAC loading. I don't trust NI's claim that
104 two writes to the PCI bus slows IO enough. I would prefer to
105 use udelay(). Timing specs: (clock)
113 #include <linux/delay.h>
114 #include <linux/delay.h>
116 #include "../comedidev.h"
118 #include <asm/byteorder.h>
123 /* #define PCI_DEBUG */
130 #define MAX_N_CALDACS (16+16+2)
132 #define DRV_NAME "ni_pcimio"
134 /* These are not all the possible ao ranges for 628x boards.
135 They can do OFFSET +- REFERENCE where OFFSET can be
136 0V, 5V, APFI<0,1>, or AO<0...3> and RANGE can
137 be 10V, 5V, 2V, 1V, APFI<0,1>, AO<0...3>. That's
138 63 different possibilities. An AO channel
139 can not act as it's own OFFSET or REFERENCE.
141 static const struct comedi_lrange range_ni_M_628x_ao = { 8, {
154 static const struct comedi_lrange range_ni_M_625x_ao = { 3, {
161 static const struct comedi_lrange range_ni_M_622x_ao = { 1, {
166 static const struct ni_board_struct ni_boards[] = {
168 .device_id = 0x0162, /* NI also says 0x1620. typo? */
169 .name = "pci-mio-16xe-50",
172 .ai_fifo_depth = 2048,
174 .gainlkup = ai_gain_8,
179 .ao_range_table = &range_bipolar10,
182 .num_p0_dio_channels = 8,
183 .caldac = {dac8800, dac8043},
188 .name = "pci-mio-16xe-10", /* aka pci-6030E */
191 .ai_fifo_depth = 512,
193 .gainlkup = ai_gain_14,
197 .ao_fifo_depth = 2048,
198 .ao_range_table = &range_ni_E_ao_ext,
201 .num_p0_dio_channels = 8,
202 .caldac = {dac8800, dac8043, ad8522},
210 .ai_fifo_depth = 512,
212 .gainlkup = ai_gain_4,
217 .ao_range_table = &range_bipolar10,
220 .num_p0_dio_channels = 8,
221 .caldac = {ad8804_debug},
229 .ai_fifo_depth = 512,
231 .gainlkup = ai_gain_14,
235 .ao_fifo_depth = 2048,
236 .ao_range_table = &range_ni_E_ao_ext,
239 .num_p0_dio_channels = 8,
240 .caldac = {dac8800, dac8043, ad8522},
245 .name = "pci-mio-16e-1", /* aka pci-6070e */
248 .ai_fifo_depth = 512,
250 .gainlkup = ai_gain_16,
254 .ao_fifo_depth = 2048,
255 .ao_range_table = &range_ni_E_ao_ext,
258 .num_p0_dio_channels = 8,
264 .name = "pci-mio-16e-4", /* aka pci-6040e */
267 .ai_fifo_depth = 512,
269 .gainlkup = ai_gain_16,
270 /* .Note = there have been reported problems with full speed
275 .ao_fifo_depth = 512,
276 .ao_range_table = &range_ni_E_ao_ext,
279 .num_p0_dio_channels = 8,
280 .caldac = {ad8804_debug}, /* doc says mb88341 */
288 .ai_fifo_depth = 512,
290 .gainlkup = ai_gain_16,
294 .ao_fifo_depth = 512,
295 .ao_range_table = &range_ni_E_ao_ext,
298 .num_p0_dio_channels = 8,
308 .ai_fifo_depth = 512,
310 .gainlkup = ai_gain_14,
314 .ao_fifo_depth = 2048,
315 .ao_range_table = &range_ni_E_ao_ext,
318 .num_p0_dio_channels = 8,
319 .caldac = {dac8800, dac8043, ad8522},
327 .ai_fifo_depth = 512,
329 .gainlkup = ai_gain_14,
335 .num_p0_dio_channels = 8,
336 .caldac = {dac8800, dac8043, ad8522},
344 .ai_fifo_depth = 512,
346 .gainlkup = ai_gain_14,
352 .num_p0_dio_channels = 8,
353 .caldac = {dac8800, dac8043, ad8522},
361 .ai_fifo_depth = 512,
363 .gainlkup = ai_gain_16,
367 .ao_fifo_depth = 2048,
368 .ao_range_table = &range_ni_E_ao_ext,
371 .num_p0_dio_channels = 8,
372 .caldac = {ad8804_debug},
380 .ai_fifo_depth = 512,
382 .gainlkup = ai_gain_4,
387 .num_p0_dio_channels = 8,
388 .caldac = {ad8804_debug}, /* manual is wrong */
396 .ai_fifo_depth = 512,
398 .gainlkup = ai_gain_4,
403 .ao_range_table = &range_bipolar10,
406 .num_p0_dio_channels = 8,
407 .caldac = {ad8804_debug}, /* manual is wrong */
415 .ai_fifo_depth = 512,
417 .gainlkup = ai_gain_4,
422 .ao_range_table = &range_bipolar10,
425 .num_p0_dio_channels = 8,
426 .caldac = {ad8804_debug}, /* manual is wrong */
434 .ai_fifo_depth = 512,
436 .gainlkup = ai_gain_4,
441 .ao_range_table = &range_ni_E_ao_ext,
444 .num_p0_dio_channels = 8,
445 .caldac = {ad8804_debug}, /* manual is wrong */
454 .ai_fifo_depth = 512,
456 .gainlkup = ai_gain_4,
462 .num_p0_dio_channels = 8,
463 .caldac = {ad8804_debug},
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},
490 .ai_fifo_depth = 512,
492 .gainlkup = ai_gain_16,
497 .ao_fifo_depth = 2048,
498 .ao_range_table = &range_ni_E_ao_ext,
500 .num_p0_dio_channels = 8,
501 .caldac = {ad8804_debug, ad8804_debug, ad8522}, /* manual is wrong */
503 {.device_id = 0x14e0,
507 .ai_fifo_depth = 8192,
509 .gainlkup = ai_gain_611x,
513 .reg_type = ni_reg_611x,
514 .ao_range_table = &range_bipolar10,
516 .ao_fifo_depth = 2048,
518 .num_p0_dio_channels = 8,
519 .caldac = {ad8804, ad8804},
526 .ai_fifo_depth = 8192,
528 .gainlkup = ai_gain_611x,
532 .reg_type = ni_reg_611x,
533 .ao_range_table = &range_bipolar10,
535 .ao_fifo_depth = 2048,
537 .num_p0_dio_channels = 8,
538 .caldac = {ad8804, ad8804},
541 /* The 6115 boards probably need their own driver */
547 .ai_fifo_depth = 8192,
549 .gainlkup = ai_gain_611x,
555 .ao_fifo_depth = 2048,
557 .num_p0_dio_channels = 8,
559 .caldac = {ad8804_debug, ad8804_debug, ad8804_debug}, /* XXX */
568 .ai_fifo_depth = 8192,
570 .gainlkup = ai_gain_611x,
576 .ao_fifo_depth = 2048,
579 .num_p0_dio_channels = 8,
580 caldac = {ad8804_debug, ad8804_debug, ad8804_debug}, /* XXX */
586 .n_adchan = 0, /* no analog input */
590 .ao_fifo_depth = 16384,
591 /* data sheet says 8192, but fifo really holds 16384 samples */
592 .ao_range_table = &range_bipolar10,
594 .num_p0_dio_channels = 8,
595 .reg_type = ni_reg_6711,
596 .caldac = {ad8804_debug},
601 .n_adchan = 0, /* no analog input */
605 .ao_fifo_depth = 16384,
606 .ao_range_table = &range_bipolar10,
608 .num_p0_dio_channels = 8,
609 .reg_type = ni_reg_6711,
610 .caldac = {ad8804_debug},
615 .n_adchan = 0, /* no analog input */
619 .ao_fifo_depth = 16384,
620 .ao_range_table = &range_bipolar10,
622 .num_p0_dio_channels = 8,
623 .reg_type = ni_reg_6713,
624 .caldac = {ad8804_debug, ad8804_debug},
629 .n_adchan = 0, /* no analog input */
633 .ao_fifo_depth = 16384,
634 .ao_range_table = &range_bipolar10,
636 .num_p0_dio_channels = 8,
637 .reg_type = ni_reg_6713,
638 .caldac = {ad8804_debug, ad8804_debug},
643 .n_adchan = 0, /* no analog input */
647 .ao_fifo_depth = 8192,
648 .ao_range_table = &range_bipolar10,
650 .num_p0_dio_channels = 8,
651 .reg_type = ni_reg_6711,
652 .caldac = {ad8804_debug},
654 #if 0 /* need device ids */
658 .n_adchan = 0, /* no analog input */
662 .ao_fifo_depth = 8192,
663 .ao_range_table = &range_bipolar10,
664 .num_p0_dio_channels = 8,
665 .reg_type = ni_reg_6711,
666 .caldac = {ad8804_debug},
672 .n_adchan = 0, /* no analog input */
676 .ao_fifo_depth = 16384,
677 .ao_range_table = &range_bipolar10,
679 .num_p0_dio_channels = 8,
680 .reg_type = ni_reg_6713,
681 .caldac = {ad8804_debug, ad8804_debug},
686 .n_adchan = 0, /* no analog input */
690 .ao_fifo_depth = 16384,
691 .ao_range_table = &range_bipolar10,
693 .num_p0_dio_channels = 8,
694 .reg_type = ni_reg_6713,
695 .caldac = {ad8804_debug, ad8804_debug},
702 .ai_fifo_depth = 512,
704 .gainlkup = ai_gain_16,
708 .ao_fifo_depth = 2048,
709 .ao_range_table = &range_ni_E_ao_ext,
712 .num_p0_dio_channels = 8,
713 .caldac = {ad8804_debug},
721 .ai_fifo_depth = 512,
723 .gainlkup = ai_gain_16,
727 .ao_fifo_depth = 2048,
728 .ao_range_table = &range_ni_E_ao_ext,
731 .num_p0_dio_channels = 8,
732 .caldac = {ad8804_debug},
740 .ai_fifo_depth = 512,
742 .gainlkup = ai_gain_16,
747 .ao_fifo_depth = 2048,
748 .ao_range_table = &range_ni_E_ao_ext,
750 .num_p0_dio_channels = 8,
751 .caldac = {mb88341, mb88341, ad8522},
758 .ai_fifo_depth = 512,
760 .gainlkup = ai_gain_14,
764 .ao_fifo_depth = 2048,
765 .ao_range_table = &range_ni_E_ao_ext,
768 .num_p0_dio_channels = 8,
769 .caldac = {dac8800, dac8043, ad8522},
776 .ai_fifo_depth = 512,
778 .gainlkup = ai_gain_4,
783 .ao_range_table = &range_bipolar10,
786 .num_p0_dio_channels = 8,
787 .caldac = {ad8804_debug},
795 .ai_fifo_depth = 512,
797 .gainlkup = ai_gain_622x,
802 .num_p0_dio_channels = 8,
803 .reg_type = ni_reg_622x,
805 .caldac = {caldac_none},
813 .ai_fifo_depth = 4095,
814 .gainlkup = ai_gain_622x,
818 .ao_fifo_depth = 8191,
819 .ao_range_table = &range_ni_M_622x_ao,
820 .reg_type = ni_reg_622x,
823 .num_p0_dio_channels = 8,
824 .caldac = {caldac_none},
829 .name = "pci-6221_37pin",
832 .ai_fifo_depth = 4095,
833 .gainlkup = ai_gain_622x,
837 .ao_fifo_depth = 8191,
838 .ao_range_table = &range_ni_M_622x_ao,
839 .reg_type = ni_reg_622x,
842 .num_p0_dio_channels = 8,
843 .caldac = {caldac_none},
851 .ai_fifo_depth = 4095,
852 .gainlkup = ai_gain_622x,
857 .reg_type = ni_reg_622x,
859 .num_p0_dio_channels = 32,
860 .caldac = {caldac_none},
868 .ai_fifo_depth = 4095,
869 .gainlkup = ai_gain_622x,
874 .reg_type = ni_reg_622x,
876 .num_p0_dio_channels = 32,
877 .caldac = {caldac_none},
885 .ai_fifo_depth = 4095,
886 .gainlkup = ai_gain_622x,
890 .ao_fifo_depth = 8191,
891 .ao_range_table = &range_ni_M_622x_ao,
892 .reg_type = ni_reg_622x,
895 .num_p0_dio_channels = 32,
896 .caldac = {caldac_none},
904 .ai_fifo_depth = 4095,
905 .gainlkup = ai_gain_622x,
909 .ao_fifo_depth = 8191,
910 .ao_range_table = &range_ni_M_622x_ao,
911 .reg_type = ni_reg_622x,
914 .num_p0_dio_channels = 32,
915 .caldac = {caldac_none},
923 .ai_fifo_depth = 4095,
924 .gainlkup = ai_gain_622x,
928 .ao_fifo_depth = 8191,
929 .ao_range_table = &range_ni_M_622x_ao,
930 .reg_type = ni_reg_622x,
933 .num_p0_dio_channels = 32,
934 .caldac = {caldac_none},
942 .ai_fifo_depth = 4095,
943 .gainlkup = ai_gain_628x,
948 .reg_type = ni_reg_625x,
950 .num_p0_dio_channels = 8,
951 .caldac = {caldac_none},
959 .ai_fifo_depth = 4095,
960 .gainlkup = ai_gain_628x,
964 .ao_fifo_depth = 8191,
965 .ao_range_table = &range_ni_M_625x_ao,
966 .reg_type = ni_reg_625x,
969 .num_p0_dio_channels = 8,
970 .caldac = {caldac_none},
978 .ai_fifo_depth = 4095,
979 .gainlkup = ai_gain_628x,
983 .ao_fifo_depth = 8191,
984 .ao_range_table = &range_ni_M_625x_ao,
985 .reg_type = ni_reg_625x,
988 .num_p0_dio_channels = 8,
989 .caldac = {caldac_none},
997 .ai_fifo_depth = 4095,
998 .gainlkup = ai_gain_628x,
1002 .ao_fifo_depth = 8191,
1003 .ao_range_table = &range_ni_M_625x_ao,
1004 .reg_type = ni_reg_625x,
1007 .num_p0_dio_channels = 8,
1008 .caldac = {caldac_none},
1012 .device_id = 0x70b7,
1016 .ai_fifo_depth = 4095,
1017 .gainlkup = ai_gain_628x,
1022 .reg_type = ni_reg_625x,
1024 .num_p0_dio_channels = 32,
1025 .caldac = {caldac_none},
1029 .device_id = 0x70ab,
1033 .ai_fifo_depth = 4095,
1034 .gainlkup = ai_gain_628x,
1038 .ao_fifo_depth = 8191,
1039 .ao_range_table = &range_ni_M_625x_ao,
1040 .reg_type = ni_reg_625x,
1043 .num_p0_dio_channels = 32,
1044 .caldac = {caldac_none},
1048 .device_id = 0x717f,
1049 .name = "pcie-6259",
1052 .ai_fifo_depth = 4095,
1053 .gainlkup = ai_gain_628x,
1057 .ao_fifo_depth = 8191,
1058 .ao_range_table = &range_ni_M_625x_ao,
1059 .reg_type = ni_reg_625x,
1062 .num_p0_dio_channels = 32,
1063 .caldac = {caldac_none},
1067 .device_id = 0x70b6,
1071 .ai_fifo_depth = 2047,
1072 .gainlkup = ai_gain_628x,
1076 .ao_fifo_depth = 8191,
1077 .reg_type = ni_reg_628x,
1079 .num_p0_dio_channels = 8,
1080 .caldac = {caldac_none},
1084 .device_id = 0x70bd,
1088 .ai_fifo_depth = 2047,
1089 .gainlkup = ai_gain_628x,
1093 .ao_fifo_depth = 8191,
1094 .ao_range_table = &range_ni_M_628x_ao,
1095 .reg_type = ni_reg_628x,
1098 .num_p0_dio_channels = 8,
1099 .caldac = {caldac_none},
1103 .device_id = 0x70bf,
1107 .ai_fifo_depth = 2047,
1108 .gainlkup = ai_gain_628x,
1112 .ao_fifo_depth = 8191,
1113 .ao_range_table = &range_ni_M_628x_ao,
1114 .reg_type = ni_reg_628x,
1117 .num_p0_dio_channels = 8,
1118 .caldac = {caldac_none},
1122 .device_id = 0x70bc,
1126 .ai_fifo_depth = 2047,
1127 .gainlkup = ai_gain_628x,
1132 .reg_type = ni_reg_628x,
1134 .num_p0_dio_channels = 32,
1135 .caldac = {caldac_none},
1139 .device_id = 0x70ac,
1143 .ai_fifo_depth = 2047,
1144 .gainlkup = ai_gain_628x,
1148 .ao_fifo_depth = 8191,
1149 .ao_range_table = &range_ni_M_628x_ao,
1150 .reg_type = ni_reg_628x,
1153 .num_p0_dio_channels = 32,
1154 .caldac = {caldac_none},
1158 .device_id = 0x70C0,
1162 .ai_fifo_depth = 1024,
1164 .gainlkup = ai_gain_6143,
1168 .reg_type = ni_reg_6143,
1171 .num_p0_dio_channels = 8,
1172 .caldac = {ad8804_debug, ad8804_debug},
1175 .device_id = 0x710D,
1179 .ai_fifo_depth = 1024,
1181 .gainlkup = ai_gain_6143,
1185 .reg_type = ni_reg_6143,
1188 .num_p0_dio_channels = 8,
1189 .caldac = {ad8804_debug, ad8804_debug},
1196 /* How we access registers */
1198 #define ni_writel(a, b) (writel((a), devpriv->mite->daq_io_addr + (b)))
1199 #define ni_readl(a) (readl(devpriv->mite->daq_io_addr + (a)))
1200 #define ni_writew(a, b) (writew((a), devpriv->mite->daq_io_addr + (b)))
1201 #define ni_readw(a) (readw(devpriv->mite->daq_io_addr + (a)))
1202 #define ni_writeb(a, b) (writeb((a), devpriv->mite->daq_io_addr + (b)))
1203 #define ni_readb(a) (readb(devpriv->mite->daq_io_addr + (a)))
1205 /* How we access STC registers */
1207 /* We automatically take advantage of STC registers that can be
1208 * read/written directly in the I/O space of the board. Most
1209 * PCIMIO devices map the low 8 STC registers to iobase+addr*2.
1210 * The 611x devices map the write registers to iobase+addr*2, and
1211 * the read registers to iobase+(addr-1)*2. */
1212 /* However, the 611x boards still aren't working, so I'm disabling
1213 * non-windowed STC access temporarily */
1215 static void e_series_win_out(struct comedi_device *dev, uint16_t data, int reg)
1217 struct ni_private *devpriv = dev->private;
1218 unsigned long flags;
1220 spin_lock_irqsave(&devpriv->window_lock, flags);
1221 ni_writew(reg, Window_Address);
1222 ni_writew(data, Window_Data);
1223 spin_unlock_irqrestore(&devpriv->window_lock, flags);
1226 static uint16_t e_series_win_in(struct comedi_device *dev, int reg)
1228 struct ni_private *devpriv = dev->private;
1229 unsigned long flags;
1232 spin_lock_irqsave(&devpriv->window_lock, flags);
1233 ni_writew(reg, Window_Address);
1234 ret = ni_readw(Window_Data);
1235 spin_unlock_irqrestore(&devpriv->window_lock, flags);
1240 static void m_series_stc_writew(struct comedi_device *dev, uint16_t data,
1243 struct ni_private *devpriv = dev->private;
1247 case ADC_FIFO_Clear:
1248 offset = M_Offset_AI_FIFO_Clear;
1250 case AI_Command_1_Register:
1251 offset = M_Offset_AI_Command_1;
1253 case AI_Command_2_Register:
1254 offset = M_Offset_AI_Command_2;
1256 case AI_Mode_1_Register:
1257 offset = M_Offset_AI_Mode_1;
1259 case AI_Mode_2_Register:
1260 offset = M_Offset_AI_Mode_2;
1262 case AI_Mode_3_Register:
1263 offset = M_Offset_AI_Mode_3;
1265 case AI_Output_Control_Register:
1266 offset = M_Offset_AI_Output_Control;
1268 case AI_Personal_Register:
1269 offset = M_Offset_AI_Personal;
1271 case AI_SI2_Load_A_Register:
1272 /* this is actually a 32 bit register on m series boards */
1273 ni_writel(data, M_Offset_AI_SI2_Load_A);
1276 case AI_SI2_Load_B_Register:
1277 /* this is actually a 32 bit register on m series boards */
1278 ni_writel(data, M_Offset_AI_SI2_Load_B);
1281 case AI_START_STOP_Select_Register:
1282 offset = M_Offset_AI_START_STOP_Select;
1284 case AI_Trigger_Select_Register:
1285 offset = M_Offset_AI_Trigger_Select;
1287 case Analog_Trigger_Etc_Register:
1288 offset = M_Offset_Analog_Trigger_Etc;
1290 case AO_Command_1_Register:
1291 offset = M_Offset_AO_Command_1;
1293 case AO_Command_2_Register:
1294 offset = M_Offset_AO_Command_2;
1296 case AO_Mode_1_Register:
1297 offset = M_Offset_AO_Mode_1;
1299 case AO_Mode_2_Register:
1300 offset = M_Offset_AO_Mode_2;
1302 case AO_Mode_3_Register:
1303 offset = M_Offset_AO_Mode_3;
1305 case AO_Output_Control_Register:
1306 offset = M_Offset_AO_Output_Control;
1308 case AO_Personal_Register:
1309 offset = M_Offset_AO_Personal;
1311 case AO_Start_Select_Register:
1312 offset = M_Offset_AO_Start_Select;
1314 case AO_Trigger_Select_Register:
1315 offset = M_Offset_AO_Trigger_Select;
1317 case Clock_and_FOUT_Register:
1318 offset = M_Offset_Clock_and_FOUT;
1320 case Configuration_Memory_Clear:
1321 offset = M_Offset_Configuration_Memory_Clear;
1323 case DAC_FIFO_Clear:
1324 offset = M_Offset_AO_FIFO_Clear;
1326 case DIO_Control_Register:
1328 ("%s: FIXME: register 0x%x does not map cleanly on to m-series boards.\n",
1332 case G_Autoincrement_Register(0):
1333 offset = M_Offset_G0_Autoincrement;
1335 case G_Autoincrement_Register(1):
1336 offset = M_Offset_G1_Autoincrement;
1338 case G_Command_Register(0):
1339 offset = M_Offset_G0_Command;
1341 case G_Command_Register(1):
1342 offset = M_Offset_G1_Command;
1344 case G_Input_Select_Register(0):
1345 offset = M_Offset_G0_Input_Select;
1347 case G_Input_Select_Register(1):
1348 offset = M_Offset_G1_Input_Select;
1350 case G_Mode_Register(0):
1351 offset = M_Offset_G0_Mode;
1353 case G_Mode_Register(1):
1354 offset = M_Offset_G1_Mode;
1356 case Interrupt_A_Ack_Register:
1357 offset = M_Offset_Interrupt_A_Ack;
1359 case Interrupt_A_Enable_Register:
1360 offset = M_Offset_Interrupt_A_Enable;
1362 case Interrupt_B_Ack_Register:
1363 offset = M_Offset_Interrupt_B_Ack;
1365 case Interrupt_B_Enable_Register:
1366 offset = M_Offset_Interrupt_B_Enable;
1368 case Interrupt_Control_Register:
1369 offset = M_Offset_Interrupt_Control;
1371 case IO_Bidirection_Pin_Register:
1372 offset = M_Offset_IO_Bidirection_Pin;
1374 case Joint_Reset_Register:
1375 offset = M_Offset_Joint_Reset;
1377 case RTSI_Trig_A_Output_Register:
1378 offset = M_Offset_RTSI_Trig_A_Output;
1380 case RTSI_Trig_B_Output_Register:
1381 offset = M_Offset_RTSI_Trig_B_Output;
1383 case RTSI_Trig_Direction_Register:
1384 offset = M_Offset_RTSI_Trig_Direction;
1386 /* FIXME: DIO_Output_Register (16 bit reg) is replaced by M_Offset_Static_Digital_Output (32 bit)
1387 and M_Offset_SCXI_Serial_Data_Out (8 bit) */
1389 dev_warn(dev->class_dev,
1390 "%s: bug! unhandled register=0x%x in switch.\n",
1396 ni_writew(data, offset);
1399 static uint16_t m_series_stc_readw(struct comedi_device *dev, int reg)
1401 struct ni_private *devpriv = dev->private;
1405 case AI_Status_1_Register:
1406 offset = M_Offset_AI_Status_1;
1408 case AO_Status_1_Register:
1409 offset = M_Offset_AO_Status_1;
1411 case AO_Status_2_Register:
1412 offset = M_Offset_AO_Status_2;
1414 case DIO_Serial_Input_Register:
1415 return ni_readb(M_Offset_SCXI_Serial_Data_In);
1417 case Joint_Status_1_Register:
1418 offset = M_Offset_Joint_Status_1;
1420 case Joint_Status_2_Register:
1421 offset = M_Offset_Joint_Status_2;
1423 case G_Status_Register:
1424 offset = M_Offset_G01_Status;
1427 dev_warn(dev->class_dev,
1428 "%s: bug! unhandled register=0x%x in switch.\n",
1434 return ni_readw(offset);
1437 static void m_series_stc_writel(struct comedi_device *dev, uint32_t data,
1440 struct ni_private *devpriv = dev->private;
1444 case AI_SC_Load_A_Registers:
1445 offset = M_Offset_AI_SC_Load_A;
1447 case AI_SI_Load_A_Registers:
1448 offset = M_Offset_AI_SI_Load_A;
1450 case AO_BC_Load_A_Register:
1451 offset = M_Offset_AO_BC_Load_A;
1453 case AO_UC_Load_A_Register:
1454 offset = M_Offset_AO_UC_Load_A;
1456 case AO_UI_Load_A_Register:
1457 offset = M_Offset_AO_UI_Load_A;
1459 case G_Load_A_Register(0):
1460 offset = M_Offset_G0_Load_A;
1462 case G_Load_A_Register(1):
1463 offset = M_Offset_G1_Load_A;
1465 case G_Load_B_Register(0):
1466 offset = M_Offset_G0_Load_B;
1468 case G_Load_B_Register(1):
1469 offset = M_Offset_G1_Load_B;
1472 dev_warn(dev->class_dev,
1473 "%s: bug! unhandled register=0x%x in switch.\n",
1479 ni_writel(data, offset);
1482 static uint32_t m_series_stc_readl(struct comedi_device *dev, int reg)
1484 struct ni_private *devpriv = dev->private;
1488 case G_HW_Save_Register(0):
1489 offset = M_Offset_G0_HW_Save;
1491 case G_HW_Save_Register(1):
1492 offset = M_Offset_G1_HW_Save;
1494 case G_Save_Register(0):
1495 offset = M_Offset_G0_Save;
1497 case G_Save_Register(1):
1498 offset = M_Offset_G1_Save;
1501 dev_warn(dev->class_dev,
1502 "%s: bug! unhandled register=0x%x in switch.\n",
1508 return ni_readl(offset);
1511 #define interrupt_pin(a) 0
1512 #define IRQ_POLARITY 1
1514 #define NI_E_IRQ_FLAGS IRQF_SHARED
1516 #include "ni_mio_common.c"
1518 static int pcimio_ai_change(struct comedi_device *dev,
1519 struct comedi_subdevice *s, unsigned long new_size);
1520 static int pcimio_ao_change(struct comedi_device *dev,
1521 struct comedi_subdevice *s, unsigned long new_size);
1522 static int pcimio_gpct0_change(struct comedi_device *dev,
1523 struct comedi_subdevice *s,
1524 unsigned long new_size);
1525 static int pcimio_gpct1_change(struct comedi_device *dev,
1526 struct comedi_subdevice *s,
1527 unsigned long new_size);
1528 static int pcimio_dio_change(struct comedi_device *dev,
1529 struct comedi_subdevice *s,
1530 unsigned long new_size);
1532 static void m_series_init_eeprom_buffer(struct comedi_device *dev)
1534 struct ni_private *devpriv = dev->private;
1535 static const int Start_Cal_EEPROM = 0x400;
1536 static const unsigned window_size = 10;
1537 static const int serial_number_eeprom_offset = 0x4;
1538 static const int serial_number_eeprom_length = 0x4;
1539 unsigned old_iodwbsr_bits;
1540 unsigned old_iodwbsr1_bits;
1541 unsigned old_iodwcr1_bits;
1544 old_iodwbsr_bits = readl(devpriv->mite->mite_io_addr + MITE_IODWBSR);
1545 old_iodwbsr1_bits = readl(devpriv->mite->mite_io_addr + MITE_IODWBSR_1);
1546 old_iodwcr1_bits = readl(devpriv->mite->mite_io_addr + MITE_IODWCR_1);
1547 writel(0x0, devpriv->mite->mite_io_addr + MITE_IODWBSR);
1548 writel(((0x80 | window_size) | devpriv->mite->daq_phys_addr),
1549 devpriv->mite->mite_io_addr + MITE_IODWBSR_1);
1550 writel(0x1 | old_iodwcr1_bits,
1551 devpriv->mite->mite_io_addr + MITE_IODWCR_1);
1552 writel(0xf, devpriv->mite->mite_io_addr + 0x30);
1554 BUG_ON(serial_number_eeprom_length > sizeof(devpriv->serial_number));
1555 for (i = 0; i < serial_number_eeprom_length; ++i) {
1556 char *byte_ptr = (char *)&devpriv->serial_number + i;
1557 *byte_ptr = ni_readb(serial_number_eeprom_offset + i);
1559 devpriv->serial_number = be32_to_cpu(devpriv->serial_number);
1561 for (i = 0; i < M_SERIES_EEPROM_SIZE; ++i)
1562 devpriv->eeprom_buffer[i] = ni_readb(Start_Cal_EEPROM + i);
1564 writel(old_iodwbsr1_bits, devpriv->mite->mite_io_addr + MITE_IODWBSR_1);
1565 writel(old_iodwbsr_bits, devpriv->mite->mite_io_addr + MITE_IODWBSR);
1566 writel(old_iodwcr1_bits, devpriv->mite->mite_io_addr + MITE_IODWCR_1);
1567 writel(0x0, devpriv->mite->mite_io_addr + 0x30);
1570 static void init_6143(struct comedi_device *dev)
1572 struct ni_private *devpriv = dev->private;
1574 /* Disable interrupts */
1575 devpriv->stc_writew(dev, 0, Interrupt_Control_Register);
1577 /* Initialise 6143 AI specific bits */
1578 ni_writeb(0x00, Magic_6143); /* Set G0,G1 DMA mode to E series version */
1579 ni_writeb(0x80, PipelineDelay_6143); /* Set EOCMode, ADCMode and pipelinedelay */
1580 ni_writeb(0x00, EOC_Set_6143); /* Set EOC Delay */
1582 ni_writel(boardtype.ai_fifo_depth / 2, AIFIFO_Flag_6143); /* Set the FIFO half full level */
1584 /* Strobe Relay disable bit */
1585 devpriv->ai_calib_source_enabled = 0;
1586 ni_writew(devpriv->ai_calib_source | Calibration_Channel_6143_RelayOff,
1587 Calibration_Channel_6143);
1588 ni_writew(devpriv->ai_calib_source, Calibration_Channel_6143);
1591 static void pcimio_detach(struct comedi_device *dev)
1593 struct ni_private *devpriv = dev->private;
1595 mio_common_detach(dev);
1597 free_irq(dev->irq, dev);
1599 mite_free_ring(devpriv->ai_mite_ring);
1600 mite_free_ring(devpriv->ao_mite_ring);
1601 mite_free_ring(devpriv->cdo_mite_ring);
1602 mite_free_ring(devpriv->gpct_mite_ring[0]);
1603 mite_free_ring(devpriv->gpct_mite_ring[1]);
1604 if (devpriv->mite) {
1605 mite_unsetup(devpriv->mite);
1606 mite_free(devpriv->mite);
1611 static const struct ni_board_struct *
1612 pcimio_find_boardinfo(struct pci_dev *pcidev)
1614 unsigned int device_id = pcidev->device;
1617 for (n = 0; n < ARRAY_SIZE(ni_boards); n++) {
1618 const struct ni_board_struct *board = &ni_boards[n];
1619 if (board->device_id == device_id)
1625 static int pcimio_auto_attach(struct comedi_device *dev,
1626 unsigned long context_unused)
1628 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
1629 struct ni_private *devpriv;
1632 dev_info(dev->class_dev, "ni_pcimio: attach %s\n", pci_name(pcidev));
1634 ret = ni_alloc_private(dev);
1637 devpriv = dev->private;
1639 dev->board_ptr = pcimio_find_boardinfo(pcidev);
1640 if (!dev->board_ptr)
1643 devpriv->mite = mite_alloc(pcidev);
1647 dev_dbg(dev->class_dev, "%s\n", boardtype.name);
1648 dev->board_name = boardtype.name;
1650 if (boardtype.reg_type & ni_reg_m_series_mask) {
1651 devpriv->stc_writew = &m_series_stc_writew;
1652 devpriv->stc_readw = &m_series_stc_readw;
1653 devpriv->stc_writel = &m_series_stc_writel;
1654 devpriv->stc_readl = &m_series_stc_readl;
1656 devpriv->stc_writew = &e_series_win_out;
1657 devpriv->stc_readw = &e_series_win_in;
1658 devpriv->stc_writel = &win_out2;
1659 devpriv->stc_readl = &win_in2;
1662 ret = mite_setup(devpriv->mite);
1664 pr_warn("error setting up mite\n");
1668 devpriv->ai_mite_ring = mite_alloc_ring(devpriv->mite);
1669 if (devpriv->ai_mite_ring == NULL)
1671 devpriv->ao_mite_ring = mite_alloc_ring(devpriv->mite);
1672 if (devpriv->ao_mite_ring == NULL)
1674 devpriv->cdo_mite_ring = mite_alloc_ring(devpriv->mite);
1675 if (devpriv->cdo_mite_ring == NULL)
1677 devpriv->gpct_mite_ring[0] = mite_alloc_ring(devpriv->mite);
1678 if (devpriv->gpct_mite_ring[0] == NULL)
1680 devpriv->gpct_mite_ring[1] = mite_alloc_ring(devpriv->mite);
1681 if (devpriv->gpct_mite_ring[1] == NULL)
1684 if (boardtype.reg_type & ni_reg_m_series_mask)
1685 m_series_init_eeprom_buffer(dev);
1686 if (boardtype.reg_type == ni_reg_6143)
1689 dev->irq = mite_irq(devpriv->mite);
1691 if (dev->irq == 0) {
1692 pr_warn("unknown irq (bad)\n");
1694 pr_debug("( irq = %u )\n", dev->irq);
1695 ret = request_irq(dev->irq, ni_E_interrupt, NI_E_IRQ_FLAGS,
1698 pr_warn("irq not available\n");
1703 ret = ni_E_init(dev);
1707 dev->subdevices[NI_AI_SUBDEV].buf_change = &pcimio_ai_change;
1708 dev->subdevices[NI_AO_SUBDEV].buf_change = &pcimio_ao_change;
1709 dev->subdevices[NI_GPCT_SUBDEV(0)].buf_change = &pcimio_gpct0_change;
1710 dev->subdevices[NI_GPCT_SUBDEV(1)].buf_change = &pcimio_gpct1_change;
1711 dev->subdevices[NI_DIO_SUBDEV].buf_change = &pcimio_dio_change;
1716 static int pcimio_ai_change(struct comedi_device *dev,
1717 struct comedi_subdevice *s, unsigned long new_size)
1719 struct ni_private *devpriv = dev->private;
1722 ret = mite_buf_change(devpriv->ai_mite_ring, s->async);
1729 static int pcimio_ao_change(struct comedi_device *dev,
1730 struct comedi_subdevice *s, unsigned long new_size)
1732 struct ni_private *devpriv = dev->private;
1735 ret = mite_buf_change(devpriv->ao_mite_ring, s->async);
1742 static int pcimio_gpct0_change(struct comedi_device *dev,
1743 struct comedi_subdevice *s,
1744 unsigned long new_size)
1746 struct ni_private *devpriv = dev->private;
1749 ret = mite_buf_change(devpriv->gpct_mite_ring[0], s->async);
1756 static int pcimio_gpct1_change(struct comedi_device *dev,
1757 struct comedi_subdevice *s,
1758 unsigned long new_size)
1760 struct ni_private *devpriv = dev->private;
1763 ret = mite_buf_change(devpriv->gpct_mite_ring[1], s->async);
1770 static int pcimio_dio_change(struct comedi_device *dev,
1771 struct comedi_subdevice *s, unsigned long new_size)
1773 struct ni_private *devpriv = dev->private;
1776 ret = mite_buf_change(devpriv->cdo_mite_ring, s->async);
1783 static struct comedi_driver ni_pcimio_driver = {
1784 .driver_name = "ni_pcimio",
1785 .module = THIS_MODULE,
1786 .auto_attach = pcimio_auto_attach,
1787 .detach = pcimio_detach,
1790 static int ni_pcimio_pci_probe(struct pci_dev *dev,
1791 const struct pci_device_id *ent)
1793 return comedi_pci_auto_config(dev, &ni_pcimio_driver);
1796 static DEFINE_PCI_DEVICE_TABLE(ni_pcimio_pci_table) = {
1797 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x0162) },
1798 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1170) },
1799 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1180) },
1800 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1190) },
1801 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11b0) },
1802 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11c0) },
1803 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11d0) },
1804 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1270) },
1805 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1330) },
1806 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1340) },
1807 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1350) },
1808 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x14e0) },
1809 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x14f0) },
1810 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1580) },
1811 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x15b0) },
1812 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1880) },
1813 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1870) },
1814 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x18b0) },
1815 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x18c0) },
1816 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2410) },
1817 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2420) },
1818 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2430) },
1819 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2890) },
1820 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x28c0) },
1821 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a60) },
1822 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a70) },
1823 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a80) },
1824 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2ab0) },
1825 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b80) },
1826 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b90) },
1827 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c80) },
1828 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2ca0) },
1829 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70aa) },
1830 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70ab) },
1831 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70ac) },
1832 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70af) },
1833 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b0) },
1834 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b4) },
1835 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b6) },
1836 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b7) },
1837 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b8) },
1838 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bc) },
1839 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bd) },
1840 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bf) },
1841 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70c0) },
1842 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70f2) },
1843 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x710d) },
1844 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x716c) },
1845 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x716d) },
1846 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x717f) },
1847 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x71bc) },
1848 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x717d) },
1849 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x72e8) },
1852 MODULE_DEVICE_TABLE(pci, ni_pcimio_pci_table);
1854 static struct pci_driver ni_pcimio_pci_driver = {
1855 .name = "ni_pcimio",
1856 .id_table = ni_pcimio_pci_table,
1857 .probe = ni_pcimio_pci_probe,
1858 .remove = comedi_pci_auto_unconfig,
1860 module_comedi_pci_driver(ni_pcimio_driver, ni_pcimio_pci_driver);
1862 MODULE_AUTHOR("Comedi http://www.comedi.org");
1863 MODULE_DESCRIPTION("Comedi low-level driver");
1864 MODULE_LICENSE("GPL");