104 #include <linux/slab.h>
106 #include "../comedidev.h"
115 #define DAS1800_SIZE 16
116 #define FIFO_SIZE 1024
117 #define TIMER_BASE 200
119 #define DMA_BUF_SIZE 0x1ff00
122 #define DAS1800_FIFO 0x0
123 #define DAS1800_QRAM 0x0
124 #define DAS1800_DAC 0x0
125 #define DAS1800_SELECT 0x2
128 #define DAC(a) (0x2 + a)
129 #define DAS1800_DIGITAL 0x3
130 #define DAS1800_CONTROL_A 0x4
137 #define DAS1800_CONTROL_B 0x5
141 #define DMA_CH5_CH6 0x5
142 #define DMA_CH6_CH7 0x6
143 #define DMA_CH7_CH5 0x7
144 #define DMA_ENABLED 0x3
153 #define DAS1800_CONTROL_C 0X6
161 #define DAS1800_STATUS 0x7
163 #define CLEAR_INTR_MASK (CVEN_MASK | 0x1f)
170 #define CVEN_MASK 0x40
172 #define DAS1800_BURST_LENGTH 0x8
173 #define DAS1800_BURST_RATE 0x9
174 #define DAS1800_QRAM_ADDRESS 0xa
175 #define DAS1800_COUNTER 0xc
177 #define IOBASE2 0x400
233 .name =
"das-1701st",
241 .range_ai = &range_ai_das1801,
244 .name =
"das-1701st-da",
252 .range_ai = &range_ai_das1801,
255 .name =
"das-1702st",
263 .range_ai = &range_ai_das1802,
266 .name =
"das-1702st-da",
274 .range_ai = &range_ai_das1802,
277 .name =
"das-1702hr",
285 .range_ai = &range_ai_das1802,
288 .name =
"das-1702hr-da",
296 .range_ai = &range_ai_das1802,
299 .name =
"das-1701ao",
307 .range_ai = &range_ai_das1801,
310 .name =
"das-1702ao",
318 .range_ai = &range_ai_das1802,
321 .name =
"das-1801st",
329 .range_ai = &range_ai_das1801,
332 .name =
"das-1801st-da",
340 .range_ai = &range_ai_das1801,
343 .name =
"das-1802st",
351 .range_ai = &range_ai_das1802,
354 .name =
"das-1802st-da",
362 .range_ai = &range_ai_das1802,
365 .name =
"das-1802hr",
373 .range_ai = &range_ai_das1802,
376 .name =
"das-1802hr-da",
384 .range_ai = &range_ai_das1802,
387 .name =
"das-1801hc",
395 .range_ai = &range_ai_das1801,
398 .name =
"das-1802hc",
406 .range_ai = &range_ai_das1802,
409 .name =
"das-1801ao",
417 .range_ai = &range_ai_das1801,
420 .name =
"das-1802ao",
428 .range_ai = &range_ai_das1802,
435 #define thisboard ((const struct das1800_board *)dev->board_ptr)
457 #define devpriv ((struct das1800_private *)dev->private)
481 sample += 1 << (
thisboard->resolution - 1);
497 array[i] = munge_bipolar_sample(dev, array[i]);
501 static void das1800_handle_fifo_half_full(
struct comedi_device *dev,
512 munge_data(dev,
devpriv->ai_buf0, numPoints);
514 numPoints *
sizeof(
devpriv->ai_buf0[0]));
520 static void das1800_handle_fifo_not_empty(
struct comedi_device *dev,
536 dpnt = munge_bipolar_sample(dev, dpnt);
537 cfc_write_to_buffer(s, dpnt);
547 static void das1800_flush_dma_channel(
struct comedi_device *dev,
558 clear_dma_ff(channel);
562 num_samples = num_bytes /
sizeof(
short);
568 munge_data(dev, buffer, num_samples);
585 das1800_flush_dma_channel(dev, s,
devpriv->dma_current,
597 das1800_flush_dma_channel(dev, s,
devpriv->dma_current,
604 das1800_handle_fifo_not_empty(dev, s);
616 das1800_flush_dma_channel(dev, s,
devpriv->dma_current,
619 set_dma_addr(
devpriv->dma_current,
625 if (status &
DMATC) {
670 das1800_handle_dma(dev, s, status);
671 }
else if (status &
FHF) {
672 das1800_handle_fifo_half_full(dev, s);
673 }
else if (status & FNE) {
674 das1800_handle_fifo_not_empty(dev, s);
683 das1800_cancel(dev, s);
690 if (status &
CT0TC) {
695 das1800_flush_dma(dev, s);
697 das1800_handle_fifo_not_empty(dev, s);
698 das1800_cancel(dev, s);
701 das1800_cancel(dev, s);
717 das1800_ai_handler(dev);
718 spin_unlock_irqrestore(&dev->
spinlock, flags);
720 return s->
async->buf_write_count - s->
async->buf_read_count;
739 if (!(status &
INT)) {
746 das1800_ai_handler(dev);
755 static unsigned int burst_convert_arg(
unsigned int convert_arg,
int round_mode)
757 unsigned int micro_sec;
760 if (convert_arg > 64000)
764 switch (round_mode) {
767 micro_sec = (convert_arg + 500) / 1000;
770 micro_sec = convert_arg / 1000;
773 micro_sec = (convert_arg - 1) / 1000 + 1;
778 return micro_sec * 1000;
787 unsigned int tmp_arg;
798 err |= cfc_check_trigger_src(&cmd->
stop_src,
806 err |= cfc_check_trigger_is_unique(cmd->
start_src);
808 err |= cfc_check_trigger_is_unique(cmd->
convert_src);
809 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
923 "unipolar and bipolar ranges cannot be mixed in the chanlist");
937 static int control_a_bits(
const struct comedi_cmd *cmd)
959 static int control_c_bits(
const struct comedi_cmd *cmd)
1043 if (das1800_set_frequency(dev) < 0)
1053 if (das1800_set_frequency(dev) < 0)
1070 static unsigned int suggest_transfer_size(
const struct comedi_cmd *cmd)
1074 unsigned int fill_time = 300000000;
1081 size = (fill_time / cmd->
convert_arg) * sample_size;
1099 if (size > max_size)
1101 if (size < sample_size)
1117 devpriv->dma_transfer_size = suggest_transfer_size(cmd);
1149 int i,
n, chan_range;
1150 unsigned long irq_flags;
1151 const int range_mask = 0x3;
1152 const int range_bitshift = 8;
1160 for (i = 0; i <
n; i++) {
1168 spin_unlock_irqrestore(&dev->
spinlock, irq_flags);
1178 int control_a, control_c;
1184 "no irq assigned for das-1800, cannot do hardware conversions");
1206 das1800_cancel(dev, s);
1209 control_a = control_a_bits(cmd);
1210 control_c = control_c_bits(cmd);
1213 program_chanlist(dev, cmd);
1214 ret = setup_counters(dev, cmd);
1219 setup_dma(dev, cmd);
1222 if (control_c &
BMDE) {
1245 unsigned long irq_flags;
1266 chan_range = chan | (range << 8);
1274 for (n = 0; n < insn->
n; n++) {
1277 for (i = 0; i < timeout; i++) {
1288 if ((conv_flags &
UB) == 0)
1289 dpnt += 1 << (
thisboard->resolution - 1);
1293 spin_unlock_irqrestore(&dev->
spinlock, irq_flags);
1305 int update_chan =
thisboard->ao_n_chan - 1;
1307 unsigned long irq_flags;
1310 output = data[0] - (1 << (
thisboard->resolution - 1));
1312 if (chan == update_chan)
1319 if (chan != update_chan) {
1323 spin_unlock_irqrestore(&dev->
spinlock, irq_flags);
1348 data[0] &= (1 << s->
n_chan) - 1;
1351 wbits |= data[0] & data[1];
1361 static int das1800_init_dma(
struct comedi_device *dev,
unsigned int dma0,
1364 unsigned long flags;
1367 if (dev->
irq && dma0) {
1369 switch ((dma0 & 0x7) | (dma1 << 4)) {
1390 "only supports dma channels 5 through 7\n");
1392 "Dual dma only allows the following combinations:\n");
1394 "dma 5,6 / 6,7 / or 7,5\n");
1400 "failed to allocate dma channel %i\n", dma0);
1408 "failed to allocate dma channel %i\n",
1449 das1800_boards[board].
name);
1453 (
" Board model (probed, not recommended): das-1800st-da series\n");
1459 das1800_boards[board].
name);
1463 (
" Board model (probed, not recommended): das-1802hr-da\n");
1470 das1800_boards[board].
name);
1474 (
" Board model (probed, not recommended): das-1800ao series\n");
1480 das1800_boards[board].
name);
1484 (
" Board model (probed, not recommended): das-1802hr\n");
1491 das1800_boards[board].
name);
1495 (
" Board model (probed, not recommended): das-1800st series\n");
1501 das1800_boards[board].
name);
1505 (
" Board model (probed, not recommended): das-1800hc series\n");
1510 (
" Board model: probe returned 0x%x (unknown, please report)\n",
1523 unsigned int irq = it->
options[1];
1524 unsigned int dma0 = it->
options[2];
1525 unsigned int dma1 = it->
options[3];
1526 unsigned long iobase2;
1535 dev->
driver->driver_name, iobase);
1554 (
" I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n",
1560 board = das1800_probe(dev);
1566 dev->
board_ptr = das1800_boards + board;
1573 dev->
driver->driver_name)) {
1575 (
" I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n",
1585 dev->
driver->driver_name, dev)) {
1601 devpriv->irq_dma_bits |= 0x10;
1604 devpriv->irq_dma_bits |= 0x18;
1607 devpriv->irq_dma_bits |= 0x28;
1610 devpriv->irq_dma_bits |= 0x30;
1613 devpriv->irq_dma_bits |= 0x38;
1621 retval = das1800_init_dma(dev, dma0, dma1);
1647 s->
do_cmd = das1800_ai_do_cmd;
1650 s->
poll = das1800_ai_poll;
1651 s->
cancel = das1800_cancel;
1719 .driver_name =
"das1800",
1721 .attach = das1800_attach,
1722 .detach = das1800_detach,
1724 .board_name = &das1800_boards[0].
name,