3 * Comedi PCI driver specific functions.
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
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.
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.
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.
23 #include <linux/pci.h>
25 #include "comedidev.h"
28 * comedi_to_pci_dev() - comedi_device pointer to pci_dev pointer.
29 * @dev: comedi_device struct
31 struct pci_dev
*comedi_to_pci_dev(struct comedi_device
*dev
)
33 return dev
->hw_dev
? to_pci_dev(dev
->hw_dev
) : NULL
;
35 EXPORT_SYMBOL_GPL(comedi_to_pci_dev
);
38 * comedi_pci_enable() - Enable the PCI device and request the regions.
39 * @dev: comedi_device struct
41 int comedi_pci_enable(struct comedi_device
*dev
)
43 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
49 rc
= pci_enable_device(pcidev
);
53 rc
= pci_request_regions(pcidev
, dev
->board_name
55 : dev
->driver
->driver_name
);
57 pci_disable_device(pcidev
);
59 dev
->ioenabled
= true;
63 EXPORT_SYMBOL_GPL(comedi_pci_enable
);
66 * comedi_pci_disable() - Release the regions and disable the PCI device.
67 * @dev: comedi_device struct
69 void comedi_pci_disable(struct comedi_device
*dev
)
71 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
73 if (pcidev
&& dev
->ioenabled
) {
74 pci_release_regions(pcidev
);
75 pci_disable_device(pcidev
);
77 dev
->ioenabled
= false;
79 EXPORT_SYMBOL_GPL(comedi_pci_disable
);
82 * comedi_pci_auto_config() - Configure/probe a comedi PCI driver.
83 * @pcidev: pci_dev struct
84 * @driver: comedi_driver struct
85 * @context: driver specific data, passed to comedi_auto_config()
87 * Typically called from the pci_driver (*probe) function.
89 int comedi_pci_auto_config(struct pci_dev
*pcidev
,
90 struct comedi_driver
*driver
,
91 unsigned long context
)
93 return comedi_auto_config(&pcidev
->dev
, driver
, context
);
95 EXPORT_SYMBOL_GPL(comedi_pci_auto_config
);
98 * comedi_pci_auto_unconfig() - Unconfigure/remove a comedi PCI driver.
99 * @pcidev: pci_dev struct
101 * Typically called from the pci_driver (*remove) function.
103 void comedi_pci_auto_unconfig(struct pci_dev
*pcidev
)
105 comedi_auto_unconfig(&pcidev
->dev
);
107 EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig
);
110 * comedi_pci_driver_register() - Register a comedi PCI driver.
111 * @comedi_driver: comedi_driver struct
112 * @pci_driver: pci_driver struct
114 * This function is used for the module_init() of comedi PCI drivers.
115 * Do not call it directly, use the module_comedi_pci_driver() helper
118 int comedi_pci_driver_register(struct comedi_driver
*comedi_driver
,
119 struct pci_driver
*pci_driver
)
123 ret
= comedi_driver_register(comedi_driver
);
127 ret
= pci_register_driver(pci_driver
);
129 comedi_driver_unregister(comedi_driver
);
135 EXPORT_SYMBOL_GPL(comedi_pci_driver_register
);
138 * comedi_pci_driver_unregister() - Unregister a comedi PCI driver.
139 * @comedi_driver: comedi_driver struct
140 * @pci_driver: pci_driver struct
142 * This function is used for the module_exit() of comedi PCI drivers.
143 * Do not call it directly, use the module_comedi_pci_driver() helper
146 void comedi_pci_driver_unregister(struct comedi_driver
*comedi_driver
,
147 struct pci_driver
*pci_driver
)
149 pci_unregister_driver(pci_driver
);
150 comedi_driver_unregister(comedi_driver
);
152 EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister
);