79 #include <linux/slab.h>
80 #include "../comedidev.h"
83 #include <linux/pci.h>
85 #define CHANS_PER_PORT 8
86 #define PORTS_PER_ASIC 6
87 #define INTR_PORTS_PER_ASIC 3
88 #define MAX_CHANS_PER_SUBDEV 24
89 #define PORTS_PER_SUBDEV (MAX_CHANS_PER_SUBDEV/CHANS_PER_PORT)
90 #define CHANS_PER_ASIC (CHANS_PER_PORT*PORTS_PER_ASIC)
91 #define INTR_CHANS_PER_ASIC 24
92 #define INTR_PORTS_PER_SUBDEV (INTR_CHANS_PER_ASIC/CHANS_PER_PORT)
93 #define MAX_DIO_CHANS (PORTS_PER_ASIC*2*CHANS_PER_PORT)
94 #define MAX_ASICS (MAX_DIO_CHANS/CHANS_PER_ASIC)
95 #define SDEV_NO ((int)(s - dev->subdevices))
96 #define CALC_N_SUBDEVS(nchans) ((nchans)/MAX_CHANS_PER_SUBDEV + (!!((nchans)%MAX_CHANS_PER_SUBDEV)) )
98 #define ASIC_IOSIZE (0x10)
99 #define PCMUIO48_IOSIZE ASIC_IOSIZE
100 #define PCMUIO96_IOSIZE (ASIC_IOSIZE*2)
115 #define REG_PORT0 0x0
116 #define REG_PORT1 0x1
117 #define REG_PORT2 0x2
118 #define REG_PORT3 0x3
119 #define REG_PORT4 0x4
120 #define REG_PORT5 0x5
121 #define REG_INT_PENDING 0x6
122 #define REG_PAGELOCK 0x7
128 #define REG_ENAB0 0x8
129 #define REG_ENAB1 0x9
130 #define REG_ENAB2 0xA
131 #define REG_INT_ID0 0x8
132 #define REG_INT_ID1 0x9
133 #define REG_INT_ID2 0xA
135 #define NUM_PAGED_REGS 3
137 #define FIRST_PAGED_REG 0x8
138 #define REG_PAGE_BITOFFSET 6
139 #define REG_LOCK_BITOFFSET 0
140 #define REG_PAGE_MASK (~((0x1<<REG_PAGE_BITOFFSET)-1))
141 #define REG_LOCK_MASK ~(REG_PAGE_MASK)
144 #define PAGE_INT_ID 3
201 #define devpriv ((struct pcmuio_private *)dev->private)
202 #define subpriv ((struct pcmuio_subdev_private *)s->private)
226 #ifdef DAMMIT_ITS_BROKEN
236 unsigned long ioaddr =
subpriv->iobases[byte_no],
240 unsigned char byte = 0,
242 write_mask_byte = (data[0] >>
offset) & 0xff,
244 data_byte = (data[1] >>
offset) & 0xff;
248 #ifdef DAMMIT_ITS_BROKEN
251 (
"byte %d wmb %02x db %02x offset %02d io %04x, data_in %02x ",
252 byte_no, (
unsigned)write_mask_byte, (
unsigned)data_byte,
253 offset, ioaddr, (
unsigned)byte);
256 if (write_mask_byte) {
258 byte &= ~write_mask_byte;
259 byte |= ~data_byte & write_mask_byte;
263 #ifdef DAMMIT_ITS_BROKEN
274 #ifdef DAMMIT_ITS_BROKEN
293 unsigned long ioaddr;
297 ioaddr =
subpriv->iobases[byte_no];
352 if (asic < 0 || asic >= board->
num_asics)
375 switch_page(dev, asic, 0);
385 switch_page(dev, asic, page);
388 outb(0, baseaddr + reg);
398 switch_page(dev, asic, 0);
404 static void lock_port(
struct comedi_device *dev,
int asic,
int port)
408 if (asic < 0 || asic >= board->
num_asics)
419 static void unlock_port(
struct comedi_device *dev,
int asic,
int port)
423 if (asic < 0 || asic >= board->
num_asics)
443 subpriv->intr.enabled_mask = 0;
449 for (port = firstport; port < firstport + nports; ++
port) {
462 if (irq ==
devpriv->asics[asic].irq) {
464 unsigned triggered = 0;
467 unsigned char int_pend;
478 if (int_pend & (0x1 << port)) {
480 io_lines_with_edges = 0;
481 switch_page(dev, asic,
483 io_lines_with_edges =
487 if (io_lines_with_edges)
494 io_lines_with_edges <<
502 spin_unlock_irqrestore(&
devpriv->asics[asic].spinlock,
509 (
"PCMUIO DEBUG: got edge detect interrupt %d asic %d which_chans: %06x\n",
510 irq, asic, triggered);
513 if (
subpriv->intr.asic == asic) {
521 oldevents = s->
async->events;
543 async->cmd.chanlist_len;
548 if (mytrig & (1
U << ch)) {
570 if (!
subpriv->intr.continuous) {
572 if (
subpriv->intr.stop_count > 0) {
574 if (
subpriv->intr.stop_count == 0) {
586 spin_unlock_irqrestore
616 unsigned bits = 0, pol_bits = 0,
n;
624 subpriv->intr.enabled_mask = 0;
637 bits &= ((0x1 <<
subpriv->intr.num_asic_chans) -
638 1) <<
subpriv->intr.first_chan;
642 for (port = firstport; port < firstport + nports; ++
port) {
644 bits >> (
subpriv->intr.first_chan + (port -
647 pol_bits >> (
subpriv->intr.first_chan +
648 (port - firstport) * 8) & 0xff;
666 pcmuio_stop_intr(dev, s);
667 spin_unlock_irqrestore(&
subpriv->intr.spinlock, flags);
677 unsigned int trignum)
688 event = pcmuio_start_intr(dev, s);
690 spin_unlock_irqrestore(&
subpriv->intr.spinlock, flags);
726 s->
async->inttrig = pcmuio_inttrig_start_intr;
730 event = pcmuio_start_intr(dev, s);
733 spin_unlock_irqrestore(&
subpriv->intr.spinlock, flags);
752 int sdev_no, chans_left, n_subdevs,
port,
asic, thisasic_chanct = 0;
762 dev->
driver->driver_name, iobase);
768 dev->
driver->driver_name)) {
781 "cannot allocate private data structure\n");
801 "cannot allocate subdevice private data structures\n");
826 subpriv->intr.num_asic_chans = -1;
833 if (port >= PORTS_PER_ASIC) {
841 if (thisasic_chanct <
848 subpriv->intr.first_chan = byte_no * 8;
849 subpriv->intr.asic_chan = thisasic_chanct;
854 s->
cancel = pcmuio_cancel;
880 for (i = asic - 1; i >= 0; --
i) {
933 .driver_name =
"pcmuio",
935 .attach = pcmuio_attach,
936 .detach = pcmuio_detach,
937 .board_name = &pcmuio_boards[0].
name,