3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
8 * Tel: +19(0)7223/9493-0
9 * Fax: +49(0)7223/9493-92
10 * http://www.addi-data.com
13 * This program is free software; you can redistribute it and/or modify it under
14 * the terms of the GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the License, or (at your option) any later
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
25 * Driver: addi_apci_1564
26 * Description: ADDI-DATA APCI-1564 Digital I/O board
27 * Devices: [ADDI-DATA] APCI-1564 (addi_apci_1564)
28 * Author: H Hartley Sweeten <hsweeten@visionengravers.com>
29 * Updated: Thu, 02 Jun 2016 13:12:46 -0700
32 * Configuration Options: not applicable, uses comedi PCI auto config
34 * This board has the following features:
35 * - 32 optically isolated digital inputs (24V), 16 of which can
36 * generate change-of-state (COS) interrupts (channels 4 to 19)
37 * - 32 optically isolated digital outputs (10V to 36V)
38 * - 1 8-bit watchdog for resetting the outputs
41 * - 2 diagnostic inputs
43 * The COS, timer, and counter subdevices all use the dev->read_subdev to
44 * return the interrupt status. The sample data is updated and returned when
45 * any of these subdevices generate an interrupt. The sample data format is:
48 * ----- ------------------------------------------
51 * 29 counter 2 interrupt
52 * 28 counter 1 interrupt
53 * 27 counter 0 interrupt
55 * 19:4 COS digital input state (channels 19 to 4)
58 * The COS interrupts must be configured using an INSN_CONFIG_DIGITAL_TRIG
59 * instruction before they can be enabled by an async command. The COS
60 * interrupts will stay active until canceled.
62 * The timer subdevice does not use an async command. All control is handled
63 * by the (*insn_config).
65 * FIXME: The format of the ADDI_TCW_TIMEBASE_REG is not descibed in the
66 * datasheet I have. The INSN_CONFIG_SET_CLOCK_SRC currently just writes
67 * the raw data[1] to this register along with the raw data[2] value to the
68 * ADDI_TCW_RELOAD_REG. If anyone tests this and can determine the actual
69 * timebase/reload operation please let me know.
71 * The counter subdevice also does not use an async command. All control is
72 * handled by the (*insn_config).
74 * FIXME: The operation of the counters is not really described in the
75 * datasheet I have. The (*insn_config) needs more work.
78 #include <linux/module.h>
79 #include <linux/interrupt.h>
81 #include "../comedi_pci.h"
83 #include "addi_watchdog.h"
88 * PLD Revision 1.0 I/O Mapping
90 * 0x04 - 0x18 Timer 12-Bit
92 * PLD Revision 2.x I/O Mapping
94 * 0x04 - 0x14 Digital Input
95 * 0x18 - 0x25 Digital Output
96 * 0x28 - 0x44 Watchdog 8-Bit
97 * 0x48 - 0x64 Timer 12-Bit
99 #define APCI1564_EEPROM_REG 0x00
100 #define APCI1564_EEPROM_VCC_STATUS BIT(8)
101 #define APCI1564_EEPROM_TO_REV(x) (((x) >> 4) & 0xf)
102 #define APCI1564_EEPROM_DI BIT(3)
103 #define APCI1564_EEPROM_DO BIT(2)
104 #define APCI1564_EEPROM_CS BIT(1)
105 #define APCI1564_EEPROM_CLK BIT(0)
106 #define APCI1564_REV1_TIMER_IOBASE 0x04
107 #define APCI1564_REV2_MAIN_IOBASE 0x04
108 #define APCI1564_REV2_TIMER_IOBASE 0x48
113 * PLD Revision 1.0 I/O Mapping
114 * 0x00 - 0x10 Digital Input
115 * 0x14 - 0x20 Digital Output
116 * 0x24 - 0x3c Watchdog 8-Bit
118 * PLD Revision 2.x I/O Mapping
123 #define APCI1564_REV1_MAIN_IOBASE 0x00
126 * dev->iobase Register Map
127 * PLD Revision 1.0 - PCI BAR 1 + 0x00
128 * PLD Revision 2.x - PCI BAR 0 + 0x04
130 #define APCI1564_DI_REG 0x00
131 #define APCI1564_DI_INT_MODE1_REG 0x04
132 #define APCI1564_DI_INT_MODE2_REG 0x08
133 #define APCI1564_DI_INT_MODE_MASK 0x000ffff0 /* chans [19:4] */
134 #define APCI1564_DI_INT_STATUS_REG 0x0c
135 #define APCI1564_DI_IRQ_REG 0x10
136 #define APCI1564_DI_IRQ_ENA BIT(2)
137 #define APCI1564_DI_IRQ_MODE BIT(1) /* 1=AND, 0=OR */
138 #define APCI1564_DO_REG 0x14
139 #define APCI1564_DO_INT_CTRL_REG 0x18
140 #define APCI1564_DO_INT_CTRL_CC_INT_ENA BIT(1)
141 #define APCI1564_DO_INT_CTRL_VCC_INT_ENA BIT(0)
142 #define APCI1564_DO_INT_STATUS_REG 0x1c
143 #define APCI1564_DO_INT_STATUS_CC BIT(1)
144 #define APCI1564_DO_INT_STATUS_VCC BIT(0)
145 #define APCI1564_DO_IRQ_REG 0x20
146 #define APCI1564_DO_IRQ_INTR BIT(0)
147 #define APCI1564_WDOG_IOBASE 0x24
150 * devpriv->timer Register Map (see addi_tcw.h for register/bit defines)
151 * PLD Revision 1.0 - PCI BAR 0 + 0x04
152 * PLD Revision 2.x - PCI BAR 0 + 0x48
156 * devpriv->counters Register Map (see addi_tcw.h for register/bit defines)
157 * PLD Revision 2.x - PCI BAR 1 + 0x00
159 #define APCI1564_COUNTER(x) ((x) * 0x20)
162 * The dev->read_subdev is used to return the interrupt events along with
163 * the state of the interrupt capable inputs.
165 #define APCI1564_EVENT_COS BIT(31)
166 #define APCI1564_EVENT_TIMER BIT(30)
167 #define APCI1564_EVENT_COUNTER(x) BIT(27 + (x)) /* counter 0-2 */
168 #define APCI1564_EVENT_MASK 0xfff0000f /* all but [19:4] */
170 struct apci1564_private {
171 unsigned long eeprom; /* base address of EEPROM register */
172 unsigned long timer; /* base address of 12-bit timer */
173 unsigned long counters; /* base address of 32-bit counters */
174 unsigned int mode1; /* rising-edge/high level channels */
175 unsigned int mode2; /* falling-edge/low level channels */
176 unsigned int ctrl; /* interrupt mode OR (edge) . AND (level) */
179 static int apci1564_reset(struct comedi_device *dev)
181 struct apci1564_private *devpriv = dev->private;
183 /* Disable the input interrupts and reset status register */
184 outl(0x0, dev->iobase + APCI1564_DI_IRQ_REG);
185 inl(dev->iobase + APCI1564_DI_INT_STATUS_REG);
186 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE1_REG);
187 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE2_REG);
189 /* Reset the output channels and disable interrupts */
190 outl(0x0, dev->iobase + APCI1564_DO_REG);
191 outl(0x0, dev->iobase + APCI1564_DO_INT_CTRL_REG);
193 /* Reset the watchdog registers */
194 addi_watchdog_reset(dev->iobase + APCI1564_WDOG_IOBASE);
196 /* Reset the timer registers */
197 outl(0x0, devpriv->timer + ADDI_TCW_CTRL_REG);
198 outl(0x0, devpriv->timer + ADDI_TCW_RELOAD_REG);
200 if (devpriv->counters) {
201 unsigned long iobase = devpriv->counters + ADDI_TCW_CTRL_REG;
203 /* Reset the counter registers */
204 outl(0x0, iobase + APCI1564_COUNTER(0));
205 outl(0x0, iobase + APCI1564_COUNTER(1));
206 outl(0x0, iobase + APCI1564_COUNTER(2));
212 static irqreturn_t apci1564_interrupt(int irq, void *d)
214 struct comedi_device *dev = d;
215 struct apci1564_private *devpriv = dev->private;
216 struct comedi_subdevice *s = dev->read_subdev;
221 s->state &= ~APCI1564_EVENT_MASK;
223 status = inl(dev->iobase + APCI1564_DI_IRQ_REG);
224 if (status & APCI1564_DI_IRQ_ENA) {
225 /* get the COS interrupt state and set the event flag */
226 s->state = inl(dev->iobase + APCI1564_DI_INT_STATUS_REG);
227 s->state &= APCI1564_DI_INT_MODE_MASK;
228 s->state |= APCI1564_EVENT_COS;
230 /* clear the interrupt */
231 outl(status & ~APCI1564_DI_IRQ_ENA,
232 dev->iobase + APCI1564_DI_IRQ_REG);
233 outl(status, dev->iobase + APCI1564_DI_IRQ_REG);
236 status = inl(devpriv->timer + ADDI_TCW_IRQ_REG);
237 if (status & ADDI_TCW_IRQ) {
238 s->state |= APCI1564_EVENT_TIMER;
240 /* clear the interrupt */
241 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
242 outl(0x0, devpriv->timer + ADDI_TCW_CTRL_REG);
243 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG);
246 if (devpriv->counters) {
247 for (chan = 0; chan < 3; chan++) {
248 unsigned long iobase;
250 iobase = devpriv->counters + APCI1564_COUNTER(chan);
252 status = inl(iobase + ADDI_TCW_IRQ_REG);
253 if (status & ADDI_TCW_IRQ) {
254 s->state |= APCI1564_EVENT_COUNTER(chan);
256 /* clear the interrupt */
257 ctrl = inl(iobase + ADDI_TCW_CTRL_REG);
258 outl(0x0, iobase + ADDI_TCW_CTRL_REG);
259 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
264 if (s->state & APCI1564_EVENT_MASK) {
265 comedi_buf_write_samples(s, &s->state, 1);
266 comedi_handle_events(dev, s);
272 static int apci1564_di_insn_bits(struct comedi_device *dev,
273 struct comedi_subdevice *s,
274 struct comedi_insn *insn,
277 data[1] = inl(dev->iobase + APCI1564_DI_REG);
282 static int apci1564_do_insn_bits(struct comedi_device *dev,
283 struct comedi_subdevice *s,
284 struct comedi_insn *insn,
287 s->state = inl(dev->iobase + APCI1564_DO_REG);
289 if (comedi_dio_update_state(s, data))
290 outl(s->state, dev->iobase + APCI1564_DO_REG);
297 static int apci1564_diag_insn_bits(struct comedi_device *dev,
298 struct comedi_subdevice *s,
299 struct comedi_insn *insn,
302 data[1] = inl(dev->iobase + APCI1564_DO_INT_STATUS_REG) & 3;
308 * Change-Of-State (COS) interrupt configuration
310 * Channels 4 to 19 are interruptible. These channels can be configured
311 * to generate interrupts based on AND/OR logic for the desired channels.
314 * - reacts to rising or falling edges
315 * - interrupt is generated when any enabled channel
316 * meet the desired interrupt condition
319 * - reacts to changes in level of the selected inputs
320 * - interrupt is generated when all enabled channels
321 * meet the desired interrupt condition
322 * - after an interrupt, a change in level must occur on
323 * the selected inputs to release the IRQ logic
325 * The COS interrupt must be configured before it can be enabled.
327 * data[0] : INSN_CONFIG_DIGITAL_TRIG
328 * data[1] : trigger number (= 0)
329 * data[2] : configuration operation:
330 * COMEDI_DIGITAL_TRIG_DISABLE = no interrupts
331 * COMEDI_DIGITAL_TRIG_ENABLE_EDGES = OR (edge) interrupts
332 * COMEDI_DIGITAL_TRIG_ENABLE_LEVELS = AND (level) interrupts
333 * data[3] : left-shift for data[4] and data[5]
334 * data[4] : rising-edge/high level channels
335 * data[5] : falling-edge/low level channels
337 static int apci1564_cos_insn_config(struct comedi_device *dev,
338 struct comedi_subdevice *s,
339 struct comedi_insn *insn,
342 struct apci1564_private *devpriv = dev->private;
343 unsigned int shift, oldmask;
346 case INSN_CONFIG_DIGITAL_TRIG:
350 oldmask = (1U << shift) - 1;
352 case COMEDI_DIGITAL_TRIG_DISABLE:
356 outl(0x0, dev->iobase + APCI1564_DI_IRQ_REG);
357 inl(dev->iobase + APCI1564_DI_INT_STATUS_REG);
358 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE1_REG);
359 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE2_REG);
361 case COMEDI_DIGITAL_TRIG_ENABLE_EDGES:
362 if (devpriv->ctrl != APCI1564_DI_IRQ_ENA) {
363 /* switching to 'OR' mode */
364 devpriv->ctrl = APCI1564_DI_IRQ_ENA;
365 /* wipe old channels */
369 /* preserve unspecified channels */
370 devpriv->mode1 &= oldmask;
371 devpriv->mode2 &= oldmask;
373 /* configure specified channels */
374 devpriv->mode1 |= data[4] << shift;
375 devpriv->mode2 |= data[5] << shift;
377 case COMEDI_DIGITAL_TRIG_ENABLE_LEVELS:
378 if (devpriv->ctrl != (APCI1564_DI_IRQ_ENA |
379 APCI1564_DI_IRQ_MODE)) {
380 /* switching to 'AND' mode */
381 devpriv->ctrl = APCI1564_DI_IRQ_ENA |
382 APCI1564_DI_IRQ_MODE;
383 /* wipe old channels */
387 /* preserve unspecified channels */
388 devpriv->mode1 &= oldmask;
389 devpriv->mode2 &= oldmask;
391 /* configure specified channels */
392 devpriv->mode1 |= data[4] << shift;
393 devpriv->mode2 |= data[5] << shift;
399 /* ensure the mode bits are in-range for channels [19:4] */
400 devpriv->mode1 &= APCI1564_DI_INT_MODE_MASK;
401 devpriv->mode2 &= APCI1564_DI_INT_MODE_MASK;
409 static int apci1564_cos_insn_bits(struct comedi_device *dev,
410 struct comedi_subdevice *s,
411 struct comedi_insn *insn,
419 static int apci1564_cos_cmdtest(struct comedi_device *dev,
420 struct comedi_subdevice *s,
421 struct comedi_cmd *cmd)
425 /* Step 1 : check if triggers are trivially valid */
427 err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW);
428 err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
429 err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_FOLLOW);
430 err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
431 err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_NONE);
436 /* Step 2a : make sure trigger sources are unique */
437 /* Step 2b : and mutually compatible */
439 /* Step 3: check if arguments are trivially valid */
441 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
442 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
443 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0);
444 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
446 err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0);
451 /* Step 4: fix up any arguments */
453 /* Step 5: check channel list if it exists */
459 * Change-Of-State (COS) 'do_cmd' operation
461 * Enable the COS interrupt as configured by apci1564_cos_insn_config().
463 static int apci1564_cos_cmd(struct comedi_device *dev,
464 struct comedi_subdevice *s)
466 struct apci1564_private *devpriv = dev->private;
468 if (!devpriv->ctrl && !(devpriv->mode1 || devpriv->mode2)) {
469 dev_warn(dev->class_dev,
470 "Interrupts disabled due to mode configuration!\n");
474 outl(devpriv->mode1, dev->iobase + APCI1564_DI_INT_MODE1_REG);
475 outl(devpriv->mode2, dev->iobase + APCI1564_DI_INT_MODE2_REG);
476 outl(devpriv->ctrl, dev->iobase + APCI1564_DI_IRQ_REG);
481 static int apci1564_cos_cancel(struct comedi_device *dev,
482 struct comedi_subdevice *s)
484 outl(0x0, dev->iobase + APCI1564_DI_IRQ_REG);
485 inl(dev->iobase + APCI1564_DI_INT_STATUS_REG);
486 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE1_REG);
487 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE2_REG);
492 static int apci1564_timer_insn_config(struct comedi_device *dev,
493 struct comedi_subdevice *s,
494 struct comedi_insn *insn,
497 struct apci1564_private *devpriv = dev->private;
501 case INSN_CONFIG_ARM:
502 if (data[1] > s->maxdata)
504 outl(data[1], devpriv->timer + ADDI_TCW_RELOAD_REG);
505 outl(ADDI_TCW_CTRL_IRQ_ENA | ADDI_TCW_CTRL_TIMER_ENA,
506 devpriv->timer + ADDI_TCW_CTRL_REG);
508 case INSN_CONFIG_DISARM:
509 outl(0x0, devpriv->timer + ADDI_TCW_CTRL_REG);
511 case INSN_CONFIG_GET_COUNTER_STATUS:
513 val = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
514 if (val & ADDI_TCW_CTRL_IRQ_ENA)
515 data[1] |= COMEDI_COUNTER_ARMED;
516 if (val & ADDI_TCW_CTRL_TIMER_ENA)
517 data[1] |= COMEDI_COUNTER_COUNTING;
518 val = inl(devpriv->timer + ADDI_TCW_STATUS_REG);
519 if (val & ADDI_TCW_STATUS_OVERFLOW)
520 data[1] |= COMEDI_COUNTER_TERMINAL_COUNT;
521 data[2] = COMEDI_COUNTER_ARMED | COMEDI_COUNTER_COUNTING |
522 COMEDI_COUNTER_TERMINAL_COUNT;
524 case INSN_CONFIG_SET_CLOCK_SRC:
525 if (data[2] > s->maxdata)
527 outl(data[1], devpriv->timer + ADDI_TCW_TIMEBASE_REG);
528 outl(data[2], devpriv->timer + ADDI_TCW_RELOAD_REG);
530 case INSN_CONFIG_GET_CLOCK_SRC:
531 data[1] = inl(devpriv->timer + ADDI_TCW_TIMEBASE_REG);
532 data[2] = inl(devpriv->timer + ADDI_TCW_RELOAD_REG);
541 static int apci1564_timer_insn_write(struct comedi_device *dev,
542 struct comedi_subdevice *s,
543 struct comedi_insn *insn,
546 struct apci1564_private *devpriv = dev->private;
548 /* just write the last last to the reload register */
550 unsigned int val = data[insn->n - 1];
552 outl(val, devpriv->timer + ADDI_TCW_RELOAD_REG);
558 static int apci1564_timer_insn_read(struct comedi_device *dev,
559 struct comedi_subdevice *s,
560 struct comedi_insn *insn,
563 struct apci1564_private *devpriv = dev->private;
566 /* return the actual value of the timer */
567 for (i = 0; i < insn->n; i++)
568 data[i] = inl(devpriv->timer + ADDI_TCW_VAL_REG);
573 static int apci1564_counter_insn_config(struct comedi_device *dev,
574 struct comedi_subdevice *s,
575 struct comedi_insn *insn,
578 struct apci1564_private *devpriv = dev->private;
579 unsigned int chan = CR_CHAN(insn->chanspec);
580 unsigned long iobase = devpriv->counters + APCI1564_COUNTER(chan);
584 case INSN_CONFIG_ARM:
585 val = inl(iobase + ADDI_TCW_CTRL_REG);
586 val |= ADDI_TCW_CTRL_IRQ_ENA | ADDI_TCW_CTRL_CNTR_ENA;
587 outl(data[1], iobase + ADDI_TCW_RELOAD_REG);
588 outl(val, iobase + ADDI_TCW_CTRL_REG);
590 case INSN_CONFIG_DISARM:
591 val = inl(iobase + ADDI_TCW_CTRL_REG);
592 val &= ~(ADDI_TCW_CTRL_IRQ_ENA | ADDI_TCW_CTRL_CNTR_ENA);
593 outl(val, iobase + ADDI_TCW_CTRL_REG);
595 case INSN_CONFIG_SET_COUNTER_MODE:
597 * FIXME: The counter operation is not described in the
598 * datasheet. For now just write the raw data[1] value to
599 * the control register.
601 outl(data[1], iobase + ADDI_TCW_CTRL_REG);
603 case INSN_CONFIG_GET_COUNTER_STATUS:
605 val = inl(iobase + ADDI_TCW_CTRL_REG);
606 if (val & ADDI_TCW_CTRL_IRQ_ENA)
607 data[1] |= COMEDI_COUNTER_ARMED;
608 if (val & ADDI_TCW_CTRL_CNTR_ENA)
609 data[1] |= COMEDI_COUNTER_COUNTING;
610 val = inl(iobase + ADDI_TCW_STATUS_REG);
611 if (val & ADDI_TCW_STATUS_OVERFLOW)
612 data[1] |= COMEDI_COUNTER_TERMINAL_COUNT;
613 data[2] = COMEDI_COUNTER_ARMED | COMEDI_COUNTER_COUNTING |
614 COMEDI_COUNTER_TERMINAL_COUNT;
623 static int apci1564_counter_insn_write(struct comedi_device *dev,
624 struct comedi_subdevice *s,
625 struct comedi_insn *insn,
628 struct apci1564_private *devpriv = dev->private;
629 unsigned int chan = CR_CHAN(insn->chanspec);
630 unsigned long iobase = devpriv->counters + APCI1564_COUNTER(chan);
632 /* just write the last last to the reload register */
634 unsigned int val = data[insn->n - 1];
636 outl(val, iobase + ADDI_TCW_RELOAD_REG);
642 static int apci1564_counter_insn_read(struct comedi_device *dev,
643 struct comedi_subdevice *s,
644 struct comedi_insn *insn,
647 struct apci1564_private *devpriv = dev->private;
648 unsigned int chan = CR_CHAN(insn->chanspec);
649 unsigned long iobase = devpriv->counters + APCI1564_COUNTER(chan);
652 /* return the actual value of the counter */
653 for (i = 0; i < insn->n; i++)
654 data[i] = inl(iobase + ADDI_TCW_VAL_REG);
659 static int apci1564_auto_attach(struct comedi_device *dev,
660 unsigned long context_unused)
662 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
663 struct apci1564_private *devpriv;
664 struct comedi_subdevice *s;
668 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
672 ret = comedi_pci_enable(dev);
676 /* read the EEPROM register and check the I/O map revision */
677 devpriv->eeprom = pci_resource_start(pcidev, 0);
678 val = inl(devpriv->eeprom + APCI1564_EEPROM_REG);
679 if (APCI1564_EEPROM_TO_REV(val) == 0) {
680 /* PLD Revision 1.0 I/O Mapping */
681 dev->iobase = pci_resource_start(pcidev, 1) +
682 APCI1564_REV1_MAIN_IOBASE;
683 devpriv->timer = devpriv->eeprom + APCI1564_REV1_TIMER_IOBASE;
685 /* PLD Revision 2.x I/O Mapping */
686 dev->iobase = devpriv->eeprom + APCI1564_REV2_MAIN_IOBASE;
687 devpriv->timer = devpriv->eeprom + APCI1564_REV2_TIMER_IOBASE;
688 devpriv->counters = pci_resource_start(pcidev, 1);
693 if (pcidev->irq > 0) {
694 ret = request_irq(pcidev->irq, apci1564_interrupt, IRQF_SHARED,
695 dev->board_name, dev);
697 dev->irq = pcidev->irq;
700 ret = comedi_alloc_subdevices(dev, 7);
704 /* Allocate and Initialise DI Subdevice Structures */
705 s = &dev->subdevices[0];
706 s->type = COMEDI_SUBD_DI;
707 s->subdev_flags = SDF_READABLE;
710 s->range_table = &range_digital;
711 s->insn_bits = apci1564_di_insn_bits;
713 /* Allocate and Initialise DO Subdevice Structures */
714 s = &dev->subdevices[1];
715 s->type = COMEDI_SUBD_DO;
716 s->subdev_flags = SDF_WRITABLE;
719 s->range_table = &range_digital;
720 s->insn_bits = apci1564_do_insn_bits;
722 /* Change-Of-State (COS) interrupt subdevice */
723 s = &dev->subdevices[2];
725 dev->read_subdev = s;
726 s->type = COMEDI_SUBD_DI;
727 s->subdev_flags = SDF_READABLE | SDF_CMD_READ | SDF_LSAMPL;
730 s->range_table = &range_digital;
732 s->insn_config = apci1564_cos_insn_config;
733 s->insn_bits = apci1564_cos_insn_bits;
734 s->do_cmdtest = apci1564_cos_cmdtest;
735 s->do_cmd = apci1564_cos_cmd;
736 s->cancel = apci1564_cos_cancel;
738 s->type = COMEDI_SUBD_UNUSED;
741 /* Timer subdevice */
742 s = &dev->subdevices[3];
743 s->type = COMEDI_SUBD_TIMER;
744 s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
747 s->range_table = &range_digital;
748 s->insn_config = apci1564_timer_insn_config;
749 s->insn_write = apci1564_timer_insn_write;
750 s->insn_read = apci1564_timer_insn_read;
752 /* Counter subdevice */
753 s = &dev->subdevices[4];
754 if (devpriv->counters) {
755 s->type = COMEDI_SUBD_COUNTER;
756 s->subdev_flags = SDF_WRITABLE | SDF_READABLE | SDF_LSAMPL;
758 s->maxdata = 0xffffffff;
759 s->range_table = &range_digital;
760 s->insn_config = apci1564_counter_insn_config;
761 s->insn_write = apci1564_counter_insn_write;
762 s->insn_read = apci1564_counter_insn_read;
764 s->type = COMEDI_SUBD_UNUSED;
767 /* Initialize the watchdog subdevice */
768 s = &dev->subdevices[5];
769 ret = addi_watchdog_init(s, dev->iobase + APCI1564_WDOG_IOBASE);
773 /* Initialize the diagnostic status subdevice */
774 s = &dev->subdevices[6];
775 s->type = COMEDI_SUBD_DI;
776 s->subdev_flags = SDF_READABLE;
779 s->range_table = &range_digital;
780 s->insn_bits = apci1564_diag_insn_bits;
785 static void apci1564_detach(struct comedi_device *dev)
789 comedi_pci_detach(dev);
792 static struct comedi_driver apci1564_driver = {
793 .driver_name = "addi_apci_1564",
794 .module = THIS_MODULE,
795 .auto_attach = apci1564_auto_attach,
796 .detach = apci1564_detach,
799 static int apci1564_pci_probe(struct pci_dev *dev,
800 const struct pci_device_id *id)
802 return comedi_pci_auto_config(dev, &apci1564_driver, id->driver_data);
805 static const struct pci_device_id apci1564_pci_table[] = {
806 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1006) },
809 MODULE_DEVICE_TABLE(pci, apci1564_pci_table);
811 static struct pci_driver apci1564_pci_driver = {
812 .name = "addi_apci_1564",
813 .id_table = apci1564_pci_table,
814 .probe = apci1564_pci_probe,
815 .remove = comedi_pci_auto_unconfig,
817 module_comedi_pci_driver(apci1564_driver, apci1564_pci_driver);
819 MODULE_AUTHOR("Comedi http://www.comedi.org");
820 MODULE_DESCRIPTION("ADDI-DATA APCI-1564, 32 channel DI / 32 channel DO boards");
821 MODULE_LICENSE("GPL");