1 #include "../comedidev.h"
2 #include "addi_watchdog.h"
5 #include "addi-data/addi_common.h"
10 #define APCI2200_DI_REG 0x00
11 #define APCI2200_DO_REG 0x04
12 #define APCI2200_WDOG_REG 0x08
14 static const struct addi_board apci2200_boardtypes[] = {
16 .pc_DriverName = "apci2200",
17 .i_VendorId = PCI_VENDOR_ID_ADDIDATA,
22 static int apci2200_di_insn_bits(struct comedi_device *dev,
23 struct comedi_subdevice *s,
24 struct comedi_insn *insn,
27 data[1] = inw(dev->iobase + APCI2200_DI_REG);
32 static int apci2200_do_insn_bits(struct comedi_device *dev,
33 struct comedi_subdevice *s,
34 struct comedi_insn *insn,
37 unsigned int mask = data[0];
38 unsigned int bits = data[1];
40 s->state = inw(dev->iobase + APCI2200_DO_REG);
43 s->state |= (bits & mask);
45 outw(s->state, dev->iobase + APCI2200_DO_REG);
53 static int apci2200_reset(struct comedi_device *dev)
55 outw(0x0, dev->iobase + APCI2200_DO_REG);
57 addi_watchdog_reset(dev->iobase + APCI2200_WDOG_REG);
62 static const void *addi_find_boardinfo(struct comedi_device *dev,
63 struct pci_dev *pcidev)
65 const void *p = dev->driver->board_name;
66 const struct addi_board *this_board;
69 for (i = 0; i < dev->driver->num_names; i++) {
71 if (this_board->i_VendorId == pcidev->vendor &&
72 this_board->i_DeviceId == pcidev->device)
74 p += dev->driver->offset;
79 static int apci2200_auto_attach(struct comedi_device *dev,
80 unsigned long context_unused)
82 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
83 const struct addi_board *this_board;
84 struct addi_private *devpriv;
85 struct comedi_subdevice *s;
86 int ret, n_subdevices;
88 this_board = addi_find_boardinfo(dev, pcidev);
91 dev->board_ptr = this_board;
92 dev->board_name = this_board->pc_DriverName;
94 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
97 dev->private = devpriv;
99 ret = comedi_pci_enable(pcidev, dev->board_name);
103 dev->iobase = pci_resource_start(pcidev, 1);
106 ret = comedi_alloc_subdevices(dev, n_subdevices);
110 /* Allocate and Initialise AI Subdevice Structures */
111 s = &dev->subdevices[0];
112 s->type = COMEDI_SUBD_UNUSED;
114 /* Allocate and Initialise AO Subdevice Structures */
115 s = &dev->subdevices[1];
116 s->type = COMEDI_SUBD_UNUSED;
118 /* Allocate and Initialise DI Subdevice Structures */
119 s = &dev->subdevices[2];
120 s->type = COMEDI_SUBD_DI;
121 s->subdev_flags = SDF_READABLE;
124 s->range_table = &range_digital;
125 s->insn_bits = apci2200_di_insn_bits;
127 /* Allocate and Initialise DO Subdevice Structures */
128 s = &dev->subdevices[3];
129 s->type = COMEDI_SUBD_DO;
130 s->subdev_flags = SDF_WRITEABLE;
133 s->range_table = &range_digital;
134 s->insn_bits = apci2200_do_insn_bits;
136 /* Allocate and Initialise Timer Subdevice Structures */
137 s = &dev->subdevices[4];
138 ret = addi_watchdog_init(s, dev->iobase + APCI2200_WDOG_REG);
142 /* Allocate and Initialise TTL */
143 s = &dev->subdevices[5];
144 s->type = COMEDI_SUBD_UNUSED;
147 s = &dev->subdevices[6];
148 s->type = COMEDI_SUBD_UNUSED;
154 static void apci2200_detach(struct comedi_device *dev)
156 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
157 struct addi_private *devpriv = dev->private;
164 addi_watchdog_cleanup(&dev->subdevices[4]);
167 comedi_pci_disable(pcidev);
171 static struct comedi_driver apci2200_driver = {
172 .driver_name = "addi_apci_2200",
173 .module = THIS_MODULE,
174 .auto_attach = apci2200_auto_attach,
175 .detach = apci2200_detach,
176 .num_names = ARRAY_SIZE(apci2200_boardtypes),
177 .board_name = &apci2200_boardtypes[0].pc_DriverName,
178 .offset = sizeof(struct addi_board),
181 static int apci2200_pci_probe(struct pci_dev *dev,
182 const struct pci_device_id *ent)
184 return comedi_pci_auto_config(dev, &apci2200_driver);
187 static void apci2200_pci_remove(struct pci_dev *dev)
189 comedi_pci_auto_unconfig(dev);
192 static DEFINE_PCI_DEVICE_TABLE(apci2200_pci_table) = {
193 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1005) },
196 MODULE_DEVICE_TABLE(pci, apci2200_pci_table);
198 static struct pci_driver apci2200_pci_driver = {
199 .name = "addi_apci_2200",
200 .id_table = apci2200_pci_table,
201 .probe = apci2200_pci_probe,
202 .remove = apci2200_pci_remove,
204 module_comedi_pci_driver(apci2200_driver, apci2200_pci_driver);
206 MODULE_AUTHOR("Comedi http://www.comedi.org");
207 MODULE_DESCRIPTION("Comedi low-level driver");
208 MODULE_LICENSE("GPL");