blob: feb33f86023b0514564fcc3dc817243debf92369 [file] [log] [blame]
David Schleefed9eccb2008-11-04 20:29:31 -08001/*
2 module/drivers.c
3 functions for manipulating drivers
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 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.
21
22*/
23
24#define _GNU_SOURCE
25
26#define __NO_VERSION__
27#include "comedi_fops.h"
28#include <linux/device.h>
29#include <linux/module.h>
30#include <linux/pci.h>
Bernd Porrc28264d2008-12-08 23:30:13 +000031#include <linux/usb.h>
David Schleefed9eccb2008-11-04 20:29:31 -080032#include <linux/errno.h>
33#include <linux/kernel.h>
34#include <linux/sched.h>
35#include <linux/fcntl.h>
36#include <linux/delay.h>
37#include <linux/ioport.h>
38#include <linux/mm.h>
39#include <linux/slab.h>
David Schleefed9eccb2008-11-04 20:29:31 -080040#include <linux/highmem.h> /* for SuSE brokenness */
41#include <linux/vmalloc.h>
42#include <linux/cdev.h>
43#include <linux/dma-mapping.h>
Andrea Gelmini5617f9d2010-02-26 17:37:00 +010044#include <linux/io.h>
David Schleefed9eccb2008-11-04 20:29:31 -080045
Greg Kroah-Hartman242e7ad2010-05-03 15:20:29 -070046#include "comedidev.h"
47#include "internal.h"
48
Bill Pemberton71b5f4f2009-03-16 22:05:08 -040049static int postconfig(struct comedi_device *dev);
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +053050static int insn_rw_emulate_bits(struct comedi_device *dev,
51 struct comedi_subdevice *s,
52 struct comedi_insn *insn, unsigned int *data);
53static void *comedi_recognize(struct comedi_driver *driv, const char *name);
Bill Pemberton139dfbd2009-03-16 22:05:25 -040054static void comedi_report_boards(struct comedi_driver *driv);
Bill Pemberton34c43922009-03-16 22:05:14 -040055static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s);
David Schleefed9eccb2008-11-04 20:29:31 -080056
Bill Pemberton139dfbd2009-03-16 22:05:25 -040057struct comedi_driver *comedi_drivers;
David Schleefed9eccb2008-11-04 20:29:31 -080058
Bill Pemberton71b5f4f2009-03-16 22:05:08 -040059static void cleanup_device(struct comedi_device *dev)
David Schleefed9eccb2008-11-04 20:29:31 -080060{
61 int i;
Bill Pemberton34c43922009-03-16 22:05:14 -040062 struct comedi_subdevice *s;
David Schleefed9eccb2008-11-04 20:29:31 -080063
64 if (dev->subdevices) {
65 for (i = 0; i < dev->n_subdevices; i++) {
66 s = dev->subdevices + i;
67 comedi_free_subdevice_minor(s);
68 if (s->async) {
69 comedi_buf_alloc(dev, s, 0);
70 kfree(s->async);
71 }
72 }
73 kfree(dev->subdevices);
74 dev->subdevices = NULL;
75 dev->n_subdevices = 0;
76 }
Bill Pembertondedd1322009-03-16 22:04:18 -040077 kfree(dev->private);
78 dev->private = NULL;
Greg Kroah-Hartman7029a872010-05-03 15:55:45 -070079 dev->driver = NULL;
David Schleefed9eccb2008-11-04 20:29:31 -080080 dev->board_name = NULL;
81 dev->board_ptr = NULL;
82 dev->iobase = 0;
83 dev->irq = 0;
84 dev->read_subdev = NULL;
85 dev->write_subdev = NULL;
86 dev->open = NULL;
87 dev->close = NULL;
88 comedi_set_hw_dev(dev, NULL);
89}
90
Bill Pemberton71b5f4f2009-03-16 22:05:08 -040091static void __comedi_device_detach(struct comedi_device *dev)
David Schleefed9eccb2008-11-04 20:29:31 -080092{
93 dev->attached = 0;
Andrea Gelmini5617f9d2010-02-26 17:37:00 +010094 if (dev->driver)
David Schleefed9eccb2008-11-04 20:29:31 -080095 dev->driver->detach(dev);
Andrea Gelmini5617f9d2010-02-26 17:37:00 +010096 else
Mark Rankilor67b0e642010-05-06 17:36:38 +080097 printk(KERN_WARNING
98 "BUG: dev->driver=NULL in comedi_device_detach()\n");
David Schleefed9eccb2008-11-04 20:29:31 -080099 cleanup_device(dev);
100}
101
Bill Pemberton71b5f4f2009-03-16 22:05:08 -0400102void comedi_device_detach(struct comedi_device *dev)
David Schleefed9eccb2008-11-04 20:29:31 -0800103{
104 if (!dev->attached)
105 return;
106 __comedi_device_detach(dev);
107}
108
Bill Pemberton0707bb02009-03-16 22:06:20 -0400109int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
David Schleefed9eccb2008-11-04 20:29:31 -0800110{
Bill Pemberton139dfbd2009-03-16 22:05:25 -0400111 struct comedi_driver *driv;
David Schleefed9eccb2008-11-04 20:29:31 -0800112 int ret;
113
114 if (dev->attached)
115 return -EBUSY;
116
117 for (driv = comedi_drivers; driv; driv = driv->next) {
118 if (!try_module_get(driv->module)) {
Xenofon Foukas88ab8a82010-12-04 00:17:55 +0200119 printk(KERN_INFO "comedi: failed to increment module count, skipping\n");
David Schleefed9eccb2008-11-04 20:29:31 -0800120 continue;
121 }
122 if (driv->num_names) {
123 dev->board_ptr = comedi_recognize(driv, it->board_name);
124 if (dev->board_ptr == NULL) {
125 module_put(driv->module);
126 continue;
127 }
128 } else {
129 if (strcmp(driv->driver_name, it->board_name)) {
130 module_put(driv->module);
131 continue;
132 }
133 }
Zachary Richeyac4898a2010-04-26 07:49:37 -0400134 /* initialize dev->driver here so
135 * comedi_error() can be called from attach */
David Schleefed9eccb2008-11-04 20:29:31 -0800136 dev->driver = driv;
137 ret = driv->attach(dev, it);
138 if (ret < 0) {
139 module_put(dev->driver->module);
140 __comedi_device_detach(dev);
141 return ret;
142 }
143 goto attached;
144 }
145
Bill Pembertonb6c77752009-03-16 22:03:24 -0400146 /* recognize has failed if we get here */
147 /* report valid board names before returning error */
David Schleefed9eccb2008-11-04 20:29:31 -0800148 for (driv = comedi_drivers; driv; driv = driv->next) {
149 if (!try_module_get(driv->module)) {
Mark Rankilor67b0e642010-05-06 17:36:38 +0800150 printk(KERN_INFO
151 "comedi: failed to increment module count\n");
David Schleefed9eccb2008-11-04 20:29:31 -0800152 continue;
153 }
154 comedi_report_boards(driv);
155 module_put(driv->module);
156 }
157 return -EIO;
158
159attached:
160 /* do a little post-config cleanup */
161 ret = postconfig(dev);
162 module_put(dev->driver->module);
163 if (ret < 0) {
164 __comedi_device_detach(dev);
165 return ret;
166 }
167
168 if (!dev->board_name) {
Mark Rankiloraad40292010-05-03 18:07:36 +0800169 printk(KERN_WARNING "BUG: dev->board_name=<%p>\n",
170 dev->board_name);
David Schleefed9eccb2008-11-04 20:29:31 -0800171 dev->board_name = "BUG";
172 }
173 smp_wmb();
174 dev->attached = 1;
175
176 return 0;
177}
178
Bill Pemberton139dfbd2009-03-16 22:05:25 -0400179int comedi_driver_register(struct comedi_driver *driver)
David Schleefed9eccb2008-11-04 20:29:31 -0800180{
181 driver->next = comedi_drivers;
182 comedi_drivers = driver;
183
184 return 0;
185}
Greg Kroah-Hartmand58214b2010-05-01 11:54:07 -0700186EXPORT_SYMBOL(comedi_driver_register);
David Schleefed9eccb2008-11-04 20:29:31 -0800187
Bill Pemberton139dfbd2009-03-16 22:05:25 -0400188int comedi_driver_unregister(struct comedi_driver *driver)
David Schleefed9eccb2008-11-04 20:29:31 -0800189{
Bill Pemberton139dfbd2009-03-16 22:05:25 -0400190 struct comedi_driver *prev;
David Schleefed9eccb2008-11-04 20:29:31 -0800191 int i;
192
193 /* check for devices using this driver */
194 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530195 struct comedi_device_file_info *dev_file_info =
196 comedi_get_device_file_info(i);
Bill Pemberton71b5f4f2009-03-16 22:05:08 -0400197 struct comedi_device *dev;
David Schleefed9eccb2008-11-04 20:29:31 -0800198
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530199 if (dev_file_info == NULL)
200 continue;
David Schleefed9eccb2008-11-04 20:29:31 -0800201 dev = dev_file_info->device;
202
203 mutex_lock(&dev->mutex);
204 if (dev->attached && dev->driver == driver) {
205 if (dev->use_count)
Xenofon Foukas88ab8a82010-12-04 00:17:55 +0200206 printk(KERN_WARNING "BUG! detaching device with use_count=%d\n",
207 dev->use_count);
David Schleefed9eccb2008-11-04 20:29:31 -0800208 comedi_device_detach(dev);
209 }
210 mutex_unlock(&dev->mutex);
211 }
212
213 if (comedi_drivers == driver) {
214 comedi_drivers = driver->next;
215 return 0;
216 }
217
218 for (prev = comedi_drivers; prev->next; prev = prev->next) {
219 if (prev->next == driver) {
220 prev->next = driver->next;
221 return 0;
222 }
223 }
224 return -EINVAL;
225}
Greg Kroah-Hartmand58214b2010-05-01 11:54:07 -0700226EXPORT_SYMBOL(comedi_driver_unregister);
David Schleefed9eccb2008-11-04 20:29:31 -0800227
Bill Pemberton71b5f4f2009-03-16 22:05:08 -0400228static int postconfig(struct comedi_device *dev)
David Schleefed9eccb2008-11-04 20:29:31 -0800229{
230 int i;
Bill Pemberton34c43922009-03-16 22:05:14 -0400231 struct comedi_subdevice *s;
Bill Pembertond1636792009-03-16 22:05:20 -0400232 struct comedi_async *async = NULL;
David Schleefed9eccb2008-11-04 20:29:31 -0800233 int ret;
234
235 for (i = 0; i < dev->n_subdevices; i++) {
236 s = dev->subdevices + i;
237
238 if (s->type == COMEDI_SUBD_UNUSED)
239 continue;
240
241 if (s->len_chanlist == 0)
242 s->len_chanlist = 1;
243
244 if (s->do_cmd) {
245 BUG_ON((s->subdev_flags & (SDF_CMD_READ |
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530246 SDF_CMD_WRITE)) == 0);
David Schleefed9eccb2008-11-04 20:29:31 -0800247 BUG_ON(!s->do_cmdtest);
248
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530249 async =
250 kzalloc(sizeof(struct comedi_async), GFP_KERNEL);
David Schleefed9eccb2008-11-04 20:29:31 -0800251 if (async == NULL) {
Mark Rankilor67b0e642010-05-06 17:36:38 +0800252 printk(KERN_INFO
253 "failed to allocate async struct\n");
David Schleefed9eccb2008-11-04 20:29:31 -0800254 return -ENOMEM;
255 }
256 init_waitqueue_head(&async->wait_head);
257 async->subdevice = s;
258 s->async = async;
259
260#define DEFAULT_BUF_MAXSIZE (64*1024)
261#define DEFAULT_BUF_SIZE (64*1024)
262
263 async->max_bufsize = DEFAULT_BUF_MAXSIZE;
264
265 async->prealloc_buf = NULL;
266 async->prealloc_bufsz = 0;
267 if (comedi_buf_alloc(dev, s, DEFAULT_BUF_SIZE) < 0) {
Zachary Richeyac4898a2010-04-26 07:49:37 -0400268 printk(KERN_INFO "Buffer allocation failed\n");
David Schleefed9eccb2008-11-04 20:29:31 -0800269 return -ENOMEM;
270 }
271 if (s->buf_change) {
272 ret = s->buf_change(dev, s, DEFAULT_BUF_SIZE);
273 if (ret < 0)
274 return ret;
275 }
276 comedi_alloc_subdevice_minor(dev, s);
277 }
278
279 if (!s->range_table && !s->range_table_list)
280 s->range_table = &range_unknown;
281
282 if (!s->insn_read && s->insn_bits)
283 s->insn_read = insn_rw_emulate_bits;
284 if (!s->insn_write && s->insn_bits)
285 s->insn_write = insn_rw_emulate_bits;
286
287 if (!s->insn_read)
288 s->insn_read = insn_inval;
289 if (!s->insn_write)
290 s->insn_write = insn_inval;
291 if (!s->insn_bits)
292 s->insn_bits = insn_inval;
293 if (!s->insn_config)
294 s->insn_config = insn_inval;
295
296 if (!s->poll)
297 s->poll = poll_invalid;
298 }
299
300 return 0;
301}
302
Zachary Richeyac4898a2010-04-26 07:49:37 -0400303/* generic recognize function for drivers
304 * that register their supported board names */
Greg Kroah-Hartman7029a872010-05-03 15:55:45 -0700305static void *comedi_recognize(struct comedi_driver *driv, const char *name)
David Schleefed9eccb2008-11-04 20:29:31 -0800306{
307 unsigned i;
308 const char *const *name_ptr = driv->board_name;
309 for (i = 0; i < driv->num_names; i++) {
310 if (strcmp(*name_ptr, name) == 0)
311 return (void *)name_ptr;
312 name_ptr =
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530313 (const char *const *)((const char *)name_ptr +
314 driv->offset);
David Schleefed9eccb2008-11-04 20:29:31 -0800315 }
316
317 return NULL;
318}
319
Greg Kroah-Hartman7029a872010-05-03 15:55:45 -0700320static void comedi_report_boards(struct comedi_driver *driv)
David Schleefed9eccb2008-11-04 20:29:31 -0800321{
322 unsigned int i;
323 const char *const *name_ptr;
324
Zachary Richeyac4898a2010-04-26 07:49:37 -0400325 printk(KERN_INFO "comedi: valid board names for %s driver are:\n",
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530326 driv->driver_name);
David Schleefed9eccb2008-11-04 20:29:31 -0800327
328 name_ptr = driv->board_name;
329 for (i = 0; i < driv->num_names; i++) {
Zachary Richeyac4898a2010-04-26 07:49:37 -0400330 printk(KERN_INFO " %s\n", *name_ptr);
David Schleefed9eccb2008-11-04 20:29:31 -0800331 name_ptr = (const char **)((char *)name_ptr + driv->offset);
332 }
333
334 if (driv->num_names == 0)
Zachary Richeyac4898a2010-04-26 07:49:37 -0400335 printk(KERN_INFO " %s\n", driv->driver_name);
David Schleefed9eccb2008-11-04 20:29:31 -0800336}
337
Bill Pemberton34c43922009-03-16 22:05:14 -0400338static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s)
David Schleefed9eccb2008-11-04 20:29:31 -0800339{
340 return -EINVAL;
341}
342
Bill Pemberton34c43922009-03-16 22:05:14 -0400343int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530344 struct comedi_insn *insn, unsigned int *data)
David Schleefed9eccb2008-11-04 20:29:31 -0800345{
346 return -EINVAL;
347}
348
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530349static int insn_rw_emulate_bits(struct comedi_device *dev,
350 struct comedi_subdevice *s,
351 struct comedi_insn *insn, unsigned int *data)
David Schleefed9eccb2008-11-04 20:29:31 -0800352{
Bill Pemberton90035c02009-03-16 22:05:53 -0400353 struct comedi_insn new_insn;
David Schleefed9eccb2008-11-04 20:29:31 -0800354 int ret;
355 static const unsigned channels_per_bitfield = 32;
356
357 unsigned chan = CR_CHAN(insn->chanspec);
358 const unsigned base_bitfield_channel =
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530359 (chan < channels_per_bitfield) ? 0 : chan;
Bill Pemberton790c5542009-03-16 22:05:02 -0400360 unsigned int new_data[2];
David Schleefed9eccb2008-11-04 20:29:31 -0800361 memset(new_data, 0, sizeof(new_data));
362 memset(&new_insn, 0, sizeof(new_insn));
363 new_insn.insn = INSN_BITS;
364 new_insn.chanspec = base_bitfield_channel;
365 new_insn.n = 2;
366 new_insn.data = new_data;
367 new_insn.subdev = insn->subdev;
368
369 if (insn->insn == INSN_WRITE) {
370 if (!(s->subdev_flags & SDF_WRITABLE))
371 return -EINVAL;
Mark Rankiloraad40292010-05-03 18:07:36 +0800372 new_data[0] = 1 << (chan - base_bitfield_channel); /* mask */
373 new_data[1] = data[0] ? (1 << (chan - base_bitfield_channel))
374 : 0; /* bits */
David Schleefed9eccb2008-11-04 20:29:31 -0800375 }
376
377 ret = s->insn_bits(dev, s, &new_insn, new_data);
378 if (ret < 0)
379 return ret;
380
Andrea Gelmini5617f9d2010-02-26 17:37:00 +0100381 if (insn->insn == INSN_READ)
David Schleefed9eccb2008-11-04 20:29:31 -0800382 data[0] = (new_data[1] >> (chan - base_bitfield_channel)) & 1;
David Schleefed9eccb2008-11-04 20:29:31 -0800383
384 return 1;
385}
386
Mithlesh Thukrald43d27a2009-09-21 11:53:27 -0700387static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr)
David Schleefed9eccb2008-11-04 20:29:31 -0800388{
389 unsigned long ret = 0UL;
390 pmd_t *pmd;
391 pte_t *ptep, pte;
392 pud_t *pud;
393
394 if (!pgd_none(*pgd)) {
395 pud = pud_offset(pgd, adr);
396 pmd = pmd_offset(pud, adr);
397 if (!pmd_none(*pmd)) {
398 ptep = pte_offset_kernel(pmd, adr);
399 pte = *ptep;
400 if (pte_present(pte)) {
401 ret = (unsigned long)
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530402 page_address(pte_page(pte));
David Schleefed9eccb2008-11-04 20:29:31 -0800403 ret |= (adr & (PAGE_SIZE - 1));
404 }
405 }
406 }
407 return ret;
408}
409
410static inline unsigned long kvirt_to_kva(unsigned long adr)
411{
412 unsigned long va, kva;
413
414 va = adr;
415 kva = uvirt_to_kva(pgd_offset_k(va), va);
416
417 return kva;
418}
419
Bill Pemberton34c43922009-03-16 22:05:14 -0400420int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530421 unsigned long new_size)
David Schleefed9eccb2008-11-04 20:29:31 -0800422{
Bill Pembertond1636792009-03-16 22:05:20 -0400423 struct comedi_async *async = s->async;
David Schleefed9eccb2008-11-04 20:29:31 -0800424
425 /* Round up new_size to multiple of PAGE_SIZE */
426 new_size = (new_size + PAGE_SIZE - 1) & PAGE_MASK;
427
428 /* if no change is required, do nothing */
Andrea Gelmini5617f9d2010-02-26 17:37:00 +0100429 if (async->prealloc_buf && async->prealloc_bufsz == new_size)
David Schleefed9eccb2008-11-04 20:29:31 -0800430 return 0;
Andrea Gelmini5617f9d2010-02-26 17:37:00 +0100431
Bill Pembertonb6c77752009-03-16 22:03:24 -0400432 /* deallocate old buffer */
David Schleefed9eccb2008-11-04 20:29:31 -0800433 if (async->prealloc_buf) {
434 vunmap(async->prealloc_buf);
435 async->prealloc_buf = NULL;
436 async->prealloc_bufsz = 0;
437 }
438 if (async->buf_page_list) {
439 unsigned i;
440 for (i = 0; i < async->n_buf_pages; ++i) {
441 if (async->buf_page_list[i].virt_addr) {
Xenofon Foukas88ab8a82010-12-04 00:17:55 +0200442 clear_bit(PG_reserved,
443 &(virt_to_page(async->buf_page_list[i].
444 virt_addr)->flags));
David Schleefed9eccb2008-11-04 20:29:31 -0800445 if (s->async_dma_dir != DMA_NONE) {
446 dma_free_coherent(dev->hw_dev,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530447 PAGE_SIZE,
448 async->
449 buf_page_list
450 [i].virt_addr,
451 async->
452 buf_page_list
453 [i].dma_addr);
David Schleefed9eccb2008-11-04 20:29:31 -0800454 } else {
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530455 free_page((unsigned long)
456 async->buf_page_list[i].
457 virt_addr);
David Schleefed9eccb2008-11-04 20:29:31 -0800458 }
459 }
460 }
461 vfree(async->buf_page_list);
462 async->buf_page_list = NULL;
463 async->n_buf_pages = 0;
464 }
Bill Pembertonb6c77752009-03-16 22:03:24 -0400465 /* allocate new buffer */
David Schleefed9eccb2008-11-04 20:29:31 -0800466 if (new_size) {
467 unsigned i = 0;
468 unsigned n_pages = new_size >> PAGE_SHIFT;
469 struct page **pages = NULL;
470
471 async->buf_page_list =
Joe Perches5b84cc72010-11-04 20:07:59 -0700472 vzalloc(sizeof(struct comedi_buf_page) * n_pages);
Micha Hergarden3ad4e212011-02-02 21:25:07 +0100473 if (async->buf_page_list)
David Schleefed9eccb2008-11-04 20:29:31 -0800474 pages = vmalloc(sizeof(struct page *) * n_pages);
Micha Hergarden3ad4e212011-02-02 21:25:07 +0100475
David Schleefed9eccb2008-11-04 20:29:31 -0800476 if (pages) {
477 for (i = 0; i < n_pages; i++) {
478 if (s->async_dma_dir != DMA_NONE) {
479 async->buf_page_list[i].virt_addr =
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530480 dma_alloc_coherent(dev->hw_dev,
481 PAGE_SIZE,
482 &async->
483 buf_page_list
484 [i].dma_addr,
485 GFP_KERNEL |
486 __GFP_COMP);
David Schleefed9eccb2008-11-04 20:29:31 -0800487 } else {
488 async->buf_page_list[i].virt_addr =
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530489 (void *)
490 get_zeroed_page(GFP_KERNEL);
David Schleefed9eccb2008-11-04 20:29:31 -0800491 }
Andrea Gelmini5617f9d2010-02-26 17:37:00 +0100492 if (async->buf_page_list[i].virt_addr == NULL)
David Schleefed9eccb2008-11-04 20:29:31 -0800493 break;
Andrea Gelmini5617f9d2010-02-26 17:37:00 +0100494
Greg Kroah-Hartmanbe29eac2010-04-30 15:55:39 -0700495 set_bit(PG_reserved,
Xenofon Foukas88ab8a82010-12-04 00:17:55 +0200496 &(virt_to_page(async->buf_page_list[i].
497 virt_addr)->flags));
498 pages[i] = virt_to_page(async->buf_page_list[i].
499 virt_addr);
David Schleefed9eccb2008-11-04 20:29:31 -0800500 }
501 }
502 if (i == n_pages) {
503 async->prealloc_buf =
Greg Kroah-Hartman408093d2011-06-09 12:13:08 -0700504#ifdef PAGE_KERNEL_NOCACHE
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530505 vmap(pages, n_pages, VM_MAP, PAGE_KERNEL_NOCACHE);
Greg Kroah-Hartman408093d2011-06-09 12:13:08 -0700506#else
507 vmap(pages, n_pages, VM_MAP, PAGE_KERNEL);
508#endif
David Schleefed9eccb2008-11-04 20:29:31 -0800509 }
Figo.zhangb4550732009-06-06 19:11:31 +0800510 vfree(pages);
511
David Schleefed9eccb2008-11-04 20:29:31 -0800512 if (async->prealloc_buf == NULL) {
513 /* Some allocation failed above. */
514 if (async->buf_page_list) {
515 for (i = 0; i < n_pages; i++) {
516 if (async->buf_page_list[i].virt_addr ==
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530517 NULL) {
David Schleefed9eccb2008-11-04 20:29:31 -0800518 break;
519 }
Xenofon Foukas88ab8a82010-12-04 00:17:55 +0200520 clear_bit(PG_reserved,
521 &(virt_to_page(async->
522 buf_page_list[i].
523 virt_addr)->flags));
David Schleefed9eccb2008-11-04 20:29:31 -0800524 if (s->async_dma_dir != DMA_NONE) {
525 dma_free_coherent(dev->hw_dev,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530526 PAGE_SIZE,
527 async->
528 buf_page_list
529 [i].virt_addr,
530 async->
531 buf_page_list
532 [i].dma_addr);
David Schleefed9eccb2008-11-04 20:29:31 -0800533 } else {
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530534 free_page((unsigned long)
535 async->buf_page_list
536 [i].virt_addr);
David Schleefed9eccb2008-11-04 20:29:31 -0800537 }
538 }
539 vfree(async->buf_page_list);
540 async->buf_page_list = NULL;
541 }
542 return -ENOMEM;
543 }
544 async->n_buf_pages = n_pages;
545 }
546 async->prealloc_bufsz = new_size;
547
548 return 0;
549}
550
551/* munging is applied to data by core as it passes between user
552 * and kernel space */
Greg Kroah-Hartman7029a872010-05-03 15:55:45 -0700553static unsigned int comedi_buf_munge(struct comedi_async *async,
554 unsigned int num_bytes)
David Schleefed9eccb2008-11-04 20:29:31 -0800555{
Bill Pemberton34c43922009-03-16 22:05:14 -0400556 struct comedi_subdevice *s = async->subdevice;
David Schleefed9eccb2008-11-04 20:29:31 -0800557 unsigned int count = 0;
558 const unsigned num_sample_bytes = bytes_per_sample(s);
559
560 if (s->munge == NULL || (async->cmd.flags & CMDF_RAWDATA)) {
561 async->munge_count += num_bytes;
Stoyan Gaydarov2961f242009-03-10 00:10:27 -0500562 BUG_ON((int)(async->munge_count - async->buf_write_count) > 0);
David Schleefed9eccb2008-11-04 20:29:31 -0800563 return num_bytes;
564 }
565 /* don't munge partial samples */
566 num_bytes -= num_bytes % num_sample_bytes;
567 while (count < num_bytes) {
568 int block_size;
569
570 block_size = num_bytes - count;
571 if (block_size < 0) {
Mark Rankilor67b0e642010-05-06 17:36:38 +0800572 printk(KERN_WARNING
573 "%s: %s: bug! block_size is negative\n",
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530574 __FILE__, __func__);
David Schleefed9eccb2008-11-04 20:29:31 -0800575 break;
576 }
577 if ((int)(async->munge_ptr + block_size -
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530578 async->prealloc_bufsz) > 0)
David Schleefed9eccb2008-11-04 20:29:31 -0800579 block_size = async->prealloc_bufsz - async->munge_ptr;
580
581 s->munge(s->device, s, async->prealloc_buf + async->munge_ptr,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530582 block_size, async->munge_chan);
David Schleefed9eccb2008-11-04 20:29:31 -0800583
Zachary Richeyac4898a2010-04-26 07:49:37 -0400584 smp_wmb(); /* barrier insures data is munged in buffer
585 * before munge_count is incremented */
David Schleefed9eccb2008-11-04 20:29:31 -0800586
587 async->munge_chan += block_size / num_sample_bytes;
588 async->munge_chan %= async->cmd.chanlist_len;
589 async->munge_count += block_size;
590 async->munge_ptr += block_size;
591 async->munge_ptr %= async->prealloc_bufsz;
592 count += block_size;
593 }
Stoyan Gaydarov2961f242009-03-10 00:10:27 -0500594 BUG_ON((int)(async->munge_count - async->buf_write_count) > 0);
David Schleefed9eccb2008-11-04 20:29:31 -0800595 return count;
596}
597
Bill Pembertond1636792009-03-16 22:05:20 -0400598unsigned int comedi_buf_write_n_available(struct comedi_async *async)
David Schleefed9eccb2008-11-04 20:29:31 -0800599{
600 unsigned int free_end;
601 unsigned int nbytes;
602
603 if (async == NULL)
604 return 0;
605
606 free_end = async->buf_read_count + async->prealloc_bufsz;
607 nbytes = free_end - async->buf_write_alloc_count;
608 nbytes -= nbytes % bytes_per_sample(async->subdevice);
609 /* barrier insures the read of buf_read_count in this
610 query occurs before any following writes to the buffer which
611 might be based on the return value from this query.
612 */
613 smp_mb();
614 return nbytes;
615}
616
617/* allocates chunk for the writer from free buffer space */
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530618unsigned int comedi_buf_write_alloc(struct comedi_async *async,
619 unsigned int nbytes)
David Schleefed9eccb2008-11-04 20:29:31 -0800620{
621 unsigned int free_end = async->buf_read_count + async->prealloc_bufsz;
622
Andrea Gelmini5617f9d2010-02-26 17:37:00 +0100623 if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0)
David Schleefed9eccb2008-11-04 20:29:31 -0800624 nbytes = free_end - async->buf_write_alloc_count;
Andrea Gelmini5617f9d2010-02-26 17:37:00 +0100625
David Schleefed9eccb2008-11-04 20:29:31 -0800626 async->buf_write_alloc_count += nbytes;
627 /* barrier insures the read of buf_read_count above occurs before
628 we write data to the write-alloc'ed buffer space */
629 smp_mb();
630 return nbytes;
631}
Greg Kroah-Hartmand58214b2010-05-01 11:54:07 -0700632EXPORT_SYMBOL(comedi_buf_write_alloc);
David Schleefed9eccb2008-11-04 20:29:31 -0800633
634/* allocates nothing unless it can completely fulfill the request */
Bill Pembertond1636792009-03-16 22:05:20 -0400635unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530636 unsigned int nbytes)
David Schleefed9eccb2008-11-04 20:29:31 -0800637{
638 unsigned int free_end = async->buf_read_count + async->prealloc_bufsz;
639
Andrea Gelmini5617f9d2010-02-26 17:37:00 +0100640 if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0)
David Schleefed9eccb2008-11-04 20:29:31 -0800641 nbytes = 0;
Andrea Gelmini5617f9d2010-02-26 17:37:00 +0100642
David Schleefed9eccb2008-11-04 20:29:31 -0800643 async->buf_write_alloc_count += nbytes;
644 /* barrier insures the read of buf_read_count above occurs before
645 we write data to the write-alloc'ed buffer space */
646 smp_mb();
647 return nbytes;
648}
649
650/* transfers a chunk from writer to filled buffer space */
Bill Pembertond1636792009-03-16 22:05:20 -0400651unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes)
David Schleefed9eccb2008-11-04 20:29:31 -0800652{
653 if ((int)(async->buf_write_count + nbytes -
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530654 async->buf_write_alloc_count) > 0) {
Xenofon Foukas88ab8a82010-12-04 00:17:55 +0200655 printk(KERN_INFO "comedi: attempted to write-free more bytes than have been write-allocated.\n");
David Schleefed9eccb2008-11-04 20:29:31 -0800656 nbytes = async->buf_write_alloc_count - async->buf_write_count;
657 }
658 async->buf_write_count += nbytes;
659 async->buf_write_ptr += nbytes;
660 comedi_buf_munge(async, async->buf_write_count - async->munge_count);
Andrea Gelmini5617f9d2010-02-26 17:37:00 +0100661 if (async->buf_write_ptr >= async->prealloc_bufsz)
David Schleefed9eccb2008-11-04 20:29:31 -0800662 async->buf_write_ptr %= async->prealloc_bufsz;
Andrea Gelmini5617f9d2010-02-26 17:37:00 +0100663
David Schleefed9eccb2008-11-04 20:29:31 -0800664 return nbytes;
665}
Greg Kroah-Hartmand58214b2010-05-01 11:54:07 -0700666EXPORT_SYMBOL(comedi_buf_write_free);
David Schleefed9eccb2008-11-04 20:29:31 -0800667
668/* allocates a chunk for the reader from filled (and munged) buffer space */
Bill Pembertond1636792009-03-16 22:05:20 -0400669unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes)
David Schleefed9eccb2008-11-04 20:29:31 -0800670{
671 if ((int)(async->buf_read_alloc_count + nbytes - async->munge_count) >
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530672 0) {
David Schleefed9eccb2008-11-04 20:29:31 -0800673 nbytes = async->munge_count - async->buf_read_alloc_count;
674 }
675 async->buf_read_alloc_count += nbytes;
676 /* barrier insures read of munge_count occurs before we actually read
677 data out of buffer */
678 smp_rmb();
679 return nbytes;
680}
Greg Kroah-Hartmand58214b2010-05-01 11:54:07 -0700681EXPORT_SYMBOL(comedi_buf_read_alloc);
David Schleefed9eccb2008-11-04 20:29:31 -0800682
683/* transfers control of a chunk from reader to free buffer space */
Bill Pembertond1636792009-03-16 22:05:20 -0400684unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes)
David Schleefed9eccb2008-11-04 20:29:31 -0800685{
Zachary Richeyac4898a2010-04-26 07:49:37 -0400686 /* barrier insures data has been read out of
687 * buffer before read count is incremented */
David Schleefed9eccb2008-11-04 20:29:31 -0800688 smp_mb();
689 if ((int)(async->buf_read_count + nbytes -
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530690 async->buf_read_alloc_count) > 0) {
Mark Rankilor67b0e642010-05-06 17:36:38 +0800691 printk(KERN_INFO
692 "comedi: attempted to read-free more bytes than have been read-allocated.\n");
David Schleefed9eccb2008-11-04 20:29:31 -0800693 nbytes = async->buf_read_alloc_count - async->buf_read_count;
694 }
695 async->buf_read_count += nbytes;
696 async->buf_read_ptr += nbytes;
697 async->buf_read_ptr %= async->prealloc_bufsz;
698 return nbytes;
699}
Greg Kroah-Hartmand58214b2010-05-01 11:54:07 -0700700EXPORT_SYMBOL(comedi_buf_read_free);
David Schleefed9eccb2008-11-04 20:29:31 -0800701
Bill Pembertond1636792009-03-16 22:05:20 -0400702void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530703 const void *data, unsigned int num_bytes)
David Schleefed9eccb2008-11-04 20:29:31 -0800704{
705 unsigned int write_ptr = async->buf_write_ptr + offset;
706
707 if (write_ptr >= async->prealloc_bufsz)
708 write_ptr %= async->prealloc_bufsz;
709
710 while (num_bytes) {
711 unsigned int block_size;
712
713 if (write_ptr + num_bytes > async->prealloc_bufsz)
714 block_size = async->prealloc_bufsz - write_ptr;
715 else
716 block_size = num_bytes;
717
718 memcpy(async->prealloc_buf + write_ptr, data, block_size);
719
720 data += block_size;
721 num_bytes -= block_size;
722
723 write_ptr = 0;
724 }
725}
Greg Kroah-Hartmand58214b2010-05-01 11:54:07 -0700726EXPORT_SYMBOL(comedi_buf_memcpy_to);
David Schleefed9eccb2008-11-04 20:29:31 -0800727
Bill Pembertond1636792009-03-16 22:05:20 -0400728void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530729 void *dest, unsigned int nbytes)
David Schleefed9eccb2008-11-04 20:29:31 -0800730{
731 void *src;
732 unsigned int read_ptr = async->buf_read_ptr + offset;
733
734 if (read_ptr >= async->prealloc_bufsz)
735 read_ptr %= async->prealloc_bufsz;
736
737 while (nbytes) {
738 unsigned int block_size;
739
740 src = async->prealloc_buf + read_ptr;
741
742 if (nbytes >= async->prealloc_bufsz - read_ptr)
743 block_size = async->prealloc_bufsz - read_ptr;
744 else
745 block_size = nbytes;
746
747 memcpy(dest, src, block_size);
748 nbytes -= block_size;
749 dest += block_size;
750 read_ptr = 0;
751 }
752}
Greg Kroah-Hartmand58214b2010-05-01 11:54:07 -0700753EXPORT_SYMBOL(comedi_buf_memcpy_from);
David Schleefed9eccb2008-11-04 20:29:31 -0800754
Bill Pembertond1636792009-03-16 22:05:20 -0400755unsigned int comedi_buf_read_n_available(struct comedi_async *async)
David Schleefed9eccb2008-11-04 20:29:31 -0800756{
757 unsigned num_bytes;
758
759 if (async == NULL)
760 return 0;
761 num_bytes = async->munge_count - async->buf_read_count;
762 /* barrier insures the read of munge_count in this
763 query occurs before any following reads of the buffer which
764 might be based on the return value from this query.
765 */
766 smp_rmb();
767 return num_bytes;
768}
Greg Kroah-Hartmand58214b2010-05-01 11:54:07 -0700769EXPORT_SYMBOL(comedi_buf_read_n_available);
David Schleefed9eccb2008-11-04 20:29:31 -0800770
Bill Pembertond1636792009-03-16 22:05:20 -0400771int comedi_buf_get(struct comedi_async *async, short *x)
David Schleefed9eccb2008-11-04 20:29:31 -0800772{
773 unsigned int n = comedi_buf_read_n_available(async);
774
Bill Pemberton790c5542009-03-16 22:05:02 -0400775 if (n < sizeof(short))
David Schleefed9eccb2008-11-04 20:29:31 -0800776 return 0;
Bill Pemberton790c5542009-03-16 22:05:02 -0400777 comedi_buf_read_alloc(async, sizeof(short));
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530778 *x = *(short *)(async->prealloc_buf + async->buf_read_ptr);
Bill Pemberton790c5542009-03-16 22:05:02 -0400779 comedi_buf_read_free(async, sizeof(short));
David Schleefed9eccb2008-11-04 20:29:31 -0800780 return 1;
781}
Greg Kroah-Hartmand58214b2010-05-01 11:54:07 -0700782EXPORT_SYMBOL(comedi_buf_get);
David Schleefed9eccb2008-11-04 20:29:31 -0800783
Bill Pembertond1636792009-03-16 22:05:20 -0400784int comedi_buf_put(struct comedi_async *async, short x)
David Schleefed9eccb2008-11-04 20:29:31 -0800785{
Bill Pemberton790c5542009-03-16 22:05:02 -0400786 unsigned int n = comedi_buf_write_alloc_strict(async, sizeof(short));
David Schleefed9eccb2008-11-04 20:29:31 -0800787
Bill Pemberton790c5542009-03-16 22:05:02 -0400788 if (n < sizeof(short)) {
David Schleefed9eccb2008-11-04 20:29:31 -0800789 async->events |= COMEDI_CB_ERROR;
790 return 0;
791 }
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530792 *(short *)(async->prealloc_buf + async->buf_write_ptr) = x;
Bill Pemberton790c5542009-03-16 22:05:02 -0400793 comedi_buf_write_free(async, sizeof(short));
David Schleefed9eccb2008-11-04 20:29:31 -0800794 return 1;
795}
Greg Kroah-Hartmand58214b2010-05-01 11:54:07 -0700796EXPORT_SYMBOL(comedi_buf_put);
David Schleefed9eccb2008-11-04 20:29:31 -0800797
Bill Pembertond1636792009-03-16 22:05:20 -0400798void comedi_reset_async_buf(struct comedi_async *async)
David Schleefed9eccb2008-11-04 20:29:31 -0800799{
800 async->buf_write_alloc_count = 0;
801 async->buf_write_count = 0;
802 async->buf_read_alloc_count = 0;
803 async->buf_read_count = 0;
804
805 async->buf_write_ptr = 0;
806 async->buf_read_ptr = 0;
807
808 async->cur_chan = 0;
809 async->scan_progress = 0;
810 async->munge_chan = 0;
811 async->munge_count = 0;
812 async->munge_ptr = 0;
813
814 async->events = 0;
815}
816
Greg Kroah-Hartman7029a872010-05-03 15:55:45 -0700817static int comedi_auto_config(struct device *hardware_device,
818 const char *board_name, const int *options,
819 unsigned num_options)
David Schleefed9eccb2008-11-04 20:29:31 -0800820{
Bill Pemberton0707bb02009-03-16 22:06:20 -0400821 struct comedi_devconfig it;
David Schleefed9eccb2008-11-04 20:29:31 -0800822 int minor;
823 struct comedi_device_file_info *dev_file_info;
824 int retval;
825
Ian Abbottc43435d2012-03-30 17:14:58 +0100826 if (!comedi_autoconfig)
Ian Abbott719548e2008-12-09 11:07:22 +0000827 return 0;
Ian Abbott6a9d7a22008-12-08 17:05:50 +0000828
David Schleefed9eccb2008-11-04 20:29:31 -0800829 minor = comedi_alloc_board_minor(hardware_device);
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530830 if (minor < 0)
831 return minor;
Bernd Porrc28264d2008-12-08 23:30:13 +0000832
David Schleefed9eccb2008-11-04 20:29:31 -0800833 dev_file_info = comedi_get_device_file_info(minor);
834
835 memset(&it, 0, sizeof(it));
836 strncpy(it.board_name, board_name, COMEDI_NAMELEN);
837 it.board_name[COMEDI_NAMELEN - 1] = '\0';
838 BUG_ON(num_options > COMEDI_NDEVCONFOPTS);
839 memcpy(it.options, options, num_options * sizeof(int));
840
841 mutex_lock(&dev_file_info->device->mutex);
842 retval = comedi_device_attach(dev_file_info->device, &it);
843 mutex_unlock(&dev_file_info->device->mutex);
Bernd Porrc28264d2008-12-08 23:30:13 +0000844
Ian Abbottc43435d2012-03-30 17:14:58 +0100845 if (retval < 0)
David Schleefed9eccb2008-11-04 20:29:31 -0800846 comedi_free_board_minor(minor);
David Schleefed9eccb2008-11-04 20:29:31 -0800847 return retval;
848}
849
Greg Kroah-Hartman7029a872010-05-03 15:55:45 -0700850static void comedi_auto_unconfig(struct device *hardware_device)
David Schleefed9eccb2008-11-04 20:29:31 -0800851{
Ian Abbottc43435d2012-03-30 17:14:58 +0100852 int minor;
853
854 if (hardware_device == NULL)
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530855 return;
Ian Abbottc43435d2012-03-30 17:14:58 +0100856 minor = comedi_find_board_minor(hardware_device);
857 if (minor < 0)
858 return;
859 BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
860 comedi_free_board_minor(minor);
David Schleefed9eccb2008-11-04 20:29:31 -0800861}
862
Ian Abbott4c093a62012-03-30 17:14:56 +0100863int comedi_pci_auto_config(struct pci_dev *pcidev, struct comedi_driver *driver)
David Schleefed9eccb2008-11-04 20:29:31 -0800864{
865 int options[2];
866
Bill Pembertonb6c77752009-03-16 22:03:24 -0400867 /* pci bus */
David Schleefed9eccb2008-11-04 20:29:31 -0800868 options[0] = pcidev->bus->number;
Bill Pembertonb6c77752009-03-16 22:03:24 -0400869 /* pci slot */
David Schleefed9eccb2008-11-04 20:29:31 -0800870 options[1] = PCI_SLOT(pcidev->devfn);
871
Ian Abbott4c093a62012-03-30 17:14:56 +0100872 return comedi_auto_config(&pcidev->dev, driver->driver_name,
Bill Pemberton8629efa2009-04-23 15:54:56 -0400873 options, ARRAY_SIZE(options));
David Schleefed9eccb2008-11-04 20:29:31 -0800874}
Greg Kroah-Hartman4bf93552010-05-01 12:38:02 -0700875EXPORT_SYMBOL_GPL(comedi_pci_auto_config);
David Schleefed9eccb2008-11-04 20:29:31 -0800876
877void comedi_pci_auto_unconfig(struct pci_dev *pcidev)
878{
879 comedi_auto_unconfig(&pcidev->dev);
880}
Greg Kroah-Hartman4bf93552010-05-01 12:38:02 -0700881EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig);
Bernd Porrc28264d2008-12-08 23:30:13 +0000882
Ian Abbottd8b6ca02012-03-30 17:14:59 +0100883int comedi_usb_auto_config(struct usb_interface *intf,
Ian Abbott4c093a62012-03-30 17:14:56 +0100884 struct comedi_driver *driver)
Bernd Porrc28264d2008-12-08 23:30:13 +0000885{
Ian Abbottd8b6ca02012-03-30 17:14:59 +0100886 BUG_ON(intf == NULL);
887 return comedi_auto_config(&intf->dev, driver->driver_name, NULL, 0);
Bernd Porrc28264d2008-12-08 23:30:13 +0000888}
Greg Kroah-Hartman4bf93552010-05-01 12:38:02 -0700889EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
Bernd Porrc28264d2008-12-08 23:30:13 +0000890
Ian Abbottd8b6ca02012-03-30 17:14:59 +0100891void comedi_usb_auto_unconfig(struct usb_interface *intf)
Bernd Porrc28264d2008-12-08 23:30:13 +0000892{
Ian Abbottd8b6ca02012-03-30 17:14:59 +0100893 BUG_ON(intf == NULL);
894 comedi_auto_unconfig(&intf->dev);
Bernd Porrc28264d2008-12-08 23:30:13 +0000895}
Greg Kroah-Hartman4bf93552010-05-01 12:38:02 -0700896EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);