linux/drivers/staging/comedi/drivers/amplc_pci263.c
<<
>>
Prefs
   1/*
   2    comedi/drivers/amplc_pci263.c
   3    Driver for Amplicon PCI263 relay board.
   4
   5    Copyright (C) 2002 MEV Ltd. <http://www.mev.co.uk/>
   6
   7    COMEDI - Linux Control and Measurement Device Interface
   8    Copyright (C) 2000 David A. Schleef <ds@schleef.org>
   9
  10    This program is free software; you can redistribute it and/or modify
  11    it under the terms of the GNU General Public License as published by
  12    the Free Software Foundation; either version 2 of the License, or
  13    (at your option) any later version.
  14
  15    This program is distributed in the hope that it will be useful,
  16    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18    GNU General Public License for more details.
  19*/
  20/*
  21Driver: amplc_pci263
  22Description: Amplicon PCI263
  23Author: Ian Abbott <abbotti@mev.co.uk>
  24Devices: [Amplicon] PCI263 (amplc_pci263)
  25Updated: Fri, 12 Apr 2013 15:19:36 +0100
  26Status: works
  27
  28Configuration options: not applicable, uses PCI auto config
  29
  30The board appears as one subdevice, with 16 digital outputs, each
  31connected to a reed-relay. Relay contacts are closed when output is 1.
  32The state of the outputs can be read.
  33*/
  34
  35#include <linux/module.h>
  36#include <linux/pci.h>
  37
  38#include "../comedidev.h"
  39
  40static int pci263_do_insn_bits(struct comedi_device *dev,
  41                               struct comedi_subdevice *s,
  42                               struct comedi_insn *insn,
  43                               unsigned int *data)
  44{
  45        if (comedi_dio_update_state(s, data)) {
  46                outb(s->state & 0xff, dev->iobase);
  47                outb((s->state >> 8) & 0xff, dev->iobase + 1);
  48        }
  49
  50        data[1] = s->state;
  51
  52        return insn->n;
  53}
  54
  55static int pci263_auto_attach(struct comedi_device *dev,
  56                              unsigned long context_unused)
  57{
  58        struct pci_dev *pci_dev = comedi_to_pci_dev(dev);
  59        struct comedi_subdevice *s;
  60        int ret;
  61
  62        ret = comedi_pci_enable(dev);
  63        if (ret)
  64                return ret;
  65
  66        dev->iobase = pci_resource_start(pci_dev, 2);
  67        ret = comedi_alloc_subdevices(dev, 1);
  68        if (ret)
  69                return ret;
  70
  71        s = &dev->subdevices[0];
  72        /* digital output subdevice */
  73        s->type = COMEDI_SUBD_DO;
  74        s->subdev_flags = SDF_WRITABLE;
  75        s->n_chan = 16;
  76        s->maxdata = 1;
  77        s->range_table = &range_digital;
  78        s->insn_bits = pci263_do_insn_bits;
  79        /* read initial relay state */
  80        s->state = inb(dev->iobase) | (inb(dev->iobase + 1) << 8);
  81
  82        return 0;
  83}
  84
  85static struct comedi_driver amplc_pci263_driver = {
  86        .driver_name    = "amplc_pci263",
  87        .module         = THIS_MODULE,
  88        .auto_attach    = pci263_auto_attach,
  89        .detach         = comedi_pci_detach,
  90};
  91
  92static const struct pci_device_id pci263_pci_table[] = {
  93        { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, 0x000c) },
  94        {0}
  95};
  96MODULE_DEVICE_TABLE(pci, pci263_pci_table);
  97
  98static int amplc_pci263_pci_probe(struct pci_dev *dev,
  99                                  const struct pci_device_id *id)
 100{
 101        return comedi_pci_auto_config(dev, &amplc_pci263_driver,
 102                                      id->driver_data);
 103}
 104
 105static struct pci_driver amplc_pci263_pci_driver = {
 106        .name           = "amplc_pci263",
 107        .id_table       = pci263_pci_table,
 108        .probe          = &amplc_pci263_pci_probe,
 109        .remove         = comedi_pci_auto_unconfig,
 110};
 111module_comedi_pci_driver(amplc_pci263_driver, amplc_pci263_pci_driver);
 112
 113MODULE_AUTHOR("Comedi http://www.comedi.org");
 114MODULE_DESCRIPTION("Comedi driver for Amplicon PCI263 relay board");
 115MODULE_LICENSE("GPL");
 116
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.