]> Pileus Git - ~andy/linux/blob - drivers/staging/comedi/drivers/das08_cs.c
d908d2d04f8c7cac1f62d7964e7fcbdc6c6ebda2
[~andy/linux] / drivers / staging / comedi / drivers / das08_cs.c
1 /*
2     comedi/drivers/das08_cs.c
3     DAS08 driver
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7     Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net>
8
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with this program; if not, write to the Free Software
21     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23     PCMCIA support code for this driver is adapted from the dummy_cs.c
24     driver of the Linux PCMCIA Card Services package.
25
26     The initial developer of the original code is David A. Hinds
27     <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
28     are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
29
30 *****************************************************************
31
32 */
33 /*
34 Driver: das08_cs
35 Description: DAS-08 PCMCIA boards
36 Author: Warren Jasper, ds, Frank Hess
37 Devices: [ComputerBoards] PCM-DAS08 (pcm-das08)
38 Status: works
39
40 This is the PCMCIA-specific support split off from the
41 das08 driver.
42
43 Options (for pcm-das08):
44         NONE
45
46 Command support does not exist, but could be added for this board.
47 */
48
49 #include "../comedidev.h"
50
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/slab.h>
54
55 #include "das08.h"
56
57 /* pcmcia includes */
58 #include <pcmcia/cistpl.h>
59 #include <pcmcia/ds.h>
60
61 static const struct das08_board_struct das08_cs_boards[] = {
62         {
63                 .name = "pcm-das08",
64                 .id = 0x0,              /*  XXX */
65                 .bustype = pcmcia,
66                 .ai_nbits = 12,
67                 .ai_pg = das08_bipolar5,
68                 .ai_encoding = das08_pcm_encode12,
69                 .di_nchan = 3,
70                 .do_nchan = 3,
71                 .iosize = 16,
72         },
73         /*  duplicate so driver name can be used also */
74         {
75                 .name = "das08_cs",
76                 .id = 0x0,              /*  XXX */
77                 .bustype = pcmcia,
78                 .ai_nbits = 12,
79                 .ai_pg = das08_bipolar5,
80                 .ai_encoding = das08_pcm_encode12,
81                 .di_nchan = 3,
82                 .do_nchan = 3,
83                 .iosize = 16,
84         },
85 };
86
87 static struct pcmcia_device *cur_dev;
88
89 static int das08_cs_attach(struct comedi_device *dev,
90                            struct comedi_devconfig *it)
91 {
92         const struct das08_board_struct *thisboard = comedi_board(dev);
93         struct das08_private_struct *devpriv;
94         int ret;
95         unsigned long iobase;
96         struct pcmcia_device *link = cur_dev;   /*  XXX hack */
97
98         ret = alloc_private(dev, sizeof(*devpriv));
99         if (ret)
100                 return ret;
101         devpriv = dev->private;
102
103         dev_info(dev->class_dev, "das08_cs: attach\n");
104         /*  deal with a pci board */
105
106         if (thisboard->bustype == pcmcia) {
107                 if (link == NULL) {
108                         dev_err(dev->class_dev, "no pcmcia cards found\n");
109                         return -EIO;
110                 }
111                 iobase = link->resource[0]->start;
112         } else {
113                 dev_err(dev->class_dev,
114                         "bug! board does not have PCMCIA bustype\n");
115                 return -EINVAL;
116         }
117
118         return das08_common_attach(dev, iobase);
119 }
120
121 static struct comedi_driver driver_das08_cs = {
122         .driver_name    = "das08_cs",
123         .module         = THIS_MODULE,
124         .attach         = das08_cs_attach,
125         .detach         = das08_common_detach,
126         .board_name     = &das08_cs_boards[0].name,
127         .num_names      = ARRAY_SIZE(das08_cs_boards),
128         .offset         = sizeof(struct das08_board_struct),
129 };
130
131 static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev,
132                                 void *priv_data)
133 {
134         if (p_dev->config_index == 0)
135                 return -EINVAL;
136
137         return pcmcia_request_io(p_dev);
138 }
139
140 static int das08_pcmcia_attach(struct pcmcia_device *link)
141 {
142         int ret;
143
144         link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
145
146         ret = pcmcia_loop_config(link, das08_pcmcia_config_loop, NULL);
147         if (ret)
148                 goto failed;
149
150         if (!link->irq)
151                 goto failed;
152
153         ret = pcmcia_enable_device(link);
154         if (ret)
155                 goto failed;
156
157         cur_dev = link;
158         return 0;
159
160 failed:
161         pcmcia_disable_device(link);
162         return ret;
163 }
164
165 static void das08_pcmcia_detach(struct pcmcia_device *link)
166 {
167         pcmcia_disable_device(link);
168         cur_dev = NULL;
169 }
170
171 static const struct pcmcia_device_id das08_cs_id_table[] = {
172         PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x4001),
173         PCMCIA_DEVICE_NULL
174 };
175 MODULE_DEVICE_TABLE(pcmcia, das08_cs_id_table);
176
177 static struct pcmcia_driver das08_cs_driver = {
178         .name           = "pcm-das08",
179         .owner          = THIS_MODULE,
180         .probe          = das08_pcmcia_attach,
181         .remove         = das08_pcmcia_detach,
182         .id_table       = das08_cs_id_table,
183 };
184
185 static int __init das08_cs_init_module(void)
186 {
187         int ret;
188
189         ret = comedi_driver_register(&driver_das08_cs);
190         if (ret < 0)
191                 return ret;
192
193         ret = pcmcia_register_driver(&das08_cs_driver);
194         if (ret < 0) {
195                 comedi_driver_unregister(&driver_das08_cs);
196                 return ret;
197         }
198
199         return 0;
200
201 }
202 module_init(das08_cs_init_module);
203
204 static void __exit das08_cs_exit_module(void)
205 {
206         pcmcia_unregister_driver(&das08_cs_driver);
207         comedi_driver_unregister(&driver_das08_cs);
208 }
209 module_exit(das08_cs_exit_module);
210
211 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>, "
212               "Frank Mori Hess <fmhess@users.sourceforge.net>");
213 MODULE_DESCRIPTION("Comedi driver for ComputerBoards DAS-08 PCMCIA boards");
214 MODULE_LICENSE("GPL");