209 #include <linux/slab.h>
211 #include "../comedidev.h"
217 #define DIO200_DRIVER_NAME "amplc_dio200"
219 #define DO_ISA IS_ENABLED(CONFIG_COMEDI_AMPLC_DIO200_ISA)
220 #define DO_PCI IS_ENABLED(CONFIG_COMEDI_AMPLC_DIO200_PCI)
223 #define PCI_VENDOR_ID_AMPLICON 0x14dc
224 #define PCI_DEVICE_ID_AMPLICON_PCI272 0x000a
225 #define PCI_DEVICE_ID_AMPLICON_PCI215 0x000b
226 #define PCI_DEVICE_ID_INVALID 0xffff
229 #define DIO200_IO_SIZE 0x20
230 #define DIO200_XCLK_SCE 0x18
231 #define DIO200_YCLK_SCE 0x19
232 #define DIO200_ZCLK_SCE 0x1a
233 #define DIO200_XGAT_SCE 0x1b
234 #define DIO200_YGAT_SCE 0x1c
235 #define DIO200_ZGAT_SCE 0x1d
236 #define DIO200_INT_SCE 0x1e
246 #define CLK_SCE(which, chan, source) (((which) << 5) | ((chan) << 3) | (source))
247 #define GAT_SCE(which, chan, source) (((which) << 5) | ((chan) << 3) | (source))
252 static const unsigned clock_period[8] = {
304 .layout = pc212_layout,
310 .layout = pc214_layout,
322 .layout = pc218_layout,
362 #define DIO200_MAX_SUBDEVS 7
363 #define DIO200_MAX_ISNS 6
380 .sdinfo = {0x00, 0x08, 0x0C, 0x10, 0x14,
383 .has_clk_gat_sce = 1,
389 .sdinfo = {0x00, 0x08, 0x10, 0x01},
391 .has_clk_gat_sce = 0,
399 .sdinfo = {0x00, 0x08, 0x10, 0x14, 0x3F},
401 .has_clk_gat_sce = 1,
409 .sdinfo = {0x00, 0x04, 0x08, 0x0C, 0x10,
413 .has_clk_gat_sce = 1,
420 .sdinfo = {0x00, 0x08, 0x10, 0x3F},
422 .has_clk_gat_sce = 0,
474 for (i = 0; i <
ARRAY_SIZE(dio200_boards); i++)
475 if (is_pci_board(&dio200_boards[i]) &&
477 return &dio200_boards[i];
489 struct pci_dev *pci_dev =
NULL;
495 if (bus != pci_dev->
bus->number ||
506 foundboard = dio200_find_pci_board(pci_dev);
507 if (foundboard ==
NULL)
519 "No supported board found! (req. bus %d, slot %d)\n",
614 unsigned int trignum)
628 event = dio200_start_intr(dev, s);
630 spin_unlock_irqrestore(&subpriv->
spinlock, flags);
642 static int dio200_handle_read_intr(
struct comedi_device *dev,
648 unsigned cur_enabled;
649 unsigned int oldevents;
655 oldevents = s->
async->events;
669 & ~triggered)) != 0) {
670 triggered |= intstat;
671 cur_enabled &= ~triggered;
704 unsigned int n, ch,
len;
707 len = s->
async->cmd.chanlist_len;
708 for (n = 0; n < len; n++) {
710 if (triggered & (1
U << ch))
719 dio200_stop_intr(dev, s);
733 dio200_stop_intr(dev,
741 spin_unlock_irqrestore(&subpriv->
spinlock, flags);
743 if (oldevents != s->
async->events)
746 return (triggered != 0);
752 static int dio200_subdev_intr_cancel(
struct comedi_device *dev,
760 dio200_stop_intr(dev, s);
762 spin_unlock_irqrestore(&subpriv->
spinlock, flags);
789 err |= cfc_check_trigger_is_unique(cmd->
start_src);
790 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
877 s->
async->inttrig = dio200_inttrig_start_intr;
881 event = dio200_start_intr(dev, s);
884 spin_unlock_irqrestore(&subpriv->
spinlock, flags);
902 subpriv = kzalloc(
sizeof(*subpriv),
GFP_KERNEL);
928 s->
insn_bits = dio200_subdev_intr_insn_bits;
930 s->
do_cmd = dio200_subdev_intr_cmd;
931 s->
cancel = dio200_subdev_intr_cancel;
962 handled = dio200_handle_read_intr(dev, s);
982 data[0] = i8254_read(subpriv->
iobase, 0, chan);
983 spin_unlock_irqrestore(&subpriv->
spinlock, flags);
1000 i8254_write(subpriv->
iobase, 0, chan, data[0]);
1001 spin_unlock_irqrestore(&subpriv->
spinlock, flags);
1011 unsigned int counter_number,
unsigned int gate_src)
1017 if (counter_number > 2)
1023 byte =
GAT_SCE(subpriv->
which, counter_number, gate_src);
1034 unsigned int counter_number)
1038 if (counter_number > 2)
1041 return subpriv->
gate_src[counter_number];
1049 unsigned int counter_number,
unsigned int clock_src)
1055 if (counter_number > 2)
1061 byte =
CLK_SCE(subpriv->
which, counter_number, clock_src);
1072 unsigned int counter_number,
unsigned int *period_ns)
1078 if (counter_number > 2)
1081 clock_src = subpriv->
clock_src[counter_number];
1096 unsigned long flags;
1101 ret = i8254_set_mode(subpriv->
iobase, 0, chan, data[1]);
1106 data[1] = i8254_status(subpriv->
iobase, 0, chan);
1109 ret = dio200_set_gate_src(subpriv, chan, data[2]);
1114 ret = dio200_get_gate_src(subpriv, chan);
1122 ret = dio200_set_clock_src(subpriv, chan, data[1]);
1127 ret = dio200_get_clock_src(subpriv, chan, &data[2]);
1138 spin_unlock_irqrestore(&subpriv->
spinlock, flags);
1139 return ret < 0 ? ret : insn->
n;
1150 unsigned long iobase,
unsigned offset,
1156 subpriv = kzalloc(
sizeof(*subpriv),
GFP_KERNEL);
1174 if (has_clk_gat_sce) {
1181 subpriv->
which = (offset >> 2) & 1;
1185 for (chan = 0; chan < 3; chan++) {
1186 i8254_set_mode(subpriv->
iobase, 0, chan,
1190 dio200_set_gate_src(subpriv, chan, 0);
1192 dio200_set_clock_src(subpriv, chan, 0);
1210 static void dio200_report_attach(
struct comedi_device *dev,
unsigned int irq)
1212 const struct dio200_board *thisboard = comedi_board(dev);
1213 struct pci_dev *
pcidev = comedi_to_pci_dev(dev);
1217 if (is_isa_board(thisboard))
1218 tmplen =
scnprintf(tmpbuf,
sizeof(tmpbuf),
1219 "(base %#lx) ", dev->
iobase);
1220 else if (is_pci_board(thisboard))
1221 tmplen =
scnprintf(tmpbuf,
sizeof(tmpbuf),
1222 "(pci %s) ", pci_name(pcidev));
1226 tmplen +=
scnprintf(&tmpbuf[tmplen],
sizeof(tmpbuf) - tmplen,
1228 (dev->
irq ?
"" :
" UNAVAILABLE"));
1230 tmplen +=
scnprintf(&tmpbuf[tmplen],
sizeof(tmpbuf) - tmplen,
1235 static int dio200_common_attach(
struct comedi_device *dev,
unsigned long iobase,
1236 unsigned int irq,
unsigned long req_irq_flags)
1238 const struct dio200_board *thisboard = comedi_board(dev);
1241 &dio200_layouts[thisboard->
layout];
1257 switch (layout->
sdtype[n]) {
1260 ret = dio200_subdev_8254_init(dev, s, iobase,
1269 iobase + layout->
sdinfo[n]);
1276 ret = dio200_subdev_intr_init(dev, s,
1295 if (sdx >= 0 && sdx < dev->n_subdevices)
1298 if (
request_irq(irq, dio200_interrupt, req_irq_flags,
1303 "warning! irq %u unavailable!\n", irq);
1306 dio200_report_attach(dev, irq);
1310 static int dio200_pci_common_attach(
struct comedi_device *dev,
1311 struct pci_dev *pci_dev)
1316 comedi_set_hw_dev(dev, &pci_dev->
dev);
1321 "error! cannot enable PCI device and request regions!\n");
1325 return dio200_common_attach(dev, iobase, pci_dev->
irq,
IRQF_SHARED);
1336 const struct dio200_board *thisboard = comedi_board(dev);
1348 if (is_isa_board(thisboard)) {
1357 return dio200_common_attach(dev, iobase, irq, 0);
1358 }
else if (is_pci_board(thisboard)) {
1361 pci_dev = dio200_find_pci_dev(dev, it);
1364 return dio200_pci_common_attach(dev, pci_dev);
1367 ": BUG! cannot determine board type!\n");
1378 struct pci_dev *pci_dev)
1392 dev->
board_ptr = dio200_find_pci_board(pci_dev);
1404 return dio200_pci_common_attach(dev, pci_dev);
1409 const struct dio200_board *thisboard = comedi_board(dev);
1418 layout = &dio200_layouts[thisboard->
layout];
1421 switch (layout->
sdtype[n]) {
1423 dio200_subdev_8254_cleanup(dev, s);
1429 dio200_subdev_intr_cleanup(dev, s);
1436 if (is_isa_board(thisboard)) {
1439 }
else if (is_pci_board(thisboard)) {
1440 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
1458 .attach = dio200_attach,
1459 .attach_pci = dio200_attach_pci,
1460 .detach = dio200_detach,
1461 .board_name = &dio200_boards[0].
name,
1475 static int __devinit amplc_dio200_pci_probe(
struct pci_dev *dev,
1482 static void __devexit amplc_dio200_pci_remove(
struct pci_dev *dev)
1487 static struct pci_driver amplc_dio200_pci_driver = {
1489 .id_table = dio200_pci_table,
1490 .probe = &lc_dio200_pci_probe,