82 #include <linux/pci.h>
83 #include <linux/slab.h>
86 #include "../comedidev.h"
96 #define DEBUG_PRINT(format, args...) \
97 printk(KERN_DEBUG "das16: " format, ## args)
99 #define DEBUG_PRINT(format, args...)
102 #define DAS16_SIZE 20
103 #define DAS16_DMA_SIZE 0xff00
195 #define DAS16_AI_LSB 0
196 #define DAS16_AI_MSB 1
199 #define DAS16_AO_LSB(x) ((x) ? 6 : 4)
200 #define DAS16_AO_MSB(x) ((x) ? 7 : 5)
201 #define DAS16_STATUS 8
203 #define UNIPOLAR (1<<6)
204 #define DAS16_MUXBIT (1<<5)
205 #define DAS16_INT (1<<4)
206 #define DAS16_CONTROL 9
207 #define DAS16_INTE (1<<7)
208 #define DAS16_IRQ(x) (((x) & 0x7) << 4)
209 #define DMA_ENABLE (1<<2)
210 #define PACING_MASK 0x3
211 #define INT_PACER 0x03
212 #define EXT_PACER 0x02
213 #define DAS16_SOFT 0x00
214 #define DAS16_PACER 0x0A
215 #define DAS16_CTR0 (1<<1)
216 #define DAS16_TRIG0 (1<<0)
217 #define BURST_LEN_BITS(x) (((x) & 0xf) << 4)
218 #define DAS16_GAIN 0x0B
219 #define DAS16_CNTR0_DATA 0x0C
220 #define DAS16_CNTR1_DATA 0x0D
221 #define DAS16_CNTR2_DATA 0x0E
222 #define DAS16_CNTR_CONTROL 0x0F
223 #define DAS16_TERM_CNT 0x00
224 #define DAS16_ONE_SHOT 0x02
225 #define DAS16_RATE_GEN 0x04
226 #define DAS16_CNTR_LSB_MSB 0x30
227 #define DAS16_CNTR0 0x00
228 #define DAS16_CNTR1 0x40
229 #define DAS16_CNTR2 0x80
231 #define DAS1600_CONV 0x404
232 #define DAS1600_CONV_DISABLE 0x40
233 #define DAS1600_BURST 0x405
234 #define DAS1600_BURST_VAL 0x40
235 #define DAS1600_ENABLE 0x406
236 #define DAS1600_ENABLE_VAL 0x40
237 #define DAS1600_STATUS_B 0x407
238 #define DAS1600_BME 0x40
239 #define DAS1600_ME 0x20
240 #define DAS1600_CD 0x10
241 #define DAS1600_WS 0x02
242 #define DAS1600_CLK_10MHZ 0x01
252 static const struct comedi_lrange range_das1x01_unip = { 4, {
268 static const struct comedi_lrange range_das1x02_unip = { 4, {
302 static const int das16jr_gainlist[] = { 8, 0, 1, 2, 3, 4, 5, 6, 7 };
303 static const int das16jr_16_gainlist[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
304 static const int das1600_gainlist[] = { 0, 1, 2, 3 };
313 static const int *
const das16_gainlists[] = {
321 static const struct comedi_lrange *
const das16_ai_uni_lranges[] = {
329 static const struct comedi_lrange *
const das16_ai_bip_lranges[] = {
360 #define DAS16_TIMEOUT 1000
364 static inline int timer_period(
void)
395 #define devpriv ((struct das16_private_struct *)(dev->private))
402 int gain, start_chan,
i;
411 if (board->
size > 0x400)
418 if (board->
size > 0x400)
420 err |= cfc_check_trigger_src(&cmd->
convert_src, mask);
431 err |= cfc_check_trigger_is_unique(cmd->
convert_src);
432 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
492 i8253_cascade_ns_to_timer_2div(
devpriv->clockbase,
502 i8253_cascade_ns_to_timer_2div(
devpriv->clockbase,
518 (start_chan + i) % s->
n_chan) {
520 "entries in chanlist must be "
521 "consecutive channels, "
522 "counting upwards\n");
527 "entries in chanlist must all "
528 "have the same gain\n");
576 size =
devpriv->adc_byte_count;
581 static unsigned int das16_set_pacer(
struct comedi_device *dev,
unsigned int ns,
584 i8253_cascade_ns_to_timer_2div(
devpriv->clockbase, &(
devpriv->divisor1),
605 &&
devpriv->timer_mode == 0)) {
607 "irq (or use of 'timer mode') dma required to "
608 "execute comedi_cmd");
612 comedi_error(dev,
"isa dma transfers cannot be performed with "
613 "TRIG_RT, aborting");
621 if (board->
size > 0x400)
634 outb((das16_gainlists[board->
ai_pg])[range],
647 if (board->
size > 0x400) {
663 clear_dma_ff(
devpriv->dma_chan);
665 set_dma_addr(
devpriv->dma_chan,
668 devpriv->dma_transfer_size = das16_suggest_transfer_size(dev, cmd);
694 if (board->
size > 0x400)
703 const struct das16_board *board = comedi_board(dev);
720 if (board->
size > 0x400)
724 spin_unlock_irqrestore(&dev->
spinlock, flags);
740 const struct das16_board *board = comedi_board(dev);
758 outb((das16_gainlists[board->
ai_pg])[range],
762 for (n = 0; n < insn->
n; n++) {
770 if (i == DAS16_TIMEOUT) {
771 printk(
"das16: timeout\n");
777 data[
n] = ((lsb >> 4) & 0xf) | (msb << 4);
779 data[
n] = lsb | (msb << 8);
809 wbits |= data[0] & data[1];
821 const struct das16_board *board = comedi_board(dev);
828 for (i = 0; i < insn->
n; i++) {
830 lsb = (data[
i] << 4) & 0xff;
831 msb = (data[
i] >> 4) & 0xff;
833 lsb = data[
i] & 0xff;
834 msb = (data[
i] >> 8) & 0xff;
853 static const int disable_limit = 100;
854 static const int enable_timeout = 100;
857 for (i = 0; i < disable_limit && (residue % 2); ++
i) {
860 for (j = 0; j < enable_timeout; ++
j) {
864 if (new_residue != residue)
870 if (i == disable_limit) {
871 comedi_error(dev,
"failed to get an even dma transfer, "
872 "could be trouble.");
879 const struct das16_board *board = comedi_board(dev);
880 unsigned long dma_flags, spin_flags;
902 spin_unlock_irqrestore(&dev->
spinlock, spin_flags);
908 clear_dma_ff(
devpriv->dma_chan);
909 residue = disable_dma_on_even(dev);
912 if (residue >
devpriv->dma_transfer_size) {
917 num_bytes =
devpriv->dma_transfer_size - residue;
920 num_bytes >=
devpriv->adc_byte_count) {
921 num_bytes =
devpriv->adc_byte_count;
925 buffer_index =
devpriv->current_buffer;
936 set_dma_addr(
devpriv->dma_chan,
941 if (board->
size > 0x400 &&
devpriv->timer_mode == 0)
947 spin_unlock_irqrestore(&dev->
spinlock, spin_flags);
950 devpriv->dma_buffer[buffer_index], num_bytes);
955 static irqreturn_t das16_dma_interrupt(
int irq,
void *
d)
969 das16_interrupt(dev);
973 static void das16_timer_interrupt(
unsigned long arg)
977 das16_interrupt(dev);
985 DEBUG_PRINT(
"********DAS1600 REGISTER DUMP********\n");
1003 const struct das16_board *board = comedi_board(dev);
1028 if (board->
id != diobits) {
1057 unsigned int num_bytes,
1058 unsigned int start_chan_index)
1060 const struct das16_board *board = comedi_board(dev);
1061 unsigned int i, num_samples = num_bytes /
sizeof(
short);
1062 short *data = array;
1064 for (i = 0; i < num_samples; i++) {
1067 data[
i] = (data[
i] >> 4) & 0xfff;
1082 const struct das16_board *board = comedi_board(dev);
1089 unsigned long flags;
1111 (
"\n Invalid option. Master clock must be set "
1112 "to 1 or 10 (MHz)\n");
1121 if (board->
size < 0x400) {
1122 printk(
" 0x%04lx-0x%04lx\n", iobase, iobase + board->
size);
1129 iobase, iobase + 0x0f,
1131 iobase + 0x400 + (board->
size & 0x3ff));
1134 iobase, iobase + 0x0f);
1142 iobase + 0x400 + (board->
size & 0x3ff));
1150 if (das16_probe(dev, it)) {
1151 printk(
KERN_ERR " id bits do not match selected board, aborting\n");
1157 if (board->
size < 0x400) {
1163 das1600_mode_detect(dev);
1167 if (irq > 1 && irq < 8) {
1168 ret =
request_irq(irq, das16_dma_interrupt, 0,
"das16", dev);
1174 }
else if (irq == 0) {
1177 printk(
" invalid irq\n");
1183 if (dma_chan == 1 || dma_chan == 3) {
1186 for (i = 0; i < 2; i++) {
1189 &
devpriv->dma_buffer_addr[i]);
1205 }
else if (dma_chan == 0) {
1216 devpriv->user_ai_range_table =
1220 devpriv->user_ai_range_table->length = 1;
1221 user_ai_range =
devpriv->user_ai_range_table->range;
1229 devpriv->user_ao_range_table =
1233 devpriv->user_ao_range_table->length = 1;
1234 user_ao_range =
devpriv->user_ao_range_table->range;
1242 devpriv->timer.function = das16_timer_interrupt;
1245 devpriv->timer_mode = timer_mode ? 1 : 0;
1257 if (
devpriv->ai_singleended) {
1267 if (
devpriv->user_ai_range_table) {
1269 }
else if (
devpriv->ai_unipolar) {
1276 s->
do_cmd = das16_cmd_exec;
1277 s->
cancel = das16_cancel;
1278 s->
munge = das16_ai_munge;
1291 if (
devpriv->user_ao_range_table)
1344 if (board->
size > 0x400) {
1355 const struct das16_board *board = comedi_board(dev);
1362 for (i = 0; i < 2; i++) {
1367 dma_buffer_addr[i]);
1377 if (board->
size < 0x400) {
1382 board->
size & 0x3ff);
1387 static const struct das16_board das16_boards[] = {
1390 .ai = das16_ai_rinsn,
1394 .ao = das16_ao_winsn,
1396 .di = das16_di_rbits,
1397 .do_ = das16_do_wbits,
1398 .i8255_offset = 0x10,
1399 .i8254_offset = 0x0c,
1404 .ai = das16_ai_rinsn,
1408 .ao = das16_ao_winsn,
1410 .di = das16_di_rbits,
1411 .do_ = das16_do_wbits,
1412 .i8255_offset = 0x10,
1413 .i8254_offset = 0x0c,
1418 .ai = das16_ai_rinsn,
1422 .ao = das16_ao_winsn,
1424 .di = das16_di_rbits,
1425 .do_ = das16_do_wbits,
1426 .i8255_offset = 0x10,
1427 .i8254_offset = 0x0c,
1431 .name =
"cio-das16",
1432 .ai = das16_ai_rinsn,
1436 .ao = das16_ao_winsn,
1438 .di = das16_di_rbits,
1439 .do_ = das16_do_wbits,
1440 .i8255_offset = 0x10,
1441 .i8254_offset = 0x0c,
1445 .name =
"cio-das16/f",
1446 .ai = das16_ai_rinsn,
1450 .ao = das16_ao_winsn,
1452 .di = das16_di_rbits,
1453 .do_ = das16_do_wbits,
1454 .i8255_offset = 0x10,
1455 .i8254_offset = 0x0c,
1459 .name =
"cio-das16/jr",
1460 .ai = das16_ai_rinsn,
1465 .di = das16_di_rbits,
1466 .do_ = das16_do_wbits,
1468 .i8254_offset = 0x0c,
1472 .name =
"pc104-das16jr",
1473 .ai = das16_ai_rinsn,
1478 .di = das16_di_rbits,
1479 .do_ = das16_do_wbits,
1481 .i8254_offset = 0x0c,
1485 .name =
"cio-das16jr/16",
1486 .ai = das16_ai_rinsn,
1491 .di = das16_di_rbits,
1492 .do_ = das16_do_wbits,
1494 .i8254_offset = 0x0c,
1498 .name =
"pc104-das16jr/16",
1499 .ai = das16_ai_rinsn,
1504 .di = das16_di_rbits,
1505 .do_ = das16_do_wbits,
1507 .i8254_offset = 0x0c,
1512 .ai = das16_ai_rinsn,
1517 .di = das16_di_rbits,
1518 .do_ = das16_do_wbits,
1519 .i8255_offset = 0x400,
1520 .i8254_offset = 0x0c,
1525 .ai = das16_ai_rinsn,
1530 .di = das16_di_rbits,
1531 .do_ = das16_do_wbits,
1532 .i8255_offset = 0x400,
1533 .i8254_offset = 0x0c,
1538 .ai = das16_ai_rinsn,
1543 .di = das16_di_rbits,
1544 .do_ = das16_do_wbits,
1545 .i8255_offset = 0x0,
1546 .i8254_offset = 0x0c,
1551 .ai = das16_ai_rinsn,
1556 .di = das16_di_rbits,
1557 .do_ = das16_do_wbits,
1558 .i8255_offset = 0x0,
1559 .i8254_offset = 0x0c,
1564 .ai = das16_ai_rinsn,
1568 .ao = das16_ao_winsn,
1570 .di = das16_di_rbits,
1571 .do_ = das16_do_wbits,
1572 .i8255_offset = 0x400,
1573 .i8254_offset = 0x0c,
1578 .ai = das16_ai_rinsn,
1582 .ao = das16_ao_winsn,
1584 .di = das16_di_rbits,
1585 .do_ = das16_do_wbits,
1586 .i8255_offset = 0x400,
1587 .i8254_offset = 0x0c,
1591 .name =
"cio-das1401/12",
1592 .ai = das16_ai_rinsn,
1597 .di = das16_di_rbits,
1598 .do_ = das16_do_wbits,
1600 .i8254_offset = 0x0c,
1604 .name =
"cio-das1402/12",
1605 .ai = das16_ai_rinsn,
1610 .di = das16_di_rbits,
1611 .do_ = das16_do_wbits,
1613 .i8254_offset = 0x0c,
1617 .name =
"cio-das1402/16",
1618 .ai = das16_ai_rinsn,
1623 .di = das16_di_rbits,
1624 .do_ = das16_do_wbits,
1626 .i8254_offset = 0x0c,
1630 .name =
"cio-das1601/12",
1631 .ai = das16_ai_rinsn,
1635 .ao = das16_ao_winsn,
1637 .di = das16_di_rbits,
1638 .do_ = das16_do_wbits,
1639 .i8255_offset = 0x400,
1640 .i8254_offset = 0x0c,
1644 .name =
"cio-das1602/12",
1645 .ai = das16_ai_rinsn,
1649 .ao = das16_ao_winsn,
1651 .di = das16_di_rbits,
1652 .do_ = das16_do_wbits,
1653 .i8255_offset = 0x400,
1654 .i8254_offset = 0x0c,
1658 .name =
"cio-das1602/16",
1659 .ai = das16_ai_rinsn,
1663 .ao = das16_ao_winsn,
1665 .di = das16_di_rbits,
1666 .do_ = das16_do_wbits,
1667 .i8255_offset = 0x400,
1668 .i8254_offset = 0x0c,
1672 .name =
"cio-das16/330",
1673 .ai = das16_ai_rinsn,
1678 .di = das16_di_rbits,
1679 .do_ = das16_do_wbits,
1681 .i8254_offset = 0x0c,
1688 .driver_name =
"das16",
1690 .attach = das16_attach,
1691 .detach = das16_detach,
1692 .board_name = &das16_boards[0].
name,
1694 .offset =
sizeof(das16_boards[0]),