Loading...
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 | /*
comedi/drivers/dt282x.c
Hardware driver for Data Translation DT2821 series
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.
*/
/*
Driver: dt282x
Description: Data Translation DT2821 series (including DT-EZ)
Author: ds
Devices: [Data Translation] DT2821 (dt2821),
DT2821-F-16SE (dt2821-f), DT2821-F-8DI (dt2821-f),
DT2821-G-16SE (dt2821-f), DT2821-G-8DI (dt2821-g),
DT2823 (dt2823),
DT2824-PGH (dt2824-pgh), DT2824-PGL (dt2824-pgl), DT2825 (dt2825),
DT2827 (dt2827), DT2828 (dt2828), DT21-EZ (dt21-ez), DT23-EZ (dt23-ez),
DT24-EZ (dt24-ez), DT24-EZ-PGL (dt24-ez-pgl)
Status: complete
Updated: Wed, 22 Aug 2001 17:11:34 -0700
Configuration options:
[0] - I/O port base address
[1] - IRQ
[2] - DMA 1
[3] - DMA 2
[4] - AI jumpered for 0=single ended, 1=differential
[5] - AI jumpered for 0=straight binary, 1=2's complement
[6] - AO 0 jumpered for 0=straight binary, 1=2's complement
[7] - AO 1 jumpered for 0=straight binary, 1=2's complement
[8] - AI jumpered for 0=[-10,10]V, 1=[0,10], 2=[-5,5], 3=[0,5]
[9] - AO 0 jumpered for 0=[-10,10]V, 1=[0,10], 2=[-5,5], 3=[0,5],
4=[-2.5,2.5]
[10]- A0 1 jumpered for 0=[-10,10]V, 1=[0,10], 2=[-5,5], 3=[0,5],
4=[-2.5,2.5]
Notes:
- AO commands might be broken.
- If you try to run a command on both the AI and AO subdevices
simultaneously, bad things will happen. The driver needs to
be fixed to check for this situation and return an error.
*/
#include "../comedidev.h"
#include <linux/gfp.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <asm/dma.h>
#include "comedi_fc.h"
#define DEBUG
#define DT2821_TIMEOUT 100 /* 500 us */
#define DT2821_SIZE 0x10
/*
* Registers in the DT282x
*/
#define DT2821_ADCSR 0x00 /* A/D Control/Status */
#define DT2821_CHANCSR 0x02 /* Channel Control/Status */
#define DT2821_ADDAT 0x04 /* A/D data */
#define DT2821_DACSR 0x06 /* D/A Control/Status */
#define DT2821_DADAT 0x08 /* D/A data */
#define DT2821_DIODAT 0x0a /* digital data */
#define DT2821_SUPCSR 0x0c /* Supervisor Control/Status */
#define DT2821_TMRCTR 0x0e /* Timer/Counter */
/*
* At power up, some registers are in a well-known state. The
* masks and values are as follows:
*/
#define DT2821_ADCSR_MASK 0xfff0
#define DT2821_ADCSR_VAL 0x7c00
#define DT2821_CHANCSR_MASK 0xf0f0
#define DT2821_CHANCSR_VAL 0x70f0
#define DT2821_DACSR_MASK 0x7c93
#define DT2821_DACSR_VAL 0x7c90
#define DT2821_SUPCSR_MASK 0xf8ff
#define DT2821_SUPCSR_VAL 0x0000
#define DT2821_TMRCTR_MASK 0xff00
#define DT2821_TMRCTR_VAL 0xf000
/*
* Bit fields of each register
*/
/* ADCSR */
#define DT2821_ADERR 0x8000 /* (R) 1 for A/D error */
#define DT2821_ADCLK 0x0200 /* (R/W) A/D clock enable */
/* 0x7c00 read as 1's */
#define DT2821_MUXBUSY 0x0100 /* (R) multiplexer busy */
#define DT2821_ADDONE 0x0080 /* (R) A/D done */
#define DT2821_IADDONE 0x0040 /* (R/W) interrupt on A/D done */
/* 0x0030 gain select */
/* 0x000f channel select */
/* CHANCSR */
#define DT2821_LLE 0x8000 /* (R/W) Load List Enable */
/* 0x7000 read as 1's */
/* 0x0f00 (R) present address */
/* 0x00f0 read as 1's */
/* 0x000f (R) number of entries - 1 */
/* DACSR */
#define DT2821_DAERR 0x8000 /* (R) D/A error */
#define DT2821_YSEL 0x0200 /* (R/W) DAC 1 select */
#define DT2821_SSEL 0x0100 /* (R/W) single channel select */
#define DT2821_DACRDY 0x0080 /* (R) DAC ready */
#define DT2821_IDARDY 0x0040 /* (R/W) interrupt on DAC ready */
#define DT2821_DACLK 0x0020 /* (R/W) D/A clock enable */
#define DT2821_HBOE 0x0002 /* (R/W) DIO high byte output enable */
#define DT2821_LBOE 0x0001 /* (R/W) DIO low byte output enable */
/* SUPCSR */
#define DT2821_DMAD 0x8000 /* (R) DMA done */
#define DT2821_ERRINTEN 0x4000 /* (R/W) interrupt on error */
#define DT2821_CLRDMADNE 0x2000 /* (W) clear DMA done */
#define DT2821_DDMA 0x1000 /* (R/W) dual DMA */
#define DT2821_DS1 0x0800 /* (R/W) DMA select 1 */
#define DT2821_DS0 0x0400 /* (R/W) DMA select 0 */
#define DT2821_BUFFB 0x0200 /* (R/W) buffer B selected */
#define DT2821_SCDN 0x0100 /* (R) scan done */
#define DT2821_DACON 0x0080 /* (W) DAC single conversion */
#define DT2821_ADCINIT 0x0040 /* (W) A/D initialize */
#define DT2821_DACINIT 0x0020 /* (W) D/A initialize */
#define DT2821_PRLD 0x0010 /* (W) preload multiplexer */
#define DT2821_STRIG 0x0008 /* (W) software trigger */
#define DT2821_XTRIG 0x0004 /* (R/W) external trigger enable */
#define DT2821_XCLK 0x0002 /* (R/W) external clock enable */
#define DT2821_BDINIT 0x0001 /* (W) initialize board */
static const struct comedi_lrange range_dt282x_ai_lo_bipolar = {
4, {
RANGE(-10, 10),
RANGE(-5, 5),
RANGE(-2.5, 2.5),
RANGE(-1.25, 1.25)
}
};
static const struct comedi_lrange range_dt282x_ai_lo_unipolar = {
4, {
RANGE(0, 10),
RANGE(0, 5),
RANGE(0, 2.5),
RANGE(0, 1.25)
}
};
static const struct comedi_lrange range_dt282x_ai_5_bipolar = {
4, {
RANGE(-5, 5),
RANGE(-2.5, 2.5),
RANGE(-1.25, 1.25),
RANGE(-0.625, 0.625)
}
};
static const struct comedi_lrange range_dt282x_ai_5_unipolar = {
4, {
RANGE(0, 5),
RANGE(0, 2.5),
RANGE(0, 1.25),
RANGE(0, 0.625),
}
};
static const struct comedi_lrange range_dt282x_ai_hi_bipolar = {
4, {
RANGE(-10, 10),
RANGE(-1, 1),
RANGE(-0.1, 0.1),
RANGE(-0.02, 0.02)
}
};
static const struct comedi_lrange range_dt282x_ai_hi_unipolar = {
4, {
RANGE(0, 10),
RANGE(0, 1),
RANGE(0, 0.1),
RANGE(0, 0.02)
}
};
struct dt282x_board {
const char *name;
int adbits;
int adchan_se;
int adchan_di;
int ai_speed;
int ispgl;
int dachan;
int dabits;
};
struct dt282x_private {
int ad_2scomp; /* we have 2's comp jumper set */
int da0_2scomp; /* same, for DAC0 */
int da1_2scomp; /* same, for DAC1 */
const struct comedi_lrange *darangelist[2];
short ao[2];
volatile int dacsr; /* software copies of registers */
volatile int adcsr;
volatile int supcsr;
volatile int ntrig;
volatile int nread;
struct {
int chan;
short *buf; /* DMA buffer */
volatile int size; /* size of current transfer */
} dma[2];
int dma_maxsize; /* max size of DMA transfer (in bytes) */
int usedma; /* driver uses DMA */
volatile int current_dma_index;
int dma_dir;
};
/*
* Some useless abstractions
*/
#define chan_to_DAC(a) ((a)&1)
#define mux_busy() (inw(dev->iobase+DT2821_ADCSR)&DT2821_MUXBUSY)
#define ad_done() (inw(dev->iobase+DT2821_ADCSR)&DT2821_ADDONE)
/*
* danger! macro abuse... a is the expression to wait on, and b is
* the statement(s) to execute if it doesn't happen.
*/
#define wait_for(a, b) \
do { \
int _i; \
for (_i = 0; _i < DT2821_TIMEOUT; _i++) { \
if (a) { \
_i = 0; \
break; \
} \
udelay(5); \
} \
if (_i) { \
b \
} \
} while (0)
static int prep_ai_dma(struct comedi_device *dev, int chan, int size);
static int prep_ao_dma(struct comedi_device *dev, int chan, int size);
static int dt282x_ai_cancel(struct comedi_device *dev,
struct comedi_subdevice *s);
static int dt282x_ao_cancel(struct comedi_device *dev,
struct comedi_subdevice *s);
static int dt282x_ns_to_timer(int *nanosec, int round_mode);
static void dt282x_disable_dma(struct comedi_device *dev);
static int dt282x_grab_dma(struct comedi_device *dev, int dma1, int dma2);
static void dt282x_munge(struct comedi_device *dev, short *buf,
unsigned int nbytes)
{
const struct dt282x_board *board = comedi_board(dev);
struct dt282x_private *devpriv = dev->private;
unsigned int i;
unsigned short mask = (1 << board->adbits) - 1;
unsigned short sign = 1 << (board->adbits - 1);
int n;
if (devpriv->ad_2scomp)
sign = 1 << (board->adbits - 1);
else
sign = 0;
if (nbytes % 2)
comedi_error(dev, "bug! odd number of bytes from dma xfer");
n = nbytes / 2;
for (i = 0; i < n; i++)
buf[i] = (buf[i] & mask) ^ sign;
}
static void dt282x_ao_dma_interrupt(struct comedi_device *dev)
{
struct dt282x_private *devpriv = dev->private;
void *ptr;
int size;
int i;
struct comedi_subdevice *s = &dev->subdevices[1];
outw(devpriv->supcsr | DT2821_CLRDMADNE, dev->iobase + DT2821_SUPCSR);
if (!s->async->prealloc_buf) {
printk(KERN_ERR "async->data disappeared. dang!\n");
return;
}
i = devpriv->current_dma_index;
ptr = devpriv->dma[i].buf;
disable_dma(devpriv->dma[i].chan);
devpriv->current_dma_index = 1 - i;
size = cfc_read_array_from_buffer(s, ptr, devpriv->dma_maxsize);
if (size == 0) {
printk(KERN_ERR "dt282x: AO underrun\n");
dt282x_ao_cancel(dev, s);
s->async->events |= COMEDI_CB_OVERFLOW;
return;
}
prep_ao_dma(dev, i, size);
return;
}
static void dt282x_ai_dma_interrupt(struct comedi_device *dev)
{
struct dt282x_private *devpriv = dev->private;
void *ptr;
int size;
int i;
int ret;
struct comedi_subdevice *s = &dev->subdevices[0];
outw(devpriv->supcsr | DT2821_CLRDMADNE, dev->iobase + DT2821_SUPCSR);
if (!s->async->prealloc_buf) {
printk(KERN_ERR "async->data disappeared. dang!\n");
return;
}
i = devpriv->current_dma_index;
ptr = devpriv->dma[i].buf;
size = devpriv->dma[i].size;
disable_dma(devpriv->dma[i].chan);
devpriv->current_dma_index = 1 - i;
dt282x_munge(dev, ptr, size);
ret = cfc_write_array_to_buffer(s, ptr, size);
if (ret != size) {
dt282x_ai_cancel(dev, s);
return;
}
devpriv->nread -= size / 2;
if (devpriv->nread < 0) {
printk(KERN_INFO "dt282x: off by one\n");
devpriv->nread = 0;
}
if (!devpriv->nread) {
dt282x_ai_cancel(dev, s);
s->async->events |= COMEDI_CB_EOA;
return;
}
#if 0
/* clear the dual dma flag, making this the last dma segment */
/* XXX probably wrong */
if (!devpriv->ntrig) {
devpriv->supcsr &= ~(DT2821_DDMA);
outw(devpriv->supcsr, dev->iobase + DT2821_SUPCSR);
}
#endif
/* restart the channel */
prep_ai_dma(dev, i, 0);
}
static int prep_ai_dma(struct comedi_device *dev, int dma_index, int n)
{
struct dt282x_private *devpriv = dev->private;
int dma_chan;
unsigned long dma_ptr;
unsigned long flags;
if (!devpriv->ntrig)
return 0;
if (n == 0)
n = devpriv->dma_maxsize;
if (n > devpriv->ntrig * 2)
n = devpriv->ntrig * 2;
devpriv->ntrig -= n / 2;
devpriv->dma[dma_index].size = n;
dma_chan = devpriv->dma[dma_index].chan;
dma_ptr = virt_to_bus(devpriv->dma[dma_index].buf);
set_dma_mode(dma_chan, DMA_MODE_READ);
flags = claim_dma_lock();
clear_dma_ff(dma_chan);
set_dma_addr(dma_chan, dma_ptr);
set_dma_count(dma_chan, n);
release_dma_lock(flags);
enable_dma(dma_chan);
return n;
}
static int prep_ao_dma(struct comedi_device *dev, int dma_index, int n)
{
struct dt282x_private *devpriv = dev->private;
int dma_chan;
unsigned long dma_ptr;
unsigned long flags;
devpriv->dma[dma_index].size = n;
dma_chan = devpriv->dma[dma_index].chan;
dma_ptr = virt_to_bus(devpriv->dma[dma_index].buf);
set_dma_mode(dma_chan, DMA_MODE_WRITE);
flags = claim_dma_lock();
clear_dma_ff(dma_chan);
set_dma_addr(dma_chan, dma_ptr);
set_dma_count(dma_chan, n);
release_dma_lock(flags);
enable_dma(dma_chan);
return n;
}
static irqreturn_t dt282x_interrupt(int irq, void *d)
{
struct comedi_device *dev = d;
struct dt282x_private *devpriv = dev->private;
struct comedi_subdevice *s;
struct comedi_subdevice *s_ao;
unsigned int supcsr, adcsr, dacsr;
int handled = 0;
if (!dev->attached) {
comedi_error(dev, "spurious interrupt");
return IRQ_HANDLED;
}
s = &dev->subdevices[0];
s_ao = &dev->subdevices[1];
adcsr = inw(dev->iobase + DT2821_ADCSR);
dacsr = inw(dev->iobase + DT2821_DACSR);
supcsr = inw(dev->iobase + DT2821_SUPCSR);
if (supcsr & DT2821_DMAD) {
if (devpriv->dma_dir == DMA_MODE_READ)
dt282x_ai_dma_interrupt(dev);
else
dt282x_ao_dma_interrupt(dev);
handled = 1;
}
if (adcsr & DT2821_ADERR) {
if (devpriv->nread != 0) {
comedi_error(dev, "A/D error");
dt282x_ai_cancel(dev, s);
s->async->events |= COMEDI_CB_ERROR;
}
handled = 1;
}
if (dacsr & DT2821_DAERR) {
#if 0
static int warn = 5;
if (--warn <= 0) {
disable_irq(dev->irq);
printk(KERN_INFO "disabling irq\n");
}
#endif
comedi_error(dev, "D/A error");
dt282x_ao_cancel(dev, s_ao);
s->async->events |= COMEDI_CB_ERROR;
handled = 1;
}
#if 0
if (adcsr & DT2821_ADDONE) {
int ret;
short data;
data = (short)inw(dev->iobase + DT2821_ADDAT);
data &= (1 << board->adbits) - 1;
if (devpriv->ad_2scomp)
data ^= 1 << (board->adbits - 1);
ret = comedi_buf_put(s->async, data);
if (ret == 0)
s->async->events |= COMEDI_CB_OVERFLOW;
devpriv->nread--;
if (!devpriv->nread) {
s->async->events |= COMEDI_CB_EOA;
} else {
if (supcsr & DT2821_SCDN)
outw(devpriv->supcsr | DT2821_STRIG,
dev->iobase + DT2821_SUPCSR);
}
handled = 1;
}
#endif
comedi_event(dev, s);
/* printk("adcsr=0x%02x dacsr-0x%02x supcsr=0x%02x\n",
adcsr, dacsr, supcsr); */
return IRQ_RETVAL(handled);
}
static void dt282x_load_changain(struct comedi_device *dev, int n,
unsigned int *chanlist)
{
struct dt282x_private *devpriv = dev->private;
unsigned int i;
unsigned int chan, range;
outw(DT2821_LLE | (n - 1), dev->iobase + DT2821_CHANCSR);
for (i = 0; i < n; i++) {
chan = CR_CHAN(chanlist[i]);
range = CR_RANGE(chanlist[i]);
outw(devpriv->adcsr | (range << 4) | chan,
dev->iobase + DT2821_ADCSR);
}
outw(n - 1, dev->iobase + DT2821_CHANCSR);
}
/*
* Performs a single A/D conversion.
* - Put channel/gain into channel-gain list
* - preload multiplexer
* - trigger conversion and wait for it to finish
*/
static int dt282x_ai_insn_read(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
const struct dt282x_board *board = comedi_board(dev);
struct dt282x_private *devpriv = dev->private;
int i;
/* XXX should we really be enabling the ad clock here? */
devpriv->adcsr = DT2821_ADCLK;
outw(devpriv->adcsr, dev->iobase + DT2821_ADCSR);
dt282x_load_changain(dev, 1, &insn->chanspec);
outw(devpriv->supcsr | DT2821_PRLD, dev->iobase + DT2821_SUPCSR);
wait_for(!mux_busy(), comedi_error(dev, "timeout\n"); return -ETIME;);
for (i = 0; i < insn->n; i++) {
outw(devpriv->supcsr | DT2821_STRIG,
dev->iobase + DT2821_SUPCSR);
wait_for(ad_done(), comedi_error(dev, "timeout\n");
return -ETIME;);
data[i] =
inw(dev->iobase +
DT2821_ADDAT) & ((1 << board->adbits) - 1);
if (devpriv->ad_2scomp)
data[i] ^= (1 << (board->adbits - 1));
}
return i;
}
static int dt282x_ai_cmdtest(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_cmd *cmd)
{
const struct dt282x_board *board = comedi_board(dev);
int err = 0;
int tmp;
/* Step 1 : check if triggers are trivially valid */
err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
err |= cfc_check_trigger_src(&cmd->scan_begin_src,
TRIG_FOLLOW | TRIG_EXT);
err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
if (err)
return 1;
/* Step 2a : make sure trigger sources are unique */
err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
err |= cfc_check_trigger_is_unique(cmd->stop_src);
/* Step 2b : and mutually compatible */
if (err)
return 2;
/* Step 3: check if arguments are trivially valid */
err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
if (cmd->scan_begin_src == TRIG_FOLLOW) {
/* internal trigger */
err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
} else {
/* external trigger */
/* should be level/edge, hi/lo specification here */
err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
}
err |= cfc_check_trigger_arg_min(&cmd->convert_arg, 4000);
#define SLOWEST_TIMER (250*(1<<15)*255)
err |= cfc_check_trigger_arg_max(&cmd->convert_arg, SLOWEST_TIMER);
err |= cfc_check_trigger_arg_min(&cmd->convert_arg, board->ai_speed);
err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
if (cmd->stop_src == TRIG_COUNT) {
/* any count is allowed */
} else { /* TRIG_NONE */
err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
}
if (err)
return 3;
/* step 4: fix up any arguments */
tmp = cmd->convert_arg;
dt282x_ns_to_timer(&cmd->convert_arg, cmd->flags & TRIG_ROUND_MASK);
if (tmp != cmd->convert_arg)
err++;
if (err)
return 4;
return 0;
}
static int dt282x_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
{
const struct dt282x_board *board = comedi_board(dev);
struct dt282x_private *devpriv = dev->private;
struct comedi_cmd *cmd = &s->async->cmd;
int timer;
if (devpriv->usedma == 0) {
comedi_error(dev,
"driver requires 2 dma channels"
" to execute command");
return -EIO;
}
dt282x_disable_dma(dev);
if (cmd->convert_arg < board->ai_speed)
cmd->convert_arg = board->ai_speed;
timer = dt282x_ns_to_timer(&cmd->convert_arg, TRIG_ROUND_NEAREST);
outw(timer, dev->iobase + DT2821_TMRCTR);
if (cmd->scan_begin_src == TRIG_FOLLOW) {
/* internal trigger */
devpriv->supcsr = DT2821_ERRINTEN | DT2821_DS0;
} else {
/* external trigger */
devpriv->supcsr = DT2821_ERRINTEN | DT2821_DS0 | DT2821_DS1;
}
outw(devpriv->supcsr | DT2821_CLRDMADNE | DT2821_BUFFB | DT2821_ADCINIT,
dev->iobase + DT2821_SUPCSR);
devpriv->ntrig = cmd->stop_arg * cmd->scan_end_arg;
devpriv->nread = devpriv->ntrig;
devpriv->dma_dir = DMA_MODE_READ;
devpriv->current_dma_index = 0;
prep_ai_dma(dev, 0, 0);
if (devpriv->ntrig) {
prep_ai_dma(dev, 1, 0);
devpriv->supcsr |= DT2821_DDMA;
outw(devpriv->supcsr, dev->iobase + DT2821_SUPCSR);
}
devpriv->adcsr = 0;
dt282x_load_changain(dev, cmd->chanlist_len, cmd->chanlist);
devpriv->adcsr = DT2821_ADCLK | DT2821_IADDONE;
outw(devpriv->adcsr, dev->iobase + DT2821_ADCSR);
outw(devpriv->supcsr | DT2821_PRLD, dev->iobase + DT2821_SUPCSR);
wait_for(!mux_busy(), comedi_error(dev, "timeout\n"); return -ETIME;);
if (cmd->scan_begin_src == TRIG_FOLLOW) {
outw(devpriv->supcsr | DT2821_STRIG,
dev->iobase + DT2821_SUPCSR);
} else {
devpriv->supcsr |= DT2821_XTRIG;
outw(devpriv->supcsr, dev->iobase + DT2821_SUPCSR);
}
return 0;
}
static void dt282x_disable_dma(struct comedi_device *dev)
{
struct dt282x_private *devpriv = dev->private;
if (devpriv->usedma) {
disable_dma(devpriv->dma[0].chan);
disable_dma(devpriv->dma[1].chan);
}
}
static int dt282x_ai_cancel(struct comedi_device *dev,
struct comedi_subdevice *s)
{
struct dt282x_private *devpriv = dev->private;
dt282x_disable_dma(dev);
devpriv->adcsr = 0;
outw(devpriv->adcsr, dev->iobase + DT2821_ADCSR);
devpriv->supcsr = 0;
outw(devpriv->supcsr | DT2821_ADCINIT, dev->iobase + DT2821_SUPCSR);
return 0;
}
static int dt282x_ns_to_timer(int *nanosec, int round_mode)
{
int prescale, base, divider;
for (prescale = 0; prescale < 16; prescale++) {
if (prescale == 1)
continue;
base = 250 * (1 << prescale);
switch (round_mode) {
case TRIG_ROUND_NEAREST:
default:
divider = (*nanosec + base / 2) / base;
break;
case TRIG_ROUND_DOWN:
divider = (*nanosec) / base;
break;
case TRIG_ROUND_UP:
divider = (*nanosec + base - 1) / base;
break;
}
if (divider < 256) {
*nanosec = divider * base;
return (prescale << 8) | (255 - divider);
}
}
base = 250 * (1 << 15);
divider = 255;
*nanosec = divider * base;
return (15 << 8) | (255 - divider);
}
/*
* Analog output routine. Selects single channel conversion,
* selects correct channel, converts from 2's compliment to
* offset binary if necessary, loads the data into the DAC
* data register, and performs the conversion.
*/
static int dt282x_ao_insn_read(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
struct dt282x_private *devpriv = dev->private;
data[0] = devpriv->ao[CR_CHAN(insn->chanspec)];
return 1;
}
static int dt282x_ao_insn_write(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
const struct dt282x_board *board = comedi_board(dev);
struct dt282x_private *devpriv = dev->private;
short d;
unsigned int chan;
chan = CR_CHAN(insn->chanspec);
d = data[0];
d &= (1 << board->dabits) - 1;
devpriv->ao[chan] = d;
devpriv->dacsr |= DT2821_SSEL;
if (chan) {
/* select channel */
devpriv->dacsr |= DT2821_YSEL;
if (devpriv->da0_2scomp)
d ^= (1 << (board->dabits - 1));
} else {
devpriv->dacsr &= ~DT2821_YSEL;
if (devpriv->da1_2scomp)
d ^= (1 << (board->dabits - 1));
}
outw(devpriv->dacsr, dev->iobase + DT2821_DACSR);
outw(d, dev->iobase + DT2821_DADAT);
outw(devpriv->supcsr | DT2821_DACON, dev->iobase + DT2821_SUPCSR);
return 1;
}
static int dt282x_ao_cmdtest(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_cmd *cmd)
{
int err = 0;
int tmp;
/* Step 1 : check if triggers are trivially valid */
err |= cfc_check_trigger_src(&cmd->start_src, TRIG_INT);
err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
if (err)
return 1;
/* Step 2a : make sure trigger sources are unique */
err |= cfc_check_trigger_is_unique(cmd->stop_src);
/* Step 2b : and mutually compatible */
if (err)
return 2;
/* Step 3: check if arguments are trivially valid */
err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg, 5000);
err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0);
err |= cfc_check_trigger_arg_max(&cmd->scan_end_arg, 2);
if (cmd->stop_src == TRIG_COUNT) {
/* any count is allowed */
} else { /* TRIG_NONE */
err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
}
if (err)
return 3;
/* step 4: fix up any arguments */
tmp = cmd->scan_begin_arg;
dt282x_ns_to_timer(&cmd->scan_begin_arg, cmd->flags & TRIG_ROUND_MASK);
if (tmp != cmd->scan_begin_arg)
err++;
if (err)
return 4;
return 0;
}
static int dt282x_ao_inttrig(struct comedi_device *dev,
struct comedi_subdevice *s, unsigned int x)
{
struct dt282x_private *devpriv = dev->private;
int size;
if (x != 0)
return -EINVAL;
size = cfc_read_array_from_buffer(s, devpriv->dma[0].buf,
devpriv->dma_maxsize);
if (size == 0) {
printk(KERN_ERR "dt282x: AO underrun\n");
return -EPIPE;
}
prep_ao_dma(dev, 0, size);
size = cfc_read_array_from_buffer(s, devpriv->dma[1].buf,
devpriv->dma_maxsize);
if (size == 0) {
printk(KERN_ERR "dt282x: AO underrun\n");
return -EPIPE;
}
prep_ao_dma(dev, 1, size);
outw(devpriv->supcsr | DT2821_STRIG, dev->iobase + DT2821_SUPCSR);
s->async->inttrig = NULL;
return 1;
}
static int dt282x_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
{
struct dt282x_private *devpriv = dev->private;
int timer;
struct comedi_cmd *cmd = &s->async->cmd;
if (devpriv->usedma == 0) {
comedi_error(dev,
"driver requires 2 dma channels"
" to execute command");
return -EIO;
}
dt282x_disable_dma(dev);
devpriv->supcsr = DT2821_ERRINTEN | DT2821_DS1 | DT2821_DDMA;
outw(devpriv->supcsr | DT2821_CLRDMADNE | DT2821_BUFFB | DT2821_DACINIT,
dev->iobase + DT2821_SUPCSR);
devpriv->ntrig = cmd->stop_arg * cmd->chanlist_len;
devpriv->nread = devpriv->ntrig;
devpriv->dma_dir = DMA_MODE_WRITE;
devpriv->current_dma_index = 0;
timer = dt282x_ns_to_timer(&cmd->scan_begin_arg, TRIG_ROUND_NEAREST);
outw(timer, dev->iobase + DT2821_TMRCTR);
devpriv->dacsr = DT2821_SSEL | DT2821_DACLK | DT2821_IDARDY;
outw(devpriv->dacsr, dev->iobase + DT2821_DACSR);
s->async->inttrig = dt282x_ao_inttrig;
return 0;
}
static int dt282x_ao_cancel(struct comedi_device *dev,
struct comedi_subdevice *s)
{
struct dt282x_private *devpriv = dev->private;
dt282x_disable_dma(dev);
devpriv->dacsr = 0;
outw(devpriv->dacsr, dev->iobase + DT2821_DACSR);
devpriv->supcsr = 0;
outw(devpriv->supcsr | DT2821_DACINIT, dev->iobase + DT2821_SUPCSR);
return 0;
}
static int dt282x_dio_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
if (data[0]) {
s->state &= ~data[0];
s->state |= (data[0] & data[1]);
outw(s->state, dev->iobase + DT2821_DIODAT);
}
data[1] = inw(dev->iobase + DT2821_DIODAT);
return insn->n;
}
static int dt282x_dio_insn_config(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
struct dt282x_private *devpriv = dev->private;
int mask;
mask = (CR_CHAN(insn->chanspec) < 8) ? 0x00ff : 0xff00;
if (data[0])
s->io_bits |= mask;
else
s->io_bits &= ~mask;
if (s->io_bits & 0x00ff)
devpriv->dacsr |= DT2821_LBOE;
else
devpriv->dacsr &= ~DT2821_LBOE;
if (s->io_bits & 0xff00)
devpriv->dacsr |= DT2821_HBOE;
else
devpriv->dacsr &= ~DT2821_HBOE;
outw(devpriv->dacsr, dev->iobase + DT2821_DACSR);
return 1;
}
static const struct comedi_lrange *const ai_range_table[] = {
&range_dt282x_ai_lo_bipolar,
&range_dt282x_ai_lo_unipolar,
&range_dt282x_ai_5_bipolar,
&range_dt282x_ai_5_unipolar
};
static const struct comedi_lrange *const ai_range_pgl_table[] = {
&range_dt282x_ai_hi_bipolar,
&range_dt282x_ai_hi_unipolar
};
static const struct comedi_lrange *opt_ai_range_lkup(int ispgl, int x)
{
if (ispgl) {
if (x < 0 || x >= 2)
x = 0;
return ai_range_pgl_table[x];
} else {
if (x < 0 || x >= 4)
x = 0;
return ai_range_table[x];
}
}
static const struct comedi_lrange *const ao_range_table[] = {
&range_bipolar10,
&range_unipolar10,
&range_bipolar5,
&range_unipolar5,
&range_bipolar2_5
};
static const struct comedi_lrange *opt_ao_range_lkup(int x)
{
if (x < 0 || x >= 5)
x = 0;
return ao_range_table[x];
}
enum { /* i/o base, irq, dma channels */
opt_iobase = 0, opt_irq, opt_dma1, opt_dma2,
opt_diff, /* differential */
opt_ai_twos, opt_ao0_twos, opt_ao1_twos, /* twos comp */
opt_ai_range, opt_ao0_range, opt_ao1_range, /* range */
};
static int dt282x_grab_dma(struct comedi_device *dev, int dma1, int dma2)
{
struct dt282x_private *devpriv = dev->private;
int ret;
devpriv->usedma = 0;
if (!dma1 && !dma2) {
printk(KERN_ERR " (no dma)");
return 0;
}
if (dma1 == dma2 || dma1 < 5 || dma2 < 5 || dma1 > 7 || dma2 > 7)
return -EINVAL;
if (dma2 < dma1) {
int i;
i = dma1;
dma1 = dma2;
dma2 = i;
}
ret = request_dma(dma1, "dt282x A");
if (ret)
return -EBUSY;
devpriv->dma[0].chan = dma1;
ret = request_dma(dma2, "dt282x B");
if (ret)
return -EBUSY;
devpriv->dma[1].chan = dma2;
devpriv->dma_maxsize = PAGE_SIZE;
devpriv->dma[0].buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
devpriv->dma[1].buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
if (!devpriv->dma[0].buf || !devpriv->dma[1].buf) {
printk(KERN_ERR " can't get DMA memory");
return -ENOMEM;
}
printk(KERN_INFO " (dma=%d,%d)", dma1, dma2);
devpriv->usedma = 1;
return 0;
}
/*
options:
0 i/o base
1 irq
2 dma1
3 dma2
4 0=single ended, 1=differential
5 ai 0=straight binary, 1=2's comp
6 ao0 0=straight binary, 1=2's comp
7 ao1 0=straight binary, 1=2's comp
8 ai 0=±10 V, 1=0-10 V, 2=±5 V, 3=0-5 V
9 ao0 0=±10 V, 1=0-10 V, 2=±5 V, 3=0-5 V, 4=±2.5 V
10 ao1 0=±10 V, 1=0-10 V, 2=±5 V, 3=0-5 V, 4=±2.5 V
*/
static int dt282x_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{
const struct dt282x_board *board = comedi_board(dev);
struct dt282x_private *devpriv;
int i, irq;
int ret;
struct comedi_subdevice *s;
ret = comedi_request_region(dev, it->options[0], DT2821_SIZE);
if (ret)
return ret;
outw(DT2821_BDINIT, dev->iobase + DT2821_SUPCSR);
i = inw(dev->iobase + DT2821_ADCSR);
#ifdef DEBUG
printk(KERN_DEBUG " fingerprint=%x,%x,%x,%x,%x",
inw(dev->iobase + DT2821_ADCSR),
inw(dev->iobase + DT2821_CHANCSR),
inw(dev->iobase + DT2821_DACSR),
inw(dev->iobase + DT2821_SUPCSR),
inw(dev->iobase + DT2821_TMRCTR));
#endif
if (((inw(dev->iobase + DT2821_ADCSR) & DT2821_ADCSR_MASK)
!= DT2821_ADCSR_VAL) ||
((inw(dev->iobase + DT2821_CHANCSR) & DT2821_CHANCSR_MASK)
!= DT2821_CHANCSR_VAL) ||
((inw(dev->iobase + DT2821_DACSR) & DT2821_DACSR_MASK)
!= DT2821_DACSR_VAL) ||
((inw(dev->iobase + DT2821_SUPCSR) & DT2821_SUPCSR_MASK)
!= DT2821_SUPCSR_VAL) ||
((inw(dev->iobase + DT2821_TMRCTR) & DT2821_TMRCTR_MASK)
!= DT2821_TMRCTR_VAL)) {
printk(KERN_ERR " board not found");
return -EIO;
}
/* should do board test */
irq = it->options[opt_irq];
#if 0
if (irq < 0) {
unsigned long flags;
int irqs;
save_flags(flags);
sti();
irqs = probe_irq_on();
/* trigger interrupt */
udelay(100);
irq = probe_irq_off(irqs);
restore_flags(flags);
if (0 /* error */)
printk(KERN_ERR " error probing irq (bad)");
}
#endif
if (irq > 0) {
printk(KERN_INFO " ( irq = %d )", irq);
ret = request_irq(irq, dt282x_interrupt, 0,
dev->board_name, dev);
if (ret < 0) {
printk(KERN_ERR " failed to get irq\n");
return -EIO;
}
dev->irq = irq;
} else if (irq == 0) {
printk(KERN_INFO " (no irq)");
} else {
#if 0
printk(KERN_INFO " (probe returned multiple irqs--bad)");
#else
printk(KERN_INFO " (irq probe not implemented)");
#endif
}
devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
if (!devpriv)
return -ENOMEM;
dev->private = devpriv;
ret = dt282x_grab_dma(dev, it->options[opt_dma1],
it->options[opt_dma2]);
if (ret < 0)
return ret;
ret = comedi_alloc_subdevices(dev, 3);
if (ret)
return ret;
s = &dev->subdevices[0];
dev->read_subdev = s;
/* ai subdevice */
s->type = COMEDI_SUBD_AI;
s->subdev_flags = SDF_READABLE | SDF_CMD_READ |
((it->options[opt_diff]) ? SDF_DIFF : SDF_COMMON);
s->n_chan =
(it->options[opt_diff]) ? board->adchan_di : board->adchan_se;
s->insn_read = dt282x_ai_insn_read;
s->do_cmdtest = dt282x_ai_cmdtest;
s->do_cmd = dt282x_ai_cmd;
s->cancel = dt282x_ai_cancel;
s->maxdata = (1 << board->adbits) - 1;
s->len_chanlist = 16;
s->range_table =
opt_ai_range_lkup(board->ispgl, it->options[opt_ai_range]);
devpriv->ad_2scomp = it->options[opt_ai_twos];
s = &dev->subdevices[1];
s->n_chan = board->dachan;
if (s->n_chan) {
/* ao subsystem */
s->type = COMEDI_SUBD_AO;
dev->write_subdev = s;
s->subdev_flags = SDF_WRITABLE | SDF_CMD_WRITE;
s->insn_read = dt282x_ao_insn_read;
s->insn_write = dt282x_ao_insn_write;
s->do_cmdtest = dt282x_ao_cmdtest;
s->do_cmd = dt282x_ao_cmd;
s->cancel = dt282x_ao_cancel;
s->maxdata = (1 << board->dabits) - 1;
s->len_chanlist = 2;
s->range_table_list = devpriv->darangelist;
devpriv->darangelist[0] =
opt_ao_range_lkup(it->options[opt_ao0_range]);
devpriv->darangelist[1] =
opt_ao_range_lkup(it->options[opt_ao1_range]);
devpriv->da0_2scomp = it->options[opt_ao0_twos];
devpriv->da1_2scomp = it->options[opt_ao1_twos];
} else {
s->type = COMEDI_SUBD_UNUSED;
}
s = &dev->subdevices[2];
/* dio subsystem */
s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
s->n_chan = 16;
s->insn_bits = dt282x_dio_insn_bits;
s->insn_config = dt282x_dio_insn_config;
s->maxdata = 1;
s->range_table = &range_digital;
printk(KERN_INFO "\n");
return 0;
}
static void dt282x_detach(struct comedi_device *dev)
{
struct dt282x_private *devpriv = dev->private;
if (dev->private) {
if (devpriv->dma[0].chan)
free_dma(devpriv->dma[0].chan);
if (devpriv->dma[1].chan)
free_dma(devpriv->dma[1].chan);
if (devpriv->dma[0].buf)
free_page((unsigned long)devpriv->dma[0].buf);
if (devpriv->dma[1].buf)
free_page((unsigned long)devpriv->dma[1].buf);
}
comedi_legacy_detach(dev);
}
static const struct dt282x_board boardtypes[] = {
{
.name = "dt2821",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 20000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
}, {
.name = "dt2821-f",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 6500,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
}, {
.name = "dt2821-g",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 4000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
}, {
.name = "dt2823",
.adbits = 16,
.adchan_se = 0,
.adchan_di = 4,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 2,
.dabits = 16,
}, {
.name = "dt2824-pgh",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 20000,
.ispgl = 0,
.dachan = 0,
.dabits = 0,
}, {
.name = "dt2824-pgl",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 20000,
.ispgl = 1,
.dachan = 0,
.dabits = 0,
}, {
.name = "dt2825",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 20000,
.ispgl = 1,
.dachan = 2,
.dabits = 12,
}, {
.name = "dt2827",
.adbits = 16,
.adchan_se = 0,
.adchan_di = 4,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
}, {
.name = "dt2828",
.adbits = 12,
.adchan_se = 4,
.adchan_di = 0,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
}, {
.name = "dt2829",
.adbits = 16,
.adchan_se = 8,
.adchan_di = 0,
.ai_speed = 33250,
.ispgl = 0,
.dachan = 2,
.dabits = 16,
}, {
.name = "dt21-ez",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
}, {
.name = "dt23-ez",
.adbits = 16,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 0,
.dabits = 0,
}, {
.name = "dt24-ez",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 0,
.dabits = 0,
}, {
.name = "dt24-ez-pgl",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 10000,
.ispgl = 1,
.dachan = 0,
.dabits = 0,
},
};
static struct comedi_driver dt282x_driver = {
.driver_name = "dt282x",
.module = THIS_MODULE,
.attach = dt282x_attach,
.detach = dt282x_detach,
.board_name = &boardtypes[0].name,
.num_names = ARRAY_SIZE(boardtypes),
.offset = sizeof(struct dt282x_board),
};
module_comedi_driver(dt282x_driver);
MODULE_AUTHOR("Comedi http://www.comedi.org");
MODULE_DESCRIPTION("Comedi low-level driver");
MODULE_LICENSE("GPL");
|