Commit | Line | Data |
---|---|---|
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 | /* | |
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): | |
d539047c | 44 | NONE |
0882eaa6 DS |
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> | |
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 | ||
d539047c | 61 | static struct pcmcia_device *cur_dev; |
0882eaa6 DS |
62 | |
63 | #define thisboard ((const struct das08_board_struct *)dev->board_ptr) | |
64 | ||
0a85b6f0 MT |
65 | static int das08_cs_attach(struct comedi_device *dev, |
66 | struct comedi_devconfig *it) | |
0882eaa6 DS |
67 | { |
68 | int ret; | |
69 | unsigned long iobase; | |
2696fb57 | 70 | struct pcmcia_device *link = cur_dev; /* XXX hack */ |
0882eaa6 | 71 | |
c3744138 BP |
72 | ret = alloc_private(dev, sizeof(struct das08_private_struct)); |
73 | if (ret < 0) | |
0882eaa6 DS |
74 | return ret; |
75 | ||
f41ad667 | 76 | dev_info(dev->class_dev, "das08_cs: attach\n"); |
2696fb57 | 77 | /* deal with a pci board */ |
0882eaa6 DS |
78 | |
79 | if (thisboard->bustype == pcmcia) { | |
80 | if (link == NULL) { | |
f41ad667 | 81 | dev_err(dev->class_dev, "no pcmcia cards found\n"); |
0882eaa6 DS |
82 | return -EIO; |
83 | } | |
9a017a91 | 84 | iobase = link->resource[0]->start; |
0882eaa6 | 85 | } else { |
f41ad667 IA |
86 | dev_err(dev->class_dev, |
87 | "bug! board does not have PCMCIA bustype\n"); | |
0882eaa6 DS |
88 | return -EINVAL; |
89 | } | |
90 | ||
0882eaa6 DS |
91 | return das08_common_attach(dev, iobase); |
92 | } | |
93 | ||
6b7de35e HS |
94 | static struct comedi_driver driver_das08_cs = { |
95 | .driver_name = "das08_cs", | |
96 | .module = THIS_MODULE, | |
97 | .attach = das08_cs_attach, | |
98 | .detach = das08_common_detach, | |
99 | .board_name = &das08_cs_boards[0].name, | |
100 | .num_names = ARRAY_SIZE(das08_cs_boards), | |
101 | .offset = sizeof(struct das08_board_struct), | |
102 | }; | |
103 | ||
55a19b39 | 104 | static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev, |
55a19b39 DB |
105 | void *priv_data) |
106 | { | |
00990e7c DB |
107 | if (p_dev->config_index == 0) |
108 | return -EINVAL; | |
109 | ||
110 | return pcmcia_request_io(p_dev); | |
55a19b39 DB |
111 | } |
112 | ||
ae6eba84 | 113 | static int das08_pcmcia_attach(struct pcmcia_device *link) |
0882eaa6 | 114 | { |
55a19b39 | 115 | int ret; |
0882eaa6 | 116 | |
00990e7c DB |
117 | link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; |
118 | ||
55a19b39 | 119 | ret = pcmcia_loop_config(link, das08_pcmcia_config_loop, NULL); |
ae6eba84 | 120 | if (ret) |
55a19b39 | 121 | goto failed; |
0882eaa6 | 122 | |
eb14120f DB |
123 | if (!link->irq) |
124 | goto failed; | |
0882eaa6 | 125 | |
1ac71e5a | 126 | ret = pcmcia_enable_device(link); |
55a19b39 DB |
127 | if (ret) |
128 | goto failed; | |
0882eaa6 | 129 | |
fb795746 | 130 | cur_dev = link; |
fb795746 | 131 | return 0; |
ae6eba84 HS |
132 | |
133 | failed: | |
134 | pcmcia_disable_device(link); | |
135 | return ret; | |
fb795746 HS |
136 | } |
137 | ||
138 | static void das08_pcmcia_detach(struct pcmcia_device *link) | |
139 | { | |
ae6eba84 HS |
140 | pcmcia_disable_device(link); |
141 | cur_dev = NULL; | |
c332d969 | 142 | } |
0882eaa6 | 143 | |
2202a5a7 | 144 | static const struct pcmcia_device_id das08_cs_id_table[] = { |
0882eaa6 DS |
145 | PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x4001), |
146 | PCMCIA_DEVICE_NULL | |
147 | }; | |
0882eaa6 DS |
148 | MODULE_DEVICE_TABLE(pcmcia, das08_cs_id_table); |
149 | ||
27fa05bc HS |
150 | static struct pcmcia_driver das08_cs_driver = { |
151 | .name = "pcm-das08", | |
152 | .owner = THIS_MODULE, | |
153 | .probe = das08_pcmcia_attach, | |
154 | .remove = das08_pcmcia_detach, | |
27fa05bc | 155 | .id_table = das08_cs_id_table, |
0882eaa6 DS |
156 | }; |
157 | ||
0882eaa6 DS |
158 | static int __init das08_cs_init_module(void) |
159 | { | |
160 | int ret; | |
161 | ||
36061c84 | 162 | ret = comedi_driver_register(&driver_das08_cs); |
0882eaa6 DS |
163 | if (ret < 0) |
164 | return ret; | |
165 | ||
36061c84 HS |
166 | ret = pcmcia_register_driver(&das08_cs_driver); |
167 | if (ret < 0) { | |
168 | comedi_driver_unregister(&driver_das08_cs); | |
169 | return ret; | |
170 | } | |
171 | ||
172 | return 0; | |
173 | ||
0882eaa6 | 174 | } |
46877702 | 175 | module_init(das08_cs_init_module); |
0882eaa6 DS |
176 | |
177 | static void __exit das08_cs_exit_module(void) | |
178 | { | |
46877702 | 179 | pcmcia_unregister_driver(&das08_cs_driver); |
0882eaa6 DS |
180 | comedi_driver_unregister(&driver_das08_cs); |
181 | } | |
0882eaa6 | 182 | module_exit(das08_cs_exit_module); |
3a36ad17 HS |
183 | |
184 | MODULE_AUTHOR("David A. Schleef <ds@schleef.org>, " | |
185 | "Frank Mori Hess <fmhess@users.sourceforge.net>"); | |
186 | MODULE_DESCRIPTION("Comedi driver for ComputerBoards DAS-08 PCMCIA boards"); | |
187 | MODULE_LICENSE("GPL"); |