Commit | Line | Data |
---|---|---|
a6136145 SR |
1 | /* |
2 | comedi/drivers/contec_pci_dio.c | |
3 | ||
4 | COMEDI - Linux Control and Measurement Device Interface | |
5 | Copyright (C) 2000 David A. Schleef <ds@schleef.org> | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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. | |
20 | ||
21 | */ | |
22 | /* | |
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 | |
28 | Status: works | |
29 | ||
8d02b3aa | 30 | Configuration Options: not applicable, uses comedi PCI auto config |
a6136145 SR |
31 | */ |
32 | ||
33782dd5 HS |
33 | #include <linux/pci.h> |
34 | ||
a6136145 SR |
35 | #include "../comedidev.h" |
36 | ||
a6136145 | 37 | #define PCI_DEVICE_ID_PIO1616L 0x8172 |
a6136145 | 38 | |
86d466b8 HS |
39 | /* |
40 | * Register map | |
41 | */ | |
42 | #define PIO1616L_DI_REG 0x00 | |
43 | #define PIO1616L_DO_REG 0x02 | |
44 | ||
ce41d7d6 HS |
45 | static int contec_do_insn_bits(struct comedi_device *dev, |
46 | struct comedi_subdevice *s, | |
47 | struct comedi_insn *insn, unsigned int *data) | |
48 | { | |
00d7a906 HS |
49 | unsigned int mask = data[0]; |
50 | unsigned int bits = data[1]; | |
51 | ||
52 | if (mask) { | |
53 | s->state &= ~mask; | |
54 | s->state |= (bits & mask); | |
f7f57eff | 55 | |
86d466b8 | 56 | outw(s->state, dev->iobase + PIO1616L_DO_REG); |
ce41d7d6 | 57 | } |
00d7a906 HS |
58 | |
59 | data[1] = s->state; | |
60 | ||
a2714e3e | 61 | return insn->n; |
ce41d7d6 | 62 | } |
a6136145 | 63 | |
0a85b6f0 MT |
64 | static int contec_di_insn_bits(struct comedi_device *dev, |
65 | struct comedi_subdevice *s, | |
ce41d7d6 HS |
66 | struct comedi_insn *insn, unsigned int *data) |
67 | { | |
86d466b8 | 68 | data[1] = inw(dev->iobase + PIO1616L_DI_REG); |
ce41d7d6 | 69 | |
a2714e3e | 70 | return insn->n; |
ce41d7d6 | 71 | } |
a6136145 | 72 | |
a690b7e5 | 73 | static int contec_auto_attach(struct comedi_device *dev, |
750af5e5 | 74 | unsigned long context_unused) |
a6136145 | 75 | { |
750af5e5 | 76 | struct pci_dev *pcidev = comedi_to_pci_dev(dev); |
f0bd6d35 HS |
77 | struct comedi_subdevice *s; |
78 | int ret; | |
a6136145 | 79 | |
818f569f | 80 | ret = comedi_pci_enable(dev); |
8d02b3aa HS |
81 | if (ret) |
82 | return ret; | |
f0bd6d35 | 83 | dev->iobase = pci_resource_start(pcidev, 0); |
a6136145 | 84 | |
8d02b3aa HS |
85 | ret = comedi_alloc_subdevices(dev, 2); |
86 | if (ret) | |
87 | return ret; | |
f0bd6d35 | 88 | |
b31654fe | 89 | s = &dev->subdevices[0]; |
8d02b3aa HS |
90 | s->type = COMEDI_SUBD_DI; |
91 | s->subdev_flags = SDF_READABLE; | |
92 | s->n_chan = 16; | |
93 | s->maxdata = 1; | |
94 | s->range_table = &range_digital; | |
95 | s->insn_bits = contec_di_insn_bits; | |
f0bd6d35 | 96 | |
b31654fe | 97 | s = &dev->subdevices[1]; |
8d02b3aa HS |
98 | s->type = COMEDI_SUBD_DO; |
99 | s->subdev_flags = SDF_WRITABLE; | |
100 | s->n_chan = 16; | |
101 | s->maxdata = 1; | |
102 | s->range_table = &range_digital; | |
103 | s->insn_bits = contec_do_insn_bits; | |
104 | ||
105 | dev_info(dev->class_dev, "%s attached\n", dev->board_name); | |
f0bd6d35 | 106 | |
8d02b3aa HS |
107 | return 0; |
108 | } | |
109 | ||
ce41d7d6 HS |
110 | static struct comedi_driver contec_pci_dio_driver = { |
111 | .driver_name = "contec_pci_dio", | |
112 | .module = THIS_MODULE, | |
750af5e5 | 113 | .auto_attach = contec_auto_attach, |
7f072f54 | 114 | .detach = comedi_pci_disable, |
ce41d7d6 | 115 | }; |
a6136145 | 116 | |
a690b7e5 | 117 | static int contec_pci_dio_pci_probe(struct pci_dev *dev, |
b8f4ac23 | 118 | const struct pci_device_id *id) |
727b286b | 119 | { |
b8f4ac23 HS |
120 | return comedi_pci_auto_config(dev, &contec_pci_dio_driver, |
121 | id->driver_data); | |
727b286b AT |
122 | } |
123 | ||
ce41d7d6 | 124 | static DEFINE_PCI_DEVICE_TABLE(contec_pci_dio_pci_table) = { |
32568373 | 125 | { PCI_DEVICE(PCI_VENDOR_ID_CONTEC, PCI_DEVICE_ID_PIO1616L) }, |
ce41d7d6 | 126 | { 0 } |
727b286b | 127 | }; |
ce41d7d6 | 128 | MODULE_DEVICE_TABLE(pci, contec_pci_dio_pci_table); |
727b286b | 129 | |
ce41d7d6 HS |
130 | static struct pci_driver contec_pci_dio_pci_driver = { |
131 | .name = "contec_pci_dio", | |
132 | .id_table = contec_pci_dio_pci_table, | |
133 | .probe = contec_pci_dio_pci_probe, | |
9901a4d7 | 134 | .remove = comedi_pci_auto_unconfig, |
ce41d7d6 HS |
135 | }; |
136 | module_comedi_pci_driver(contec_pci_dio_driver, contec_pci_dio_pci_driver); | |
90f703d3 AT |
137 | |
138 | MODULE_AUTHOR("Comedi http://www.comedi.org"); | |
139 | MODULE_DESCRIPTION("Comedi low-level driver"); | |
140 | MODULE_LICENSE("GPL"); |