Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / staging / comedi / drivers / ni_labpc.c
1 /*
2  * comedi/drivers/ni_labpc.c
3  * Driver for National Instruments Lab-PC series boards and compatibles
4  * Copyright (C) 2001-2003 Frank Mori Hess <fmhess@users.sourceforge.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  */
16
17 /*
18  * Driver: ni_labpc
19  * Description: National Instruments Lab-PC (& compatibles)
20  * Devices: [National Instruments] Lab-PC-1200 (lab-pc-1200),
21  *   Lab-PC-1200AI (lab-pc-1200ai), Lab-PC+ (lab-pc+)
22  * Author: Frank Mori Hess <fmhess@users.sourceforge.net>
23  * Status: works
24  *
25  * Configuration options - ISA boards:
26  *   [0] - I/O port base address
27  *   [1] - IRQ (optional, required for timed or externally triggered
28  *              conversions)
29  *   [2] - DMA channel (optional)
30  *
31  * Tested with lab-pc-1200.  For the older Lab-PC+, not all input
32  * ranges and analog references will work, the available ranges/arefs
33  * will depend on how you have configured the jumpers on your board
34  * (see your owner's manual).
35  *
36  * Kernel-level ISA plug-and-play support for the lab-pc-1200 boards
37  * has not yet been added to the driver, mainly due to the fact that
38  * I don't know the device id numbers. If you have one of these boards,
39  * please file a bug report at http://comedi.org/ so I can get the
40  * necessary information from you.
41  *
42  * The 1200 series boards have onboard calibration dacs for correcting
43  * analog input/output offsets and gains. The proper settings for these
44  * caldacs are stored on the board's eeprom. To read the caldac values
45  * from the eeprom and store them into a file that can be then be used
46  * by comedilib, use the comedi_calibrate program.
47  *
48  * The Lab-pc+ has quirky chanlist requirements when scanning multiple
49  * channels. Multiple channel scan sequence must start at highest channel,
50  * then decrement down to channel 0. The rest of the cards can scan down
51  * like lab-pc+ or scan up from channel zero. Chanlists consisting of all
52  * one channel are also legal, and allow you to pace conversions in bursts.
53  *
54  * NI manuals:
55  * 341309a (labpc-1200 register manual)
56  * 320502b (lab-pc+)
57  */
58
59 #include <linux/module.h>
60
61 #include "../comedidev.h"
62
63 #include "ni_labpc.h"
64 #include "ni_labpc_isadma.h"
65
66 static const struct labpc_boardinfo labpc_boards[] = {
67         {
68                 .name                   = "lab-pc-1200",
69                 .ai_speed               = 10000,
70                 .ai_scan_up             = 1,
71                 .has_ao                 = 1,
72                 .is_labpc1200           = 1,
73         }, {
74                 .name                   = "lab-pc-1200ai",
75                 .ai_speed               = 10000,
76                 .ai_scan_up             = 1,
77                 .is_labpc1200           = 1,
78         }, {
79                 .name                   = "lab-pc+",
80                 .ai_speed               = 12000,
81                 .has_ao                 = 1,
82         },
83 };
84
85 static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
86 {
87         unsigned int irq = it->options[1];
88         unsigned int dma_chan = it->options[2];
89         int ret;
90
91         ret = comedi_request_region(dev, it->options[0], 0x20);
92         if (ret)
93                 return ret;
94
95         ret = labpc_common_attach(dev, irq, 0);
96         if (ret)
97                 return ret;
98
99         if (dev->irq)
100                 labpc_init_dma_chan(dev, dma_chan);
101
102         return 0;
103 }
104
105 static void labpc_detach(struct comedi_device *dev)
106 {
107         labpc_free_dma_chan(dev);
108         labpc_common_detach(dev);
109         comedi_legacy_detach(dev);
110 }
111
112 static struct comedi_driver labpc_driver = {
113         .driver_name    = "ni_labpc",
114         .module         = THIS_MODULE,
115         .attach         = labpc_attach,
116         .detach         = labpc_detach,
117         .num_names      = ARRAY_SIZE(labpc_boards),
118         .board_name     = &labpc_boards[0].name,
119         .offset         = sizeof(struct labpc_boardinfo),
120 };
121 module_comedi_driver(labpc_driver);
122
123 MODULE_AUTHOR("Comedi http://www.comedi.org");
124 MODULE_DESCRIPTION("Comedi driver for NI Lab-PC ISA boards");
125 MODULE_LICENSE("GPL");