55 #include <linux/slab.h>
56 #include "../comedidev.h"
61 #define NI6514_DIO_SIZE 4096
62 #define NI6514_MITE_SIZE 4096
64 #define NI_65XX_MAX_NUM_PORTS 12
65 static const unsigned ni_65xx_channels_per_port = 8;
66 static const unsigned ni_65xx_port_offset = 0x10;
68 static inline unsigned Port_Data(
unsigned port)
70 return 0x40 + port * ni_65xx_port_offset;
73 static inline unsigned Port_Select(
unsigned port)
75 return 0x41 + port * ni_65xx_port_offset;
80 return 0x42 + port * ni_65xx_port_offset;
85 return 0x43 + port * ni_65xx_port_offset;
90 return 0x44 + port * ni_65xx_port_offset;
93 #define ID_Register 0x00
95 #define Clear_Register 0x01
97 #define ClrOverflow 0x04
99 #define Filter_Interval 0x08
101 #define Change_Status 0x02
102 #define MasterInterruptStatus 0x04
103 #define Overflow 0x02
104 #define EdgeStatus 0x01
106 #define Master_Interrupt_Control 0x03
107 #define FallingEdgeIntEnable 0x10
108 #define RisingEdgeIntEnable 0x08
109 #define MasterInterruptEnable 0x04
110 #define OverflowIntEnable 0x02
111 #define EdgeIntEnable 0x01
127 .invert_outputs = 0},
132 .invert_outputs = 0},
157 .invert_outputs = 1},
162 .invert_outputs = 1},
168 .invert_outputs = 1},
174 .invert_outputs = 1},
180 .invert_outputs = 1},
186 .invert_outputs = 1},
191 .invert_outputs = 1},
196 .invert_outputs = 1},
202 .invert_outputs = 1},
208 .invert_outputs = 1},
241 #define n_ni_65xx_boards ARRAY_SIZE(ni_65xx_boards)
247 static inline unsigned ni_65xx_port_by_channel(
unsigned channel)
249 return channel / ni_65xx_channels_per_port;
252 static inline unsigned ni_65xx_total_num_ports(
const struct ni_65xx_board
313 if (subdev_private ==
NULL)
315 return subdev_private;
323 const unsigned port =
324 sprivate(s)->base_port + ni_65xx_port_by_channel(chan);
329 static const unsigned filter_resolution_ns = 200;
330 static const unsigned max_filter_interval = 0xfffff;
333 (filter_resolution_ns / 2)) / filter_resolution_ns;
334 if (interval > max_filter_interval)
335 interval = max_filter_interval;
336 data[1] = interval * filter_resolution_ns;
338 if (interval !=
private(dev)->filter_interval) {
340 private(dev)->mite->daq_io_addr +
342 private(
dev)->filter_interval = interval;
345 private(
dev)->filter_enable[port] |=
346 1 << (chan % ni_65xx_channels_per_port);
348 private(
dev)->filter_enable[port] &=
349 ~(1 << (chan % ni_65xx_channels_per_port));
352 writeb(
private(dev)->filter_enable[port],
358 static int ni_65xx_dio_insn_config(
struct comedi_device *dev,
366 port = sprivate(s)->base_port +
370 return ni_65xx_config_filter(dev, s, insn, data);
376 writeb(0,
private(dev)->mite->daq_io_addr + Port_Select(port));
383 writeb(1,
private(dev)->mite->daq_io_addr + Port_Select(port));
389 data[1] =
private(
dev)->dio_direction[port];
402 unsigned base_bitfield_channel;
403 const unsigned max_ports_per_bitfield = 5;
404 unsigned read_bits = 0;
408 for (j = 0; j < max_ports_per_bitfield; ++
j) {
409 const unsigned port_offset =
410 ni_65xx_port_by_channel(base_bitfield_channel) +
j;
411 const unsigned port =
412 sprivate(s)->base_port + port_offset;
413 unsigned base_port_channel;
414 unsigned port_mask,
port_data, port_read_bits;
416 if (port >= ni_65xx_total_num_ports(
board(dev)))
418 base_port_channel = port_offset * ni_65xx_channels_per_port;
421 bitshift = base_port_channel - base_bitfield_channel;
422 if (bitshift >= 32 || bitshift <= -32)
425 port_mask >>= bitshift;
426 port_data >>= bitshift;
428 port_mask <<= -bitshift;
429 port_data <<= -bitshift;
435 private(
dev)->output_bits[port] &= ~port_mask;
436 private(
dev)->output_bits[port] |=
437 port_data & port_mask;
438 bits =
private(
dev)->output_bits[port];
439 if (
board(dev)->invert_outputs)
442 private(dev)->mite->daq_io_addr +
446 readb(
private(dev)->mite->daq_io_addr + Port_Data(port));
451 port_read_bits ^= 0xFF;
454 port_read_bits <<= bitshift;
456 port_read_bits >>= -bitshift;
458 read_bits |= port_read_bits;
574 static int ni_65xx_intr_insn_config(
struct comedi_device *dev,
585 private(dev)->mite->daq_io_addr +
588 private(dev)->mite->daq_io_addr +
591 private(dev)->mite->daq_io_addr +
594 private(dev)->mite->daq_io_addr +
598 private(dev)->mite->daq_io_addr +
601 private(dev)->mite->daq_io_addr +
604 private(dev)->mite->daq_io_addr +
607 private(dev)->mite->daq_io_addr +
619 for (n = 0; n <
ARRAY_SIZE(ni_65xx_boards); n++) {
621 if (board->
dev_id == dev_id)
638 dev->
board_ptr = ni_65xx_find_boardinfo(pcidev);
643 if (!
private(dev)->mite)
653 dev->
irq = mite_irq(
private(dev)->mite);
662 if (
board(dev)->num_di_ports) {
666 board(dev)->num_di_ports * ni_65xx_channels_per_port;
671 s->
private = ni_65xx_alloc_subdevice_private();
674 sprivate(s)->base_port = 0;
680 if (
board(dev)->num_do_ports) {
684 board(dev)->num_do_ports * ni_65xx_channels_per_port;
688 s->
private = ni_65xx_alloc_subdevice_private();
691 sprivate(s)->base_port =
board(dev)->num_di_ports;
697 if (
board(dev)->num_dio_ports) {
701 board(dev)->num_dio_ports * ni_65xx_channels_per_port;
706 s->
private = ni_65xx_alloc_subdevice_private();
709 sprivate(s)->base_port = 0;
710 for (i = 0; i <
board(dev)->num_dio_ports; ++
i) {
713 private(dev)->mite->daq_io_addr +
728 s->
do_cmd = ni_65xx_intr_cmd;
729 s->
cancel = ni_65xx_intr_cancel;
733 for (i = 0; i < ni_65xx_total_num_ports(
board(dev)); ++
i) {
736 if (
board(dev)->invert_outputs)
738 private(dev)->mite->daq_io_addr + Port_Data(i));
741 private(dev)->mite->daq_io_addr + Port_Data(i));
763 if (
private(dev) &&
private(dev)->mite
764 &&
private(dev)->mite->daq_io_addr) {
766 private(dev)->mite->daq_io_addr +
780 if (
private(dev)->mite) {
782 mite_free(
private(dev)->mite);
788 .driver_name =
"ni_65xx",
790 .attach_pci = ni_65xx_attach_pci,
791 .detach = ni_65xx_detach,
805 static struct pci_driver ni_65xx_pci_driver = {
807 .id_table = ni_65xx_pci_table,
808 .probe = ni_65xx_pci_probe,