/drivers/staging/comedi/drivers/das16m1.c
C | 794 lines | 534 code | 113 blank | 147 comment | 107 complexity | 61cbda448d5fc43fea922543e793017f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
- /*
- comedi/drivers/das16m1.c
- CIO-DAS16/M1 driver
- Author: Frank Mori Hess, based on code from the das16
- driver.
- Copyright (C) 2001 Frank Mori Hess <fmhess@users.sourceforge.net>
- COMEDI - Linux Control and Measurement Device Interface
- Copyright (C) 2000 David A. Schleef <ds@schleef.org>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ************************************************************************
- */
- /*
- Driver: das16m1
- Description: CIO-DAS16/M1
- Author: Frank Mori Hess <fmhess@users.sourceforge.net>
- Devices: [Measurement Computing] CIO-DAS16/M1 (cio-das16/m1)
- Status: works
- This driver supports a single board - the CIO-DAS16/M1.
- As far as I know, there are no other boards that have
- the same register layout. Even the CIO-DAS16/M1/16 is
- significantly different.
- I was _barely_ able to reach the full 1 MHz capability
- of this board, using a hard real-time interrupt
- (set the TRIG_RT flag in your struct comedi_cmd and use
- rtlinux or RTAI). The board can't do dma, so the bottleneck is
- pulling the data across the ISA bus. I timed the interrupt
- handler, and it took my computer ~470 microseconds to pull 512
- samples from the board. So at 1 Mhz sampling rate,
- expect your CPU to be spending almost all of its
- time in the interrupt handler.
- This board has some unusual restrictions for its channel/gain list. If the
- list has 2 or more channels in it, then two conditions must be satisfied:
- (1) - even/odd channels must appear at even/odd indices in the list
- (2) - the list must have an even number of entries.
- Options:
- [0] - base io address
- [1] - irq (optional, but you probably want it)
- irq can be omitted, although the cmd interface will not work without it.
- */
- #include <linux/ioport.h>
- #include <linux/interrupt.h>
- #include "../comedidev.h"
- #include "8255.h"
- #include "8253.h"
- #include "comedi_fc.h"
- #define DAS16M1_SIZE 16
- #define DAS16M1_SIZE2 8
- #define DAS16M1_XTAL 100 /* 10 MHz master clock */
- #define FIFO_SIZE 1024 /* 1024 sample fifo */
- /*
- CIO-DAS16_M1.pdf
- "cio-das16/m1"
- 0 a/d bits 0-3, mux start 12 bit
- 1 a/d bits 4-11 unused
- 2 status control
- 3 di 4 bit do 4 bit
- 4 unused clear interrupt
- 5 interrupt, pacer
- 6 channel/gain queue address
- 7 channel/gain queue data
- 89ab 8254
- cdef 8254
- 400 8255
- 404-407 8254
- */
- #define DAS16M1_AI 0 /* 16-bit wide register */
- #define AI_CHAN(x) ((x) & 0xf)
- #define DAS16M1_CS 2
- #define EXT_TRIG_BIT 0x1
- #define OVRUN 0x20
- #define IRQDATA 0x80
- #define DAS16M1_DIO 3
- #define DAS16M1_CLEAR_INTR 4
- #define DAS16M1_INTR_CONTROL 5
- #define EXT_PACER 0x2
- #define INT_PACER 0x3
- #define PACER_MASK 0x3
- #define INTE 0x80
- #define DAS16M1_QUEUE_ADDR 6
- #define DAS16M1_QUEUE_DATA 7
- #define Q_CHAN(x) ((x) & 0x7)
- #define Q_RANGE(x) (((x) & 0xf) << 4)
- #define UNIPOLAR 0x40
- #define DAS16M1_8254_FIRST 0x8
- #define DAS16M1_8254_FIRST_CNTRL 0xb
- #define TOTAL_CLEAR 0x30
- #define DAS16M1_8254_SECOND 0xc
- #define DAS16M1_82C55 0x400
- #define DAS16M1_8254_THIRD 0x404
- static const struct comedi_lrange range_das16m1 = { 9,
- {
- BIP_RANGE(5),
- BIP_RANGE(2.5),
- BIP_RANGE(1.25),
- BIP_RANGE(0.625),
- UNI_RANGE(10),
- UNI_RANGE(5),
- UNI_RANGE(2.5),
- UNI_RANGE(1.25),
- BIP_RANGE(10),
- }
- };
- static int das16m1_do_wbits(struct comedi_device *dev,
- struct comedi_subdevice *s,
- struct comedi_insn *insn, unsigned int *data);
- static int das16m1_di_rbits(struct comedi_device *dev,
- struct comedi_subdevice *s,
- struct comedi_insn *insn, unsigned int *data);
- static int das16m1_ai_rinsn(struct comedi_device *dev,
- struct comedi_subdevice *s,
- struct comedi_insn *insn, unsigned int *data);
- static int das16m1_cmd_test(struct comedi_device *dev,
- struct comedi_subdevice *s, struct comedi_cmd *cmd);
- static int das16m1_cmd_exec(struct comedi_device *dev,
- struct comedi_subdevice *s);
- static int das16m1_cancel(struct comedi_device *dev,
- struct comedi_subdevice *s);
- static int das16m1_poll(struct comedi_device *dev, struct comedi_subdevice *s);
- static irqreturn_t das16m1_interrupt(int irq, void *d);
- static void das16m1_handler(struct comedi_device *dev, unsigned int status);
- static unsigned int das16m1_set_pacer(struct comedi_device *dev,
- unsigned int ns, int round_flag);
- static int das16m1_irq_bits(unsigned int irq);
- struct das16m1_board {
- const char *name;
- unsigned int ai_speed;
- };
- static const struct das16m1_board das16m1_boards[] = {
- {
- .name = "cio-das16/m1", /* CIO-DAS16_M1.pdf */
- .ai_speed = 1000, /* 1MHz max speed */
- },
- };
- static int das16m1_attach(struct comedi_device *dev,
- struct comedi_devconfig *it);
- static int das16m1_detach(struct comedi_device *dev);
- static struct comedi_driver driver_das16m1 = {
- .driver_name = "das16m1",
- .module = THIS_MODULE,
- .attach = das16m1_attach,
- .detach = das16m1_detach,
- .board_name = &das16m1_boards[0].name,
- .num_names = ARRAY_SIZE(das16m1_boards),
- .offset = sizeof(das16m1_boards[0]),
- };
- struct das16m1_private_struct {
- unsigned int control_state;
- volatile unsigned int adc_count; /* number of samples completed */
- /* initial value in lower half of hardware conversion counter,
- * needed to keep track of whether new count has been loaded into
- * counter yet (loaded by first sample conversion) */
- u16 initial_hw_count;
- short ai_buffer[FIFO_SIZE];
- unsigned int do_bits; /* saves status of digital output bits */
- unsigned int divisor1; /* divides master clock to obtain conversion speed */
- unsigned int divisor2; /* divides master clock to obtain conversion speed */
- };
- #define devpriv ((struct das16m1_private_struct *)(dev->private))
- #define thisboard ((const struct das16m1_board *)(dev->board_ptr))
- static int __init driver_das16m1_init_module(void)
- {
- return comedi_driver_register(&driver_das16m1);
- }
- static void __exit driver_das16m1_cleanup_module(void)
- {
- comedi_driver_unregister(&driver_das16m1);
- }
- module_init(driver_das16m1_init_module);
- module_exit(driver_das16m1_cleanup_module);
- static inline short munge_sample(short data)
- {
- return (data >> 4) & 0xfff;
- }
- static int das16m1_cmd_test(struct comedi_device *dev,
- struct comedi_subdevice *s, struct comedi_cmd *cmd)
- {
- unsigned int err = 0, tmp, i;
- /* make sure triggers are valid */
- tmp = cmd->start_src;
- cmd->start_src &= TRIG_NOW | TRIG_EXT;
- if (!cmd->start_src || tmp != cmd->start_src)
- err++;
- tmp = cmd->scan_begin_src;
- cmd->scan_begin_src &= TRIG_FOLLOW;
- if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
- err++;
- tmp = cmd->convert_src;
- cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
- if (!cmd->convert_src || tmp != cmd->convert_src)
- err++;
- tmp = cmd->scan_end_src;
- cmd->scan_end_src &= TRIG_COUNT;
- if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
- err++;
- tmp = cmd->stop_src;
- cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
- if (!cmd->stop_src || tmp != cmd->stop_src)
-