staging: comedi: remove inline alloc_private()
[deliverable/linux.git] / drivers / staging / comedi / drivers / das08_cs.c
CommitLineData
0882eaa6
DS
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
c332d969
HS
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
0882eaa6
DS
30*****************************************************************
31
32*/
33/*
34Driver: das08_cs
35Description: DAS-08 PCMCIA boards
36Author: Warren Jasper, ds, Frank Hess
37Devices: [ComputerBoards] PCM-DAS08 (pcm-das08)
38Status: works
39
40This is the PCMCIA-specific support split off from the
41das08 driver.
42
43Options (for pcm-das08):
d539047c 44 NONE
0882eaa6
DS
45
46Command 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>
5a0e3ad6 53#include <linux/slab.h>
0882eaa6
DS
54
55#include "das08.h"
56
2696fb57 57/* pcmcia includes */
0882eaa6
DS
58#include <pcmcia/cistpl.h>
59#include <pcmcia/ds.h>
60
383ecb88
IA
61static 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
d539047c 87static struct pcmcia_device *cur_dev;
0882eaa6 88
0a85b6f0
MT
89static int das08_cs_attach(struct comedi_device *dev,
90 struct comedi_devconfig *it)
0882eaa6 91{
6f88a20a 92 const struct das08_board_struct *thisboard = comedi_board(dev);
9a1a6cf8 93 struct das08_private_struct *devpriv;
0882eaa6 94 unsigned long iobase;
2696fb57 95 struct pcmcia_device *link = cur_dev; /* XXX hack */
0882eaa6 96
c34fa261
HS
97 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
98 if (!devpriv)
99 return -ENOMEM;
100 dev->private = devpriv;
0882eaa6 101
f41ad667 102 dev_info(dev->class_dev, "das08_cs: attach\n");
2696fb57 103 /* deal with a pci board */
0882eaa6
DS
104
105 if (thisboard->bustype == pcmcia) {
106 if (link == NULL) {
f41ad667 107 dev_err(dev->class_dev, "no pcmcia cards found\n");
0882eaa6
DS
108 return -EIO;
109 }
9a017a91 110 iobase = link->resource[0]->start;
0882eaa6 111 } else {
f41ad667
IA
112 dev_err(dev->class_dev,
113 "bug! board does not have PCMCIA bustype\n");
0882eaa6
DS
114 return -EINVAL;
115 }
116
0882eaa6
DS
117 return das08_common_attach(dev, iobase);
118}
119
6b7de35e
HS
120static struct comedi_driver driver_das08_cs = {
121 .driver_name = "das08_cs",
122 .module = THIS_MODULE,
123 .attach = das08_cs_attach,
124 .detach = das08_common_detach,
125 .board_name = &das08_cs_boards[0].name,
126 .num_names = ARRAY_SIZE(das08_cs_boards),
127 .offset = sizeof(struct das08_board_struct),
128};
129
55a19b39 130static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev,
55a19b39
DB
131 void *priv_data)
132{
00990e7c
DB
133 if (p_dev->config_index == 0)
134 return -EINVAL;
135
136 return pcmcia_request_io(p_dev);
55a19b39
DB
137}
138
ae6eba84 139static int das08_pcmcia_attach(struct pcmcia_device *link)
0882eaa6 140{
55a19b39 141 int ret;
0882eaa6 142
00990e7c
DB
143 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
144
55a19b39 145 ret = pcmcia_loop_config(link, das08_pcmcia_config_loop, NULL);
ae6eba84 146 if (ret)
55a19b39 147 goto failed;
0882eaa6 148
eb14120f
DB
149 if (!link->irq)
150 goto failed;
0882eaa6 151
1ac71e5a 152 ret = pcmcia_enable_device(link);
55a19b39
DB
153 if (ret)
154 goto failed;
0882eaa6 155
fb795746 156 cur_dev = link;
fb795746 157 return 0;
ae6eba84
HS
158
159failed:
160 pcmcia_disable_device(link);
161 return ret;
fb795746
HS
162}
163
164static void das08_pcmcia_detach(struct pcmcia_device *link)
165{
ae6eba84
HS
166 pcmcia_disable_device(link);
167 cur_dev = NULL;
c332d969 168}
0882eaa6 169
2202a5a7 170static const struct pcmcia_device_id das08_cs_id_table[] = {
0882eaa6
DS
171 PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x4001),
172 PCMCIA_DEVICE_NULL
173};
0882eaa6
DS
174MODULE_DEVICE_TABLE(pcmcia, das08_cs_id_table);
175
27fa05bc
HS
176static struct pcmcia_driver das08_cs_driver = {
177 .name = "pcm-das08",
178 .owner = THIS_MODULE,
179 .probe = das08_pcmcia_attach,
180 .remove = das08_pcmcia_detach,
27fa05bc 181 .id_table = das08_cs_id_table,
0882eaa6
DS
182};
183
0882eaa6
DS
184static int __init das08_cs_init_module(void)
185{
186 int ret;
187
36061c84 188 ret = comedi_driver_register(&driver_das08_cs);
0882eaa6
DS
189 if (ret < 0)
190 return ret;
191
36061c84
HS
192 ret = pcmcia_register_driver(&das08_cs_driver);
193 if (ret < 0) {
194 comedi_driver_unregister(&driver_das08_cs);
195 return ret;
196 }
197
198 return 0;
199
0882eaa6 200}
46877702 201module_init(das08_cs_init_module);
0882eaa6
DS
202
203static void __exit das08_cs_exit_module(void)
204{
46877702 205 pcmcia_unregister_driver(&das08_cs_driver);
0882eaa6
DS
206 comedi_driver_unregister(&driver_das08_cs);
207}
0882eaa6 208module_exit(das08_cs_exit_module);
3a36ad17
HS
209
210MODULE_AUTHOR("David A. Schleef <ds@schleef.org>, "
211 "Frank Mori Hess <fmhess@users.sourceforge.net>");
212MODULE_DESCRIPTION("Comedi driver for ComputerBoards DAS-08 PCMCIA boards");
213MODULE_LICENSE("GPL");
This page took 0.423382 seconds and 5 git commands to generate.