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.
19 #include <linux/pci.h>
21 #include "comedidev.h"
24 * comedi_to_pci_dev() - comedi_device pointer to pci_dev pointer.
25 * @dev: comedi_device struct
27 struct pci_dev
*comedi_to_pci_dev(struct comedi_device
*dev
)
29 return dev
->hw_dev
? to_pci_dev(dev
->hw_dev
) : NULL
;
31 EXPORT_SYMBOL_GPL(comedi_to_pci_dev
);
34 * comedi_pci_enable() - Enable the PCI device and request the regions.
35 * @dev: comedi_device struct
37 int comedi_pci_enable(struct comedi_device
*dev
)
39 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
45 rc
= pci_enable_device(pcidev
);
49 rc
= pci_request_regions(pcidev
, dev
->board_name
);
51 pci_disable_device(pcidev
);
53 dev
->ioenabled
= true;
57 EXPORT_SYMBOL_GPL(comedi_pci_enable
);
60 * comedi_pci_disable() - Release the regions and disable the PCI device.
61 * @dev: comedi_device struct
63 void comedi_pci_disable(struct comedi_device
*dev
)
65 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
67 if (pcidev
&& dev
->ioenabled
) {
68 pci_release_regions(pcidev
);
69 pci_disable_device(pcidev
);
71 dev
->ioenabled
= false;
73 EXPORT_SYMBOL_GPL(comedi_pci_disable
);
76 * comedi_pci_auto_config() - Configure/probe a comedi PCI driver.
77 * @pcidev: pci_dev struct
78 * @driver: comedi_driver struct
79 * @context: driver specific data, passed to comedi_auto_config()
81 * Typically called from the pci_driver (*probe) function.
83 int comedi_pci_auto_config(struct pci_dev
*pcidev
,
84 struct comedi_driver
*driver
,
85 unsigned long context
)
87 return comedi_auto_config(&pcidev
->dev
, driver
, context
);
89 EXPORT_SYMBOL_GPL(comedi_pci_auto_config
);
92 * comedi_pci_auto_unconfig() - Unconfigure/remove a comedi PCI driver.
93 * @pcidev: pci_dev struct
95 * Typically called from the pci_driver (*remove) function.
97 void comedi_pci_auto_unconfig(struct pci_dev
*pcidev
)
99 comedi_auto_unconfig(&pcidev
->dev
);
101 EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig
);
104 * comedi_pci_driver_register() - Register a comedi PCI driver.
105 * @comedi_driver: comedi_driver struct
106 * @pci_driver: pci_driver struct
108 * This function is used for the module_init() of comedi PCI drivers.
109 * Do not call it directly, use the module_comedi_pci_driver() helper
112 int comedi_pci_driver_register(struct comedi_driver
*comedi_driver
,
113 struct pci_driver
*pci_driver
)
117 ret
= comedi_driver_register(comedi_driver
);
121 ret
= pci_register_driver(pci_driver
);
123 comedi_driver_unregister(comedi_driver
);
129 EXPORT_SYMBOL_GPL(comedi_pci_driver_register
);
132 * comedi_pci_driver_unregister() - Unregister a comedi PCI driver.
133 * @comedi_driver: comedi_driver struct
134 * @pci_driver: pci_driver struct
136 * This function is used for the module_exit() of comedi PCI drivers.
137 * Do not call it directly, use the module_comedi_pci_driver() helper
140 void comedi_pci_driver_unregister(struct comedi_driver
*comedi_driver
,
141 struct pci_driver
*pci_driver
)
143 pci_unregister_driver(pci_driver
);
144 comedi_driver_unregister(comedi_driver
);
146 EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister
);