blob: 7e784399a16febcfdacef3abe2c4132d78f0992b [file] [log] [blame]
H Hartley Sweeten309231d2013-01-30 15:22:44 -07001/*
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.
H Hartley Sweeten309231d2013-01-30 15:22:44 -070017 */
18
Ian Abbottaae434b2014-10-31 17:47:37 +000019#include <linux/module.h>
H Hartley Sweeten309231d2013-01-30 15:22:44 -070020#include <linux/kernel.h>
21
Ian Abbotta1d49ae2015-01-30 09:57:18 +000022#include "comedi_pcmcia.h"
H Hartley Sweeten309231d2013-01-30 15:22:44 -070023
24/**
H Hartley Sweeten1f021e1f2013-01-30 15:23:06 -070025 * comedi_to_pcmcia_dev() - comedi_device pointer to pcmcia_device pointer.
26 * @dev: comedi_device struct
27 */
28struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *dev)
29{
30 return dev->hw_dev ? to_pcmcia_dev(dev->hw_dev) : NULL;
31}
32EXPORT_SYMBOL_GPL(comedi_to_pcmcia_dev);
33
H Hartley Sweetenddb2d0a2013-02-04 14:19:35 -070034static int comedi_pcmcia_conf_check(struct pcmcia_device *link,
35 void *priv_data)
36{
37 if (link->config_index == 0)
38 return -EINVAL;
39
40 return pcmcia_request_io(link);
41}
42
43/**
44 * comedi_pcmcia_enable() - Request the regions and enable the PCMCIA device.
45 * @dev: comedi_device struct
H Hartley Sweetena3ac9512013-02-05 18:16:07 -070046 * @conf_check: optional callback to check the pcmcia_device configuration
H Hartley Sweetenddb2d0a2013-02-04 14:19:35 -070047 *
48 * The comedi PCMCIA driver needs to set the link->config_flags, as
49 * appropriate for that driver, before calling this function in order
50 * to allow pcmcia_loop_config() to do its internal autoconfiguration.
51 */
H Hartley Sweetena3ac9512013-02-05 18:16:07 -070052int comedi_pcmcia_enable(struct comedi_device *dev,
53 int (*conf_check)(struct pcmcia_device *, void *))
H Hartley Sweetenddb2d0a2013-02-04 14:19:35 -070054{
55 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
56 int ret;
57
58 if (!link)
59 return -ENODEV;
60
H Hartley Sweetena3ac9512013-02-05 18:16:07 -070061 if (!conf_check)
62 conf_check = comedi_pcmcia_conf_check;
63
64 ret = pcmcia_loop_config(link, conf_check, NULL);
H Hartley Sweetenddb2d0a2013-02-04 14:19:35 -070065 if (ret)
66 return ret;
67
68 return pcmcia_enable_device(link);
69}
70EXPORT_SYMBOL_GPL(comedi_pcmcia_enable);
71
72/**
73 * comedi_pcmcia_disable() - Disable the PCMCIA device and release the regions.
74 * @dev: comedi_device struct
75 */
76void comedi_pcmcia_disable(struct comedi_device *dev)
77{
78 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
79
80 if (link)
81 pcmcia_disable_device(link);
82}
83EXPORT_SYMBOL_GPL(comedi_pcmcia_disable);
84
H Hartley Sweeten1f021e1f2013-01-30 15:23:06 -070085/**
86 * comedi_pcmcia_auto_config() - Configure/probe a comedi PCMCIA driver.
87 * @link: pcmcia_device struct
88 * @driver: comedi_driver struct
89 *
90 * Typically called from the pcmcia_driver (*probe) function.
91 */
92int comedi_pcmcia_auto_config(struct pcmcia_device *link,
93 struct comedi_driver *driver)
94{
95 return comedi_auto_config(&link->dev, driver, 0);
96}
97EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_config);
98
99/**
100 * comedi_pcmcia_auto_unconfig() - Unconfigure/remove a comedi PCMCIA driver.
101 * @link: pcmcia_device struct
102 *
103 * Typically called from the pcmcia_driver (*remove) function.
104 */
105void comedi_pcmcia_auto_unconfig(struct pcmcia_device *link)
106{
107 comedi_auto_unconfig(&link->dev);
108}
109EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_unconfig);
110
111/**
H Hartley Sweeten309231d2013-01-30 15:22:44 -0700112 * comedi_pcmcia_driver_register() - Register a comedi PCMCIA driver.
113 * @comedi_driver: comedi_driver struct
114 * @pcmcia_driver: pcmcia_driver struct
115 *
116 * This function is used for the module_init() of comedi USB drivers.
117 * Do not call it directly, use the module_comedi_pcmcia_driver() helper
118 * macro instead.
119 */
120int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver,
121 struct pcmcia_driver *pcmcia_driver)
122{
123 int ret;
124
125 ret = comedi_driver_register(comedi_driver);
126 if (ret < 0)
127 return ret;
128
129 ret = pcmcia_register_driver(pcmcia_driver);
130 if (ret < 0) {
131 comedi_driver_unregister(comedi_driver);
132 return ret;
133 }
134
135 return 0;
136}
137EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_register);
138
139/**
140 * comedi_pcmcia_driver_unregister() - Unregister a comedi PCMCIA driver.
141 * @comedi_driver: comedi_driver struct
142 * @pcmcia_driver: pcmcia_driver struct
143 *
144 * This function is used for the module_exit() of comedi PCMCIA drivers.
145 * Do not call it directly, use the module_comedi_pcmcia_driver() helper
146 * macro instead.
147 */
148void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver,
149 struct pcmcia_driver *pcmcia_driver)
150{
151 pcmcia_unregister_driver(pcmcia_driver);
152 comedi_driver_unregister(comedi_driver);
153}
154EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister);
Ian Abbottaae434b2014-10-31 17:47:37 +0000155
156static int __init comedi_pcmcia_init(void)
157{
158 return 0;
159}
160module_init(comedi_pcmcia_init);
161
162static void __exit comedi_pcmcia_exit(void)
163{
164}
165module_exit(comedi_pcmcia_exit);
166
167MODULE_AUTHOR("http://www.comedi.org");
168MODULE_DESCRIPTION("Comedi PCMCIA interface module");
169MODULE_LICENSE("GPL");