]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/amplc_pci263.c
Merge remote-tracking branch 'staging/staging-next'
[karo-tx-linux.git] / drivers / staging / comedi / drivers / amplc_pci263.c
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 /*
21 Driver: amplc_pci263
22 Description: Amplicon PCI263
23 Author: Ian Abbott <abbotti@mev.co.uk>
24 Devices: [Amplicon] PCI263 (amplc_pci263)
25 Updated: Fri, 12 Apr 2013 15:19:36 +0100
26 Status: works
27
28 Configuration options: not applicable, uses PCI auto config
29
30 The board appears as one subdevice, with 16 digital outputs, each
31 connected to a reed-relay. Relay contacts are closed when output is 1.
32 The 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
40 #define PCI263_DRIVER_NAME      "amplc_pci263"
41
42 /* PCI263 PCI configuration register information */
43 #define PCI_DEVICE_ID_AMPLICON_PCI263 0x000c
44
45 static int pci263_do_insn_bits(struct comedi_device *dev,
46                                struct comedi_subdevice *s,
47                                struct comedi_insn *insn,
48                                unsigned int *data)
49 {
50         if (comedi_dio_update_state(s, data)) {
51                 outb(s->state & 0xff, dev->iobase);
52                 outb((s->state >> 8) & 0xff, dev->iobase + 1);
53         }
54
55         data[1] = s->state;
56
57         return insn->n;
58 }
59
60 static int pci263_auto_attach(struct comedi_device *dev,
61                               unsigned long context_unused)
62 {
63         struct pci_dev *pci_dev = comedi_to_pci_dev(dev);
64         struct comedi_subdevice *s;
65         int ret;
66
67         ret = comedi_pci_enable(dev);
68         if (ret)
69                 return ret;
70
71         dev->iobase = pci_resource_start(pci_dev, 2);
72         ret = comedi_alloc_subdevices(dev, 1);
73         if (ret)
74                 return ret;
75
76         s = &dev->subdevices[0];
77         /* digital output subdevice */
78         s->type = COMEDI_SUBD_DO;
79         s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
80         s->n_chan = 16;
81         s->maxdata = 1;
82         s->range_table = &range_digital;
83         s->insn_bits = pci263_do_insn_bits;
84         /* read initial relay state */
85         s->state = inb(dev->iobase) | (inb(dev->iobase + 1) << 8);
86
87         dev_info(dev->class_dev, "%s (pci %s) attached\n", dev->board_name,
88                  pci_name(pci_dev));
89         return 0;
90 }
91
92 static struct comedi_driver amplc_pci263_driver = {
93         .driver_name    = PCI263_DRIVER_NAME,
94         .module         = THIS_MODULE,
95         .auto_attach    = pci263_auto_attach,
96         .detach         = comedi_pci_disable,
97 };
98
99 static DEFINE_PCI_DEVICE_TABLE(pci263_pci_table) = {
100         { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI263) },
101         {0}
102 };
103 MODULE_DEVICE_TABLE(pci, pci263_pci_table);
104
105 static int amplc_pci263_pci_probe(struct pci_dev *dev,
106                                   const struct pci_device_id *id)
107 {
108         return comedi_pci_auto_config(dev, &amplc_pci263_driver,
109                                       id->driver_data);
110 }
111
112 static struct pci_driver amplc_pci263_pci_driver = {
113         .name           = PCI263_DRIVER_NAME,
114         .id_table       = pci263_pci_table,
115         .probe          = &amplc_pci263_pci_probe,
116         .remove         = comedi_pci_auto_unconfig,
117 };
118 module_comedi_pci_driver(amplc_pci263_driver, amplc_pci263_pci_driver);
119
120 MODULE_AUTHOR("Comedi http://www.comedi.org");
121 MODULE_DESCRIPTION("Comedi driver for Amplicon PCI263 relay board");
122 MODULE_LICENSE("GPL");