71 #include "../comedidev.h"
79 #define PCI9111_DRIVER_NAME "adl_pci9111"
80 #define PCI9111_HR_DEVICE_ID 0x9111
82 #define PCI9111_FIFO_HALF_SIZE 512
84 #define PCI9111_AI_ACQUISITION_PERIOD_MIN_NS 10000
86 #define PCI9111_RANGE_SETTING_DELAY 10
87 #define PCI9111_AI_INSTANT_READ_UDELAY_US 2
88 #define PCI9111_AI_INSTANT_READ_TIMEOUT 100
90 #define PCI9111_8254_CLOCK_PERIOD_NS 500
95 #define PCI9111_AI_FIFO_REG 0x00
96 #define PCI9111_AO_REG 0x00
97 #define PCI9111_DIO_REG 0x02
98 #define PCI9111_EDIO_REG 0x04
99 #define PCI9111_AI_CHANNEL_REG 0x06
100 #define PCI9111_AI_RANGE_STAT_REG 0x08
101 #define PCI9111_AI_STAT_AD_BUSY (1 << 7)
102 #define PCI9111_AI_STAT_FF_FF (1 << 6)
103 #define PCI9111_AI_STAT_FF_HF (1 << 5)
104 #define PCI9111_AI_STAT_FF_EF (1 << 4)
105 #define PCI9111_AI_RANGE_MASK (7 << 0)
106 #define PCI9111_AI_TRIG_CTRL_REG 0x0a
107 #define PCI9111_AI_TRIG_CTRL_TRGEVENT (1 << 5)
108 #define PCI9111_AI_TRIG_CTRL_POTRG (1 << 4)
109 #define PCI9111_AI_TRIG_CTRL_PTRG (1 << 3)
110 #define PCI9111_AI_TRIG_CTRL_ETIS (1 << 2)
111 #define PCI9111_AI_TRIG_CTRL_TPST (1 << 1)
112 #define PCI9111_AI_TRIG_CTRL_ASCAN (1 << 0)
113 #define PCI9111_INT_CTRL_REG 0x0c
114 #define PCI9111_INT_CTRL_ISC2 (1 << 3)
115 #define PCI9111_INT_CTRL_FFEN (1 << 2)
116 #define PCI9111_INT_CTRL_ISC1 (1 << 1)
117 #define PCI9111_INT_CTRL_ISC0 (1 << 0)
118 #define PCI9111_SOFT_TRIG_REG 0x0e
119 #define PCI9111_8254_BASE_REG 0x40
120 #define PCI9111_INT_CLR_REG 0x48
152 #define PLX9050_REGISTER_INTERRUPT_CONTROL 0x4c
154 #define PLX9050_LINTI1_ENABLE (1 << 0)
155 #define PLX9050_LINTI1_ACTIVE_HIGH (1 << 1)
156 #define PLX9050_LINTI1_STATUS (1 << 2)
157 #define PLX9050_LINTI2_ENABLE (1 << 3)
158 #define PLX9050_LINTI2_ACTIVE_HIGH (1 << 4)
159 #define PLX9050_LINTI2_STATUS (1 << 5)
160 #define PLX9050_PCI_INTERRUPT_ENABLE (1 << 6)
161 #define PLX9050_SOFTWARE_INTERRUPT (1 << 7)
163 static void plx9050_interrupt_control(
unsigned long io_base,
165 bool LINTi1_active_high,
167 bool LINTi2_active_high,
168 bool interrupt_enable)
174 if (LINTi1_active_high)
178 if (LINTi2_active_high)
181 if (interrupt_enable)
198 i8254_write(timer_base, 1, 2, dev_private->
div2);
199 i8254_write(timer_base, 1, 1, dev_private->
div1);
234 static void pci9111_pretrigger_set(
struct comedi_device *
dev,
bool pretrigger)
249 static void pci9111_autoscan_set(
struct comedi_device *dev,
bool autoscan)
274 static void pci9111_interrupt_source_set(
struct comedi_device *dev,
302 outb(0, int_ctrl_reg);
304 outb(0, int_ctrl_reg);
313 plx9050_interrupt_control(dev_private->
lcr_io_base,
true,
true,
true,
316 pci9111_trigger_source_set(dev,
software);
318 pci9111_autoscan_set(dev,
false);
320 pci9111_fifo_reset(dev);
343 error |= cfc_check_trigger_src(&cmd->
stop_src,
352 error |= cfc_check_trigger_is_unique(cmd->
convert_src);
353 error |= cfc_check_trigger_is_unique(cmd->
stop_src);
436 unsigned int scan_begin_min;
437 unsigned int scan_begin_arg;
438 unsigned int scan_factor;
443 if (scan_begin_min < cmd->scan_begin_arg) {
446 scan_begin_arg = scan_factor * scan_begin_min;
472 "entries in chanlist must be consecutive "
473 "channels,counting upwards from 0\n");
478 "entries in chanlist must all have the same gain\n");
483 "entries in chanlist must all have the same reference\n");
505 "no irq assigned for PCI9111, cannot do hardware conversion");
515 pci9111_autoscan_set(dev,
true);
519 pci9111_autoscan_set(dev,
false);
552 pci9111_trigger_source_set(dev,
software);
553 pci9111_timer_set(dev);
554 pci9111_fifo_reset(dev);
558 plx9050_interrupt_control(dev_private->
lcr_io_base,
true,
true,
572 pci9111_trigger_source_set(dev,
external);
573 pci9111_fifo_reset(dev);
576 plx9050_interrupt_control(dev_private->
lcr_io_base,
true,
true,
598 unsigned int start_chan_index)
601 unsigned int maxdata = s->
maxdata;
602 unsigned int invert = (maxdata + 1) >> 1;
603 unsigned int shift = (maxdata == 0xffff) ? 0 : 4;
604 unsigned int num_samples = num_bytes /
sizeof(
short);
607 for (i = 0; i < num_samples; i++)
608 array[i] = ((array[i] >> shift) & maxdata) ^ invert;
611 static irqreturn_t pci9111_interrupt(
int irq,
void *p_device)
618 unsigned long irq_flags;
619 unsigned char intcsr;
641 spin_unlock_irqrestore(&dev->
spinlock, irq_flags);
653 spin_unlock_irqrestore(&dev->
spinlock, irq_flags);
656 pci9111_ai_cancel(dev, s);
665 unsigned int num_samples;
666 unsigned int bytes_written = 0;
688 while (position < num_samples) {
696 num_samples - position)
706 to_read *
sizeof(
short));
713 num_samples - position)
719 sizeof(
short) * to_read;
732 bytes_written /
sizeof(
short);
738 pci9111_ai_cancel(dev, s);
743 spin_unlock_irqrestore(&dev->
spinlock, irq_flags);
756 unsigned int maxdata = s->
maxdata;
757 unsigned int invert = (maxdata + 1) >> 1;
758 unsigned int shift = (maxdata == 0xffff) ? 0 : 4;
767 outb(range & PCI9111_AI_RANGE_MASK,
771 pci9111_fifo_reset(dev);
773 for (i = 0; i < insn->
n; i++) {
783 goto conversion_done;
788 pci9111_fifo_reset(dev);
794 data[
i] = ((data[
i] >> shift) & maxdata) ^ invert;
806 unsigned int val = 0;
809 for (i = 0; i < insn->
n; i++) {
826 for (i = 0; i < insn->
n; i++)
847 unsigned int mask = data[0];
848 unsigned int bits = data[1];
867 plx9050_interrupt_control(dev_private->
lcr_io_base,
true,
true,
true,
870 pci9111_trigger_source_set(dev,
software);
871 pci9111_pretrigger_set(dev,
false);
872 pci9111_autoscan_set(dev,
false);
875 dev_private->
div1 = 0;
876 dev_private->
div2 = 0;
877 pci9111_timer_set(dev);
889 comedi_set_hw_dev(dev, &pcidev->
dev);
892 ret = alloc_private(dev,
sizeof(*dev_private));
905 if (pcidev->
irq > 0) {
925 s->
cancel = pci9111_ai_cancel;
928 s->
do_cmd = pci9111_ai_do_cmd;
929 s->
munge = pci9111_ai_munge;
964 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
977 .driver_name =
"adl_pci9111",
979 .attach_pci = pci9111_attach_pci,
980 .detach = pci9111_detach,
1001 static struct pci_driver adl_pci9111_pci_driver = {
1002 .name =
"adl_pci9111",
1003 .id_table = pci9111_pci_table,
1004 .probe = pci9111_pci_probe,