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: not applicable, uses comedi PCI auto config
33 #include <linux/pci.h>
35 #include "../comedidev.h"
37 #define PCI_DEVICE_ID_PIO1616L 0x8172
42 #define PIO1616L_DI_REG 0x00
43 #define PIO1616L_DO_REG 0x02
45 static int contec_do_insn_bits(struct comedi_device
*dev
,
46 struct comedi_subdevice
*s
,
47 struct comedi_insn
*insn
, unsigned int *data
)
49 unsigned int mask
= data
[0];
50 unsigned int bits
= data
[1];
54 s
->state
|= (bits
& mask
);
56 outw(s
->state
, dev
->iobase
+ PIO1616L_DO_REG
);
64 static int contec_di_insn_bits(struct comedi_device
*dev
,
65 struct comedi_subdevice
*s
,
66 struct comedi_insn
*insn
, unsigned int *data
)
68 data
[1] = inw(dev
->iobase
+ PIO1616L_DI_REG
);
73 static int contec_auto_attach(struct comedi_device
*dev
,
74 unsigned long context_unused
)
76 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
77 struct comedi_subdevice
*s
;
80 dev
->board_name
= dev
->driver
->driver_name
;
82 ret
= comedi_pci_enable(pcidev
, dev
->board_name
);
85 dev
->iobase
= pci_resource_start(pcidev
, 0);
87 ret
= comedi_alloc_subdevices(dev
, 2);
91 s
= &dev
->subdevices
[0];
92 s
->type
= COMEDI_SUBD_DI
;
93 s
->subdev_flags
= SDF_READABLE
;
96 s
->range_table
= &range_digital
;
97 s
->insn_bits
= contec_di_insn_bits
;
99 s
= &dev
->subdevices
[1];
100 s
->type
= COMEDI_SUBD_DO
;
101 s
->subdev_flags
= SDF_WRITABLE
;
104 s
->range_table
= &range_digital
;
105 s
->insn_bits
= contec_do_insn_bits
;
107 dev_info(dev
->class_dev
, "%s attached\n", dev
->board_name
);
112 static void contec_detach(struct comedi_device
*dev
)
114 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
118 comedi_pci_disable(pcidev
);
122 static struct comedi_driver contec_pci_dio_driver
= {
123 .driver_name
= "contec_pci_dio",
124 .module
= THIS_MODULE
,
125 .auto_attach
= contec_auto_attach
,
126 .detach
= contec_detach
,
129 static int contec_pci_dio_pci_probe(struct pci_dev
*dev
,
130 const struct pci_device_id
*ent
)
132 return comedi_pci_auto_config(dev
, &contec_pci_dio_driver
);
135 static DEFINE_PCI_DEVICE_TABLE(contec_pci_dio_pci_table
) = {
136 { PCI_DEVICE(PCI_VENDOR_ID_CONTEC
, PCI_DEVICE_ID_PIO1616L
) },
139 MODULE_DEVICE_TABLE(pci
, contec_pci_dio_pci_table
);
141 static struct pci_driver contec_pci_dio_pci_driver
= {
142 .name
= "contec_pci_dio",
143 .id_table
= contec_pci_dio_pci_table
,
144 .probe
= contec_pci_dio_pci_probe
,
145 .remove
= comedi_pci_auto_unconfig
,
147 module_comedi_pci_driver(contec_pci_dio_driver
, contec_pci_dio_pci_driver
);
149 MODULE_AUTHOR("Comedi http://www.comedi.org");
150 MODULE_DESCRIPTION("Comedi low-level driver");
151 MODULE_LICENSE("GPL");