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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | /*
* comedi/drivers/pcl730.c
* Driver for Advantech PCL-730 and clones
* José Luis Sánchez
*/
/*
Driver: pcl730
Description: Advantech PCL-730 (& compatibles)
Author: José Luis Sánchez (jsanchezv@teleline.es)
Status: untested
Devices: [Advantech] PCL-730 (pcl730), [ICP] ISO-730 (iso730),
[Adlink] ACL-7130 (acl7130)
Interrupts are not supported.
The ACL-7130 card have an 8254 timer/counter not supported by this driver.
*/
#include "../comedidev.h"
#include <linux/ioport.h>
#define PCL730_SIZE 4
#define ACL7130_SIZE 8
#define PCL730_IDIO_LO 0 /* Isolated Digital I/O low byte (ID0-ID7) */
#define PCL730_IDIO_HI 1 /* Isolated Digital I/O high byte (ID8-ID15) */
#define PCL730_DIO_LO 2 /* TTL Digital I/O low byte (D0-D7) */
#define PCL730_DIO_HI 3 /* TTL Digital I/O high byte (D8-D15) */
static int pcl730_attach(struct comedi_device *dev,
struct comedi_devconfig *it);
static int pcl730_detach(struct comedi_device *dev);
struct pcl730_board {
const char *name; /* board name */
unsigned int io_range; /* len of I/O space */
};
static const struct pcl730_board boardtypes[] = {
{"pcl730", PCL730_SIZE,},
{"iso730", PCL730_SIZE,},
{"acl7130", ACL7130_SIZE,},
};
#define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcl730_board))
#define this_board ((const struct pcl730_board *)dev->board_ptr)
static struct comedi_driver driver_pcl730 = {
.driver_name = "pcl730",
.module = THIS_MODULE,
.attach = pcl730_attach,
.detach = pcl730_detach,
.board_name = &boardtypes[0].name,
.num_names = n_boardtypes,
.offset = sizeof(struct pcl730_board),
};
static int __init driver_pcl730_init_module(void)
{
return comedi_driver_register(&driver_pcl730);
}
static void __exit driver_pcl730_cleanup_module(void)
{
comedi_driver_unregister(&driver_pcl730);
}
module_init(driver_pcl730_init_module);
module_exit(driver_pcl730_cleanup_module);
static int pcl730_do_insn(struct comedi_device *dev, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
if (insn->n != 2)
return -EINVAL;
if (data[0]) {
s->state &= ~data[0];
s->state |= (data[0] & data[1]);
}
if (data[0] & 0x00ff)
outb(s->state & 0xff,
dev->iobase + ((unsigned long)s->private));
if (data[0] & 0xff00)
outb((s->state >> 8),
dev->iobase + ((unsigned long)s->private) + 1);
data[1] = s->state;
return 2;
}
static int pcl730_di_insn(struct comedi_device *dev, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
if (insn->n != 2)
return -EINVAL;
data[1] = inb(dev->iobase + ((unsigned long)s->private)) |
(inb(dev->iobase + ((unsigned long)s->private) + 1) << 8);
return 2;
}
static int pcl730_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{
struct comedi_subdevice *s;
unsigned long iobase;
unsigned int iorange;
iobase = it->options[0];
iorange = this_board->io_range;
printk(KERN_INFO "comedi%d: pcl730: board=%s 0x%04lx ", dev->minor,
this_board->name, iobase);
if (!request_region(iobase, iorange, "pcl730")) {
printk("I/O port conflict\n");
return -EIO;
}
dev->board_name = this_board->name;
dev->iobase = iobase;
dev->irq = 0;
if (alloc_subdevices(dev, 4) < 0)
return -ENOMEM;
s = dev->subdevices + 0;
/* Isolated do */
s->type = COMEDI_SUBD_DO;
s->subdev_flags = SDF_WRITABLE;
s->maxdata = 1;
s->n_chan = 16;
s->insn_bits = pcl730_do_insn;
s->range_table = &range_digital;
s->private = (void *)PCL730_IDIO_LO;
s = dev->subdevices + 1;
/* Isolated di */
s->type = COMEDI_SUBD_DI;
s->subdev_flags = SDF_READABLE;
s->maxdata = 1;
s->n_chan = 16;
s->insn_bits = pcl730_di_insn;
s->range_table = &range_digital;
s->private = (void *)PCL730_IDIO_LO;
s = dev->subdevices + 2;
/* TTL do */
s->type = COMEDI_SUBD_DO;
s->subdev_flags = SDF_WRITABLE;
s->maxdata = 1;
s->n_chan = 16;
s->insn_bits = pcl730_do_insn;
s->range_table = &range_digital;
s->private = (void *)PCL730_DIO_LO;
s = dev->subdevices + 3;
/* TTL di */
s->type = COMEDI_SUBD_DI;
s->subdev_flags = SDF_READABLE;
s->maxdata = 1;
s->n_chan = 16;
s->insn_bits = pcl730_di_insn;
s->range_table = &range_digital;
s->private = (void *)PCL730_DIO_LO;
printk(KERN_INFO "\n");
return 0;
}
static int pcl730_detach(struct comedi_device *dev)
{
printk(KERN_INFO "comedi%d: pcl730: remove\n", dev->minor);
if (dev->iobase)
release_region(dev->iobase, this_board->io_range);
return 0;
}
MODULE_AUTHOR("Comedi http://www.comedi.org");
MODULE_DESCRIPTION("Comedi low-level driver");
MODULE_LICENSE("GPL");
|