Commit | Line | Data |
---|---|---|
22691aec IA |
1 | /* |
2 | comedi/drivers/amplc_pci263.c | |
3 | Driver for Amplicon PCI263 relay board. | |
4 | ||
5 | Copyright (C) 2002 MEV Ltd. <http://www.mev.co.uk/> | |
6 | ||
7 | COMEDI - Linux Control and Measurement Device Interface | |
8 | Copyright (C) 2000 David A. Schleef <ds@schleef.org> | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with this program; if not, write to the Free Software | |
22 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | ||
24 | */ | |
25 | /* | |
26 | Driver: amplc_pci263 | |
27 | Description: Amplicon PCI263 | |
28 | Author: Ian Abbott <abbotti@mev.co.uk> | |
29 | Devices: [Amplicon] PCI263 (amplc_pci263) | |
30 | Updated: Fri, 12 Apr 2013 15:19:36 +0100 | |
31 | Status: works | |
32 | ||
33 | Configuration options: not applicable, uses PCI auto config | |
34 | ||
35 | The board appears as one subdevice, with 16 digital outputs, each | |
36 | connected to a reed-relay. Relay contacts are closed when output is 1. | |
37 | The state of the outputs can be read. | |
38 | */ | |
39 | ||
40 | #include <linux/pci.h> | |
41 | ||
42 | #include "../comedidev.h" | |
43 | ||
44 | #define PCI263_DRIVER_NAME "amplc_pci263" | |
45 | ||
46 | /* PCI263 PCI configuration register information */ | |
47 | #define PCI_DEVICE_ID_AMPLICON_PCI263 0x000c | |
48 | ||
49 | static int pci263_do_insn_bits(struct comedi_device *dev, | |
50 | struct comedi_subdevice *s, | |
51 | struct comedi_insn *insn, unsigned int *data) | |
52 | { | |
53 | /* The insn data is a mask in data[0] and the new data | |
54 | * in data[1], each channel cooresponding to a bit. */ | |
55 | if (data[0]) { | |
56 | s->state &= ~data[0]; | |
57 | s->state |= data[0] & data[1]; | |
58 | /* Write out the new digital output lines */ | |
59 | outb(s->state & 0xFF, dev->iobase); | |
60 | outb(s->state >> 8, dev->iobase + 1); | |
61 | } | |
62 | return insn->n; | |
63 | } | |
64 | ||
65 | static int pci263_auto_attach(struct comedi_device *dev, | |
66 | unsigned long context_unused) | |
67 | { | |
68 | struct pci_dev *pci_dev = comedi_to_pci_dev(dev); | |
69 | struct comedi_subdevice *s; | |
70 | int ret; | |
71 | ||
72 | ret = comedi_pci_enable(dev); | |
73 | if (ret) | |
74 | return ret; | |
75 | ||
76 | dev->iobase = pci_resource_start(pci_dev, 2); | |
77 | ret = comedi_alloc_subdevices(dev, 1); | |
78 | if (ret) | |
79 | return ret; | |
80 | ||
81 | s = &dev->subdevices[0]; | |
82 | /* digital output subdevice */ | |
83 | s->type = COMEDI_SUBD_DO; | |
84 | s->subdev_flags = SDF_READABLE | SDF_WRITABLE; | |
85 | s->n_chan = 16; | |
86 | s->maxdata = 1; | |
87 | s->range_table = &range_digital; | |
88 | s->insn_bits = pci263_do_insn_bits; | |
89 | /* read initial relay state */ | |
90 | s->state = inb(dev->iobase) | (inb(dev->iobase + 1) << 8); | |
91 | ||
92 | dev_info(dev->class_dev, "%s (pci %s) attached\n", dev->board_name, | |
93 | pci_name(pci_dev)); | |
94 | return 0; | |
95 | } | |
96 | ||
97 | static struct comedi_driver amplc_pci263_driver = { | |
98 | .driver_name = PCI263_DRIVER_NAME, | |
99 | .module = THIS_MODULE, | |
100 | .auto_attach = pci263_auto_attach, | |
101 | .detach = comedi_pci_disable, | |
102 | }; | |
103 | ||
104 | static DEFINE_PCI_DEVICE_TABLE(pci263_pci_table) = { | |
105 | { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI263) }, | |
106 | {0} | |
107 | }; | |
108 | MODULE_DEVICE_TABLE(pci, pci263_pci_table); | |
109 | ||
110 | static int amplc_pci263_pci_probe(struct pci_dev *dev, | |
111 | const struct pci_device_id *id) | |
112 | { | |
113 | return comedi_pci_auto_config(dev, &lc_pci263_driver, | |
114 | id->driver_data); | |
115 | } | |
116 | ||
117 | static struct pci_driver amplc_pci263_pci_driver = { | |
118 | .name = PCI263_DRIVER_NAME, | |
119 | .id_table = pci263_pci_table, | |
120 | .probe = &lc_pci263_pci_probe, | |
121 | .remove = comedi_pci_auto_unconfig, | |
122 | }; | |
123 | module_comedi_pci_driver(amplc_pci263_driver, amplc_pci263_pci_driver); | |
124 | ||
125 | MODULE_AUTHOR("Comedi http://www.comedi.org"); | |
126 | MODULE_DESCRIPTION("Comedi driver for Amplicon PCI263 relay board"); | |
127 | MODULE_LICENSE("GPL"); |