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"
54 static const struct 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
) = {
61 PCI_VENDOR_ID_CONTEC
, PCI_DEVICE_ID_PIO1616L
, PCI_ANY_ID
,
62 PCI_ANY_ID
, 0, 0, PIO1616L
}, {
66 MODULE_DEVICE_TABLE(pci
, contec_pci_table
);
68 #define thisboard ((const struct contec_board *)dev->board_ptr)
70 struct contec_private
{
73 struct pci_dev
*pci_dev
;
77 #define devpriv ((struct contec_private *)dev->private)
79 static int contec_attach(struct comedi_device
*dev
,
80 struct comedi_devconfig
*it
);
81 static int contec_detach(struct comedi_device
*dev
);
82 static struct comedi_driver driver_contec
= {
83 .driver_name
= "contec_pci_dio",
84 .module
= THIS_MODULE
,
85 .attach
= contec_attach
,
86 .detach
= contec_detach
,
89 /* Classic digital IO */
90 static int contec_di_insn_bits(struct comedi_device
*dev
,
91 struct comedi_subdevice
*s
,
92 struct comedi_insn
*insn
, unsigned int *data
);
93 static int contec_do_insn_bits(struct comedi_device
*dev
,
94 struct comedi_subdevice
*s
,
95 struct comedi_insn
*insn
, unsigned int *data
);
98 static int contec_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
100 struct pci_dev
*pcidev
= NULL
;
101 struct comedi_subdevice
*s
;
103 printk("comedi%d: contec: ", dev
->minor
);
105 dev
->board_name
= thisboard
->name
;
107 if (alloc_private(dev
, sizeof(struct contec_private
)) < 0)
110 if (alloc_subdevices(dev
, 2) < 0)
113 for_each_pci_dev(pcidev
) {
114 if (pcidev
->vendor
== PCI_VENDOR_ID_CONTEC
&&
115 pcidev
->device
== PCI_DEVICE_ID_PIO1616L
) {
116 if (it
->options
[0] || it
->options
[1]) {
117 /* Check bus and slot. */
118 if (it
->options
[0] != pcidev
->bus
->number
||
119 it
->options
[1] != PCI_SLOT(pcidev
->devfn
)) {
123 devpriv
->pci_dev
= pcidev
;
124 if (comedi_pci_enable(pcidev
, "contec_pci_dio")) {
126 ("error enabling PCI device and request regions!\n");
129 dev
->iobase
= pci_resource_start(pcidev
, 0);
130 printk(" base addr %lx ", dev
->iobase
);
132 dev
->board_ptr
= contec_boards
+ 0;
134 s
= dev
->subdevices
+ 0;
136 s
->type
= COMEDI_SUBD_DI
;
137 s
->subdev_flags
= SDF_READABLE
;
140 s
->range_table
= &range_digital
;
141 s
->insn_bits
= contec_di_insn_bits
;
143 s
= dev
->subdevices
+ 1;
144 s
->type
= COMEDI_SUBD_DO
;
145 s
->subdev_flags
= SDF_WRITABLE
;
148 s
->range_table
= &range_digital
;
149 s
->insn_bits
= contec_do_insn_bits
;
151 printk("attached\n");
157 printk("card not present!\n");
162 static int contec_detach(struct comedi_device
*dev
)
164 printk("comedi%d: contec: remove\n", dev
->minor
);
166 if (devpriv
&& devpriv
->pci_dev
) {
168 comedi_pci_disable(devpriv
->pci_dev
);
169 pci_dev_put(devpriv
->pci_dev
);
176 static int contec_do_insn_bits(struct comedi_device
*dev
,
177 struct comedi_subdevice
*s
,
178 struct comedi_insn
*insn
, unsigned int *data
)
181 printk("contec_do_insn_bits called\n");
182 printk(" data: %d %d\n", data
[0], data
[1]);
188 s
->state
&= ~data
[0];
189 s
->state
|= data
[0] & data
[1];
190 printk(" out: %d on %lx\n", s
->state
,
191 dev
->iobase
+ thisboard
->out_offs
);
192 outw(s
->state
, dev
->iobase
+ thisboard
->out_offs
);
197 static int contec_di_insn_bits(struct comedi_device
*dev
,
198 struct comedi_subdevice
*s
,
199 struct comedi_insn
*insn
, unsigned int *data
)
202 printk("contec_di_insn_bits called\n");
203 printk(" data: %d %d\n", data
[0], data
[1]);
208 data
[1] = inw(dev
->iobase
+ thisboard
->in_offs
);
213 static int __devinit
driver_contec_pci_probe(struct pci_dev
*dev
,
214 const struct pci_device_id
*ent
)
216 return comedi_pci_auto_config(dev
, driver_contec
.driver_name
);
219 static void __devexit
driver_contec_pci_remove(struct pci_dev
*dev
)
221 comedi_pci_auto_unconfig(dev
);
224 static struct pci_driver driver_contec_pci_driver
= {
225 .id_table
= contec_pci_table
,
226 .probe
= &driver_contec_pci_probe
,
227 .remove
= __devexit_p(&driver_contec_pci_remove
)
230 static int __init
driver_contec_init_module(void)
234 retval
= comedi_driver_register(&driver_contec
);
238 driver_contec_pci_driver
.name
= (char *)driver_contec
.driver_name
;
239 return pci_register_driver(&driver_contec_pci_driver
);
242 static void __exit
driver_contec_cleanup_module(void)
244 pci_unregister_driver(&driver_contec_pci_driver
);
245 comedi_driver_unregister(&driver_contec
);
248 module_init(driver_contec_init_module
);
249 module_exit(driver_contec_cleanup_module
);
251 MODULE_AUTHOR("Comedi http://www.comedi.org");
252 MODULE_DESCRIPTION("Comedi low-level driver");
253 MODULE_LICENSE("GPL");