2 * comedi/drivers/amplc_pci236.c
3 * Driver for Amplicon PCI236 DIO boards.
5 * Copyright (C) 2002-2014 MEV Ltd. <http://www.mev.co.uk/>
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
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.
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.
21 * Driver: amplc_pci236
22 * Description: Amplicon PCI236
23 * Author: Ian Abbott <abbotti@mev.co.uk>
24 * Devices: [Amplicon] PCI236 (amplc_pci236)
25 * Updated: Fri, 25 Jul 2014 15:32:40 +0000
28 * Configuration options:
31 * Manual configuration of PCI board (PCI236) is not supported; it is
32 * configured automatically.
34 * The PCI236 board has a single 8255 appearing as subdevice 0.
36 * Subdevice 1 pretends to be a digital input device, but it always
37 * returns 0 when read. However, if you run a command with
38 * scan_begin_src=TRIG_EXT, a rising edge on port C bit 3 acts as an
39 * external trigger, which can be used to wake up tasks. This is like
40 * the comedi_parport device. If no interrupt is connected, then
41 * subdevice 1 is unused.
44 #include <linux/module.h>
45 #include <linux/interrupt.h>
47 #include "../comedi_pci.h"
49 #include "amplc_pc236.h"
52 /* Disable, and clear, interrupts */
53 #define PCI236_INTR_DISABLE (PLX9052_INTCSR_LI1POL | \
54 PLX9052_INTCSR_LI2POL | \
55 PLX9052_INTCSR_LI1SEL | \
56 PLX9052_INTCSR_LI1CLRINT)
58 /* Enable, and clear, interrupts */
59 #define PCI236_INTR_ENABLE (PLX9052_INTCSR_LI1ENAB | \
60 PLX9052_INTCSR_LI1POL | \
61 PLX9052_INTCSR_LI2POL | \
62 PLX9052_INTCSR_PCIENAB | \
63 PLX9052_INTCSR_LI1SEL | \
64 PLX9052_INTCSR_LI1CLRINT)
66 static void pci236_intr_update_cb(struct comedi_device *dev, bool enable)
68 struct pc236_private *devpriv = dev->private;
70 /* this will also clear the "local interrupt 1" latch */
71 outl(enable ? PCI236_INTR_ENABLE : PCI236_INTR_DISABLE,
72 devpriv->lcr_iobase + PLX9052_INTCSR);
75 static bool pci236_intr_chk_clr_cb(struct comedi_device *dev)
77 struct pc236_private *devpriv = dev->private;
79 /* check if interrupt occurred */
80 if (!(inl(devpriv->lcr_iobase + PLX9052_INTCSR) &
81 PLX9052_INTCSR_LI1STAT))
83 /* clear the interrupt */
84 pci236_intr_update_cb(dev, devpriv->enable_irq);
88 static const struct pc236_board pc236_pci_board = {
90 .intr_update_cb = pci236_intr_update_cb,
91 .intr_chk_clr_cb = pci236_intr_chk_clr_cb,
94 static int pci236_auto_attach(struct comedi_device *dev,
95 unsigned long context_unused)
97 struct pci_dev *pci_dev = comedi_to_pci_dev(dev);
98 struct pc236_private *devpriv;
102 dev_info(dev->class_dev, "amplc_pci236: attach pci %s\n",
105 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
109 dev->board_ptr = &pc236_pci_board;
110 dev->board_name = pc236_pci_board.name;
111 ret = comedi_pci_enable(dev);
115 devpriv->lcr_iobase = pci_resource_start(pci_dev, 1);
116 iobase = pci_resource_start(pci_dev, 2);
117 return amplc_pc236_common_attach(dev, iobase, pci_dev->irq,
121 static struct comedi_driver amplc_pci236_driver = {
122 .driver_name = "amplc_pci236",
123 .module = THIS_MODULE,
124 .auto_attach = pci236_auto_attach,
125 .detach = comedi_pci_detach,
128 static const struct pci_device_id pci236_pci_table[] = {
129 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, 0x0009) },
133 MODULE_DEVICE_TABLE(pci, pci236_pci_table);
135 static int amplc_pci236_pci_probe(struct pci_dev *dev,
136 const struct pci_device_id *id)
138 return comedi_pci_auto_config(dev, &lc_pci236_driver,
142 static struct pci_driver amplc_pci236_pci_driver = {
143 .name = "amplc_pci236",
144 .id_table = pci236_pci_table,
145 .probe = &lc_pci236_pci_probe,
146 .remove = comedi_pci_auto_unconfig,
149 module_comedi_pci_driver(amplc_pci236_driver, amplc_pci236_pci_driver);
151 MODULE_AUTHOR("Comedi http://www.comedi.org");
152 MODULE_DESCRIPTION("Comedi driver for Amplicon PCI236 DIO boards");
153 MODULE_LICENSE("GPL");