Loading...
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | // SPDX-License-Identifier: GPL-2.0+
/*
* addi_apci_2200.c
* Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
* Project manager: Eric Stolz
*
* ADDI-DATA GmbH
* Dieselstrasse 3
* D-77833 Ottersweier
* Tel: +19(0)7223/9493-0
* Fax: +49(0)7223/9493-92
* http://www.addi-data.com
* info@addi-data.com
*/
#include <linux/module.h>
#include "../comedi_pci.h"
#include "addi_watchdog.h"
/*
* I/O Register Map
*/
#define APCI2200_DI_REG 0x00
#define APCI2200_DO_REG 0x04
#define APCI2200_WDOG_REG 0x08
static int apci2200_di_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned int *data)
{
data[1] = inw(dev->iobase + APCI2200_DI_REG);
return insn->n;
}
static int apci2200_do_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned int *data)
{
s->state = inw(dev->iobase + APCI2200_DO_REG);
if (comedi_dio_update_state(s, data))
outw(s->state, dev->iobase + APCI2200_DO_REG);
data[1] = s->state;
return insn->n;
}
static int apci2200_reset(struct comedi_device *dev)
{
outw(0x0, dev->iobase + APCI2200_DO_REG);
addi_watchdog_reset(dev->iobase + APCI2200_WDOG_REG);
return 0;
}
static int apci2200_auto_attach(struct comedi_device *dev,
unsigned long context_unused)
{
struct pci_dev *pcidev = comedi_to_pci_dev(dev);
struct comedi_subdevice *s;
int ret;
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 1);
ret = comedi_alloc_subdevices(dev, 3);
if (ret)
return ret;
/* Initialize the digital input subdevice */
s = &dev->subdevices[0];
s->type = COMEDI_SUBD_DI;
s->subdev_flags = SDF_READABLE;
s->n_chan = 8;
s->maxdata = 1;
s->range_table = &range_digital;
s->insn_bits = apci2200_di_insn_bits;
/* Initialize the digital output subdevice */
s = &dev->subdevices[1];
s->type = COMEDI_SUBD_DO;
s->subdev_flags = SDF_WRITABLE;
s->n_chan = 16;
s->maxdata = 1;
s->range_table = &range_digital;
s->insn_bits = apci2200_do_insn_bits;
/* Initialize the watchdog subdevice */
s = &dev->subdevices[2];
ret = addi_watchdog_init(s, dev->iobase + APCI2200_WDOG_REG);
if (ret)
return ret;
apci2200_reset(dev);
return 0;
}
static void apci2200_detach(struct comedi_device *dev)
{
if (dev->iobase)
apci2200_reset(dev);
comedi_pci_detach(dev);
}
static struct comedi_driver apci2200_driver = {
.driver_name = "addi_apci_2200",
.module = THIS_MODULE,
.auto_attach = apci2200_auto_attach,
.detach = apci2200_detach,
};
static int apci2200_pci_probe(struct pci_dev *dev,
const struct pci_device_id *id)
{
return comedi_pci_auto_config(dev, &apci2200_driver, id->driver_data);
}
static const struct pci_device_id apci2200_pci_table[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1005) },
{ 0 }
};
MODULE_DEVICE_TABLE(pci, apci2200_pci_table);
static struct pci_driver apci2200_pci_driver = {
.name = "addi_apci_2200",
.id_table = apci2200_pci_table,
.probe = apci2200_pci_probe,
.remove = comedi_pci_auto_unconfig,
};
module_comedi_pci_driver(apci2200_driver, apci2200_pci_driver);
MODULE_DESCRIPTION("ADDI-DATA APCI-2200 Relay board, optically isolated");
MODULE_AUTHOR("Comedi http://www.comedi.org");
MODULE_LICENSE("GPL");
|