aboutsummaryrefslogtreecommitdiff
path: root/drivers/staging/comedi/drivers/ni_pcimio.c
blob: 27baefa32b171c2e79322d23c0d57364d29a0655 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
/*
    comedi/drivers/ni_pcimio.c
    Hardware driver for NI PCI-MIO E series cards

    COMEDI - Linux Control and Measurement Device Interface
    Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
Driver: ni_pcimio
Description: National Instruments PCI-MIO-E series and M series (all boards)
Author: ds, John Hallen, Frank Mori Hess, Rolf Mueller, Herbert Peremans,
  Herman Bruyninckx, Terry Barnaby
Status: works
Devices: [National Instruments] PCI-MIO-16XE-50 (ni_pcimio),
  PCI-MIO-16XE-10, PXI-6030E, PCI-MIO-16E-1, PCI-MIO-16E-4, PCI-6014, PCI-6040E,
  PXI-6040E, PCI-6030E, PCI-6031E, PCI-6032E, PCI-6033E, PCI-6071E, PCI-6023E,
  PCI-6024E, PCI-6025E, PXI-6025E, PCI-6034E, PCI-6035E, PCI-6052E,
  PCI-6110, PCI-6111, PCI-6220, PCI-6221, PCI-6224, PXI-6224,
  PCI-6225, PXI-6225, PCI-6229, PCI-6250, PCI-6251, PCIe-6251, PXIe-6251,
  PCI-6254, PCI-6259, PCIe-6259,
  PCI-6280, PCI-6281, PXI-6281, PCI-6284, PCI-6289,
  PCI-6711, PXI-6711, PCI-6713, PXI-6713,
  PXI-6071E, PCI-6070E, PXI-6070E,
  PXI-6052E, PCI-6036E, PCI-6731, PCI-6733, PXI-6733,
  PCI-6143, PXI-6143
Updated: Mon, 09 Jan 2012 14:52:48 +0000

These boards are almost identical to the AT-MIO E series, except that
they use the PCI bus instead of ISA (i.e., AT).  See the notes for
the ni_atmio.o driver for additional information about these boards.

Autocalibration is supported on many of the devices, using the
comedi_calibrate (or comedi_soft_calibrate for m-series) utility.
M-Series boards do analog input and analog output calibration entirely
in software. The software calibration corrects
the analog input for offset, gain and
nonlinearity.  The analog outputs are corrected for offset and gain.
See the comedilib documentation on comedi_get_softcal_converter() for
more information.

By default, the driver uses DMA to transfer analog input data to
memory.  When DMA is enabled, not all triggering features are
supported.

Digital I/O may not work on 673x.

Note that the PCI-6143 is a simultaineous sampling device with 8 convertors.
With this board all of the convertors perform one simultaineous sample during
a scan interval. The period for a scan is used for the convert time in a
Comedi cmd. The convert trigger source is normally set to TRIG_NOW by default.

The RTSI trigger bus is supported on these cards on
subdevice 10. See the comedilib documentation for details.

Information (number of channels, bits, etc.) for some devices may be
incorrect.  Please check this and submit a bug if there are problems
for your device.

SCXI is probably broken for m-series boards.

Bugs:
 - When DMA is enabled, COMEDI_EV_CONVERT does
   not work correctly.

*/
/*
	The PCI-MIO E series driver was originally written by
	Tomasz Motylewski <...>, and ported to comedi by ds.

	References:

	   341079b.pdf  PCI E Series Register-Level Programmer Manual
	   340934b.pdf  DAQ-STC reference manual

	   322080b.pdf  6711/6713/6715 User Manual

	   320945c.pdf  PCI E Series User Manual
	   322138a.pdf  PCI-6052E and DAQPad-6052E User Manual

	ISSUES:

	need to deal with external reference for DAC, and other DAC
	properties in board properties

	deal with at-mio-16de-10 revision D to N changes, etc.

	need to add other CALDAC type

	need to slow down DAC loading.  I don't trust NI's claim that
	two writes to the PCI bus slows IO enough.  I would prefer to
	use udelay().  Timing specs: (clock)
		AD8522		30ns
		DAC8043		120ns
		DAC8800		60ns
		MB88341		?

*/

#include "../comedidev.h"

#include <asm/byteorder.h>
#include <linux/delay.h>

#include "ni_stc.h"
#include "mite.h"

/* #define PCI_DEBUG */

#define PCIDMA

#define PCIMIO 1
#undef ATMIO

#define MAX_N_CALDACS (16+16+2)

#define DRV_NAME "ni_pcimio"

/* The following two tables must be in the same order */
static DEFINE_PCI_DEVICE_TABLE(ni_pci_table) = {
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x0162)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1170)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1180)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1190)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11b0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11c0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11d0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1270)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1330)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1340)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1350)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x14e0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x14f0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1580)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x15b0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1880)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1870)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x18b0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x18c0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2410)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2420)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2430)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2890)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x28c0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a60)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a70)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a80)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2ab0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b80)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b90)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c80)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2ca0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70aa)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70ab)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70ac)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70af)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b4)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b6)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b7)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b8)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bc)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bd)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bf)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70c0)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70f2)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x710d)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x716c)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x716d)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x717f)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x71bc)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x717d)},
	{PCI_DEVICE(PCI_VENDOR_ID_NI, 0x72e8)},
	{0}
};

MODULE_DEVICE_TABLE(pci, ni_pci_table);

/* These are not all the possible ao ranges for 628x boards.
 They can do OFFSET +- REFERENCE where OFFSET can be
 0V, 5V, APFI<0,1>, or AO<0...3> and RANGE can
 be 10V, 5V, 2V, 1V, APFI<0,1>, AO<0...3>.  That's
 63 different possibilities.  An AO channel
 can not act as it's own OFFSET or REFERENCE.
*/
static const struct comedi_lrange range_ni_M_628x_ao = { 8, {
							     RANGE(-10, 10),
							     RANGE(-5, 5),
							     RANGE(-2, 2),
							     RANGE(-1, 1),
							     RANGE(-5, 15),
							     RANGE(0, 10),
							     RANGE(3, 7),
							     RANGE(4, 6),
							     RANGE_ext(-1, 1)
							     }
};

static const struct comedi_lrange range_ni_M_625x_ao = { 3, {
							     RANGE(-10, 10),
							     RANGE(-5, 5),
							     RANGE_ext(-1, 1)
							     }
};

static const struct comedi_lrange range_ni_M_622x_ao = { 1, {
							     RANGE(-10, 10),
							     }
};

static const struct ni_board_struct ni_boards[] = {
	{
	 .device_id = 0x0162,	/*  NI also says 0x1620.  typo? */
	 .name = "pci-mio-16xe-50",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 2048,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_8,
	 .ai_speed = 50000,
	 .n_aochan = 2,
	 .aobits = 12,
	 .ao_fifo_depth = 0,
	 .ao_range_table = &range_bipolar10,
	 .ao_unipolar = 0,
	 .ao_speed = 50000,
	 .num_p0_dio_channels = 8,
	 .caldac = {dac8800, dac8043},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x1170,
	 .name = "pci-mio-16xe-10",	/*  aka pci-6030E */
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_14,
	 .ai_speed = 10000,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 2048,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_unipolar = 1,
	 .ao_speed = 10000,
	 .num_p0_dio_channels = 8,
	 .caldac = {dac8800, dac8043, ad8522},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x28c0,
	 .name = "pci-6014",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_4,
	 .ai_speed = 5000,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 0,
	 .ao_range_table = &range_bipolar10,
	 .ao_unipolar = 0,
	 .ao_speed = 100000,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x11d0,
	 .name = "pxi-6030e",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_14,
	 .ai_speed = 10000,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 2048,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_unipolar = 1,
	 .ao_speed = 10000,
	 .num_p0_dio_channels = 8,
	 .caldac = {dac8800, dac8043, ad8522},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x1180,
	 .name = "pci-mio-16e-1",	/* aka pci-6070e */
	 .n_adchan = 16,
	 .adbits = 12,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_16,
	 .ai_speed = 800,
	 .n_aochan = 2,
	 .aobits = 12,
	 .ao_fifo_depth = 2048,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_unipolar = 1,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .caldac = {mb88341},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x1190,
	 .name = "pci-mio-16e-4",	/* aka pci-6040e */
	 .n_adchan = 16,
	 .adbits = 12,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_16,
	 /*      .Note = there have been reported problems with full speed
	  * on this board */
	 .ai_speed = 2000,
	 .n_aochan = 2,
	 .aobits = 12,
	 .ao_fifo_depth = 512,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_unipolar = 1,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug},	/*  doc says mb88341 */
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x11c0,
	 .name = "pxi-6040e",
	 .n_adchan = 16,
	 .adbits = 12,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_16,
	 .ai_speed = 2000,
	 .n_aochan = 2,
	 .aobits = 12,
	 .ao_fifo_depth = 512,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_unipolar = 1,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .caldac = {mb88341},
	 .has_8255 = 0,
	 },

	{
	 .device_id = 0x1330,
	 .name = "pci-6031e",
	 .n_adchan = 64,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_14,
	 .ai_speed = 10000,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 2048,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_unipolar = 1,
	 .ao_speed = 10000,
	 .num_p0_dio_channels = 8,
	 .caldac = {dac8800, dac8043, ad8522},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x1270,
	 .name = "pci-6032e",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_14,
	 .ai_speed = 10000,
	 .n_aochan = 0,
	 .aobits = 0,
	 .ao_fifo_depth = 0,
	 .ao_unipolar = 0,
	 .num_p0_dio_channels = 8,
	 .caldac = {dac8800, dac8043, ad8522},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x1340,
	 .name = "pci-6033e",
	 .n_adchan = 64,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_14,
	 .ai_speed = 10000,
	 .n_aochan = 0,
	 .aobits = 0,
	 .ao_fifo_depth = 0,
	 .ao_unipolar = 0,
	 .num_p0_dio_channels = 8,
	 .caldac = {dac8800, dac8043, ad8522},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x1350,
	 .name = "pci-6071e",
	 .n_adchan = 64,
	 .adbits = 12,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_16,
	 .ai_speed = 800,
	 .n_aochan = 2,
	 .aobits = 12,
	 .ao_fifo_depth = 2048,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_unipolar = 1,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x2a60,
	 .name = "pci-6023e",
	 .n_adchan = 16,
	 .adbits = 12,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_4,
	 .ai_speed = 5000,
	 .n_aochan = 0,
	 .aobits = 0,
	 .ao_unipolar = 0,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug},	/* manual is wrong */
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x2a70,
	 .name = "pci-6024e",
	 .n_adchan = 16,
	 .adbits = 12,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_4,
	 .ai_speed = 5000,
	 .n_aochan = 2,
	 .aobits = 12,
	 .ao_fifo_depth = 0,
	 .ao_range_table = &range_bipolar10,
	 .ao_unipolar = 0,
	 .ao_speed = 100000,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug},	/* manual is wrong */
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x2a80,
	 .name = "pci-6025e",
	 .n_adchan = 16,
	 .adbits = 12,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_4,
	 .ai_speed = 5000,
	 .n_aochan = 2,
	 .aobits = 12,
	 .ao_fifo_depth = 0,
	 .ao_range_table = &range_bipolar10,
	 .ao_unipolar = 0,
	 .ao_speed = 100000,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug},	/* manual is wrong */
	 .has_8255 = 1,
	 },
	{
	 .device_id = 0x2ab0,
	 .name = "pxi-6025e",
	 .n_adchan = 16,
	 .adbits = 12,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_4,
	 .ai_speed = 5000,
	 .n_aochan = 2,
	 .aobits = 12,
	 .ao_fifo_depth = 0,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_unipolar = 1,
	 .ao_speed = 100000,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug},	/* manual is wrong */
	 .has_8255 = 1,
	 },

	{
	 .device_id = 0x2ca0,
	 .name = "pci-6034e",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_4,
	 .ai_speed = 5000,
	 .n_aochan = 0,
	 .aobits = 0,
	 .ao_fifo_depth = 0,
	 .ao_unipolar = 0,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x2c80,
	 .name = "pci-6035e",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_4,
	 .ai_speed = 5000,
	 .n_aochan = 2,
	 .aobits = 12,
	 .ao_fifo_depth = 0,
	 .ao_range_table = &range_bipolar10,
	 .ao_unipolar = 0,
	 .ao_speed = 100000,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x18b0,
	 .name = "pci-6052e",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_16,
	 .ai_speed = 3000,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_unipolar = 1,
	 .ao_fifo_depth = 2048,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_speed = 3000,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug, ad8804_debug, ad8522},	/* manual is wrong */
	 },
	{.device_id = 0x14e0,
	 .name = "pci-6110",
	 .n_adchan = 4,
	 .adbits = 12,
	 .ai_fifo_depth = 8192,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_611x,
	 .ai_speed = 200,
	 .n_aochan = 2,
	 .aobits = 16,
	 .reg_type = ni_reg_611x,
	 .ao_range_table = &range_bipolar10,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 2048,
	 .ao_speed = 250,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804, ad8804},
	 },
	{
	 .device_id = 0x14f0,
	 .name = "pci-6111",
	 .n_adchan = 2,
	 .adbits = 12,
	 .ai_fifo_depth = 8192,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_611x,
	 .ai_speed = 200,
	 .n_aochan = 2,
	 .aobits = 16,
	 .reg_type = ni_reg_611x,
	 .ao_range_table = &range_bipolar10,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 2048,
	 .ao_speed = 250,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804, ad8804},
	 },
#if 0
	/* The 6115 boards probably need their own driver */
	{
	 .device_id = 0x2ed0,
	 .name = "pci-6115",
	 .n_adchan = 4,
	 .adbits = 12,
	 .ai_fifo_depth = 8192,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_611x,
	 .ai_speed = 100,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_671x = 1,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 2048,
	 .ao_speed = 250,
	 .num_p0_dio_channels = 8,
	 .reg_611x = 1,
	 .caldac = {ad8804_debug, ad8804_debug, ad8804_debug},	/* XXX */
	 },
#endif
#if 0
	{
	 .device_id = 0x0000,
	 .name = "pxi-6115",
	 .n_adchan = 4,
	 .adbits = 12,
	 .ai_fifo_depth = 8192,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_611x,
	 .ai_speed = 100,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_671x = 1,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 2048,
	 .ao_speed = 250,
	 .reg_611x = 1,
	 .num_p0_dio_channels = 8,
	 caldac = {ad8804_debug, ad8804_debug, ad8804_debug},	/* XXX */
	 },
#endif
	{
	 .device_id = 0x1880,
	 .name = "pci-6711",
	 .n_adchan = 0,		/* no analog input */
	 .n_aochan = 4,
	 .aobits = 12,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 16384,
	 /* data sheet says 8192, but fifo really holds 16384 samples */
	 .ao_range_table = &range_bipolar10,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .reg_type = ni_reg_6711,
	 .caldac = {ad8804_debug},
	 },
	{
	 .device_id = 0x2b90,
	 .name = "pxi-6711",
	 .n_adchan = 0,		/* no analog input */
	 .n_aochan = 4,
	 .aobits = 12,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 16384,
	 .ao_range_table = &range_bipolar10,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .reg_type = ni_reg_6711,
	 .caldac = {ad8804_debug},
	 },
	{
	 .device_id = 0x1870,
	 .name = "pci-6713",
	 .n_adchan = 0,		/* no analog input */
	 .n_aochan = 8,
	 .aobits = 12,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 16384,
	 .ao_range_table = &range_bipolar10,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .reg_type = ni_reg_6713,
	 .caldac = {ad8804_debug, ad8804_debug},
	 },
	{
	 .device_id = 0x2b80,
	 .name = "pxi-6713",
	 .n_adchan = 0,		/* no analog input */
	 .n_aochan = 8,
	 .aobits = 12,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 16384,
	 .ao_range_table = &range_bipolar10,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .reg_type = ni_reg_6713,
	 .caldac = {ad8804_debug, ad8804_debug},
	 },
	{
	 .device_id = 0x2430,
	 .name = "pci-6731",
	 .n_adchan = 0,		/* no analog input */
	 .n_aochan = 4,
	 .aobits = 16,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 8192,
	 .ao_range_table = &range_bipolar10,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .reg_type = ni_reg_6711,
	 .caldac = {ad8804_debug},
	 },
#if 0				/* need device ids */
	{
	 .device_id = 0x0,
	 .name = "pxi-6731",
	 .n_adchan = 0,		/* no analog input */
	 .n_aochan = 4,
	 .aobits = 16,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 8192,
	 .ao_range_table = &range_bipolar10,
	 .num_p0_dio_channels = 8,
	 .reg_type = ni_reg_6711,
	 .caldac = {ad8804_debug},
	 },
#endif
	{
	 .device_id = 0x2410,
	 .name = "pci-6733",
	 .n_adchan = 0,		/* no analog input */
	 .n_aochan = 8,
	 .aobits = 16,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 16384,
	 .ao_range_table = &range_bipolar10,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .reg_type = ni_reg_6713,
	 .caldac = {ad8804_debug, ad8804_debug},
	 },
	{
	 .device_id = 0x2420,
	 .name = "pxi-6733",
	 .n_adchan = 0,		/* no analog input */
	 .n_aochan = 8,
	 .aobits = 16,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 16384,
	 .ao_range_table = &range_bipolar10,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .reg_type = ni_reg_6713,
	 .caldac = {ad8804_debug, ad8804_debug},
	 },
	{
	 .device_id = 0x15b0,
	 .name = "pxi-6071e",
	 .n_adchan = 64,
	 .adbits = 12,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_16,
	 .ai_speed = 800,
	 .n_aochan = 2,
	 .aobits = 12,
	 .ao_fifo_depth = 2048,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_unipolar = 1,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x11b0,
	 .name = "pxi-6070e",
	 .n_adchan = 16,
	 .adbits = 12,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_16,
	 .ai_speed = 800,
	 .n_aochan = 2,
	 .aobits = 12,
	 .ao_fifo_depth = 2048,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_unipolar = 1,
	 .ao_speed = 1000,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x18c0,
	 .name = "pxi-6052e",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_16,
	 .ai_speed = 3000,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_unipolar = 1,
	 .ao_fifo_depth = 2048,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_speed = 3000,
	 .num_p0_dio_channels = 8,
	 .caldac = {mb88341, mb88341, ad8522},
	 },
	{
	 .device_id = 0x1580,
	 .name = "pxi-6031e",
	 .n_adchan = 64,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_14,
	 .ai_speed = 10000,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 2048,
	 .ao_range_table = &range_ni_E_ao_ext,
	 .ao_unipolar = 1,
	 .ao_speed = 10000,
	 .num_p0_dio_channels = 8,
	 .caldac = {dac8800, dac8043, ad8522},
	 },
	{
	 .device_id = 0x2890,
	 .name = "pci-6036e",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 .alwaysdither = 1,
	 .gainlkup = ai_gain_4,
	 .ai_speed = 5000,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 0,
	 .ao_range_table = &range_bipolar10,
	 .ao_unipolar = 0,
	 .ao_speed = 100000,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70b0,
	 .name = "pci-6220",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 512,
	 /*      .FIXME = guess */
	 .gainlkup = ai_gain_622x,
	 .ai_speed = 4000,
	 .n_aochan = 0,
	 .aobits = 0,
	 .ao_fifo_depth = 0,
	 .num_p0_dio_channels = 8,
	 .reg_type = ni_reg_622x,
	 .ao_unipolar = 0,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70af,
	 .name = "pci-6221",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_622x,
	 .ai_speed = 4000,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_622x_ao,
	 .reg_type = ni_reg_622x,
	 .ao_unipolar = 0,
	 .ao_speed = 1200,
	 .num_p0_dio_channels = 8,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x71bc,
	 .name = "pci-6221_37pin",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_622x,
	 .ai_speed = 4000,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_622x_ao,
	 .reg_type = ni_reg_622x,
	 .ao_unipolar = 0,
	 .ao_speed = 1200,
	 .num_p0_dio_channels = 8,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70f2,
	 .name = "pci-6224",
	 .n_adchan = 32,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_622x,
	 .ai_speed = 4000,
	 .n_aochan = 0,
	 .aobits = 0,
	 .ao_fifo_depth = 0,
	 .reg_type = ni_reg_622x,
	 .ao_unipolar = 0,
	 .num_p0_dio_channels = 32,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70f3,
	 .name = "pxi-6224",
	 .n_adchan = 32,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_622x,
	 .ai_speed = 4000,
	 .n_aochan = 0,
	 .aobits = 0,
	 .ao_fifo_depth = 0,
	 .reg_type = ni_reg_622x,
	 .ao_unipolar = 0,
	 .num_p0_dio_channels = 32,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x716c,
	 .name = "pci-6225",
	 .n_adchan = 80,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_622x,
	 .ai_speed = 4000,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_622x_ao,
	 .reg_type = ni_reg_622x,
	 .ao_unipolar = 0,
	 .ao_speed = 1200,
	 .num_p0_dio_channels = 32,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x716d,
	 .name = "pxi-6225",
	 .n_adchan = 80,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_622x,
	 .ai_speed = 4000,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_622x_ao,
	 .reg_type = ni_reg_622x,
	 .ao_unipolar = 0,
	 .ao_speed = 1200,
	 .num_p0_dio_channels = 32,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	},
	{
	 .device_id = 0x70aa,
	 .name = "pci-6229",
	 .n_adchan = 32,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_622x,
	 .ai_speed = 4000,
	 .n_aochan = 4,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_622x_ao,
	 .reg_type = ni_reg_622x,
	 .ao_unipolar = 0,
	 .ao_speed = 1200,
	 .num_p0_dio_channels = 32,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70b4,
	 .name = "pci-6250",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_628x,
	 .ai_speed = 800,
	 .n_aochan = 0,
	 .aobits = 0,
	 .ao_fifo_depth = 0,
	 .reg_type = ni_reg_625x,
	 .ao_unipolar = 0,
	 .num_p0_dio_channels = 8,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70b8,
	 .name = "pci-6251",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_628x,
	 .ai_speed = 800,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_625x_ao,
	 .reg_type = ni_reg_625x,
	 .ao_unipolar = 0,
	 .ao_speed = 357,
	 .num_p0_dio_channels = 8,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x717d,
	 .name = "pcie-6251",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_628x,
	 .ai_speed = 800,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_625x_ao,
	 .reg_type = ni_reg_625x,
	 .ao_unipolar = 0,
	 .ao_speed = 357,
	 .num_p0_dio_channels = 8,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x72e8,
	 .name = "pxie-6251",
	 .n_adchan = 16,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_628x,
	 .ai_speed = 800,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_625x_ao,
	 .reg_type = ni_reg_625x,
	 .ao_unipolar = 0,
	 .ao_speed = 357,
	 .num_p0_dio_channels = 8,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70b7,
	 .name = "pci-6254",
	 .n_adchan = 32,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_628x,
	 .ai_speed = 800,
	 .n_aochan = 0,
	 .aobits = 0,
	 .ao_fifo_depth = 0,
	 .reg_type = ni_reg_625x,
	 .ao_unipolar = 0,
	 .num_p0_dio_channels = 32,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70ab,
	 .name = "pci-6259",
	 .n_adchan = 32,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_628x,
	 .ai_speed = 800,
	 .n_aochan = 4,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_625x_ao,
	 .reg_type = ni_reg_625x,
	 .ao_unipolar = 0,
	 .ao_speed = 357,
	 .num_p0_dio_channels = 32,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x717f,
	 .name = "pcie-6259",
	 .n_adchan = 32,
	 .adbits = 16,
	 .ai_fifo_depth = 4095,
	 .gainlkup = ai_gain_628x,
	 .ai_speed = 800,
	 .n_aochan = 4,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_625x_ao,
	 .reg_type = ni_reg_625x,
	 .ao_unipolar = 0,
	 .ao_speed = 357,
	 .num_p0_dio_channels = 32,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70b6,
	 .name = "pci-6280",
	 .n_adchan = 16,
	 .adbits = 18,
	 .ai_fifo_depth = 2047,
	 .gainlkup = ai_gain_628x,
	 .ai_speed = 1600,
	 .n_aochan = 0,
	 .aobits = 0,
	 .ao_fifo_depth = 8191,
	 .reg_type = ni_reg_628x,
	 .ao_unipolar = 0,
	 .num_p0_dio_channels = 8,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70bd,
	 .name = "pci-6281",
	 .n_adchan = 16,
	 .adbits = 18,
	 .ai_fifo_depth = 2047,
	 .gainlkup = ai_gain_628x,
	 .ai_speed = 1600,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_628x_ao,
	 .reg_type = ni_reg_628x,
	 .ao_unipolar = 1,
	 .ao_speed = 357,
	 .num_p0_dio_channels = 8,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70bf,
	 .name = "pxi-6281",
	 .n_adchan = 16,
	 .adbits = 18,
	 .ai_fifo_depth = 2047,
	 .gainlkup = ai_gain_628x,
	 .ai_speed = 1600,
	 .n_aochan = 2,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_628x_ao,
	 .reg_type = ni_reg_628x,
	 .ao_unipolar = 1,
	 .ao_speed = 357,
	 .num_p0_dio_channels = 8,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70bc,
	 .name = "pci-6284",
	 .n_adchan = 32,
	 .adbits = 18,
	 .ai_fifo_depth = 2047,
	 .gainlkup = ai_gain_628x,
	 .ai_speed = 1600,
	 .n_aochan = 0,
	 .aobits = 0,
	 .ao_fifo_depth = 0,
	 .reg_type = ni_reg_628x,
	 .ao_unipolar = 0,
	 .num_p0_dio_channels = 32,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70ac,
	 .name = "pci-6289",
	 .n_adchan = 32,
	 .adbits = 18,
	 .ai_fifo_depth = 2047,
	 .gainlkup = ai_gain_628x,
	 .ai_speed = 1600,
	 .n_aochan = 4,
	 .aobits = 16,
	 .ao_fifo_depth = 8191,
	 .ao_range_table = &range_ni_M_628x_ao,
	 .reg_type = ni_reg_628x,
	 .ao_unipolar = 1,
	 .ao_speed = 357,
	 .num_p0_dio_channels = 32,
	 .caldac = {caldac_none},
	 .has_8255 = 0,
	 },
	{
	 .device_id = 0x70C0,
	 .name = "pci-6143",
	 .n_adchan = 8,
	 .adbits = 16,
	 .ai_fifo_depth = 1024,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_6143,
	 .ai_speed = 4000,
	 .n_aochan = 0,
	 .aobits = 0,
	 .reg_type = ni_reg_6143,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 0,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug, ad8804_debug},
	 },
	{
	 .device_id = 0x710D,
	 .name = "pxi-6143",
	 .n_adchan = 8,
	 .adbits = 16,
	 .ai_fifo_depth = 1024,
	 .alwaysdither = 0,
	 .gainlkup = ai_gain_6143,
	 .ai_speed = 4000,
	 .n_aochan = 0,
	 .aobits = 0,
	 .reg_type = ni_reg_6143,
	 .ao_unipolar = 0,
	 .ao_fifo_depth = 0,
	 .num_p0_dio_channels = 8,
	 .caldac = {ad8804_debug, ad8804_debug},
	 },
};

#define n_pcimio_boards ARRAY_SIZE(ni_boards)

static int pcimio_attach(struct comedi_device *dev,
			 struct comedi_devconfig *it);
static int pcimio_detach(struct comedi_device *dev);
static struct comedi_driver driver_pcimio = {
	.driver_name = DRV_NAME,
	.module = THIS_MODULE,
	.attach = pcimio_attach,
	.detach = pcimio_detach,
};

static int __devinit driver_pcimio_pci_probe(struct pci_dev *dev,
					     const struct pci_device_id *ent)
{
	return comedi_pci_auto_config(dev, driver_pcimio.driver_name);
}

static void __devexit driver_pcimio_pci_remove(struct pci_dev *dev)
{
	comedi_pci_auto_unconfig(dev);
}

static struct pci_driver driver_pcimio_pci_driver = {
	.id_table = ni_pci_table,
	.probe = &driver_pcimio_pci_probe,
	.remove = __devexit_p(&driver_pcimio_pci_remove)
};

static int __init driver_pcimio_init_module(void)
{
	int retval;

	retval = comedi_driver_register(&driver_pcimio);
	if (retval < 0)
		return retval;

	driver_pcimio_pci_driver.name = (char *)driver_pcimio.driver_name;
	return pci_register_driver(&driver_pcimio_pci_driver);
}

static void __exit driver_pcimio_cleanup_module(void)
{
	pci_unregister_driver(&driver_pcimio_pci_driver);
	comedi_driver_unregister(&driver_pcimio);
}

module_init(driver_pcimio_init_module);
module_exit(driver_pcimio_cleanup_module);

struct ni_private {
NI_PRIVATE_COMMON};
#define devpriv ((struct ni_private *)dev->private)

/* How we access registers */

#define ni_writel(a, b)	(writel((a), devpriv->mite->daq_io_addr + (b)))
#define ni_readl(a)	(readl(devpriv->mite->daq_io_addr + (a)))
#define ni_writew(a, b)	(writew((a), devpriv->mite->daq_io_addr + (b)))
#define ni_readw(a)	(readw(devpriv->mite->daq_io_addr + (a)))
#define ni_writeb(a, b)	(writeb((a), devpriv->mite->daq_io_addr + (b)))
#define ni_readb(a)	(readb(devpriv->mite->daq_io_addr + (a)))

/* How we access STC registers */

/* We automatically take advantage of STC registers that can be
 * read/written directly in the I/O space of the board.  Most
 * PCIMIO devices map the low 8 STC registers to iobase+addr*2.
 * The 611x devices map the write registers to iobase+addr*2, and
 * the read registers to iobase+(addr-1)*2. */
/* However, the 611x boards still aren't working, so I'm disabling
 * non-windowed STC access temporarily */

static void e_series_win_out(struct comedi_device *dev, uint16_t data, int reg)
{
	unsigned long flags;

	spin_lock_irqsave(&devpriv->window_lock, flags);
	ni_writew(reg, Window_Address);
	ni_writew(data, Window_Data);
	spin_unlock_irqrestore(&devpriv->window_lock, flags);
}

static uint16_t e_series_win_in(struct comedi_device *dev, int reg)
{
	unsigned long flags;
	uint16_t ret;

	spin_lock_irqsave(&devpriv->window_lock, flags);
	ni_writew(reg, Window_Address);
	ret = ni_readw(Window_Data);
	spin_unlock_irqrestore(&devpriv->window_lock, flags);

	return ret;
}

static void m_series_stc_writew(struct comedi_device *dev, uint16_t data,
				int reg)
{
	unsigned offset;
	switch (reg) {
	case ADC_FIFO_Clear:
		offset = M_Offset_AI_FIFO_Clear;
		break;
	case AI_Command_1_Register:
		offset = M_Offset_AI_Command_1;
		break;
	case AI_Command_2_Register:
		offset = M_Offset_AI_Command_2;
		break;
	case AI_Mode_1_Register:
		offset = M_Offset_AI_Mode_1;
		break;
	case AI_Mode_2_Register:
		offset = M_Offset_AI_Mode_2;
		break;
	case AI_Mode_3_Register:
		offset = M_Offset_AI_Mode_3;
		break;
	case AI_Output_Control_Register:
		offset = M_Offset_AI_Output_Control;
		break;
	case AI_Personal_Register:
		offset = M_Offset_AI_Personal;
		break;
	case AI_SI2_Load_A_Register:
		/*  this is actually a 32 bit register on m series boards */
		ni_writel(data, M_Offset_AI_SI2_Load_A);
		return;
		break;
	case AI_SI2_Load_B_Register:
		/*  this is actually a 32 bit register on m series boards */
		ni_writel(data, M_Offset_AI_SI2_Load_B);
		return;
		break;
	case AI_START_STOP_Select_Register:
		offset = M_Offset_AI_START_STOP_Select;
		break;
	case AI_Trigger_Select_Register:
		offset = M_Offset_AI_Trigger_Select;
		break;
	case Analog_Trigger_Etc_Register:
		offset = M_Offset_Analog_Trigger_Etc;
		break;
	case AO_Command_1_Register:
		offset = M_Offset_AO_Command_1;
		break;
	case AO_Command_2_Register:
		offset = M_Offset_AO_Command_2;
		break;
	case AO_Mode_1_Register:
		offset = M_Offset_AO_Mode_1;
		break;
	case AO_Mode_2_Register:
		offset = M_Offset_AO_Mode_2;
		break;
	case AO_Mode_3_Register:
		offset = M_Offset_AO_Mode_3;
		break;
	case AO_Output_Control_Register:
		offset = M_Offset_AO_Output_Control;
		break;
	case AO_Personal_Register:
		offset = M_Offset_AO_Personal;
		break;
	case AO_Start_Select_Register:
		offset = M_Offset_AO_Start_Select;
		break;
	case AO_Trigger_Select_Register:
		offset = M_Offset_AO_Trigger_Select;
		break;
	case Clock_and_FOUT_Register:
		offset = M_Offset_Clock_and_FOUT;
		break;
	case Configuration_Memory_Clear:
		offset = M_Offset_Configuration_Memory_Clear;
		break;
	case DAC_FIFO_Clear:
		offset = M_Offset_AO_FIFO_Clear;
		break;
	case DIO_Control_Register:
		printk
		    ("%s: FIXME: register 0x%x does not map cleanly on to m-series boards.\n",
		     __func__, reg);
		return;
		break;
	case G_Autoincrement_Register(0):
		offset = M_Offset_G0_Autoincrement;
		break;
	case G_Autoincrement_Register(1):
		offset = M_Offset_G1_Autoincrement;
		break;
	case G_Command_Register(0):
		offset = M_Offset_G0_Command;
		break;
	case G_Command_Register(1):
		offset = M_Offset_G1_Command;
		break;
	case G_Input_Select_Register(0):
		offset = M_Offset_G0_Input_Select;
		break;
	case G_Input_Select_Register(1):
		offset = M_Offset_G1_Input_Select;
		break;
	case G_Mode_Register(0):
		offset = M_Offset_G0_Mode;
		break;
	case G_Mode_Register(1):
		offset = M_Offset_G1_Mode;
		break;
	case Interrupt_A_Ack_Register:
		offset = M_Offset_Interrupt_A_Ack;
		break;
	case Interrupt_A_Enable_Register:
		offset = M_Offset_Interrupt_A_Enable;
		break;
	case Interrupt_B_Ack_Register:
		offset = M_Offset_Interrupt_B_Ack;
		break;
	case Interrupt_B_Enable_Register:
		offset = M_Offset_Interrupt_B_Enable;
		break;
	case Interrupt_Control_Register:
		offset = M_Offset_Interrupt_Control;
		break;
	case IO_Bidirection_Pin_Register:
		offset = M_Offset_IO_Bidirection_Pin;
		break;
	case Joint_Reset_Register:
		offset = M_Offset_Joint_Reset;
		break;
	case RTSI_Trig_A_Output_Register:
		offset = M_Offset_RTSI_Trig_A_Output;
		break;
	case RTSI_Trig_B_Output_Register:
		offset = M_Offset_RTSI_Trig_B_Output;
		break;
	case RTSI_Trig_Direction_Register:
		offset = M_Offset_RTSI_Trig_Direction;
		break;
		/* FIXME: DIO_Output_Register (16 bit reg) is replaced by M_Offset_Static_Digital_Output (32 bit)
		   and M_Offset_SCXI_Serial_Data_Out (8 bit) */
	default:
		printk(KERN_WARNING "%s: bug! unhandled register=0x%x in switch.\n",
		       __func__, reg);
		BUG();
		return;
		break;
	}
	ni_writew(data, offset);
}

static uint16_t m_series_stc_readw(struct comedi_device *dev, int reg)
{
	unsigned offset;
	switch (reg) {
	case AI_Status_1_Register:
		offset = M_Offset_AI_Status_1;
		break;
	case AO_Status_1_Register:
		offset = M_Offset_AO_Status_1;
		break;
	case AO_Status_2_Register:
		offset = M_Offset_AO_Status_2;
		break;
	case DIO_Serial_Input_Register:
		return ni_readb(M_Offset_SCXI_Serial_Data_In);
		break;
	case Joint_Status_1_Register:
		offset = M_Offset_Joint_Status_1;
		break;
	case Joint_Status_2_Register:
		offset = M_Offset_Joint_Status_2;
		break;
	case G_Status_Register:
		offset = M_Offset_G01_Status;
		break;
	default:
		printk(KERN_WARNING "%s: bug! unhandled register=0x%x in switch.\n",
		       __func__, reg);
		BUG();
		return 0;
		break;
	}
	return ni_readw(offset);
}

static void m_series_stc_writel(struct comedi_device *dev, uint32_t data,
				int reg)
{
	unsigned offset;
	switch (reg) {
	case AI_SC_Load_A_Registers:
		offset = M_Offset_AI_SC_Load_A;
		break;
	case AI_SI_Load_A_Registers:
		offset = M_Offset_AI_SI_Load_A;
		break;
	case AO_BC_Load_A_Register:
		offset = M_Offset_AO_BC_Load_A;
		break;
	case AO_UC_Load_A_Register:
		offset = M_Offset_AO_UC_Load_A;
		break;
	case AO_UI_Load_A_Register:
		offset = M_Offset_AO_UI_Load_A;
		break;
	case G_Load_A_Register(0):
		offset = M_Offset_G0_Load_A;
		break;
	case G_Load_A_Register(1):
		offset = M_Offset_G1_Load_A;
		break;
	case G_Load_B_Register(0):
		offset = M_Offset_G0_Load_B;
		break;
	case G_Load_B_Register(1):
		offset = M_Offset_G1_Load_B;
		break;
	default:
		printk(KERN_WARNING "%s: bug! unhandled register=0x%x in switch.\n",
		       __func__, reg);
		BUG();
		return;
		break;
	}
	ni_writel(data, offset);
}

static uint32_t m_series_stc_readl(struct comedi_device *dev, int reg)
{
	unsigned offset;
	switch (reg) {
	case G_HW_Save_Register(0):
		offset = M_Offset_G0_HW_Save;
		break;
	case G_HW_Save_Register(1):
		offset = M_Offset_G1_HW_Save;
		break;
	case G_Save_Register(0):
		offset = M_Offset_G0_Save;
		break;
	case G_Save_Register(1):
		offset = M_Offset_G1_Save;
		break;
	default:
		printk(KERN_WARNING "%s: bug! unhandled register=0x%x in switch.\n",
		       __func__, reg);
		BUG();
		return 0;
		break;
	}
	return ni_readl(offset);
}

#define interrupt_pin(a)	0
#define IRQ_POLARITY 1

#define NI_E_IRQ_FLAGS		IRQF_SHARED

#include "ni_mio_common.c"

static int pcimio_find_device(struct comedi_device *dev, int bus, int slot);
static int pcimio_ai_change(struct comedi_device *dev,
			    struct comedi_subdevice *s, unsigned long new_size);
static int pcimio_ao_change(struct comedi_device *dev,
			    struct comedi_subdevice *s, unsigned long new_size);
static int pcimio_gpct0_change(struct comedi_device *dev,
			       struct comedi_subdevice *s,
			       unsigned long new_size);
static int pcimio_gpct1_change(struct comedi_device *dev,
			       struct comedi_subdevice *s,
			       unsigned long new_size);
static int pcimio_dio_change(struct comedi_device *dev,
			     struct comedi_subdevice *s,
			     unsigned long new_size);

static void m_series_init_eeprom_buffer(struct comedi_device *dev)
{
	static const int Start_Cal_EEPROM = 0x400;
	static const unsigned window_size = 10;
	static const int serial_number_eeprom_offset = 0x4;
	static const int serial_number_eeprom_length = 0x4;
	unsigned old_iodwbsr_bits;
	unsigned old_iodwbsr1_bits;
	unsigned old_iodwcr1_bits;
	int i;

	old_iodwbsr_bits = readl(devpriv->mite->mite_io_addr + MITE_IODWBSR);
	old_iodwbsr1_bits = readl(devpriv->mite->mite_io_addr + MITE_IODWBSR_1);
	old_iodwcr1_bits = readl(devpriv->mite->mite_io_addr + MITE_IODWCR_1);
	writel(0x0, devpriv->mite->mite_io_addr + MITE_IODWBSR);
	writel(((0x80 | window_size) | devpriv->mite->daq_phys_addr),
	       devpriv->mite->mite_io_addr + MITE_IODWBSR_1);
	writel(0x1 | old_iodwcr1_bits,
	       devpriv->mite->mite_io_addr + MITE_IODWCR_1);
	writel(0xf, devpriv->mite->mite_io_addr + 0x30);

	BUG_ON(serial_number_eeprom_length > sizeof(devpriv->serial_number));
	for (i = 0; i < serial_number_eeprom_length; ++i) {
		char *byte_ptr = (char *)&devpriv->serial_number + i;
		*byte_ptr = ni_readb(serial_number_eeprom_offset + i);
	}
	devpriv->serial_number = be32_to_cpu(devpriv->serial_number);

	for (i = 0; i < M_SERIES_EEPROM_SIZE; ++i)
		devpriv->eeprom_buffer[i] = ni_readb(Start_Cal_EEPROM + i);

	writel(old_iodwbsr1_bits, devpriv->mite->mite_io_addr + MITE_IODWBSR_1);
	writel(old_iodwbsr_bits, devpriv->mite->mite_io_addr + MITE_IODWBSR);
	writel(old_iodwcr1_bits, devpriv->mite->mite_io_addr + MITE_IODWCR_1);
	writel(0x0, devpriv->mite->mite_io_addr + 0x30);
}

static void init_6143(struct comedi_device *dev)
{
	/*  Disable interrupts */
	devpriv->stc_writew(dev, 0, Interrupt_Control_Register);

	/*  Initialise 6143 AI specific bits */
	ni_writeb(0x00, Magic_6143);	/*  Set G0,G1 DMA mode to E series version */
	ni_writeb(0x80, PipelineDelay_6143);	/*  Set EOCMode, ADCMode and pipelinedelay */
	ni_writeb(0x00, EOC_Set_6143);	/*  Set EOC Delay */

	ni_writel(boardtype.ai_fifo_depth / 2, AIFIFO_Flag_6143);	/*  Set the FIFO half full level */

	/*  Strobe Relay disable bit */
	devpriv->ai_calib_source_enabled = 0;
	ni_writew(devpriv->ai_calib_source | Calibration_Channel_6143_RelayOff,
		  Calibration_Channel_6143);
	ni_writew(devpriv->ai_calib_source, Calibration_Channel_6143);
}

/* cleans up allocated resources */
static int pcimio_detach(struct comedi_device *dev)
{
	mio_common_detach(dev);
	if (dev->irq)
		free_irq(dev->irq, dev);

	if (dev->private) {
		mite_free_ring(devpriv->ai_mite_ring);
		mite_free_ring(devpriv->ao_mite_ring);
		mite_free_ring(devpriv->cdo_mite_ring);
		mite_free_ring(devpriv->gpct_mite_ring[0]);
		mite_free_ring(devpriv->gpct_mite_ring[1]);
		if (devpriv->mite)
			mite_unsetup(devpriv->mite);
	}

	return 0;
}

static int pcimio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{
	int ret;

	dev_info(dev->hw_dev, "comedi%d: ni_pcimio:\n", dev->minor);

	ret = ni_alloc_private(dev);
	if (ret < 0)
		return ret;

	ret = pcimio_find_device(dev, it->options[0], it->options[1]);
	if (ret < 0)
		return ret;

	dev_dbg(dev->hw_dev, "%s\n", boardtype.name);
	dev->board_name = boardtype.name;

	if (boardtype.reg_type & ni_reg_m_series_mask) {
		devpriv->stc_writew = &m_series_stc_writew;
		devpriv->stc_readw = &m_series_stc_readw;
		devpriv->stc_writel = &m_series_stc_writel;
		devpriv->stc_readl = &m_series_stc_readl;
	} else {
		devpriv->stc_writew = &e_series_win_out;
		devpriv->stc_readw = &e_series_win_in;
		devpriv->stc_writel = &win_out2;
		devpriv->stc_readl = &win_in2;
	}

	ret = mite_setup(devpriv->mite);
	if (ret < 0) {
		pr_warn("error setting up mite\n");
		return ret;
	}
	comedi_set_hw_dev(dev, &devpriv->mite->pcidev->dev);
	devpriv->ai_mite_ring = mite_alloc_ring(devpriv->mite);
	if (devpriv->ai_mite_ring == NULL)
		return -ENOMEM;
	devpriv->ao_mite_ring = mite_alloc_ring(devpriv->mite);
	if (devpriv->ao_mite_ring == NULL)
		return -ENOMEM;
	devpriv->cdo_mite_ring = mite_alloc_ring(devpriv->mite);
	if (devpriv->cdo_mite_ring == NULL)
		return -ENOMEM;
	devpriv->gpct_mite_ring[0] = mite_alloc_ring(devpriv->mite);
	if (devpriv->gpct_mite_ring[0] == NULL)
		return -ENOMEM;
	devpriv->gpct_mite_ring[1] = mite_alloc_ring(devpriv->mite);
	if (devpriv->gpct_mite_ring[1] == NULL)
		return -ENOMEM;

	if (boardtype.reg_type & ni_reg_m_series_mask)
		m_series_init_eeprom_buffer(dev);
	if (boardtype.reg_type == ni_reg_6143)
		init_6143(dev);

	dev->irq = mite_irq(devpriv->mite);

	if (dev->irq == 0) {
		pr_warn("unknown irq (bad)\n");
	} else {
		pr_debug("( irq = %u )\n", dev->irq);
		ret = request_irq(dev->irq, ni_E_interrupt, NI_E_IRQ_FLAGS,
				  DRV_NAME, dev);
		if (ret < 0) {
			pr_warn("irq not available\n");
			dev->irq = 0;
		}
	}

	ret = ni_E_init(dev, it);
	if (ret < 0)
		return ret;

	dev->subdevices[NI_AI_SUBDEV].buf_change = &pcimio_ai_change;
	dev->subdevices[NI_AO_SUBDEV].buf_change = &pcimio_ao_change;
	dev->subdevices[NI_GPCT_SUBDEV(0)].buf_change = &pcimio_gpct0_change;
	dev->subdevices[NI_GPCT_SUBDEV(1)].buf_change = &pcimio_gpct1_change;
	dev->subdevices[NI_DIO_SUBDEV].buf_change = &pcimio_dio_change;

	return ret;
}

static int pcimio_find_device(struct comedi_device *dev, int bus, int slot)
{
	struct mite_struct *mite;
	int i;

	for (mite = mite_devices; mite; mite = mite->next) {
		if (mite->used)
			continue;
		if (bus || slot) {
			if (bus != mite->pcidev->bus->number ||
			    slot != PCI_SLOT(mite->pcidev->devfn))
				continue;
		}

		for (i = 0; i < n_pcimio_boards; i++) {
			if (mite_device_id(mite) == ni_boards[i].device_id) {
				dev->board_ptr = ni_boards + i;
				devpriv->mite = mite;

				return 0;
			}
		}
	}
	pr_warn("no device found\n");
	mite_list_devices();
	return -EIO;
}

static int pcimio_ai_change(struct comedi_device *dev,
			    struct comedi_subdevice *s, unsigned long new_size)
{
	int ret;

	ret = mite_buf_change(devpriv->ai_mite_ring, s->async);
	if (ret < 0)
		return ret;

	return 0;
}

static int pcimio_ao_change(struct comedi_device *dev,
			    struct comedi_subdevice *s, unsigned long new_size)
{
	int ret;

	ret = mite_buf_change(devpriv->ao_mite_ring, s->async);
	if (ret < 0)
		return ret;

	return 0;
}

static int pcimio_gpct0_change(struct comedi_device *dev,
			       struct comedi_subdevice *s,
			       unsigned long new_size)
{
	int ret;

	ret = mite_buf_change(devpriv->gpct_mite_ring[0], s->async);
	if (ret < 0)
		return ret;

	return 0;
}

static int pcimio_gpct1_change(struct comedi_device *dev,
			       struct comedi_subdevice *s,
			       unsigned long new_size)
{
	int ret;

	ret = mite_buf_change(devpriv->gpct_mite_ring[1], s->async);
	if (ret < 0)
		return ret;

	return 0;
}

static int pcimio_dio_change(struct comedi_device *dev,
			     struct comedi_subdevice *s, unsigned long new_size)
{
	int ret;

	ret = mite_buf_change(devpriv->cdo_mite_ring, s->async);
	if (ret < 0)
		return ret;

	return 0;
}

MODULE_AUTHOR("Comedi http://www.comedi.org");
MODULE_DESCRIPTION("Comedi low-level driver");
MODULE_LICENSE("GPL");