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
27
28
29
30
31
32
33
34
35#include <linux/module.h>
36#include <linux/interrupt.h>
37
38#include "../comedi_pci.h"
39
40#include "amplc_pc236.h"
41#include "plx9052.h"
42
43
44#define PCI236_INTR_DISABLE (PLX9052_INTCSR_LI1POL | \
45 PLX9052_INTCSR_LI2POL | \
46 PLX9052_INTCSR_LI1SEL | \
47 PLX9052_INTCSR_LI1CLRINT)
48
49
50#define PCI236_INTR_ENABLE (PLX9052_INTCSR_LI1ENAB | \
51 PLX9052_INTCSR_LI1POL | \
52 PLX9052_INTCSR_LI2POL | \
53 PLX9052_INTCSR_PCIENAB | \
54 PLX9052_INTCSR_LI1SEL | \
55 PLX9052_INTCSR_LI1CLRINT)
56
57static void pci236_intr_update_cb(struct comedi_device *dev, bool enable)
58{
59 struct pc236_private *devpriv = dev->private;
60
61
62 outl(enable ? PCI236_INTR_ENABLE : PCI236_INTR_DISABLE,
63 devpriv->lcr_iobase + PLX9052_INTCSR);
64}
65
66static bool pci236_intr_chk_clr_cb(struct comedi_device *dev)
67{
68 struct pc236_private *devpriv = dev->private;
69
70
71 if (!(inl(devpriv->lcr_iobase + PLX9052_INTCSR) &
72 PLX9052_INTCSR_LI1STAT))
73 return false;
74
75 pci236_intr_update_cb(dev, devpriv->enable_irq);
76 return true;
77}
78
79static const struct pc236_board pc236_pci_board = {
80 .name = "pci236",
81 .intr_update_cb = pci236_intr_update_cb,
82 .intr_chk_clr_cb = pci236_intr_chk_clr_cb,
83};
84
85static int pci236_auto_attach(struct comedi_device *dev,
86 unsigned long context_unused)
87{
88 struct pci_dev *pci_dev = comedi_to_pci_dev(dev);
89 struct pc236_private *devpriv;
90 unsigned long iobase;
91 int ret;
92
93 dev_info(dev->class_dev, "amplc_pci236: attach pci %s\n",
94 pci_name(pci_dev));
95
96 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
97 if (!devpriv)
98 return -ENOMEM;
99
100 dev->board_ptr = &pc236_pci_board;
101 dev->board_name = pc236_pci_board.name;
102 ret = comedi_pci_enable(dev);
103 if (ret)
104 return ret;
105
106 devpriv->lcr_iobase = pci_resource_start(pci_dev, 1);
107 iobase = pci_resource_start(pci_dev, 2);
108 return amplc_pc236_common_attach(dev, iobase, pci_dev->irq,
109 IRQF_SHARED);
110}
111
112static struct comedi_driver amplc_pci236_driver = {
113 .driver_name = "amplc_pci236",
114 .module = THIS_MODULE,
115 .auto_attach = pci236_auto_attach,
116 .detach = comedi_pci_detach,
117};
118
119static const struct pci_device_id pci236_pci_table[] = {
120 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, 0x0009) },
121 { 0 }
122};
123
124MODULE_DEVICE_TABLE(pci, pci236_pci_table);
125
126static int amplc_pci236_pci_probe(struct pci_dev *dev,
127 const struct pci_device_id *id)
128{
129 return comedi_pci_auto_config(dev, &lc_pci236_driver,
130 id->driver_data);
131}
132
133static struct pci_driver amplc_pci236_pci_driver = {
134 .name = "amplc_pci236",
135 .id_table = pci236_pci_table,
136 .probe = &lc_pci236_pci_probe,
137 .remove = comedi_pci_auto_unconfig,
138};
139
140module_comedi_pci_driver(amplc_pci236_driver, amplc_pci236_pci_driver);
141
142MODULE_AUTHOR("Comedi https://www.comedi.org");
143MODULE_DESCRIPTION("Comedi driver for Amplicon PCI236 DIO boards");
144MODULE_LICENSE("GPL");
145