diff options
author | H Hartley Sweeten <hartleys@visionengravers.com> | 2012-08-16 22:55:01 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-17 11:17:36 -0400 |
commit | 22f2f541d06a874d8a5b228fca0186e333a1e351 (patch) | |
tree | 146fa32e11706b98cc82310432ce374d93be88ea | |
parent | aee815b53bca1cfa092ecd742fc59512b8030336 (diff) |
staging: comedi: cb_pcimdda: use attach_pci callback
Convert this PCI driver to use the comedi PCI auto config attach
mechanism by adding an 'attach_pci' callback function.
This driver does use an external configuration option to determine
the analog output range which is controlled by a jumper on the board.
In order to remove the legacy 'attach' callback, an assumption is made
that the jumper is in the factory setting position for +/-5V outputs.
This does not effect the operation of the board just the range info
that is returned to the user.
A sysfs method will be investigated to allow the user to change the
range.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/comedi/drivers/cb_pcimdda.c | 65 |
1 files changed, 14 insertions, 51 deletions
diff --git a/drivers/staging/comedi/drivers/cb_pcimdda.c b/drivers/staging/comedi/drivers/cb_pcimdda.c index 350c8078cded..ea96514254a1 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdda.c +++ b/drivers/staging/comedi/drivers/cb_pcimdda.c | |||
@@ -57,12 +57,7 @@ output modes on the board: | |||
57 | then issue one comedi_data_read() on any channel on the AO subdevice | 57 | then issue one comedi_data_read() on any channel on the AO subdevice |
58 | to initiate the simultaneous XFER. | 58 | to initiate the simultaneous XFER. |
59 | 59 | ||
60 | Configuration Options: | 60 | Configuration Options: not applicable, uses PCI auto config |
61 | [0] PCI bus (optional) | ||
62 | [1] PCI slot (optional) | ||
63 | [2] analog output range jumper setting | ||
64 | 0 == +/- 5 V | ||
65 | 1 == +/- 10 V | ||
66 | */ | 61 | */ |
67 | 62 | ||
68 | /* | 63 | /* |
@@ -157,47 +152,21 @@ static int cb_pcimdda_ao_rinsn(struct comedi_device *dev, | |||
157 | return insn->n; | 152 | return insn->n; |
158 | } | 153 | } |
159 | 154 | ||
160 | static struct pci_dev *cb_pcimdda_probe(struct comedi_device *dev, | 155 | static int cb_pcimdda_attach_pci(struct comedi_device *dev, |
161 | struct comedi_devconfig *it) | 156 | struct pci_dev *pcidev) |
162 | { | ||
163 | struct pci_dev *pcidev = NULL; | ||
164 | |||
165 | for_each_pci_dev(pcidev) { | ||
166 | if (pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS) | ||
167 | continue; | ||
168 | if (pcidev->device != PCI_ID_PCIM_DDA06_16) | ||
169 | continue; | ||
170 | if (it->options[0] || it->options[1]) { | ||
171 | if (pcidev->bus->number != it->options[0] || | ||
172 | PCI_SLOT(pcidev->devfn) != it->options[1]) { | ||
173 | continue; | ||
174 | } | ||
175 | } | ||
176 | |||
177 | return pcidev; | ||
178 | } | ||
179 | return NULL; | ||
180 | } | ||
181 | |||
182 | static int cb_pcimdda_attach(struct comedi_device *dev, | ||
183 | struct comedi_devconfig *it) | ||
184 | { | 157 | { |
185 | struct cb_pcimdda_private *devpriv; | 158 | struct cb_pcimdda_private *devpriv; |
186 | struct pci_dev *pcidev; | ||
187 | struct comedi_subdevice *s; | 159 | struct comedi_subdevice *s; |
188 | int ret; | 160 | int ret; |
189 | 161 | ||
162 | comedi_set_hw_dev(dev, &pcidev->dev); | ||
163 | dev->board_name = dev->driver->driver_name; | ||
164 | |||
190 | ret = alloc_private(dev, sizeof(*devpriv)); | 165 | ret = alloc_private(dev, sizeof(*devpriv)); |
191 | if (ret) | 166 | if (ret) |
192 | return ret; | 167 | return ret; |
193 | devpriv = dev->private; | 168 | devpriv = dev->private; |
194 | 169 | ||
195 | pcidev = cb_pcimdda_probe(dev, it); | ||
196 | if (!pcidev) | ||
197 | return -EIO; | ||
198 | comedi_set_hw_dev(dev, &pcidev->dev); | ||
199 | dev->board_name = dev->driver->driver_name; | ||
200 | |||
201 | ret = comedi_pci_enable(pcidev, dev->board_name); | 170 | ret = comedi_pci_enable(pcidev, dev->board_name); |
202 | if (ret) | 171 | if (ret) |
203 | return ret; | 172 | return ret; |
@@ -208,19 +177,14 @@ static int cb_pcimdda_attach(struct comedi_device *dev, | |||
208 | return ret; | 177 | return ret; |
209 | 178 | ||
210 | s = dev->subdevices + 0; | 179 | s = dev->subdevices + 0; |
211 | |||
212 | /* analog output subdevice */ | 180 | /* analog output subdevice */ |
213 | s->type = COMEDI_SUBD_AO; | 181 | s->type = COMEDI_SUBD_AO; |
214 | s->subdev_flags = SDF_WRITABLE | SDF_READABLE; | 182 | s->subdev_flags = SDF_WRITABLE | SDF_READABLE; |
215 | s->n_chan = 6; | 183 | s->n_chan = 6; |
216 | s->maxdata = 0xffff; | 184 | s->maxdata = 0xffff; |
217 | /* this is hard-coded here */ | 185 | s->range_table = &range_bipolar5; |
218 | if (it->options[2]) | 186 | s->insn_write = cb_pcimdda_ao_winsn; |
219 | s->range_table = &range_bipolar10; | 187 | s->insn_read = cb_pcimdda_ao_rinsn; |
220 | else | ||
221 | s->range_table = &range_bipolar5; | ||
222 | s->insn_write = &cb_pcimdda_ao_winsn; | ||
223 | s->insn_read = &cb_pcimdda_ao_rinsn; | ||
224 | 188 | ||
225 | s = dev->subdevices + 1; | 189 | s = dev->subdevices + 1; |
226 | /* digital i/o subdevice */ | 190 | /* digital i/o subdevice */ |
@@ -243,14 +207,13 @@ static void cb_pcimdda_detach(struct comedi_device *dev) | |||
243 | if (pcidev) { | 207 | if (pcidev) { |
244 | if (dev->iobase) | 208 | if (dev->iobase) |
245 | comedi_pci_disable(pcidev); | 209 | comedi_pci_disable(pcidev); |
246 | pci_dev_put(pcidev); | ||
247 | } | 210 | } |
248 | } | 211 | } |
249 | 212 | ||
250 | static struct comedi_driver cb_pcimdda_driver = { | 213 | static struct comedi_driver cb_pcimdda_driver = { |
251 | .driver_name = "cb_pcimdda", | 214 | .driver_name = "cb_pcimdda", |
252 | .module = THIS_MODULE, | 215 | .module = THIS_MODULE, |
253 | .attach = cb_pcimdda_attach, | 216 | .attach_pci = cb_pcimdda_attach_pci, |
254 | .detach = cb_pcimdda_detach, | 217 | .detach = cb_pcimdda_detach, |
255 | }; | 218 | }; |
256 | 219 | ||