70 #include "../comedidev.h"
80 #define PCI_VENDOR_ID_CB 0x1307
82 #define TIMER_BASE 100
83 #define AI_BUFFER_SIZE 1024
84 #define AO_BUFFER_SIZE 1024
85 #define NUM_CHANNELS_8800 8
86 #define NUM_CHANNELS_7376 1
87 #define NUM_CHANNELS_8402 2
88 #define NUM_CHANNELS_DAC08 1
106 #define DAEMIE 0x1000
107 #define LADFUL 0x2000
110 #define ADCMUX_CONT 2
111 #define BEGIN_SCAN(x) ((x) & 0xf)
112 #define END_SCAN(x) (((x) & 0xf) << 4)
113 #define GAIN_BITS(x) (((x) & 0x3) << 8)
116 #define PACER_MASK 0x3000
117 #define PACER_INT 0x1000
118 #define PACER_EXT_FALL 0x2000
119 #define PACER_EXT_RISE 0x3000
122 #define TRIG_CONTSTAT 4
123 #define SW_TRIGGER 0x1
124 #define EXT_TRIGGER 0x2
125 #define ANALOG_TRIGGER 0x3
126 #define TRIGGER_MASK 0x3
133 #define CALIBRATION_REG 6
134 #define SELECT_8800_BIT 0x100
135 #define SELECT_TRIMPOT_BIT 0x200
136 #define SELECT_DAC08_BIT 0x400
137 #define CAL_SRC_BITS(x) (((x) & 0x7) << 11)
138 #define CAL_EN_BIT 0x4000
139 #define SERIAL_DATA_IN_BIT 0x8000
143 #define DAC_MODE_UPDATE_BOTH 0x80
145 static inline unsigned int DAC_RANGE(
unsigned int channel,
unsigned int range)
147 return (range & 0x3) << (8 + 2 * (channel & 0x1));
150 static inline unsigned int DAC_RANGE_MASK(
unsigned int channel)
152 return 0x3 << (8 + 2 * (channel & 0x1));
156 #define DAC_EMPTY 0x1
157 #define DAC_START 0x4
158 #define DAC_PACER_MASK 0x18
159 #define DAC_PACER_INT 0x8
160 #define DAC_PACER_EXT_FALL 0x10
161 #define DAC_PACER_EXT_RISE 0x18
163 static inline unsigned int DAC_CHAN_EN(
unsigned int channel)
165 return 1 << (5 + (channel & 0x1));
178 static inline unsigned int DAC_DATA_REG(
unsigned int channel)
180 return 2 * (channel & 0x1);
187 #define IS_UNIPOLAR 0x4
253 .name =
"pci-das1602/16",
260 .ao_scan_speed = 10000,
262 .ranges = &cb_pcidas_ranges,
267 .name =
"pci-das1200",
274 .ranges = &cb_pcidas_ranges,
277 .name =
"pci-das1602/12",
284 .ao_scan_speed = 4000,
286 .ranges = &cb_pcidas_ranges,
290 .name =
"pci-das1200/jr",
296 .ranges = &cb_pcidas_ranges,
299 .name =
"pci-das1602/16/jr",
305 .ranges = &cb_pcidas_ranges,
310 .name =
"pci-das1000",
316 .ranges = &cb_pcidas_ranges,
319 .name =
"pci-das1001",
326 .ranges = &cb_pcidas_alt_ranges,
329 .name =
"pci-das1002",
336 .ranges = &cb_pcidas_ranges,
393 outw(cal_enable_bits(dev),
414 for (n = 0; n < insn->
n; n++) {
420 for (i = 0; i < 10000; i++) {
440 unsigned int source = data[1];
446 "invalid calibration source: %i\n",
460 static int cb_pcidas_ao_nofifo_winsn(
struct comedi_device *dev,
473 ~DAC_RANGE_MASK(chan));
476 spin_unlock_irqrestore(&dev->
spinlock, flags);
488 static int cb_pcidas_ao_fifo_winsn(
struct comedi_device *dev,
507 spin_unlock_irqrestore(&dev->
spinlock, flags);
518 static int cb_pcidas_ao_readback_insn(
struct comedi_device *dev,
530 static int wait_for_nvram_ready(
unsigned long s5933_base_addr)
532 static const int timeout = 1000;
535 for (i = 0; i < timeout; i++) {
536 if ((
inb(s5933_base_addr +
551 if (wait_for_nvram_ready(iobase) < 0)
562 if (wait_for_nvram_ready(iobase) < 0)
581 data[0] = nvram_data;
586 static void write_calibration_bitstream(
struct comedi_device *dev,
587 unsigned int register_bits,
589 unsigned int bitstream_length)
592 static const int write_delay = 1;
595 for (bit = 1 << (bitstream_length - 1);
bit; bit >>= 1) {
605 static int caldac_8800_write(
struct comedi_device *dev,
unsigned int address,
609 static const int num_caldac_channels = 8;
610 static const int bitstream_length = 11;
611 unsigned int bitstream = ((address & 0x7) << 8) |
value;
612 static const int caldac_8800_udelay = 1;
614 if (address >= num_caldac_channels) {
624 write_calibration_bitstream(dev, cal_enable_bits(dev), bitstream,
627 udelay(caldac_8800_udelay);
630 udelay(caldac_8800_udelay);
642 return caldac_8800_write(dev, channel, data[0]);
657 static void dac08_write(
struct comedi_device *dev,
unsigned int value)
660 unsigned long cal_reg;
668 value |= cal_enable_bits(dev);
671 outw(value, cal_reg);
675 outw(value, cal_reg);
686 for (i = 0; i < insn->
n; i++)
687 dac08_write(dev, data[i]);
706 static const int bitstream_length = 7;
707 unsigned int bitstream = value & 0x7f;
708 unsigned int register_bits;
709 static const int ad7376_udelay = 1;
715 write_calibration_bitstream(dev, register_bits, bitstream,
731 static const int bitstream_length = 10;
732 unsigned int bitstream = ((channel & 0x3) << 8) | (value & 0xff);
733 unsigned int register_bits;
734 static const int ad8402_udelay = 1;
740 write_calibration_bitstream(dev, register_bits, bitstream,
749 static int cb_pcidas_trimpot_write(
struct comedi_device *dev,
750 unsigned int channel,
unsigned int value)
761 trimpot_7376_write(dev, value);
764 trimpot_8402_write(dev, channel, value);
781 return cb_pcidas_trimpot_write(dev, channel, data[0]);
804 int i,
gain, start_chan;
821 err |= cfc_check_trigger_is_unique(cmd->
start_src);
823 err |= cfc_check_trigger_is_unique(cmd->
convert_src);
824 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
925 (start_chan + i) % s->
n_chan) {
927 "entries in chanlist must be consecutive channels, counting upwards\n");
932 "entries in chanlist must all have the same gain\n");
944 static void cb_pcidas_load_counters(
struct comedi_device *dev,
unsigned int *
ns,
1025 spin_unlock_irqrestore(&dev->
spinlock, flags);
1074 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
1131 "channels must be ordered channel 0, channel 1 in chanlist\n");
1147 unsigned long flags;
1153 spin_unlock_irqrestore(&dev->
spinlock, flags);
1165 unsigned int trig_num)
1172 unsigned long flags;
1182 num_points *
sizeof(
short));
1183 num_points = num_bytes /
sizeof(
short);
1202 spin_unlock_irqrestore(&dev->
spinlock, flags);
1216 unsigned long flags;
1232 spin_unlock_irqrestore(&dev->
spinlock, flags);
1264 spin_unlock_irqrestore(&dev->
spinlock, flags);
1269 spin_unlock_irqrestore(&dev->
spinlock, flags);
1271 async->
inttrig = cb_pcidas_ao_inttrig;
1281 unsigned long flags;
1291 spin_unlock_irqrestore(&dev->
spinlock, flags);
1303 unsigned int half_fifo = thisboard->
fifo_size / 2;
1304 unsigned int num_points;
1305 unsigned long flags;
1309 if (status &
DAEMI) {
1314 spin_unlock_irqrestore(&dev->
spinlock, flags);
1320 cb_pcidas_ao_cancel(dev, s);
1325 }
else if (status &
DAHFI) {
1329 num_points = half_fifo;
1335 num_points *
sizeof(
short));
1336 num_points = num_bytes /
sizeof(
short);
1347 spin_unlock_irqrestore(&dev->
spinlock, flags);
1353 static irqreturn_t cb_pcidas_interrupt(
int irq,
void *
d)
1360 int status, s5933_status;
1361 int half_fifo = thisboard->
fifo_size / 2;
1362 unsigned int num_samples,
i;
1363 static const int timeout = 10000;
1364 unsigned long flags;
1386 if (status & (DAHFI | DAEMI))
1387 handle_ao_interrupt(dev, status);
1390 if (status &
ADHFI) {
1392 num_samples = half_fifo;
1394 num_samples > devpriv->
count) {
1395 num_samples = devpriv->
count;
1400 num_samples *
sizeof(
short));
1401 devpriv->
count -= num_samples;
1404 cb_pcidas_cancel(dev, s);
1410 spin_unlock_irqrestore(&dev->
spinlock, flags);
1413 for (i = 0; i < timeout; i++) {
1420 --devpriv->
count == 0) {
1422 cb_pcidas_cancel(dev, s);
1431 spin_unlock_irqrestore(&dev->
spinlock, flags);
1432 }
else if (status &
EOAI) {
1434 "bug! encountered end of acquisition interrupt?");
1439 spin_unlock_irqrestore(&dev->
spinlock, flags);
1448 spin_unlock_irqrestore(&dev->
spinlock, flags);
1449 cb_pcidas_cancel(dev, s);
1458 static const void *cb_pcidas_find_boardinfo(
struct comedi_device *dev,
1464 for (i = 0; i <
ARRAY_SIZE(cb_pcidas_boards); i++) {
1465 thisboard = &cb_pcidas_boards[
i];
1481 comedi_set_hw_dev(dev, &pcidev->
dev);
1483 thisboard = cb_pcidas_find_boardinfo(dev, pcidev);
1489 ret = alloc_private(dev,
sizeof(*devpriv));
1533 s->
do_cmd = cb_pcidas_ai_cmd;
1535 s->
cancel = cb_pcidas_cancel;
1549 s->
insn_read = cb_pcidas_ao_readback_insn;
1555 s->
do_cmd = cb_pcidas_ao_cmd;
1556 s->
cancel = cb_pcidas_ao_cancel;
1587 for (i = 0; i < s->
n_chan; i++)
1588 caldac_8800_write(dev, i, s->
maxdata / 2);
1603 for (i = 0; i < s->
n_chan; i++)
1604 cb_pcidas_trimpot_write(dev, i, s->
maxdata / 2);
1615 dac08_write(dev, s->
maxdata / 2);
1638 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
1657 .driver_name =
"cb_pcidas",
1659 .attach_pci = cb_pcidas_attach_pci,
1660 .detach = cb_pcidas_detach,
1687 static struct pci_driver cb_pcidas_pci_driver = {
1688 .name =
"cb_pcidas",
1689 .id_table = cb_pcidas_pci_table,
1690 .probe = cb_pcidas_pci_probe,