]>
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. | |
a6136145 SR |
16 | */ |
17 | /* | |
18 | Driver: contec_pci_dio | |
19 | Description: Contec PIO1616L digital I/O board | |
20 | Devices: [Contec] PIO1616L (contec_pci_dio) | |
21 | Author: Stefano Rivoir <s.rivoir@gts.it> | |
22 | Updated: Wed, 27 Jun 2007 13:00:06 +0100 | |
23 | Status: works | |
24 | ||
8d02b3aa | 25 | Configuration Options: not applicable, uses comedi PCI auto config |
a6136145 SR |
26 | */ |
27 | ||
ce157f80 | 28 | #include <linux/module.h> |
33782dd5 HS |
29 | #include <linux/pci.h> |
30 | ||
a6136145 SR |
31 | #include "../comedidev.h" |
32 | ||
86d466b8 HS |
33 | /* |
34 | * Register map | |
35 | */ | |
36 | #define PIO1616L_DI_REG 0x00 | |
37 | #define PIO1616L_DO_REG 0x02 | |
38 | ||
ce41d7d6 HS |
39 | static int contec_do_insn_bits(struct comedi_device *dev, |
40 | struct comedi_subdevice *s, | |
97f4289a HS |
41 | struct comedi_insn *insn, |
42 | unsigned int *data) | |
ce41d7d6 | 43 | { |
97f4289a | 44 | if (comedi_dio_update_state(s, data)) |
86d466b8 | 45 | outw(s->state, dev->iobase + PIO1616L_DO_REG); |
00d7a906 HS |
46 | |
47 | data[1] = s->state; | |
48 | ||
a2714e3e | 49 | return insn->n; |
ce41d7d6 | 50 | } |
a6136145 | 51 | |
0a85b6f0 MT |
52 | static int contec_di_insn_bits(struct comedi_device *dev, |
53 | struct comedi_subdevice *s, | |
ce41d7d6 HS |
54 | struct comedi_insn *insn, unsigned int *data) |
55 | { | |
86d466b8 | 56 | data[1] = inw(dev->iobase + PIO1616L_DI_REG); |
ce41d7d6 | 57 | |
a2714e3e | 58 | return insn->n; |
ce41d7d6 | 59 | } |
a6136145 | 60 | |
a690b7e5 | 61 | static int contec_auto_attach(struct comedi_device *dev, |
750af5e5 | 62 | unsigned long context_unused) |
a6136145 | 63 | { |
750af5e5 | 64 | struct pci_dev *pcidev = comedi_to_pci_dev(dev); |
f0bd6d35 HS |
65 | struct comedi_subdevice *s; |
66 | int ret; | |
a6136145 | 67 | |
818f569f | 68 | ret = comedi_pci_enable(dev); |
8d02b3aa HS |
69 | if (ret) |
70 | return ret; | |
f0bd6d35 | 71 | dev->iobase = pci_resource_start(pcidev, 0); |
a6136145 | 72 | |
8d02b3aa HS |
73 | ret = comedi_alloc_subdevices(dev, 2); |
74 | if (ret) | |
75 | return ret; | |
f0bd6d35 | 76 | |
b31654fe | 77 | s = &dev->subdevices[0]; |
8d02b3aa HS |
78 | s->type = COMEDI_SUBD_DI; |
79 | s->subdev_flags = SDF_READABLE; | |
80 | s->n_chan = 16; | |
81 | s->maxdata = 1; | |
82 | s->range_table = &range_digital; | |
83 | s->insn_bits = contec_di_insn_bits; | |
f0bd6d35 | 84 | |
b31654fe | 85 | s = &dev->subdevices[1]; |
8d02b3aa HS |
86 | s->type = COMEDI_SUBD_DO; |
87 | s->subdev_flags = SDF_WRITABLE; | |
88 | s->n_chan = 16; | |
89 | s->maxdata = 1; | |
90 | s->range_table = &range_digital; | |
91 | s->insn_bits = contec_do_insn_bits; | |
92 | ||
8d02b3aa HS |
93 | return 0; |
94 | } | |
95 | ||
ce41d7d6 HS |
96 | static struct comedi_driver contec_pci_dio_driver = { |
97 | .driver_name = "contec_pci_dio", | |
98 | .module = THIS_MODULE, | |
750af5e5 | 99 | .auto_attach = contec_auto_attach, |
aac307f9 | 100 | .detach = comedi_pci_detach, |
ce41d7d6 | 101 | }; |
a6136145 | 102 | |
a690b7e5 | 103 | static int contec_pci_dio_pci_probe(struct pci_dev *dev, |
b8f4ac23 | 104 | const struct pci_device_id *id) |
727b286b | 105 | { |
b8f4ac23 HS |
106 | return comedi_pci_auto_config(dev, &contec_pci_dio_driver, |
107 | id->driver_data); | |
727b286b AT |
108 | } |
109 | ||
41e043fc | 110 | static const struct pci_device_id contec_pci_dio_pci_table[] = { |
472cd3db | 111 | { PCI_DEVICE(PCI_VENDOR_ID_CONTEC, 0x8172) }, |
ce41d7d6 | 112 | { 0 } |
727b286b | 113 | }; |
ce41d7d6 | 114 | MODULE_DEVICE_TABLE(pci, contec_pci_dio_pci_table); |
727b286b | 115 | |
ce41d7d6 HS |
116 | static struct pci_driver contec_pci_dio_pci_driver = { |
117 | .name = "contec_pci_dio", | |
118 | .id_table = contec_pci_dio_pci_table, | |
119 | .probe = contec_pci_dio_pci_probe, | |
9901a4d7 | 120 | .remove = comedi_pci_auto_unconfig, |
ce41d7d6 HS |
121 | }; |
122 | module_comedi_pci_driver(contec_pci_dio_driver, contec_pci_dio_pci_driver); | |
90f703d3 AT |
123 | |
124 | MODULE_AUTHOR("Comedi http://www.comedi.org"); | |
125 | MODULE_DESCRIPTION("Comedi low-level driver"); | |
126 | MODULE_LICENSE("GPL"); |