]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/pcl724.c
Merge branch 'irq-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[karo-tx-linux.git] / drivers / staging / comedi / drivers / pcl724.c
1 /*
2     comedi/drivers/pcl724.c
3
4     Michal Dobes <dobes@tesnet.cz>
5
6     hardware driver for Advantech cards:
7      card:   PCL-724, PCL-722, PCL-731
8      driver: pcl724,  pcl722,  pcl731
9     and ADLink cards:
10      card:   ACL-7122, ACL-7124, PET-48DIO
11      driver: acl7122,  acl7124,  pet48dio
12
13     Options for PCL-724, PCL-731, ACL-7124 and PET-48DIO:
14      [0] - IO Base
15
16     Options for PCL-722 and ACL-7122:
17      [0] - IO Base
18      [1] - IRQ (0=disable IRQ) IRQ isn't supported at this time!
19      [2] -number of DIO:
20               0, 144: 144 DIO configuration
21               1,  96:  96 DIO configuration
22 */
23 /*
24 Driver: pcl724
25 Description: Advantech PCL-724, PCL-722, PCL-731 ADLink ACL-7122, ACL-7124,
26   PET-48DIO
27 Author: Michal Dobes <dobes@tesnet.cz>
28 Devices: [Advantech] PCL-724 (pcl724), PCL-722 (pcl722), PCL-731 (pcl731),
29   [ADLink] ACL-7122 (acl7122), ACL-7124 (acl7124), PET-48DIO (pet48dio)
30 Status: untested
31
32 This is driver for digital I/O boards PCL-722/724/731 with 144/24/48 DIO
33 and for digital I/O boards ACL-7122/7124/PET-48DIO with 144/24/48 DIO.
34 It need 8255.o for operations and only immediate mode is supported.
35 See the source for configuration details.
36 */
37 /*
38  * check_driver overrides:
39  *   struct comedi_insn
40  */
41
42 #include "../comedidev.h"
43
44 #include <linux/ioport.h>
45 #include <linux/delay.h>
46
47 #include "8255.h"
48
49 #define PCL722_SIZE    32
50 #define PCL722_96_SIZE 16
51 #define PCL724_SIZE     4
52 #define PCL731_SIZE     8
53 #define PET48_SIZE      2
54
55 #define SIZE_8255       4
56
57 /* #define PCL724_IRQ   1  no IRQ support now */
58
59 struct pcl724_board {
60
61         const char *name;       /*  board name */
62         int dio;                /*  num of DIO */
63         int numofports;         /*  num of 8255 subdevices */
64         unsigned int IRQbits;   /*  allowed interrupts */
65         unsigned int io_range;  /*  len of IO space */
66         char can_have96;
67         char is_pet48;
68 };
69
70 static int subdev_8255_cb(int dir, int port, int data, unsigned long arg)
71 {
72         unsigned long iobase = arg;
73
74         if (dir) {
75                 outb(data, iobase + port);
76                 return 0;
77         } else {
78                 return inb(iobase + port);
79         }
80 }
81
82 static int subdev_8255mapped_cb(int dir, int port, int data,
83                                 unsigned long iobase)
84 {
85         int movport = SIZE_8255 * (iobase >> 12);
86
87         iobase &= 0x0fff;
88
89         if (dir) {
90                 outb(port + movport, iobase);
91                 outb(data, iobase + 1);
92                 return 0;
93         } else {
94                 outb(port + movport, iobase);
95                 return inb(iobase + 1);
96         }
97 }
98
99 static int pcl724_attach(struct comedi_device *dev, struct comedi_devconfig *it)
100 {
101         const struct pcl724_board *board = comedi_board(dev);
102         unsigned long iobase;
103         unsigned int iorange;
104         int ret, i, n_subdevices;
105 #ifdef PCL724_IRQ
106         unsigned int irq;
107 #endif
108
109         iobase = it->options[0];
110         iorange = board->io_range;
111         if ((board->can_have96) && ((it->options[1] == 1)
112                                          || (it->options[1] == 96)))
113                 iorange = PCL722_96_SIZE; /* PCL-724 in 96 DIO configuration */
114         printk(KERN_INFO "comedi%d: pcl724: board=%s, 0x%03lx ", dev->minor,
115                board->name, iobase);
116         if (!request_region(iobase, iorange, "pcl724")) {
117                 printk("I/O port conflict\n");
118                 return -EIO;
119         }
120
121         dev->iobase = iobase;
122
123         dev->board_name = board->name;
124
125 #ifdef PCL724_IRQ
126         irq = 0;
127         if (board->IRQbits != 0) {      /* board support IRQ */
128                 irq = it->options[1];
129                 if (irq) {      /* we want to use IRQ */
130                         if (((1 << irq) & board->IRQbits) == 0) {
131                                 printk(KERN_WARNING
132                                        ", IRQ %u is out of allowed range, "
133                                        "DISABLING IT", irq);
134                                 irq = 0;        /* Bad IRQ */
135                         } else {
136                                 if (request_irq
137                                     (irq, interrupt_pcl724, 0, "pcl724", dev)) {
138                                         printk(KERN_WARNING
139                                                ", unable to allocate IRQ %u, "
140                                                "DISABLING IT", irq);
141                                         irq = 0;        /* Can't use IRQ */
142                                 } else {
143                                         printk(", irq=%u", irq);
144                                 }
145                         }
146                 }
147         }
148
149         dev->irq = irq;
150 #endif
151
152         printk("\n");
153
154         n_subdevices = board->numofports;
155         if ((board->can_have96) && ((it->options[1] == 1)
156                                          || (it->options[1] == 96)))
157                 n_subdevices = 4;       /*  PCL-724 in 96 DIO configuration */
158
159         ret = comedi_alloc_subdevices(dev, n_subdevices);
160         if (ret)
161                 return ret;
162
163         for (i = 0; i < dev->n_subdevices; i++) {
164                 if (board->is_pet48) {
165                         subdev_8255_init(dev, dev->subdevices + i,
166                                          subdev_8255mapped_cb,
167                                          (unsigned long)(dev->iobase +
168                                                          i * 0x1000));
169                 } else
170                         subdev_8255_init(dev, dev->subdevices + i,
171                                          subdev_8255_cb,
172                                          (unsigned long)(dev->iobase +
173                                                          SIZE_8255 * i));
174         }
175
176         return 0;
177 }
178
179 static void pcl724_detach(struct comedi_device *dev)
180 {
181         const struct pcl724_board *board = comedi_board(dev);
182         int i;
183
184         for (i = 0; i < dev->n_subdevices; i++)
185                 subdev_8255_cleanup(dev, dev->subdevices + i);
186 #ifdef PCL724_IRQ
187         if (dev->irq)
188                 free_irq(dev->irq, dev);
189 #endif
190         release_region(dev->iobase, board->io_range);
191 }
192
193 static const struct pcl724_board boardtypes[] = {
194         { "pcl724", 24, 1, 0x00fc, PCL724_SIZE, 0, 0, },
195         { "pcl722", 144, 6, 0x00fc, PCL722_SIZE, 1, 0, },
196         { "pcl731", 48, 2, 0x9cfc, PCL731_SIZE, 0, 0, },
197         { "acl7122", 144, 6, 0x9ee8, PCL722_SIZE, 1, 0, },
198         { "acl7124", 24, 1, 0x00fc, PCL724_SIZE, 0, 0, },
199         { "pet48dio", 48, 2, 0x9eb8, PET48_SIZE, 0, 1, },
200 };
201
202 static struct comedi_driver pcl724_driver = {
203         .driver_name    = "pcl724",
204         .module         = THIS_MODULE,
205         .attach         = pcl724_attach,
206         .detach         = pcl724_detach,
207         .board_name     = &boardtypes[0].name,
208         .num_names      = ARRAY_SIZE(boardtypes),
209         .offset         = sizeof(struct pcl724_board),
210 };
211 module_comedi_driver(pcl724_driver);
212
213 MODULE_AUTHOR("Comedi http://www.comedi.org");
214 MODULE_DESCRIPTION("Comedi low-level driver");
215 MODULE_LICENSE("GPL");