1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include <linux/module.h>
27
28#include "../comedi_pci.h"
29
30
31#define PCI263_DO_0_7_REG 0x00
32#define PCI263_DO_8_15_REG 0x01
33
34static int pci263_do_insn_bits(struct comedi_device *dev,
35 struct comedi_subdevice *s,
36 struct comedi_insn *insn,
37 unsigned int *data)
38{
39 if (comedi_dio_update_state(s, data)) {
40 outb(s->state & 0xff, dev->iobase + PCI263_DO_0_7_REG);
41 outb((s->state >> 8) & 0xff, dev->iobase + PCI263_DO_8_15_REG);
42 }
43
44 data[1] = s->state;
45
46 return insn->n;
47}
48
49static int pci263_auto_attach(struct comedi_device *dev,
50 unsigned long context_unused)
51{
52 struct pci_dev *pci_dev = comedi_to_pci_dev(dev);
53 struct comedi_subdevice *s;
54 int ret;
55
56 ret = comedi_pci_enable(dev);
57 if (ret)
58 return ret;
59
60 dev->iobase = pci_resource_start(pci_dev, 2);
61 ret = comedi_alloc_subdevices(dev, 1);
62 if (ret)
63 return ret;
64
65
66 s = &dev->subdevices[0];
67 s->type = COMEDI_SUBD_DO;
68 s->subdev_flags = SDF_WRITABLE;
69 s->n_chan = 16;
70 s->maxdata = 1;
71 s->range_table = &range_digital;
72 s->insn_bits = pci263_do_insn_bits;
73
74
75 s->state = inb(dev->iobase + PCI263_DO_0_7_REG) |
76 (inb(dev->iobase + PCI263_DO_8_15_REG) << 8);
77
78 return 0;
79}
80
81static struct comedi_driver amplc_pci263_driver = {
82 .driver_name = "amplc_pci263",
83 .module = THIS_MODULE,
84 .auto_attach = pci263_auto_attach,
85 .detach = comedi_pci_detach,
86};
87
88static const struct pci_device_id pci263_pci_table[] = {
89 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, 0x000c) },
90 {0}
91};
92MODULE_DEVICE_TABLE(pci, pci263_pci_table);
93
94static int amplc_pci263_pci_probe(struct pci_dev *dev,
95 const struct pci_device_id *id)
96{
97 return comedi_pci_auto_config(dev, &lc_pci263_driver,
98 id->driver_data);
99}
100
101static struct pci_driver amplc_pci263_pci_driver = {
102 .name = "amplc_pci263",
103 .id_table = pci263_pci_table,
104 .probe = &lc_pci263_pci_probe,
105 .remove = comedi_pci_auto_unconfig,
106};
107module_comedi_pci_driver(amplc_pci263_driver, amplc_pci263_pci_driver);
108
109MODULE_AUTHOR("Comedi https://www.comedi.org");
110MODULE_DESCRIPTION("Comedi driver for Amplicon PCI263 relay board");
111MODULE_LICENSE("GPL");
112