1 // SPDX-License-Identifier: GPL-2.0+
4 * Comedi PCMCIA driver specific functions.
6 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/comedi/comedi_pcmcia.h>
15 * comedi_to_pcmcia_dev() - Return PCMCIA device attached to COMEDI device
16 * @dev: COMEDI device.
18 * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
19 * a &struct device embedded in a &struct pcmcia_device.
21 * Return: Attached PCMCIA device if @dev->hw_dev is non-%NULL.
22 * Return %NULL if @dev->hw_dev is %NULL.
24 struct pcmcia_device
*comedi_to_pcmcia_dev(struct comedi_device
*dev
)
26 return dev
->hw_dev
? to_pcmcia_dev(dev
->hw_dev
) : NULL
;
28 EXPORT_SYMBOL_GPL(comedi_to_pcmcia_dev
);
30 static int comedi_pcmcia_conf_check(struct pcmcia_device
*link
,
33 if (link
->config_index
== 0)
36 return pcmcia_request_io(link
);
40 * comedi_pcmcia_enable() - Request the regions and enable the PCMCIA device
41 * @dev: COMEDI device.
42 * @conf_check: Optional callback to check each configuration option of the
43 * PCMCIA device and request I/O regions.
45 * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a a
46 * &struct device embedded in a &struct pcmcia_device. The comedi PCMCIA
47 * driver needs to set the 'config_flags' member in the &struct pcmcia_device,
48 * as appropriate for that driver, before calling this function in order to
49 * allow pcmcia_loop_config() to do its internal autoconfiguration.
51 * If @conf_check is %NULL it is set to a default function. If is
52 * passed to pcmcia_loop_config() and should return %0 if the configuration
53 * is valid and I/O regions requested successfully, otherwise it should return
54 * a negative error value. The default function returns -%EINVAL if the
55 * 'config_index' member is %0, otherwise it calls pcmcia_request_io() and
58 * If the above configuration check passes, pcmcia_enable_device() is called
59 * to set up and activate the PCMCIA device.
61 * If this function returns an error, comedi_pcmcia_disable() should be called
62 * to release requested resources.
66 * -%ENODEV id @dev->hw_dev is %NULL,
67 * a negative error number from pcmcia_loop_config() if it fails,
68 * or a negative error number from pcmcia_enable_device() if it fails.
70 int comedi_pcmcia_enable(struct comedi_device
*dev
,
71 int (*conf_check
)(struct pcmcia_device
*p_dev
,
74 struct pcmcia_device
*link
= comedi_to_pcmcia_dev(dev
);
81 conf_check
= comedi_pcmcia_conf_check
;
83 ret
= pcmcia_loop_config(link
, conf_check
, NULL
);
87 return pcmcia_enable_device(link
);
89 EXPORT_SYMBOL_GPL(comedi_pcmcia_enable
);
92 * comedi_pcmcia_disable() - Disable the PCMCIA device and release the regions
93 * @dev: COMEDI device.
95 * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
96 * a &struct device embedded in a &struct pcmcia_device. Call
97 * pcmcia_disable_device() to disable and clean up the PCMCIA device.
99 void comedi_pcmcia_disable(struct comedi_device
*dev
)
101 struct pcmcia_device
*link
= comedi_to_pcmcia_dev(dev
);
104 pcmcia_disable_device(link
);
106 EXPORT_SYMBOL_GPL(comedi_pcmcia_disable
);
109 * comedi_pcmcia_auto_config() - Configure/probe a PCMCIA COMEDI device
110 * @link: PCMCIA device.
111 * @driver: Registered COMEDI driver.
113 * Typically called from the pcmcia_driver (*probe) function. Auto-configure
114 * a COMEDI device, using a pointer to the &struct device embedded in *@link
115 * as the hardware device. The @driver's "auto_attach" handler may call
116 * comedi_to_pcmcia_dev() on the passed in COMEDI device to recover @link.
118 * Return: The result of calling comedi_auto_config() (0 on success, or a
119 * negative error number on failure).
121 int comedi_pcmcia_auto_config(struct pcmcia_device
*link
,
122 struct comedi_driver
*driver
)
124 return comedi_auto_config(&link
->dev
, driver
, 0);
126 EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_config
);
129 * comedi_pcmcia_auto_unconfig() - Unconfigure/remove a PCMCIA COMEDI device
130 * @link: PCMCIA device.
132 * Typically called from the pcmcia_driver (*remove) function.
133 * Auto-unconfigure a COMEDI device attached to this PCMCIA device, using a
134 * pointer to the &struct device embedded in *@link as the hardware device.
135 * The COMEDI driver's "detach" handler will be called during unconfiguration
136 * of the COMEDI device.
138 * Note that the COMEDI device may have already been unconfigured using the
139 * %COMEDI_DEVCONFIG ioctl, in which case this attempt to unconfigure it
140 * again should be ignored.
142 void comedi_pcmcia_auto_unconfig(struct pcmcia_device
*link
)
144 comedi_auto_unconfig(&link
->dev
);
146 EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_unconfig
);
149 * comedi_pcmcia_driver_register() - Register a PCMCIA COMEDI driver
150 * @comedi_driver: COMEDI driver to be registered.
151 * @pcmcia_driver: PCMCIA driver to be registered.
153 * This function is used for the module_init() of PCMCIA COMEDI driver modules
154 * to register the COMEDI driver and the PCMCIA driver. Do not call it
155 * directly, use the module_comedi_pcmcia_driver() helper macro instead.
157 * Return: 0 on success, or a negative error number on failure.
159 int comedi_pcmcia_driver_register(struct comedi_driver
*comedi_driver
,
160 struct pcmcia_driver
*pcmcia_driver
)
164 ret
= comedi_driver_register(comedi_driver
);
168 ret
= pcmcia_register_driver(pcmcia_driver
);
170 comedi_driver_unregister(comedi_driver
);
176 EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_register
);
179 * comedi_pcmcia_driver_unregister() - Unregister a PCMCIA COMEDI driver
180 * @comedi_driver: COMEDI driver to be registered.
181 * @pcmcia_driver: PCMCIA driver to be registered.
183 * This function is called from the module_exit() of PCMCIA COMEDI driver
184 * modules to unregister the PCMCIA driver and the COMEDI driver. Do not call
185 * it directly, use the module_comedi_pcmcia_driver() helper macro instead.
187 void comedi_pcmcia_driver_unregister(struct comedi_driver
*comedi_driver
,
188 struct pcmcia_driver
*pcmcia_driver
)
190 pcmcia_unregister_driver(pcmcia_driver
);
191 comedi_driver_unregister(comedi_driver
);
193 EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister
);
195 static int __init
comedi_pcmcia_init(void)
199 module_init(comedi_pcmcia_init
);
201 static void __exit
comedi_pcmcia_exit(void)
204 module_exit(comedi_pcmcia_exit
);
206 MODULE_AUTHOR("https://www.comedi.org");
207 MODULE_DESCRIPTION("Comedi PCMCIA interface module");
208 MODULE_LICENSE("GPL");