2 comedi/drivers/contec_pci_dio.c
4 COMEDI - Linux Control and Measurement Device Interface
5 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 Driver: contec_pci_dio
24 Description: Contec PIO1616L digital I/O board
25 Devices: [Contec] PIO1616L (contec_pci_dio)
26 Author: Stefano Rivoir <s.rivoir@gts.it>
27 Updated: Wed, 27 Jun 2007 13:00:06 +0100
30 Configuration Options:
31 [0] - PCI bus of device (optional)
32 [1] - PCI slot of device (optional)
33 If bus/slot is not specified, the first supported
34 PCI device found will be used.
37 #include "../comedidev.h"
39 #include "comedi_pci.h"
41 typedef enum contec_model
{
45 typedef struct contec_board
{
54 static const contec_board contec_boards
[] = {
55 {"PIO1616L", PIO1616L
, 16, 16, 0, 2, 10},
58 #define PCI_DEVICE_ID_PIO1616L 0x8172
59 static DEFINE_PCI_DEVICE_TABLE(contec_pci_table
) = {
60 {PCI_VENDOR_ID_CONTEC
, PCI_DEVICE_ID_PIO1616L
, PCI_ANY_ID
, PCI_ANY_ID
,
65 MODULE_DEVICE_TABLE(pci
, contec_pci_table
);
67 #define thisboard ((const contec_board *)dev->board_ptr)
72 struct pci_dev
*pci_dev
;
76 #define devpriv ((contec_private *)dev->private)
78 static int contec_attach(comedi_device
* dev
, comedi_devconfig
* it
);
79 static int contec_detach(comedi_device
* dev
);
80 static comedi_driver driver_contec
= {
81 driver_name
:"contec_pci_dio",
87 /* Classic digital IO */
88 static int contec_di_insn_bits(comedi_device
* dev
, comedi_subdevice
* s
,
89 comedi_insn
* insn
, unsigned int * data
);
90 static int contec_do_insn_bits(comedi_device
* dev
, comedi_subdevice
* s
,
91 comedi_insn
* insn
, unsigned int * data
);
94 static int contec_cmdtest(comedi_device
* dev
, comedi_subdevice
* s
,
97 static int contec_ns_to_timer(unsigned int *ns
, int round
);
100 static int contec_attach(comedi_device
* dev
, comedi_devconfig
* it
)
102 struct pci_dev
*pcidev
;
105 printk("comedi%d: contec: ", dev
->minor
);
107 dev
->board_name
= thisboard
->name
;
109 if (alloc_private(dev
, sizeof(contec_private
)) < 0)
112 if (alloc_subdevices(dev
, 2) < 0)
115 for (pcidev
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, NULL
);
117 pcidev
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, pcidev
)) {
119 if (pcidev
->vendor
== PCI_VENDOR_ID_CONTEC
&&
120 pcidev
->device
== PCI_DEVICE_ID_PIO1616L
) {
121 if (it
->options
[0] || it
->options
[1]) {
122 /* Check bus and slot. */
123 if (it
->options
[0] != pcidev
->bus
->number
||
125 PCI_SLOT(pcidev
->devfn
)) {
129 devpriv
->pci_dev
= pcidev
;
130 if (comedi_pci_enable(pcidev
, "contec_pci_dio")) {
131 printk("error enabling PCI device and request regions!\n");
134 dev
->iobase
= pci_resource_start(pcidev
, 0);
135 printk(" base addr %lx ", dev
->iobase
);
137 dev
->board_ptr
= contec_boards
+ 0;
139 s
= dev
->subdevices
+ 0;
141 s
->type
= COMEDI_SUBD_DI
;
142 s
->subdev_flags
= SDF_READABLE
;
145 s
->range_table
= &range_digital
;
146 s
->insn_bits
= contec_di_insn_bits
;
148 s
= dev
->subdevices
+ 1;
149 s
->type
= COMEDI_SUBD_DO
;
150 s
->subdev_flags
= SDF_WRITABLE
;
153 s
->range_table
= &range_digital
;
154 s
->insn_bits
= contec_do_insn_bits
;
156 printk("attached\n");
162 printk("card not present!\n");
167 static int contec_detach(comedi_device
* dev
)
169 printk("comedi%d: contec: remove\n", dev
->minor
);
171 if (devpriv
&& devpriv
->pci_dev
) {
173 comedi_pci_disable(devpriv
->pci_dev
);
175 pci_dev_put(devpriv
->pci_dev
);
182 static int contec_cmdtest(comedi_device
* dev
, comedi_subdevice
* s
,
185 printk("contec_cmdtest called\n");
189 static int contec_ns_to_timer(unsigned int *ns
, int round
)
195 static int contec_do_insn_bits(comedi_device
* dev
, comedi_subdevice
* s
,
196 comedi_insn
* insn
, unsigned int * data
)
199 printk("contec_do_insn_bits called\n");
200 printk(" data: %d %d\n", data
[0], data
[1]);
206 s
->state
&= ~data
[0];
207 s
->state
|= data
[0] & data
[1];
208 rt_printk(" out: %d on %lx\n", s
->state
,
209 dev
->iobase
+ thisboard
->out_offs
);
210 outw(s
->state
, dev
->iobase
+ thisboard
->out_offs
);
215 static int contec_di_insn_bits(comedi_device
* dev
, comedi_subdevice
* s
,
216 comedi_insn
* insn
, unsigned int * data
)
219 rt_printk("contec_di_insn_bits called\n");
220 rt_printk(" data: %d %d\n", data
[0], data
[1]);
225 data
[1] = inw(dev
->iobase
+ thisboard
->in_offs
);
230 COMEDI_PCI_INITCLEANUP(driver_contec
, contec_pci_table
);