From 037cc20a174b509cf9a9ea7b3f7954fd15f485c8 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Mon, 14 Aug 2006 02:58:52 +0000 Subject: [PATCH] New drivers from Pablo Mejia : We have written basic drivers for two PC-104 boards we are using at work and we would like to contribute them to the Comedi project. The drivers are for two Advanced Digital Logic (www.adlogic-pc104.com) boards: 104-AIO12-8 http://www.adlogic-pc104.com/products/peripherals/datasheets/104-AIO12-8.pdf 104-IIRO-16 http://www.adlogic-pc104.com/products/peripherals/datasheets/104-IIRO-16.pdf The actual manufacturer is Acces I/O (http://accesio.com). I believe the same boards are also available from (http://kontron.com) The drivers are basic. For instance no asynchronous operations are supported. The drivers do work (tested on Fedora Core 4 and 5). --- comedi/drivers/Kbuild | 2 + comedi/drivers/Makefile.am | 4 + comedi/drivers/aio_aio12_8.c | 225 +++++++++++++++++++++++++++++++++++ comedi/drivers/aio_iiro_16.c | 175 +++++++++++++++++++++++++++ 4 files changed, 406 insertions(+) create mode 100644 comedi/drivers/aio_aio12_8.c create mode 100644 comedi/drivers/aio_iiro_16.c diff --git a/comedi/drivers/Kbuild b/comedi/drivers/Kbuild index 2dcb48c1..3f307066 100644 --- a/comedi/drivers/Kbuild +++ b/comedi/drivers/Kbuild @@ -30,6 +30,8 @@ obj-m += adl_pci9111.o obj-m += adl_pci9118.o obj-m += adv_pci1710.o obj-m += adv_pci_dio.o +obj-m += aio_aio12_8.o +obj-m += aio_iiro_16.o obj-m += amplc_pci224.o obj-m += amplc_pci230.o obj-m += amplc_pc236.o diff --git a/comedi/drivers/Makefile.am b/comedi/drivers/Makefile.am index c3e169ef..01915510 100644 --- a/comedi/drivers/Makefile.am +++ b/comedi/drivers/Makefile.am @@ -100,6 +100,8 @@ module_PROGRAMS = \ amplc_pc236.ko \ amplc_pc263.ko \ amplc_dio200.ko \ + aio_aio12_8.ko \ + aio_iiro_16.ko \ c6xdigio.ko \ cb_pcidas.ko \ cb_pcidas64.ko \ @@ -176,6 +178,8 @@ adl_pci9111_ko_SOURCES = adl_pci9111.c adl_pci9118_ko_SOURCES = adl_pci9118.c adv_pci1710_ko_SOURCES = adv_pci1710.c adv_pci_dio_ko_SOURCES = adv_pci_dio.c +aio_aio12_8_ko_SOURCES = aio_aio12_8.c +aio_iiro_16_ko_SOURCES = aio_iiro_16.c amplc_pci224_ko_SOURCES = amplc_pci224.c amplc_pci230_ko_SOURCES = amplc_pci230.c amplc_pc236_ko_SOURCES = amplc_pc236.c diff --git a/comedi/drivers/aio_aio12_8.c b/comedi/drivers/aio_aio12_8.c new file mode 100644 index 00000000..d7ec0dbd --- /dev/null +++ b/comedi/drivers/aio_aio12_8.c @@ -0,0 +1,225 @@ +/* + + Driver for Acces I/O Products PC-104 AIO12-8 Analog I/O Board + Copyright (C) 2006 C&C Technologies, Inc. + +*/ + +/* + +Driver: aio_aio12_8.o +Description: Acces I/O Products PC-104 AIO12-8 Analog I/O Board +Author: Pablo Mejia +Devices: + [Acces I/O] PC-104 AIO12-8 +Status: experimental + +Configuration Options: + [0] - I/O port base address + +Notes: + + Only synchronous operations are supported. + +*/ + + +#include +#include +#include "8255.h" + + +#define AIO12_8_STATUS 0x00 +#define AIO12_8_INTERRUPT 0x01 +#define AIO12_8_ADC 0x02 +#define AIO12_8_DAC_0 0x04 +#define AIO12_8_DAC_1 0x06 +#define AIO12_8_DAC_2 0x08 +#define AIO12_8_DAC_3 0x0A +#define AIO12_8_COUNTER_0 0x0C +#define AIO12_8_COUNTER_1 0x0D +#define AIO12_8_COUNTER_2 0x0E +#define AIO12_8_COUNTER_CONTROL 0x0F +#define AIO12_8_DIO_0 0x10 +#define AIO12_8_DIO_1 0x11 +#define AIO12_8_DIO_2 0x12 +#define AIO12_8_DIO_STATUS 0x13 +#define AIO12_8_DIO_CONTROL 0x14 +#define AIO12_8_ADC_TRIGGER_CONTROL 0x15 +#define AIO12_8_TRIGGER 0x16 +#define AIO12_8_POWER 0x17 + +#define STATUS_ADC_EOC 0x80 + +#define ADC_MODE_NORMAL 0x00 +#define ADC_MODE_INTERNAL_CLOCK 0x40 +#define ADC_MODE_STANDBY 0x80 +#define ADC_MODE_POWERDOWN 0xC0 + +#define DAC_ENABLE 0x18 + +typedef struct +{ + char *name; +} board_type; + +static board_type board_types[] = +{ + { + name: "aio_aio12_8" + }, +}; + +#define thisboard ((board_type *) dev->board_ptr) + +typedef struct +{ + lsampl_t ao_readback[4]; +} aio12_8_private; + +#define devpriv ((aio12_8_private *) dev->private) + +static int aio_aio12_8_ai_read (comedi_device *dev, comedi_subdevice *s, + comedi_insn *insn, lsampl_t *data) +{ + int n; + unsigned char control = + ADC_MODE_NORMAL | + (CR_RANGE(insn->chanspec) << 3) | + CR_CHAN(insn->chanspec); + + //read status to clear EOC latch + inb (dev->iobase + AIO12_8_STATUS); + + for (n = 0; n < insn->n; n++) + { + int timeout = 5; + + // Setup and start conversion + outb (control, dev->iobase + AIO12_8_ADC); + + // Wait for conversion to complete + while (timeout && + ! (inb (dev->iobase + AIO12_8_STATUS) & STATUS_ADC_EOC)) + { + timeout--; + printk ("timeout %d\n", timeout); + comedi_udelay (1); + } + if (timeout == 0) + { + comedi_error (dev, "ADC timeout"); + return -EIO; + } + + data[n] = inw (dev->iobase + AIO12_8_ADC) & 0x0FFF; + } + return n; +} + +static int aio_aio12_8_ao_read (comedi_device *dev, comedi_subdevice *s, + comedi_insn *insn, lsampl_t *data) +{ + int i; + int val = devpriv->ao_readback[CR_CHAN(insn->chanspec)]; + + for (i = 0; i < insn->n; i++) + data[i] = val; + return insn->n; +} + +static int aio_aio12_8_ao_write (comedi_device *dev, comedi_subdevice *s, + comedi_insn *insn, lsampl_t *data) +{ + int i; + int chan = CR_CHAN(insn->chanspec); + unsigned long port = dev->iobase + AIO12_8_DAC_0 + (2 * chan); + + //enable DACs + outb(0x01, dev->iobase + DAC_ENABLE); + + for (i = 0; i < insn->n; i++) + { + outb (data[i] & 0xFF, port); // LSB + outb ((data[i] >> 8) & 0x0F, port + 1); // MSB + devpriv->ao_readback[chan] = data[i]; + } + return insn->n; +} + +static comedi_lrange range_aio_aio12_8 = +{ + 4, + { + UNI_RANGE(5), + BIP_RANGE(5), + UNI_RANGE(10), + BIP_RANGE(10), + } +}; + +static int aio_aio12_8_attach (comedi_device *dev, comedi_devconfig *it) +{ + int iobase; + comedi_subdevice *s; + + iobase = it->options[0]; + if (! request_region (iobase, 24, "aio_aio12_8")) + { + printk ("I/O port conflict"); + return -EIO; + } + + dev->board_name = thisboard->name; + + dev->iobase = iobase; + + if (alloc_private (dev, sizeof (aio12_8_private)) < 0) + return -ENOMEM; + + if (alloc_subdevices (dev, 3) < 0) + return -ENOMEM; + + s = &dev->subdevices[0]; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF; + s->n_chan = 8; + s->maxdata = (1 << 12) - 1; + s->range_table = &range_aio_aio12_8; + s->insn_read = aio_aio12_8_ai_read; + + s = &dev->subdevices[1]; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_DIFF; + s->n_chan = 4; + s->maxdata = (1 << 12) - 1; + s->range_table = &range_aio_aio12_8; + s->insn_read = aio_aio12_8_ao_read; + s->insn_write = aio_aio12_8_ao_write; + + s = &dev->subdevices[2]; + subdev_8255_init (dev, s, NULL, dev->iobase + AIO12_8_DIO_0); + + return 0; +} + +static int aio_aio12_8_detach (comedi_device *dev) +{ + subdev_8255_cleanup (dev, &dev->subdevices[2]); + if (dev->iobase) + release_region (dev->iobase, 24); + return 0; +} + +static comedi_driver driver_aio_aio12_8 = +{ + driver_name: "aio_aio12_8", + module: THIS_MODULE, + attach: aio_aio12_8_attach, + detach: aio_aio12_8_detach, + board_name: board_types, + num_names: 1, + offset: sizeof (board_type), +}; + +COMEDI_INITCLEANUP(driver_aio_aio12_8); diff --git a/comedi/drivers/aio_iiro_16.c b/comedi/drivers/aio_iiro_16.c new file mode 100644 index 00000000..f3196740 --- /dev/null +++ b/comedi/drivers/aio_iiro_16.c @@ -0,0 +1,175 @@ +/* + + Driver for Acces I/O Products PC-104 AIO-IIRO-16 Digital I/O board + Copyright (C) 2006 C&C Technologies, Inc. + +*/ + +/* + +Driver: aio_iiro_16.o +Description: Acces I/O Products PC-104 IIRO16 Relay And Isolated Input Board +Author: Zachary Ware +Devices: + [Acces I/O] PC-104 AIO12-8 +Status: experimental + +Configuration Options: + [0] - I/O port base address + +*/ + +#include +#include + +#define AIO_IIRO_16_SIZE 0x08 +#define AIO_IIRO_16_RELAY_0_7 0x00 +#define AIO_IIRO_16_INPUT_0_7 0x01 +#define AIO_IIRO_16_IRQ 0x02 +#define AIO_IIRO_16_RELAY_8_15 0x04 +#define AIO_IIRO_16_INPUT_8_15 0x05 + + +typedef struct aio_iiro_16_board_struct +{ + char *name; + int do_; + int di; +} aio_iiro_16_board; + +static aio_iiro_16_board aio_iiro_16_boards[] = +{ + { + name: "aio_iiro_16", + di: 16, + do_: 16 + }, +}; + +#define thisboard ((aio_iiro_16_board *) dev->board_ptr) + +typedef struct +{ + int data; + struct pci_dev *pci_dev; + lsampl_t ao_readback[2]; +} aio_iiro_16_private; + + +#define devpriv ((aio_iiro_16_private *) dev->private) + +static int aio_iiro_16_attach (comedi_device *dev, comedi_devconfig *it); + +static int aio_iiro_16_detach (comedi_device *dev); + +static comedi_driver driver_aio_iiro_16 = +{ + driver_name: "aio_iiro_16", + module: THIS_MODULE, + attach: aio_iiro_16_attach, + detach: aio_iiro_16_detach, + board_name: aio_iiro_16_boards, + offset: sizeof (aio_iiro_16_board), + num_names: sizeof (aio_iiro_16_boards) / + sizeof (aio_iiro_16_board), +}; + +static int aio_iiro_16_dio_insn_bits_read (comedi_device *dev, + comedi_subdevice *s, + comedi_insn *insn, lsampl_t *data); + +static int aio_iiro_16_dio_insn_bits_write (comedi_device *dev, + comedi_subdevice *s, + comedi_insn *insn, lsampl_t *data); + +static int aio_iiro_16_attach (comedi_device *dev, comedi_devconfig *it) +{ + int iobase; + comedi_subdevice *s; + + printk ("comedi%d: aio_iiro_16: ", dev->minor); + + dev->board_name = thisboard->name; + + iobase = it->options[0]; + + if (! request_region (iobase, AIO_IIRO_16_SIZE, dev->board_name)) + { + printk ("I/O port conflict"); + return -EIO; + } + + dev->iobase = iobase; + + if (alloc_private (dev, sizeof (aio_iiro_16_private)) < 0) + return -ENOMEM; + + if (alloc_subdevices (dev, 2) < 0) + return -ENOMEM; + + s = dev->subdevices + 0; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 16; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = aio_iiro_16_dio_insn_bits_write; + + s = dev->subdevices + 1; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE; + s->n_chan = 16; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = aio_iiro_16_dio_insn_bits_read; + + printk ("attached\n"); + + return 1; +} + +static int aio_iiro_16_detach (comedi_device *dev) +{ + printk ("comedi%d: aio_iiro_16: remove\n", dev->minor); + + if (dev->iobase) release_region (dev->iobase, AIO_IIRO_16_SIZE); + + return 0; +} + +static int aio_iiro_16_dio_insn_bits_write (comedi_device *dev, + comedi_subdevice *s, + comedi_insn *insn, lsampl_t *data) +{ + if (insn->n != 2) + return -EINVAL; + + if (data[0]) + { + s->state &= ~data[0]; + s->state |= data[0] & data[1]; + outb (s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7); + outb ((s->state >> 8) & 0xff, + dev->iobase + AIO_IIRO_16_RELAY_8_15); + } + + data[1] = s->state; + + return 2; +} + +static int aio_iiro_16_dio_insn_bits_read (comedi_device *dev, + comedi_subdevice *s, + comedi_insn *insn, lsampl_t *data) +{ + if (insn->n != 2) + return -EINVAL; + + data[1] = 0; + data[1] |= inb (dev->iobase + AIO_IIRO_16_INPUT_0_7); + data[1] |= inb (dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8; + + return 2; +} + +COMEDI_INITCLEANUP(driver_aio_iiro_16); -- 2.26.2