1 /*
2 * comedi_pcmcia.c
3 * Comedi PCMCIA driver specific functions.
4 *
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include <linux/kernel.h>
24
25 #include <pcmcia/cistpl.h>
26 #include <pcmcia/ds.h>
27
28 #include "comedidev.h"
29
30 /**
31 * comedi_to_pcmcia_dev() - comedi_device pointer to pcmcia_device pointer.
32 * @dev: comedi_device struct
33 */
comedi_to_pcmcia_dev(struct comedi_device * dev)34 struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *dev)
35 {
36 return dev->hw_dev ? to_pcmcia_dev(dev->hw_dev) : NULL;
37 }
38 EXPORT_SYMBOL_GPL(comedi_to_pcmcia_dev);
39
comedi_pcmcia_conf_check(struct pcmcia_device * link,void * priv_data)40 static int comedi_pcmcia_conf_check(struct pcmcia_device *link,
41 void *priv_data)
42 {
43 if (link->config_index == 0)
44 return -EINVAL;
45
46 return pcmcia_request_io(link);
47 }
48
49 /**
50 * comedi_pcmcia_enable() - Request the regions and enable the PCMCIA device.
51 * @dev: comedi_device struct
52 * @conf_check: optional callback to check the pcmcia_device configuration
53 *
54 * The comedi PCMCIA driver needs to set the link->config_flags, as
55 * appropriate for that driver, before calling this function in order
56 * to allow pcmcia_loop_config() to do its internal autoconfiguration.
57 */
comedi_pcmcia_enable(struct comedi_device * dev,int (* conf_check)(struct pcmcia_device *,void *))58 int comedi_pcmcia_enable(struct comedi_device *dev,
59 int (*conf_check)(struct pcmcia_device *, void *))
60 {
61 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
62 int ret;
63
64 if (!link)
65 return -ENODEV;
66
67 if (!conf_check)
68 conf_check = comedi_pcmcia_conf_check;
69
70 ret = pcmcia_loop_config(link, conf_check, NULL);
71 if (ret)
72 return ret;
73
74 return pcmcia_enable_device(link);
75 }
76 EXPORT_SYMBOL_GPL(comedi_pcmcia_enable);
77
78 /**
79 * comedi_pcmcia_disable() - Disable the PCMCIA device and release the regions.
80 * @dev: comedi_device struct
81 */
comedi_pcmcia_disable(struct comedi_device * dev)82 void comedi_pcmcia_disable(struct comedi_device *dev)
83 {
84 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
85
86 if (link)
87 pcmcia_disable_device(link);
88 }
89 EXPORT_SYMBOL_GPL(comedi_pcmcia_disable);
90
91 /**
92 * comedi_pcmcia_auto_config() - Configure/probe a comedi PCMCIA driver.
93 * @link: pcmcia_device struct
94 * @driver: comedi_driver struct
95 *
96 * Typically called from the pcmcia_driver (*probe) function.
97 */
comedi_pcmcia_auto_config(struct pcmcia_device * link,struct comedi_driver * driver)98 int comedi_pcmcia_auto_config(struct pcmcia_device *link,
99 struct comedi_driver *driver)
100 {
101 return comedi_auto_config(&link->dev, driver, 0);
102 }
103 EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_config);
104
105 /**
106 * comedi_pcmcia_auto_unconfig() - Unconfigure/remove a comedi PCMCIA driver.
107 * @link: pcmcia_device struct
108 *
109 * Typically called from the pcmcia_driver (*remove) function.
110 */
comedi_pcmcia_auto_unconfig(struct pcmcia_device * link)111 void comedi_pcmcia_auto_unconfig(struct pcmcia_device *link)
112 {
113 comedi_auto_unconfig(&link->dev);
114 }
115 EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_unconfig);
116
117 /**
118 * comedi_pcmcia_driver_register() - Register a comedi PCMCIA driver.
119 * @comedi_driver: comedi_driver struct
120 * @pcmcia_driver: pcmcia_driver struct
121 *
122 * This function is used for the module_init() of comedi USB drivers.
123 * Do not call it directly, use the module_comedi_pcmcia_driver() helper
124 * macro instead.
125 */
comedi_pcmcia_driver_register(struct comedi_driver * comedi_driver,struct pcmcia_driver * pcmcia_driver)126 int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver,
127 struct pcmcia_driver *pcmcia_driver)
128 {
129 int ret;
130
131 ret = comedi_driver_register(comedi_driver);
132 if (ret < 0)
133 return ret;
134
135 ret = pcmcia_register_driver(pcmcia_driver);
136 if (ret < 0) {
137 comedi_driver_unregister(comedi_driver);
138 return ret;
139 }
140
141 return 0;
142 }
143 EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_register);
144
145 /**
146 * comedi_pcmcia_driver_unregister() - Unregister a comedi PCMCIA driver.
147 * @comedi_driver: comedi_driver struct
148 * @pcmcia_driver: pcmcia_driver struct
149 *
150 * This function is used for the module_exit() of comedi PCMCIA drivers.
151 * Do not call it directly, use the module_comedi_pcmcia_driver() helper
152 * macro instead.
153 */
comedi_pcmcia_driver_unregister(struct comedi_driver * comedi_driver,struct pcmcia_driver * pcmcia_driver)154 void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver,
155 struct pcmcia_driver *pcmcia_driver)
156 {
157 pcmcia_unregister_driver(pcmcia_driver);
158 comedi_driver_unregister(comedi_driver);
159 }
160 EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister);
161