staging: comedi: remove FSF address from boilerplate text
[deliverable/linux.git] / drivers / staging / comedi / comedi_pci.c
1 /*
2 * comedi_pci.c
3 * Comedi PCI 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.
17 */
18
19 #include <linux/pci.h>
20
21 #include "comedidev.h"
22
23 /**
24 * comedi_to_pci_dev() - comedi_device pointer to pci_dev pointer.
25 * @dev: comedi_device struct
26 */
27 struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
28 {
29 return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL;
30 }
31 EXPORT_SYMBOL_GPL(comedi_to_pci_dev);
32
33 /**
34 * comedi_pci_enable() - Enable the PCI device and request the regions.
35 * @dev: comedi_device struct
36 */
37 int comedi_pci_enable(struct comedi_device *dev)
38 {
39 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
40 int rc;
41
42 if (!pcidev)
43 return -ENODEV;
44
45 rc = pci_enable_device(pcidev);
46 if (rc < 0)
47 return rc;
48
49 rc = pci_request_regions(pcidev, dev->board_name);
50 if (rc < 0)
51 pci_disable_device(pcidev);
52 else
53 dev->ioenabled = true;
54
55 return rc;
56 }
57 EXPORT_SYMBOL_GPL(comedi_pci_enable);
58
59 /**
60 * comedi_pci_disable() - Release the regions and disable the PCI device.
61 * @dev: comedi_device struct
62 */
63 void comedi_pci_disable(struct comedi_device *dev)
64 {
65 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
66
67 if (pcidev && dev->ioenabled) {
68 pci_release_regions(pcidev);
69 pci_disable_device(pcidev);
70 }
71 dev->ioenabled = false;
72 }
73 EXPORT_SYMBOL_GPL(comedi_pci_disable);
74
75 /**
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()
80 *
81 * Typically called from the pci_driver (*probe) function.
82 */
83 int comedi_pci_auto_config(struct pci_dev *pcidev,
84 struct comedi_driver *driver,
85 unsigned long context)
86 {
87 return comedi_auto_config(&pcidev->dev, driver, context);
88 }
89 EXPORT_SYMBOL_GPL(comedi_pci_auto_config);
90
91 /**
92 * comedi_pci_auto_unconfig() - Unconfigure/remove a comedi PCI driver.
93 * @pcidev: pci_dev struct
94 *
95 * Typically called from the pci_driver (*remove) function.
96 */
97 void comedi_pci_auto_unconfig(struct pci_dev *pcidev)
98 {
99 comedi_auto_unconfig(&pcidev->dev);
100 }
101 EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig);
102
103 /**
104 * comedi_pci_driver_register() - Register a comedi PCI driver.
105 * @comedi_driver: comedi_driver struct
106 * @pci_driver: pci_driver struct
107 *
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
110 * macro instead.
111 */
112 int comedi_pci_driver_register(struct comedi_driver *comedi_driver,
113 struct pci_driver *pci_driver)
114 {
115 int ret;
116
117 ret = comedi_driver_register(comedi_driver);
118 if (ret < 0)
119 return ret;
120
121 ret = pci_register_driver(pci_driver);
122 if (ret < 0) {
123 comedi_driver_unregister(comedi_driver);
124 return ret;
125 }
126
127 return 0;
128 }
129 EXPORT_SYMBOL_GPL(comedi_pci_driver_register);
130
131 /**
132 * comedi_pci_driver_unregister() - Unregister a comedi PCI driver.
133 * @comedi_driver: comedi_driver struct
134 * @pci_driver: pci_driver struct
135 *
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
138 * macro instead.
139 */
140 void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver,
141 struct pci_driver *pci_driver)
142 {
143 pci_unregister_driver(pci_driver);
144 comedi_driver_unregister(comedi_driver);
145 }
146 EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister);
This page took 0.037884 seconds and 5 git commands to generate.