/drivers/staging/comedi/drivers/cb_pcimdas.c
C | 532 lines | 319 code | 73 blank | 140 comment | 32 complexity | 423249ec0bf97f2731aacebdd6f4d647 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
- /*
- comedi/drivers/cb_pcimdas.c
- Comedi driver for Computer Boards PCIM-DAS1602/16
- 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: cb_pcimdas
- Description: Measurement Computing PCI Migration series boards
- Devices: [ComputerBoards] PCIM-DAS1602/16 (cb_pcimdas)
- Author: Richard Bytheway
- Updated: Wed, 13 Nov 2002 12:34:56 +0000
- Status: experimental
- Written to support the PCIM-DAS1602/16 on a 2.4 series kernel.
- Configuration Options:
- [0] - PCI bus number
- [1] - PCI slot number
- Developed from cb_pcidas and skel by Richard Bytheway (mocelet@sucs.org).
- Only supports DIO, AO and simple AI in it's present form.
- No interrupts, multi channel or FIFO AI, although the card looks like it could support this.
- See http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf for more details.
- */
- #include "../comedidev.h"
- #include <linux/delay.h>
- #include <linux/interrupt.h>
- #include "comedi_pci.h"
- #include "plx9052.h"
- #include "8255.h"
- /* #define CBPCIMDAS_DEBUG */
- #undef CBPCIMDAS_DEBUG
- #define PCI_VENDOR_ID_COMPUTERBOARDS 0x1307
- /* Registers for the PCIM-DAS1602/16 */
- /* sizes of io regions (bytes) */
- #define BADR0_SIZE 2 /* ?? */
- #define BADR1_SIZE 4
- #define BADR2_SIZE 6
- #define BADR3_SIZE 16
- #define BADR4_SIZE 4
- /* DAC Offsets */
- #define ADC_TRIG 0
- #define DAC0_OFFSET 2
- #define DAC1_OFFSET 4
- /* AI and Counter Constants */
- #define MUX_LIMITS 0
- #define MAIN_CONN_DIO 1
- #define ADC_STAT 2
- #define ADC_CONV_STAT 3
- #define ADC_INT 4
- #define ADC_PACER 5
- #define BURST_MODE 6
- #define PROG_GAIN 7
- #define CLK8254_1_DATA 8
- #define CLK8254_2_DATA 9
- #define CLK8254_3_DATA 10
- #define CLK8254_CONTROL 11
- #define USER_COUNTER 12
- #define RESID_COUNT_H 13
- #define RESID_COUNT_L 14
- /* Board description */
- struct cb_pcimdas_board {
- const char *name;
- unsigned short device_id;
- int ai_se_chans; /* Inputs in single-ended mode */
- int ai_diff_chans; /* Inputs in differential mode */
- int ai_bits; /* analog input resolution */
- int ai_speed; /* fastest conversion period in ns */
- int ao_nchan; /* number of analog out channels */
- int ao_bits; /* analogue output resolution */
- int has_ao_fifo; /* analog output has fifo */
- int ao_scan_speed; /* analog output speed for 1602 series (for a scan, not conversion) */
- int fifo_size; /* number of samples fifo can hold */
- int dio_bits; /* number of dio bits */
- int has_dio; /* has DIO */
- const struct comedi_lrange *ranges;
- };
- static const struct cb_pcimdas_board cb_pcimdas_boards[] = {
- {
- .name = "PCIM-DAS1602/16",
- .device_id = 0x56,
- .ai_se_chans = 16,
- .ai_diff_chans = 8,
- .ai_bits = 16,
- .ai_speed = 10000, /* ?? */
- .ao_nchan = 2,
- .ao_bits = 12,
- .has_ao_fifo = 0, /* ?? */
- .ao_scan_speed = 10000,
- /* ?? */
- .fifo_size = 1024,
- .dio_bits = 24,
- .has_dio = 1,
- /* .ranges = &cb_pcimdas_ranges, */
- },
- };
- /* This is used by modprobe to translate PCI IDs to drivers. Should
- * only be used for PCI and ISA-PnP devices */
- static DEFINE_PCI_DEVICE_TABLE(cb_pcimdas_pci_table) = {
- { PCI_DEVICE(PCI_VENDOR_ID_COMPUTERBOARDS, 0x0056) },
- { 0 }
- };
- MODULE_DEVICE_TABLE(pci, cb_pcimdas_pci_table);
- #define N_BOARDS 1 /* Max number of boards supported */
- /*
- * Useful for shorthand access to the particular board structure
- */
- #define thisboard ((const struct cb_pcimdas_board *)dev->board_ptr)
- /* this structure is for data unique to this hardware driver. If
- several hardware drivers keep similar information in this structure,
- feel free to suggest moving the variable to the struct comedi_device struct. */
- struct cb_pcimdas_private {
- int data;
- /* would be useful for a PCI device */
- struct pci_dev *pci_dev;
- /* base addresses */
- unsigned long BADR0;
- unsigned long BADR1;
- unsigned long BADR2;
- unsigned long BADR3;
- unsigned long BADR4;
- /* Used for AO readback */
- unsigned int ao_readback[2];
- /* Used for DIO */
- unsigned short int port_a; /* copy of BADR4+0 */
- unsigned short int port_b; /* copy of BADR4+1 */
- unsigned short int port_c; /* copy of BADR4+2 */
- unsigned short int dio_mode; /* copy of BADR4+3 */
- };
- /*
- * most drivers define the following macro to make it easy to
- * access the private structure.
- */
- #define devpriv ((struct cb_pcimdas_private *)dev->private)
- /*
- * The struct comedi_driver structure tells the Comedi core module
- * which functions to call to configure/deconfigure (attach/detach)
- * the board, and also about the kernel module that contains
- * the device code.
- */
- static int cb_pcimdas_attach(struct comedi_device *dev,
- struct comedi_devconfig *it);
- static int cb_pcimdas_detach(struct comedi_device *dev);
- static struct comedi_driver driver_cb_pcimdas = {
- .driver_name = "cb_pcimdas",
- .module = THIS_MODULE,
- .attach = cb_pcimdas_attach,
- .detach = cb_pcimdas_detach,
- };
- static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
- struct comedi_subdevice *s,
- struct comedi_insn *insn, unsigned int *data);
- static int cb_pcimdas_ao_winsn(struct comedi_device *dev,
- struct comedi_subdevice *s,
- struct comedi_insn *insn, unsigned int *data);
- static int cb_pcimdas_ao_rinsn(struct comedi_device *dev,
- struct comedi_subdevice *s,
- struct comedi_insn *insn, unsigned int *data);
- /*
- * Attach is called by the Comedi core to configure the driver
- * for a particular board. If you specified a board_name array
- * in the driver structure, dev->board_ptr contains that
- * address.
- */
- static int cb_pcimdas_attach(struct comedi_device *dev,
- struct comedi_devconfig *it)
- {
- struct comedi_subdevice *s;
- struct pci_dev *pcidev = NULL;
- int index;
- /* int i; */
- printk("comedi%d: cb_pcimdas: ", dev->minor);
- /*
- * Allocate the private structure area.
- */
- if (alloc_private(dev, sizeof(struct cb_pcimdas_private)) < 0)
- return -ENOMEM;
- /*
- * Probe the device to determine what device in the series it is.
- */
- printk("\n");
- for_each_pci_dev(pcidev) {
- /* is it not a computer boards card? */
- if (pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS)
- continue;
- /* loop through cards supported by this driver */
- for (index = 0; index < N_BOARDS; index++) {
- if (cb_pcimdas_boards[index].device_id !=
- pcidev->device)
- continue;
- /* was a particular bus/slot requested? */
- if (it->options[0] || it->options[1]) {
- /* are we on the wrong bus/slot? */
- if (pcidev->bus->number != it->options[0] ||
- PCI_SLOT(pcidev->devfn) != it->options[1]) {
- continue;
- }
- }
- devpriv->pci_dev = pcidev;
- dev->board_ptr = cb_pcimdas_boards + index;
- goto found;
-