Merge branch 'kconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
[linux-2.6-block.git] / drivers / staging / comedi / drivers / pcmuio.c
1 /*
2  * pcmuio.c
3  * Comedi driver for Winsystems PC-104 based 48/96-channel DIO boards.
4  *
5  * COMEDI - Linux Control and Measurement Device Interface
6  * Copyright (C) 2006 Calin A. Culianu <calin@ajvar.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  */
18
19 /*
20  * Driver: pcmuio
21  * Description: Winsystems PC-104 based 48/96-channel DIO boards.
22  * Devices: [Winsystems] PCM-UIO48A (pcmuio48), PCM-UIO96A (pcmuio96)
23  * Author: Calin Culianu <calin@ajvar.org>
24  * Updated: Fri, 13 Jan 2006 12:01:01 -0500
25  * Status: works
26  *
27  * A driver for the relatively straightforward-to-program PCM-UIO48A and
28  * PCM-UIO96A boards from Winsystems. These boards use either one or two
29  * (in the 96-DIO version) WS16C48 ASIC HighDensity I/O Chips (HDIO). This
30  * chip is interesting in that each I/O line is individually programmable
31  * for INPUT or OUTPUT (thus comedi_dio_config can be done on a per-channel
32  * basis). Also, each chip supports edge-triggered interrupts for the first
33  * 24 I/O lines. Of course, since the 96-channel version of the board has
34  * two ASICs, it can detect polarity changes on up to 48 I/O lines. Since
35  * this is essentially an (non-PnP) ISA board, I/O Address and IRQ selection
36  * are done through jumpers on the board. You need to pass that information
37  * to this driver as the first and second comedi_config option, respectively.
38  * Note that the 48-channel version uses 16 bytes of IO memory and the 96-
39  * channel version uses 32-bytes (in case you are worried about conflicts).
40  * The 48-channel board is split into two 24-channel comedi subdevices. The
41  * 96-channel board is split into 4 24-channel DIO subdevices.
42  *
43  * Note that IRQ support has been added, but it is untested.
44  *
45  * To use edge-detection IRQ support, pass the IRQs of both ASICS (for the
46  * 96 channel version) or just 1 ASIC (for 48-channel version). Then, use
47  * comedi_commands with TRIG_NOW. Your callback will be called each time an
48  * edge is triggered, and the data values will be two sample_t's, which
49  * should be concatenated to form one 32-bit unsigned int.  This value is
50  * the mask of channels that had edges detected from your channel list. Note
51  * that the bits positions in the mask correspond to positions in your
52  * chanlist when you specified the command and *not* channel id's!
53  *
54  * To set the polarity of the edge-detection interrupts pass a nonzero value
55  * for either CR_RANGE or CR_AREF for edge-up polarity, or a zero value for
56  * both CR_RANGE and CR_AREF if you want edge-down polarity.
57  *
58  * In the 48-channel version:
59  *
60  * On subdev 0, the first 24 channels channels are edge-detect channels.
61  *
62  * In the 96-channel board you have the following channels that can do edge
63  * detection:
64  *
65  * subdev 0, channels 0-24  (first 24 channels of 1st ASIC)
66  * subdev 2, channels 0-24  (first 24 channels of 2nd ASIC)
67  *
68  * Configuration Options:
69  *  [0] - I/O port base address
70  *  [1] - IRQ (for first ASIC, or first 24 channels)
71  *  [2] - IRQ (for second ASIC, pcmuio96 only - IRQ for chans 48-72
72  *             can be the same as first irq!)
73  */
74
75 #include <linux/module.h>
76 #include <linux/interrupt.h>
77
78 #include "../comedidev.h"
79
80 #include "comedi_fc.h"
81
82 /*
83  * Register I/O map
84  *
85  * Offset    Page 0       Page 1       Page 2       Page 3
86  * ------  -----------  -----------  -----------  -----------
87  *  0x00   Port 0 I/O   Port 0 I/O   Port 0 I/O   Port 0 I/O
88  *  0x01   Port 1 I/O   Port 1 I/O   Port 1 I/O   Port 1 I/O
89  *  0x02   Port 2 I/O   Port 2 I/O   Port 2 I/O   Port 2 I/O
90  *  0x03   Port 3 I/O   Port 3 I/O   Port 3 I/O   Port 3 I/O
91  *  0x04   Port 4 I/O   Port 4 I/O   Port 4 I/O   Port 4 I/O
92  *  0x05   Port 5 I/O   Port 5 I/O   Port 5 I/O   Port 5 I/O
93  *  0x06   INT_PENDING  INT_PENDING  INT_PENDING  INT_PENDING
94  *  0x07    Page/Lock    Page/Lock    Page/Lock    Page/Lock
95  *  0x08       N/A         POL_0       ENAB_0       INT_ID0
96  *  0x09       N/A         POL_1       ENAB_1       INT_ID1
97  *  0x0a       N/A         POL_2       ENAB_2       INT_ID2
98  */
99 #define PCMUIO_PORT_REG(x)              (0x00 + (x))
100 #define PCMUIO_INT_PENDING_REG          0x06
101 #define PCMUIO_PAGE_LOCK_REG            0x07
102 #define PCMUIO_LOCK_PORT(x)             ((1 << (x)) & 0x3f)
103 #define PCMUIO_PAGE(x)                  (((x) & 0x3) << 6)
104 #define PCMUIO_PAGE_MASK                PCMUIO_PAGE(3)
105 #define PCMUIO_PAGE_POL                 1
106 #define PCMUIO_PAGE_ENAB                2
107 #define PCMUIO_PAGE_INT_ID              3
108 #define PCMUIO_PAGE_REG(x)              (0x08 + (x))
109
110 #define PCMUIO_ASIC_IOSIZE              0x10
111 #define PCMUIO_MAX_ASICS                2
112
113 struct pcmuio_board {
114         const char *name;
115         const int num_asics;
116 };
117
118 static const struct pcmuio_board pcmuio_boards[] = {
119         {
120                 .name           = "pcmuio48",
121                 .num_asics      = 1,
122         }, {
123                 .name           = "pcmuio96",
124                 .num_asics      = 2,
125         },
126 };
127
128 struct pcmuio_asic {
129         spinlock_t pagelock;    /* protects the page registers */
130         spinlock_t spinlock;    /* protects member variables */
131         unsigned int enabled_mask;
132         unsigned int active:1;
133 };
134
135 struct pcmuio_private {
136         struct pcmuio_asic asics[PCMUIO_MAX_ASICS];
137         unsigned int irq2;
138 };
139
140 static inline unsigned long pcmuio_asic_iobase(struct comedi_device *dev,
141                                                int asic)
142 {
143         return dev->iobase + (asic * PCMUIO_ASIC_IOSIZE);
144 }
145
146 static inline int pcmuio_subdevice_to_asic(struct comedi_subdevice *s)
147 {
148         /*
149          * subdevice 0 and 1 are handled by the first asic
150          * subdevice 2 and 3 are handled by the second asic
151          */
152         return s->index / 2;
153 }
154
155 static inline int pcmuio_subdevice_to_port(struct comedi_subdevice *s)
156 {
157         /*
158          * subdevice 0 and 2 use port registers 0-2
159          * subdevice 1 and 3 use port registers 3-5
160          */
161         return (s->index % 2) ? 3 : 0;
162 }
163
164 static void pcmuio_write(struct comedi_device *dev, unsigned int val,
165                          int asic, int page, int port)
166 {
167         struct pcmuio_private *devpriv = dev->private;
168         struct pcmuio_asic *chip = &devpriv->asics[asic];
169         unsigned long iobase = pcmuio_asic_iobase(dev, asic);
170         unsigned long flags;
171
172         spin_lock_irqsave(&chip->pagelock, flags);
173         if (page == 0) {
174                 /* Port registers are valid for any page */
175                 outb(val & 0xff, iobase + PCMUIO_PORT_REG(port + 0));
176                 outb((val >> 8) & 0xff, iobase + PCMUIO_PORT_REG(port + 1));
177                 outb((val >> 16) & 0xff, iobase + PCMUIO_PORT_REG(port + 2));
178         } else {
179                 outb(PCMUIO_PAGE(page), iobase + PCMUIO_PAGE_LOCK_REG);
180                 outb(val & 0xff, iobase + PCMUIO_PAGE_REG(0));
181                 outb((val >> 8) & 0xff, iobase + PCMUIO_PAGE_REG(1));
182                 outb((val >> 16) & 0xff, iobase + PCMUIO_PAGE_REG(2));
183         }
184         spin_unlock_irqrestore(&chip->pagelock, flags);
185 }
186
187 static unsigned int pcmuio_read(struct comedi_device *dev,
188                                 int asic, int page, int port)
189 {
190         struct pcmuio_private *devpriv = dev->private;
191         struct pcmuio_asic *chip = &devpriv->asics[asic];
192         unsigned long iobase = pcmuio_asic_iobase(dev, asic);
193         unsigned long flags;
194         unsigned int val;
195
196         spin_lock_irqsave(&chip->pagelock, flags);
197         if (page == 0) {
198                 /* Port registers are valid for any page */
199                 val = inb(iobase + PCMUIO_PORT_REG(port + 0));
200                 val |= (inb(iobase + PCMUIO_PORT_REG(port + 1)) << 8);
201                 val |= (inb(iobase + PCMUIO_PORT_REG(port + 2)) << 16);
202         } else {
203                 outb(PCMUIO_PAGE(page), iobase + PCMUIO_PAGE_LOCK_REG);
204                 val = inb(iobase + PCMUIO_PAGE_REG(0));
205                 val |= (inb(iobase + PCMUIO_PAGE_REG(1)) << 8);
206                 val |= (inb(iobase + PCMUIO_PAGE_REG(2)) << 16);
207         }
208         spin_unlock_irqrestore(&chip->pagelock, flags);
209
210         return val;
211 }
212
213 /*
214  * Each channel can be individually programmed for input or output.
215  * Writing a '0' to a channel causes the corresponding output pin
216  * to go to a high-z state (pulled high by an external 10K resistor).
217  * This allows it to be used as an input. When used in the input mode,
218  * a read reflects the inverted state of the I/O pin, such that a
219  * high on the pin will read as a '0' in the register. Writing a '1'
220  * to a bit position causes the pin to sink current (up to 12mA),
221  * effectively pulling it low.
222  */
223 static int pcmuio_dio_insn_bits(struct comedi_device *dev,
224                                 struct comedi_subdevice *s,
225                                 struct comedi_insn *insn,
226                                 unsigned int *data)
227 {
228         int asic = pcmuio_subdevice_to_asic(s);
229         int port = pcmuio_subdevice_to_port(s);
230         unsigned int chanmask = (1 << s->n_chan) - 1;
231         unsigned int mask;
232         unsigned int val;
233
234         mask = comedi_dio_update_state(s, data);
235         if (mask) {
236                 /*
237                  * Outputs are inverted, invert the state and
238                  * update the channels.
239                  *
240                  * The s->io_bits mask makes sure the input channels
241                  * are '0' so that the outputs pins stay in a high
242                  * z-state.
243                  */
244                 val = ~s->state & chanmask;
245                 val &= s->io_bits;
246                 pcmuio_write(dev, val, asic, 0, port);
247         }
248
249         /* get inverted state of the channels from the port */
250         val = pcmuio_read(dev, asic, 0, port);
251
252         /* return the true state of the channels */
253         data[1] = ~val & chanmask;
254
255         return insn->n;
256 }
257
258 static int pcmuio_dio_insn_config(struct comedi_device *dev,
259                                   struct comedi_subdevice *s,
260                                   struct comedi_insn *insn,
261                                   unsigned int *data)
262 {
263         int asic = pcmuio_subdevice_to_asic(s);
264         int port = pcmuio_subdevice_to_port(s);
265         int ret;
266
267         ret = comedi_dio_insn_config(dev, s, insn, data, 0);
268         if (ret)
269                 return ret;
270
271         if (data[0] == INSN_CONFIG_DIO_INPUT)
272                 pcmuio_write(dev, s->io_bits, asic, 0, port);
273
274         return insn->n;
275 }
276
277 static void pcmuio_reset(struct comedi_device *dev)
278 {
279         const struct pcmuio_board *board = dev->board_ptr;
280         int asic;
281
282         for (asic = 0; asic < board->num_asics; ++asic) {
283                 /* first, clear all the DIO port bits */
284                 pcmuio_write(dev, 0, asic, 0, 0);
285                 pcmuio_write(dev, 0, asic, 0, 3);
286
287                 /* Next, clear all the paged registers for each page */
288                 pcmuio_write(dev, 0, asic, PCMUIO_PAGE_POL, 0);
289                 pcmuio_write(dev, 0, asic, PCMUIO_PAGE_ENAB, 0);
290                 pcmuio_write(dev, 0, asic, PCMUIO_PAGE_INT_ID, 0);
291         }
292 }
293
294 /* chip->spinlock is already locked */
295 static void pcmuio_stop_intr(struct comedi_device *dev,
296                              struct comedi_subdevice *s)
297 {
298         struct pcmuio_private *devpriv = dev->private;
299         int asic = pcmuio_subdevice_to_asic(s);
300         struct pcmuio_asic *chip = &devpriv->asics[asic];
301
302         chip->enabled_mask = 0;
303         chip->active = 0;
304         s->async->inttrig = NULL;
305
306         /* disable all intrs for this subdev.. */
307         pcmuio_write(dev, 0, asic, PCMUIO_PAGE_ENAB, 0);
308 }
309
310 static void pcmuio_handle_intr_subdev(struct comedi_device *dev,
311                                       struct comedi_subdevice *s,
312                                       unsigned triggered)
313 {
314         struct pcmuio_private *devpriv = dev->private;
315         int asic = pcmuio_subdevice_to_asic(s);
316         struct pcmuio_asic *chip = &devpriv->asics[asic];
317         struct comedi_cmd *cmd = &s->async->cmd;
318         unsigned int val = 0;
319         unsigned long flags;
320         unsigned int i;
321
322         spin_lock_irqsave(&chip->spinlock, flags);
323
324         if (!chip->active)
325                 goto done;
326
327         if (!(triggered & chip->enabled_mask))
328                 goto done;
329
330         for (i = 0; i < cmd->chanlist_len; i++) {
331                 unsigned int chan = CR_CHAN(cmd->chanlist[i]);
332
333                 if (triggered & (1 << chan))
334                         val |= (1 << i);
335         }
336
337         comedi_buf_write_samples(s, &val, 1);
338
339         if (cmd->stop_src == TRIG_COUNT &&
340             s->async->scans_done >= cmd->stop_arg)
341                 s->async->events |= COMEDI_CB_EOA;
342
343 done:
344         spin_unlock_irqrestore(&chip->spinlock, flags);
345
346         comedi_handle_events(dev, s);
347 }
348
349 static int pcmuio_handle_asic_interrupt(struct comedi_device *dev, int asic)
350 {
351         /* there are could be two asics so we can't use dev->read_subdev */
352         struct comedi_subdevice *s = &dev->subdevices[asic * 2];
353         unsigned long iobase = pcmuio_asic_iobase(dev, asic);
354         unsigned int val;
355
356         /* are there any interrupts pending */
357         val = inb(iobase + PCMUIO_INT_PENDING_REG) & 0x07;
358         if (!val)
359                 return 0;
360
361         /* get, and clear, the pending interrupts */
362         val = pcmuio_read(dev, asic, PCMUIO_PAGE_INT_ID, 0);
363         pcmuio_write(dev, 0, asic, PCMUIO_PAGE_INT_ID, 0);
364
365         /* handle the pending interrupts */
366         pcmuio_handle_intr_subdev(dev, s, val);
367
368         return 1;
369 }
370
371 static irqreturn_t pcmuio_interrupt(int irq, void *d)
372 {
373         struct comedi_device *dev = d;
374         struct pcmuio_private *devpriv = dev->private;
375         int handled = 0;
376
377         if (irq == dev->irq)
378                 handled += pcmuio_handle_asic_interrupt(dev, 0);
379         if (irq == devpriv->irq2)
380                 handled += pcmuio_handle_asic_interrupt(dev, 1);
381
382         return handled ? IRQ_HANDLED : IRQ_NONE;
383 }
384
385 /* chip->spinlock is already locked */
386 static void pcmuio_start_intr(struct comedi_device *dev,
387                               struct comedi_subdevice *s)
388 {
389         struct pcmuio_private *devpriv = dev->private;
390         int asic = pcmuio_subdevice_to_asic(s);
391         struct pcmuio_asic *chip = &devpriv->asics[asic];
392         struct comedi_cmd *cmd = &s->async->cmd;
393         unsigned int bits = 0;
394         unsigned int pol_bits = 0;
395         int i;
396
397         chip->enabled_mask = 0;
398         chip->active = 1;
399         if (cmd->chanlist) {
400                 for (i = 0; i < cmd->chanlist_len; i++) {
401                         unsigned int chanspec = cmd->chanlist[i];
402                         unsigned int chan = CR_CHAN(chanspec);
403                         unsigned int range = CR_RANGE(chanspec);
404                         unsigned int aref = CR_AREF(chanspec);
405
406                         bits |= (1 << chan);
407                         pol_bits |= ((aref || range) ? 1 : 0) << chan;
408                 }
409         }
410         bits &= ((1 << s->n_chan) - 1);
411         chip->enabled_mask = bits;
412
413         /* set pol and enab intrs for this subdev.. */
414         pcmuio_write(dev, pol_bits, asic, PCMUIO_PAGE_POL, 0);
415         pcmuio_write(dev, bits, asic, PCMUIO_PAGE_ENAB, 0);
416 }
417
418 static int pcmuio_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
419 {
420         struct pcmuio_private *devpriv = dev->private;
421         int asic = pcmuio_subdevice_to_asic(s);
422         struct pcmuio_asic *chip = &devpriv->asics[asic];
423         unsigned long flags;
424
425         spin_lock_irqsave(&chip->spinlock, flags);
426         if (chip->active)
427                 pcmuio_stop_intr(dev, s);
428         spin_unlock_irqrestore(&chip->spinlock, flags);
429
430         return 0;
431 }
432
433 static int pcmuio_inttrig_start_intr(struct comedi_device *dev,
434                                      struct comedi_subdevice *s,
435                                      unsigned int trig_num)
436 {
437         struct pcmuio_private *devpriv = dev->private;
438         struct comedi_cmd *cmd = &s->async->cmd;
439         int asic = pcmuio_subdevice_to_asic(s);
440         struct pcmuio_asic *chip = &devpriv->asics[asic];
441         unsigned long flags;
442
443         if (trig_num != cmd->start_arg)
444                 return -EINVAL;
445
446         spin_lock_irqsave(&chip->spinlock, flags);
447         s->async->inttrig = NULL;
448         if (chip->active)
449                 pcmuio_start_intr(dev, s);
450
451         spin_unlock_irqrestore(&chip->spinlock, flags);
452
453         return 1;
454 }
455
456 /*
457  * 'do_cmd' function for an 'INTERRUPT' subdevice.
458  */
459 static int pcmuio_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
460 {
461         struct pcmuio_private *devpriv = dev->private;
462         struct comedi_cmd *cmd = &s->async->cmd;
463         int asic = pcmuio_subdevice_to_asic(s);
464         struct pcmuio_asic *chip = &devpriv->asics[asic];
465         unsigned long flags;
466
467         spin_lock_irqsave(&chip->spinlock, flags);
468         chip->active = 1;
469
470         /* Set up start of acquisition. */
471         if (cmd->start_src == TRIG_INT)
472                 s->async->inttrig = pcmuio_inttrig_start_intr;
473         else    /* TRIG_NOW */
474                 pcmuio_start_intr(dev, s);
475
476         spin_unlock_irqrestore(&chip->spinlock, flags);
477
478         return 0;
479 }
480
481 static int pcmuio_cmdtest(struct comedi_device *dev,
482                           struct comedi_subdevice *s,
483                           struct comedi_cmd *cmd)
484 {
485         int err = 0;
486
487         /* Step 1 : check if triggers are trivially valid */
488
489         err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
490         err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
491         err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
492         err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
493         err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
494
495         if (err)
496                 return 1;
497
498         /* Step 2a : make sure trigger sources are unique */
499
500         err |= cfc_check_trigger_is_unique(cmd->start_src);
501         err |= cfc_check_trigger_is_unique(cmd->stop_src);
502
503         /* Step 2b : and mutually compatible */
504
505         if (err)
506                 return 2;
507
508         /* Step 3: check if arguments are trivially valid */
509
510         err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
511         err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
512         err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0);
513         err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
514
515         if (cmd->stop_src == TRIG_COUNT)
516                 err |= cfc_check_trigger_arg_min(&cmd->stop_arg, 1);
517         else    /* TRIG_NONE */
518                 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
519
520         if (err)
521                 return 3;
522
523         /* step 4: fix up any arguments */
524
525         /* if (err) return 4; */
526
527         return 0;
528 }
529
530 static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
531 {
532         const struct pcmuio_board *board = dev->board_ptr;
533         struct comedi_subdevice *s;
534         struct pcmuio_private *devpriv;
535         int ret;
536         int i;
537
538         ret = comedi_request_region(dev, it->options[0],
539                                     board->num_asics * PCMUIO_ASIC_IOSIZE);
540         if (ret)
541                 return ret;
542
543         devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
544         if (!devpriv)
545                 return -ENOMEM;
546
547         for (i = 0; i < PCMUIO_MAX_ASICS; ++i) {
548                 struct pcmuio_asic *chip = &devpriv->asics[i];
549
550                 spin_lock_init(&chip->pagelock);
551                 spin_lock_init(&chip->spinlock);
552         }
553
554         pcmuio_reset(dev);
555
556         if (it->options[1]) {
557                 /* request the irq for the 1st asic */
558                 ret = request_irq(it->options[1], pcmuio_interrupt, 0,
559                                   dev->board_name, dev);
560                 if (ret == 0)
561                         dev->irq = it->options[1];
562         }
563
564         if (board->num_asics == 2) {
565                 if (it->options[2] == dev->irq) {
566                         /* the same irq (or none) is used by both asics */
567                         devpriv->irq2 = it->options[2];
568                 } else if (it->options[2]) {
569                         /* request the irq for the 2nd asic */
570                         ret = request_irq(it->options[2], pcmuio_interrupt, 0,
571                                         dev->board_name, dev);
572                         if (ret == 0)
573                                 devpriv->irq2 = it->options[2];
574                 }
575         }
576
577         ret = comedi_alloc_subdevices(dev, board->num_asics * 2);
578         if (ret)
579                 return ret;
580
581         for (i = 0; i < dev->n_subdevices; ++i) {
582                 s = &dev->subdevices[i];
583                 s->type         = COMEDI_SUBD_DIO;
584                 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
585                 s->n_chan       = 24;
586                 s->maxdata      = 1;
587                 s->range_table  = &range_digital;
588                 s->insn_bits    = pcmuio_dio_insn_bits;
589                 s->insn_config  = pcmuio_dio_insn_config;
590
591                 /* subdevices 0 and 2 can suppport interrupts */
592                 if ((i == 0 && dev->irq) || (i == 2 && devpriv->irq2)) {
593                         /* setup the interrupt subdevice */
594                         dev->read_subdev = s;
595                         s->subdev_flags |= SDF_CMD_READ | SDF_LSAMPL |
596                                            SDF_PACKED;
597                         s->len_chanlist = s->n_chan;
598                         s->cancel       = pcmuio_cancel;
599                         s->do_cmd       = pcmuio_cmd;
600                         s->do_cmdtest   = pcmuio_cmdtest;
601                 }
602         }
603
604         return 0;
605 }
606
607 static void pcmuio_detach(struct comedi_device *dev)
608 {
609         struct pcmuio_private *devpriv = dev->private;
610
611         if (devpriv) {
612                 pcmuio_reset(dev);
613
614                 /* free the 2nd irq if used, the core will free the 1st one */
615                 if (devpriv->irq2 && devpriv->irq2 != dev->irq)
616                         free_irq(devpriv->irq2, dev);
617         }
618         comedi_legacy_detach(dev);
619 }
620
621 static struct comedi_driver pcmuio_driver = {
622         .driver_name    = "pcmuio",
623         .module         = THIS_MODULE,
624         .attach         = pcmuio_attach,
625         .detach         = pcmuio_detach,
626         .board_name     = &pcmuio_boards[0].name,
627         .offset         = sizeof(struct pcmuio_board),
628         .num_names      = ARRAY_SIZE(pcmuio_boards),
629 };
630 module_comedi_driver(pcmuio_driver);
631
632 MODULE_AUTHOR("Comedi http://www.comedi.org");
633 MODULE_DESCRIPTION("Comedi low-level driver");
634 MODULE_LICENSE("GPL");