GNU Linux-libre 4.14.262-gnu1
[releases.git] / drivers / staging / comedi / drivers / ni_labpc_cs.c
1 /*
2  * Driver for National Instruments daqcard-1200 boards
3  * Copyright (C) 2001, 2002, 2003 Frank Mori Hess <fmhess@users.sourceforge.net>
4  *
5  * PCMCIA crap is adapted from dummy_cs.c 1.31 2001/08/24 12:13:13
6  * from the pcmcia package.
7  * The initial developer of the pcmcia dummy_cs.c code is David A. Hinds
8  * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
9  * are Copyright (C) 1999 David A. Hinds.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * General Public License for more details.
20  */
21
22 /*
23  * Driver: ni_labpc_cs
24  * Description: National Instruments Lab-PC (& compatibles)
25  * Author: Frank Mori Hess <fmhess@users.sourceforge.net>
26  * Devices: [National Instruments] DAQCard-1200 (daqcard-1200)
27  * Status: works
28  *
29  * Thanks go to Fredrik Lingvall for much testing and perseverance in
30  * helping to debug daqcard-1200 support.
31  *
32  * The 1200 series boards have onboard calibration dacs for correcting
33  * analog input/output offsets and gains. The proper settings for these
34  * caldacs are stored on the board's eeprom. To read the caldac values
35  * from the eeprom and store them into a file that can be then be used by
36  * comedilib, use the comedi_calibrate program.
37  *
38  * Configuration options: none
39  *
40  * The daqcard-1200 has quirky chanlist requirements when scanning multiple
41  * channels. Multiple channel scan sequence must start at highest channel,
42  * then decrement down to channel 0.  Chanlists consisting of all one channel
43  * are also legal, and allow you to pace conversions in bursts.
44  *
45  * NI manuals:
46  *   340988a (daqcard-1200)
47  */
48
49 #include <linux/module.h>
50
51 #include "../comedi_pcmcia.h"
52
53 #include "ni_labpc.h"
54
55 static const struct labpc_boardinfo labpc_cs_boards[] = {
56         {
57                 .name                   = "daqcard-1200",
58                 .ai_speed               = 10000,
59                 .has_ao                 = 1,
60                 .is_labpc1200           = 1,
61         },
62 };
63
64 static int labpc_cs_auto_attach(struct comedi_device *dev,
65                                 unsigned long context)
66 {
67         struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
68         int ret;
69
70         /* The ni_labpc driver needs the board_ptr */
71         dev->board_ptr = &labpc_cs_boards[0];
72
73         link->config_flags |= CONF_AUTO_SET_IO |
74                               CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ;
75         ret = comedi_pcmcia_enable(dev, NULL);
76         if (ret)
77                 return ret;
78         dev->iobase = link->resource[0]->start;
79
80         if (!link->irq)
81                 return -EINVAL;
82
83         return labpc_common_attach(dev, link->irq, IRQF_SHARED);
84 }
85
86 static void labpc_cs_detach(struct comedi_device *dev)
87 {
88         labpc_common_detach(dev);
89         comedi_pcmcia_disable(dev);
90 }
91
92 static struct comedi_driver driver_labpc_cs = {
93         .driver_name    = "ni_labpc_cs",
94         .module         = THIS_MODULE,
95         .auto_attach    = labpc_cs_auto_attach,
96         .detach         = labpc_cs_detach,
97 };
98
99 static int labpc_cs_attach(struct pcmcia_device *link)
100 {
101         return comedi_pcmcia_auto_config(link, &driver_labpc_cs);
102 }
103
104 static const struct pcmcia_device_id labpc_cs_ids[] = {
105         PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0103),        /* daqcard-1200 */
106         PCMCIA_DEVICE_NULL
107 };
108 MODULE_DEVICE_TABLE(pcmcia, labpc_cs_ids);
109
110 static struct pcmcia_driver labpc_cs_driver = {
111         .name           = "daqcard-1200",
112         .owner          = THIS_MODULE,
113         .id_table       = labpc_cs_ids,
114         .probe          = labpc_cs_attach,
115         .remove         = comedi_pcmcia_auto_unconfig,
116 };
117 module_comedi_pcmcia_driver(driver_labpc_cs, labpc_cs_driver);
118
119 MODULE_DESCRIPTION("Comedi driver for National Instruments Lab-PC");
120 MODULE_AUTHOR("Frank Mori Hess <fmhess@users.sourceforge.net>");
121 MODULE_LICENSE("GPL");