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. | |
22691aec IA |
19 | */ |
20 | /* | |
21 | Driver: amplc_pci263 | |
22 | Description: Amplicon PCI263 | |
23 | Author: Ian Abbott <abbotti@mev.co.uk> | |
24 | Devices: [Amplicon] PCI263 (amplc_pci263) | |
25 | Updated: Fri, 12 Apr 2013 15:19:36 +0100 | |
26 | Status: works | |
27 | ||
28 | Configuration options: not applicable, uses PCI auto config | |
29 | ||
30 | The board appears as one subdevice, with 16 digital outputs, each | |
31 | connected to a reed-relay. Relay contacts are closed when output is 1. | |
32 | The state of the outputs can be read. | |
33 | */ | |
34 | ||
ce157f80 | 35 | #include <linux/module.h> |
22691aec | 36 | |
61873d0a | 37 | #include "../comedi_pci.h" |
22691aec | 38 | |
22691aec IA |
39 | static int pci263_do_insn_bits(struct comedi_device *dev, |
40 | struct comedi_subdevice *s, | |
97f4289a HS |
41 | struct comedi_insn *insn, |
42 | unsigned int *data) | |
22691aec | 43 | { |
97f4289a HS |
44 | if (comedi_dio_update_state(s, data)) { |
45 | outb(s->state & 0xff, dev->iobase); | |
46 | outb((s->state >> 8) & 0xff, dev->iobase + 1); | |
22691aec | 47 | } |
97f4289a HS |
48 | |
49 | data[1] = s->state; | |
50 | ||
22691aec IA |
51 | return insn->n; |
52 | } | |
53 | ||
54 | static int pci263_auto_attach(struct comedi_device *dev, | |
55 | unsigned long context_unused) | |
56 | { | |
57 | struct pci_dev *pci_dev = comedi_to_pci_dev(dev); | |
58 | struct comedi_subdevice *s; | |
59 | int ret; | |
60 | ||
61 | ret = comedi_pci_enable(dev); | |
62 | if (ret) | |
63 | return ret; | |
64 | ||
65 | dev->iobase = pci_resource_start(pci_dev, 2); | |
66 | ret = comedi_alloc_subdevices(dev, 1); | |
67 | if (ret) | |
68 | return ret; | |
69 | ||
70 | s = &dev->subdevices[0]; | |
71 | /* digital output subdevice */ | |
72 | s->type = COMEDI_SUBD_DO; | |
453fd2b3 | 73 | s->subdev_flags = SDF_WRITABLE; |
22691aec IA |
74 | s->n_chan = 16; |
75 | s->maxdata = 1; | |
76 | s->range_table = &range_digital; | |
77 | s->insn_bits = pci263_do_insn_bits; | |
78 | /* read initial relay state */ | |
79 | s->state = inb(dev->iobase) | (inb(dev->iobase + 1) << 8); | |
80 | ||
22691aec IA |
81 | return 0; |
82 | } | |
83 | ||
84 | static struct comedi_driver amplc_pci263_driver = { | |
3d03cfca | 85 | .driver_name = "amplc_pci263", |
22691aec IA |
86 | .module = THIS_MODULE, |
87 | .auto_attach = pci263_auto_attach, | |
aac307f9 | 88 | .detach = comedi_pci_detach, |
22691aec IA |
89 | }; |
90 | ||
41e043fc | 91 | static const struct pci_device_id pci263_pci_table[] = { |
472cd3db | 92 | { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, 0x000c) }, |
22691aec IA |
93 | {0} |
94 | }; | |
95 | MODULE_DEVICE_TABLE(pci, pci263_pci_table); | |
96 | ||
97 | static int amplc_pci263_pci_probe(struct pci_dev *dev, | |
98 | const struct pci_device_id *id) | |
99 | { | |
100 | return comedi_pci_auto_config(dev, &lc_pci263_driver, | |
101 | id->driver_data); | |
102 | } | |
103 | ||
104 | static struct pci_driver amplc_pci263_pci_driver = { | |
3d03cfca | 105 | .name = "amplc_pci263", |
22691aec IA |
106 | .id_table = pci263_pci_table, |
107 | .probe = &lc_pci263_pci_probe, | |
108 | .remove = comedi_pci_auto_unconfig, | |
109 | }; | |
110 | module_comedi_pci_driver(amplc_pci263_driver, amplc_pci263_pci_driver); | |
111 | ||
112 | MODULE_AUTHOR("Comedi http://www.comedi.org"); | |
113 | MODULE_DESCRIPTION("Comedi driver for Amplicon PCI263 relay board"); | |
114 | MODULE_LICENSE("GPL"); |