]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/contec_pci_dio.c
Merge tag 'jfs-3.11' of git://github.com/kleikamp/linux-shaggy
[karo-tx-linux.git] / drivers / staging / comedi / drivers / contec_pci_dio.c
1 /*
2     comedi/drivers/contec_pci_dio.c
3
4     COMEDI - Linux Control and Measurement Device Interface
5     Copyright (C) 2000 David A. Schleef <ds@schleef.org>
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 */
17 /*
18 Driver: contec_pci_dio
19 Description: Contec PIO1616L digital I/O board
20 Devices: [Contec] PIO1616L (contec_pci_dio)
21 Author: Stefano Rivoir <s.rivoir@gts.it>
22 Updated: Wed, 27 Jun 2007 13:00:06 +0100
23 Status: works
24
25 Configuration Options: not applicable, uses comedi PCI auto config
26 */
27
28 #include <linux/pci.h>
29
30 #include "../comedidev.h"
31
32 #define PCI_DEVICE_ID_PIO1616L 0x8172
33
34 /*
35  * Register map
36  */
37 #define PIO1616L_DI_REG         0x00
38 #define PIO1616L_DO_REG         0x02
39
40 static int contec_do_insn_bits(struct comedi_device *dev,
41                                struct comedi_subdevice *s,
42                                struct comedi_insn *insn, unsigned int *data)
43 {
44         unsigned int mask = data[0];
45         unsigned int bits = data[1];
46
47         if (mask) {
48                 s->state &= ~mask;
49                 s->state |= (bits & mask);
50
51                 outw(s->state, dev->iobase + PIO1616L_DO_REG);
52         }
53
54         data[1] = s->state;
55
56         return insn->n;
57 }
58
59 static int contec_di_insn_bits(struct comedi_device *dev,
60                                struct comedi_subdevice *s,
61                                struct comedi_insn *insn, unsigned int *data)
62 {
63         data[1] = inw(dev->iobase + PIO1616L_DI_REG);
64
65         return insn->n;
66 }
67
68 static int contec_auto_attach(struct comedi_device *dev,
69                                         unsigned long context_unused)
70 {
71         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
72         struct comedi_subdevice *s;
73         int ret;
74
75         ret = comedi_pci_enable(dev);
76         if (ret)
77                 return ret;
78         dev->iobase = pci_resource_start(pcidev, 0);
79
80         ret = comedi_alloc_subdevices(dev, 2);
81         if (ret)
82                 return ret;
83
84         s = &dev->subdevices[0];
85         s->type         = COMEDI_SUBD_DI;
86         s->subdev_flags = SDF_READABLE;
87         s->n_chan       = 16;
88         s->maxdata      = 1;
89         s->range_table  = &range_digital;
90         s->insn_bits    = contec_di_insn_bits;
91
92         s = &dev->subdevices[1];
93         s->type         = COMEDI_SUBD_DO;
94         s->subdev_flags = SDF_WRITABLE;
95         s->n_chan       = 16;
96         s->maxdata      = 1;
97         s->range_table  = &range_digital;
98         s->insn_bits    = contec_do_insn_bits;
99
100         dev_info(dev->class_dev, "%s attached\n", dev->board_name);
101
102         return 0;
103 }
104
105 static struct comedi_driver contec_pci_dio_driver = {
106         .driver_name    = "contec_pci_dio",
107         .module         = THIS_MODULE,
108         .auto_attach    = contec_auto_attach,
109         .detach         = comedi_pci_disable,
110 };
111
112 static int contec_pci_dio_pci_probe(struct pci_dev *dev,
113                                     const struct pci_device_id *id)
114 {
115         return comedi_pci_auto_config(dev, &contec_pci_dio_driver,
116                                       id->driver_data);
117 }
118
119 static DEFINE_PCI_DEVICE_TABLE(contec_pci_dio_pci_table) = {
120         { PCI_DEVICE(PCI_VENDOR_ID_CONTEC, PCI_DEVICE_ID_PIO1616L) },
121         { 0 }
122 };
123 MODULE_DEVICE_TABLE(pci, contec_pci_dio_pci_table);
124
125 static struct pci_driver contec_pci_dio_pci_driver = {
126         .name           = "contec_pci_dio",
127         .id_table       = contec_pci_dio_pci_table,
128         .probe          = contec_pci_dio_pci_probe,
129         .remove         = comedi_pci_auto_unconfig,
130 };
131 module_comedi_pci_driver(contec_pci_dio_driver, contec_pci_dio_pci_driver);
132
133 MODULE_AUTHOR("Comedi http://www.comedi.org");
134 MODULE_DESCRIPTION("Comedi low-level driver");
135 MODULE_LICENSE("GPL");