/drivers/staging/comedi/drivers/das16.c
C | 1791 lines | 1335 code | 182 blank | 274 comment | 230 complexity | 3c3127dd5a3c8f2641ef1a928ecc1737 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
- /*
- comedi/drivers/das16.c
- DAS16 driver
- COMEDI - Linux Control and Measurement Device Interface
- Copyright (C) 2000 David A. Schleef <ds@schleef.org>
- Copyright (C) 2000 Chris R. Baugher <baugher@enteract.com>
- Copyright (C) 2001,2002 Frank Mori Hess <fmhess@users.sourceforge.net>
- 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: das16
- Description: DAS16 compatible boards
- Author: Sam Moore, Warren Jasper, ds, Chris Baugher, Frank Hess, Roman Fietze
- Devices: [Keithley Metrabyte] DAS-16 (das-16), DAS-16G (das-16g),
- DAS-16F (das-16f), DAS-1201 (das-1201), DAS-1202 (das-1202),
- DAS-1401 (das-1401), DAS-1402 (das-1402), DAS-1601 (das-1601),
- DAS-1602 (das-1602),
- [ComputerBoards] PC104-DAS16/JR (pc104-das16jr),
- PC104-DAS16JR/16 (pc104-das16jr/16),
- CIO-DAS16JR/16 (cio-das16jr/16),
- CIO-DAS16/JR (cio-das16/jr), CIO-DAS1401/12 (cio-das1401/12),
- CIO-DAS1402/12 (cio-das1402/12), CIO-DAS1402/16 (cio-das1402/16),
- CIO-DAS1601/12 (cio-das1601/12), CIO-DAS1602/12 (cio-das1602/12),
- CIO-DAS1602/16 (cio-das1602/16), CIO-DAS16/330 (cio-das16/330)
- Status: works
- Updated: 2003-10-12
- A rewrite of the das16 and das1600 drivers.
- Options:
- [0] - base io address
- [1] - irq (does nothing, irq is not used anymore)
- [2] - dma (optional, required for comedi_command support)
- [3] - master clock speed in MHz (optional, 1 or 10, ignored if
- board can probe clock, defaults to 1)
- [4] - analog input range lowest voltage in microvolts (optional,
- only useful if your board does not have software
- programmable gain)
- [5] - analog input range highest voltage in microvolts (optional,
- only useful if board does not have software programmable
- gain)
- [6] - analog output range lowest voltage in microvolts (optional)
- [7] - analog output range highest voltage in microvolts (optional)
- [8] - use timer mode for DMA. Timer mode is needed e.g. for
- buggy DMA controllers in NS CS5530A (Geode Companion), and for
- 'jr' cards that lack a hardware fifo. This option is no
- longer needed, since timer mode is _always_ used.
- Passing a zero for an option is the same as leaving it unspecified.
- */
- /*
- Testing and debugging help provided by Daniel Koch.
- Keithley Manuals:
- 2309.PDF (das16)
- 4919.PDF (das1400, 1600)
- 4922.PDF (das-1400)
- 4923.PDF (das1200, 1400, 1600)
- Computer boards manuals also available from their website
- www.measurementcomputing.com
- */
- #include <linux/pci.h>
- #include <linux/slab.h>
- #include <linux/interrupt.h>
- #include <asm/dma.h>
- #include "../comedidev.h"
- #include "8253.h"
- #include "8255.h"
- #include "comedi_fc.h"
- #undef DEBUG
- /* #define DEBUG */
- #ifdef DEBUG
- #define DEBUG_PRINT(format, args...) \
- printk(KERN_DEBUG "das16: " format, ## args)
- #else
- #define DEBUG_PRINT(format, args...)
- #endif
- #define DAS16_SIZE 20 /* number of ioports */
- #define DAS16_DMA_SIZE 0xff00 /* size in bytes of allocated dma buffer */
- /*
- cio-das16.pdf
- "das16"
- "das16/f"
- 0 a/d bits 0-3 start 12 bit
- 1 a/d bits 4-11 unused
- 2 mux read mux set
- 3 di 4 bit do 4 bit
- 4 unused ao0_lsb
- 5 unused ao0_msb
- 6 unused ao1_lsb
- 7 unused ao1_msb
- 8 status eoc uni/bip interrupt reset
- 9 dma, int, trig ctrl set dma, int
- a pacer control unused
- b reserved reserved
- cdef 8254
- 0123 8255
- */
- /*
- cio-das16jr.pdf
- "das16jr"
- 0 a/d bits 0-3 start 12 bit
- 1 a/d bits 4-11 unused
- 2 mux read mux set
- 3 di 4 bit do 4 bit
- 4567 unused unused
- 8 status eoc uni/bip interrupt reset
- 9 dma, int, trig ctrl set dma, int
- a pacer control unused
- b gain status gain control
- cdef 8254
- */
- /*
- cio-das16jr_16.pdf
- "das16jr_16"
- 0 a/d bits 0-7 start 16 bit
- 1 a/d bits 8-15 unused
- 2 mux read mux set
- 3 di 4 bit do 4 bit
- 4567 unused unused
- 8 status eoc uni/bip interrupt reset
- 9 dma, int, trig ctrl set dma, int
- a pacer control unused
- b gain status gain control
- cdef 8254
- */
- /*
- cio-das160x-1x.pdf
- "das1601/12"
- "das1602/12"
- "das1602/16"
- 0 a/d bits 0-3 start 12 bit
- 1 a/d bits 4-11 unused
- 2 mux read mux set
- 3 di 4 bit do 4 bit
- 4 unused ao0_lsb
- 5 unused ao0_msb
- 6 unused ao1_lsb
- 7 unused ao1_msb
- 8 status eoc uni/bip interrupt reset
- 9 dma, int, trig ctrl set dma, int
- a pacer control unused
- b gain status gain control
- cdef 8254
- 400 8255
- 404 unused conversion enable
- 405 unused burst enable
- 406 unused das1600 enable
- 407 status
- */
- /* size in bytes of a sample from board */
- static const int sample_size = 2;
- #define DAS16_TRIG 0
- #define DAS16_AI_LSB 0
- #define DAS16_AI_MSB 1
- #define DAS16_MUX 2
- #define DAS16_DIO 3
- #define DAS16_AO_LSB(x) ((x) ? 6 : 4)
- #define DAS16_AO_MSB(x) ((x) ? 7 : 5)
- #define DAS16_STATUS 8
- #define BUSY (1<<7)
- #define UNIPOLAR (1<<6)
- #define DAS16_MUXBIT (1<<5)
- #define DAS16_INT (1<<4)
- #define DAS16_CONTROL 9
- #define DAS16_INTE (1<<7)
- #define DAS16_IRQ(x) (((x) & 0x7) << 4)
- #define DMA_ENABLE (1<<2)
- #define PACING_MASK 0x3
- #define INT_PACER 0x03
- #define EXT_PACER 0x02
- #define DAS16_SOFT 0x00
- #define DAS16_PACER 0x0A
- #define DAS16_CTR0 (1<<1)
- #define DAS16_TRIG0 (1<<0)
- #define BURST_LEN_BITS(x) (((x) & 0xf) << 4)
- #define DAS16_GAIN 0x0B
- #define DAS16_CNTR0_DATA 0x0C
- #define DAS16_CNTR1_DATA 0x0D
- #define DAS16_CNTR2_DATA 0x0E
- #define DAS16_CNTR_CONTROL 0x0F
- #define DAS16_TERM_CNT 0x00
- #define DAS16_ONE_SHOT 0x02
- #define DAS16_RATE_GEN 0x04
- #define DAS16_CNTR_LSB_MSB 0x30
- #define DAS16_CNTR0 0x00
- #define DAS16_CNTR1 0x40
- #define DAS16_CNTR2 0x80
- #define DAS1600_CONV 0x404
- #define DAS1600_CONV_DISABLE 0x40
- #define DAS1600_BURST 0x405
- #define DAS1600_BURST_VAL 0x40
- #define DAS1600_ENABLE 0x406
- #define DAS1600_ENABLE_VAL 0x40
- #define DAS1600_STATUS_B 0x407
- #define DAS1600_BME 0x40
- #define DAS1600_ME 0x20
- #define DAS1600_CD 0x10
- #define DAS1600_WS 0x02
- #define DAS1600_CLK_10MHZ 0x01
- static const struct comedi_lrange range_das1x01_bip = { 4, {
- BIP_RANGE(10),
- BIP_RANGE(1),
- BIP_RANGE(0.1),
-