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 pci_disable_device(pcidev);
57 dev->ioenabled = true;
61 EXPORT_SYMBOL_GPL(comedi_pci_enable);
64 * comedi_pci_disable() - Release the regions and disable the PCI device.
65 * @dev: comedi_device struct
67 void comedi_pci_disable(struct comedi_device *dev)
69 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
71 if (pcidev && dev->ioenabled) {
72 pci_release_regions(pcidev);
73 pci_disable_device(pcidev);
75 dev->ioenabled = false;
77 EXPORT_SYMBOL_GPL(comedi_pci_disable);
80 * comedi_pci_auto_config() - Configure/probe a comedi PCI driver.
81 * @pcidev: pci_dev struct
82 * @driver: comedi_driver struct
83 * @context: driver specific data, passed to comedi_auto_config()
85 * Typically called from the pci_driver (*probe) function.
87 int comedi_pci_auto_config(struct pci_dev *pcidev,
88 struct comedi_driver *driver,
89 unsigned long context)
91 return comedi_auto_config(&pcidev->dev, driver, context);
93 EXPORT_SYMBOL_GPL(comedi_pci_auto_config);
96 * comedi_pci_auto_unconfig() - Unconfigure/remove a comedi PCI driver.
97 * @pcidev: pci_dev struct
99 * Typically called from the pci_driver (*remove) function.
101 void comedi_pci_auto_unconfig(struct pci_dev *pcidev)
103 comedi_auto_unconfig(&pcidev->dev);
105 EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig);
108 * comedi_pci_driver_register() - Register a comedi PCI driver.
109 * @comedi_driver: comedi_driver struct
110 * @pci_driver: pci_driver struct
112 * This function is used for the module_init() of comedi PCI drivers.
113 * Do not call it directly, use the module_comedi_pci_driver() helper
116 int comedi_pci_driver_register(struct comedi_driver *comedi_driver,
117 struct pci_driver *pci_driver)
121 ret = comedi_driver_register(comedi_driver);
125 ret = pci_register_driver(pci_driver);
127 comedi_driver_unregister(comedi_driver);
133 EXPORT_SYMBOL_GPL(comedi_pci_driver_register);
136 * comedi_pci_driver_unregister() - Unregister a comedi PCI driver.
137 * @comedi_driver: comedi_driver struct
138 * @pci_driver: pci_driver struct
140 * This function is used for the module_exit() of comedi PCI drivers.
141 * Do not call it directly, use the module_comedi_pci_driver() helper
144 void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver,
145 struct pci_driver *pci_driver)
147 pci_unregister_driver(pci_driver);
148 comedi_driver_unregister(comedi_driver);
150 EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister);