3 functions for manipulating drivers
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.
26 #define __NO_VERSION__
27 #include "comedi_fops.h"
28 #include <linux/device.h>
29 #include <linux/module.h>
30 #include <linux/pci.h>
31 #include <linux/usb.h>
32 #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>
39 #include <linux/slab.h>
40 #include <linux/highmem.h> /* for SuSE brokenness */
41 #include <linux/vmalloc.h>
42 #include <linux/cdev.h>
43 #include <linux/dma-mapping.h>
45 #include <asm/system.h>
47 #include "comedidev.h"
50 static int postconfig(struct comedi_device
*dev
);
51 static int insn_rw_emulate_bits(struct comedi_device
*dev
,
52 struct comedi_subdevice
*s
,
53 struct comedi_insn
*insn
, unsigned int *data
);
54 static void *comedi_recognize(struct comedi_driver
*driv
, const char *name
);
55 static void comedi_report_boards(struct comedi_driver
*driv
);
56 static int poll_invalid(struct comedi_device
*dev
, struct comedi_subdevice
*s
);
58 struct comedi_driver
*comedi_drivers
;
60 static void cleanup_device(struct comedi_device
*dev
)
63 struct comedi_subdevice
*s
;
65 if (dev
->subdevices
) {
66 for (i
= 0; i
< dev
->n_subdevices
; i
++) {
67 s
= dev
->subdevices
+ i
;
68 comedi_free_subdevice_minor(s
);
70 comedi_buf_alloc(dev
, s
, 0);
74 kfree(dev
->subdevices
);
75 dev
->subdevices
= NULL
;
76 dev
->n_subdevices
= 0;
81 dev
->board_name
= NULL
;
82 dev
->board_ptr
= NULL
;
85 dev
->read_subdev
= NULL
;
86 dev
->write_subdev
= NULL
;
89 comedi_set_hw_dev(dev
, NULL
);
92 static void __comedi_device_detach(struct comedi_device
*dev
)
96 dev
->driver
->detach(dev
);
99 "BUG: dev->driver=NULL in comedi_device_detach()\n");
103 void comedi_device_detach(struct comedi_device
*dev
)
107 __comedi_device_detach(dev
);
110 int comedi_device_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
112 struct comedi_driver
*driv
;
118 for (driv
= comedi_drivers
; driv
; driv
= driv
->next
) {
119 if (!try_module_get(driv
->module
)) {
121 (KERN_INFO
"comedi: failed to increment module count, skipping\n");
124 if (driv
->num_names
) {
125 dev
->board_ptr
= comedi_recognize(driv
, it
->board_name
);
126 if (dev
->board_ptr
== NULL
) {
127 module_put(driv
->module
);
131 if (strcmp(driv
->driver_name
, it
->board_name
)) {
132 module_put(driv
->module
);
136 /* initialize dev->driver here so
137 * comedi_error() can be called from attach */
139 ret
= driv
->attach(dev
, it
);
141 module_put(dev
->driver
->module
);
142 __comedi_device_detach(dev
);
148 /* recognize has failed if we get here */
149 /* report valid board names before returning error */
150 for (driv
= comedi_drivers
; driv
; driv
= driv
->next
) {
151 if (!try_module_get(driv
->module
)) {
153 "comedi: failed to increment module count\n");
156 comedi_report_boards(driv
);
157 module_put(driv
->module
);
162 /* do a little post-config cleanup */
163 ret
= postconfig(dev
);
164 module_put(dev
->driver
->module
);
166 __comedi_device_detach(dev
);
170 if (!dev
->board_name
) {
171 printk(KERN_WARNING
"BUG: dev->board_name=<%p>\n",
173 dev
->board_name
= "BUG";
181 int comedi_driver_register(struct comedi_driver
*driver
)
183 driver
->next
= comedi_drivers
;
184 comedi_drivers
= driver
;
188 EXPORT_SYMBOL(comedi_driver_register
);
190 int comedi_driver_unregister(struct comedi_driver
*driver
)
192 struct comedi_driver
*prev
;
195 /* check for devices using this driver */
196 for (i
= 0; i
< COMEDI_NUM_BOARD_MINORS
; i
++) {
197 struct comedi_device_file_info
*dev_file_info
=
198 comedi_get_device_file_info(i
);
199 struct comedi_device
*dev
;
201 if (dev_file_info
== NULL
)
203 dev
= dev_file_info
->device
;
205 mutex_lock(&dev
->mutex
);
206 if (dev
->attached
&& dev
->driver
== driver
) {
209 (KERN_WARNING
"BUG! detaching device with use_count=%d\n",
211 comedi_device_detach(dev
);
213 mutex_unlock(&dev
->mutex
);
216 if (comedi_drivers
== driver
) {
217 comedi_drivers
= driver
->next
;
221 for (prev
= comedi_drivers
; prev
->next
; prev
= prev
->next
) {
222 if (prev
->next
== driver
) {
223 prev
->next
= driver
->next
;
229 EXPORT_SYMBOL(comedi_driver_unregister
);
231 static int postconfig(struct comedi_device
*dev
)
234 struct comedi_subdevice
*s
;
235 struct comedi_async
*async
= NULL
;
238 for (i
= 0; i
< dev
->n_subdevices
; i
++) {
239 s
= dev
->subdevices
+ i
;
241 if (s
->type
== COMEDI_SUBD_UNUSED
)
244 if (s
->len_chanlist
== 0)
248 BUG_ON((s
->subdev_flags
& (SDF_CMD_READ
|
249 SDF_CMD_WRITE
)) == 0);
250 BUG_ON(!s
->do_cmdtest
);
253 kzalloc(sizeof(struct comedi_async
), GFP_KERNEL
);
256 "failed to allocate async struct\n");
259 init_waitqueue_head(&async
->wait_head
);
260 async
->subdevice
= s
;
263 #define DEFAULT_BUF_MAXSIZE (64*1024)
264 #define DEFAULT_BUF_SIZE (64*1024)
266 async
->max_bufsize
= DEFAULT_BUF_MAXSIZE
;
268 async
->prealloc_buf
= NULL
;
269 async
->prealloc_bufsz
= 0;
270 if (comedi_buf_alloc(dev
, s
, DEFAULT_BUF_SIZE
) < 0) {
271 printk(KERN_INFO
"Buffer allocation failed\n");
275 ret
= s
->buf_change(dev
, s
, DEFAULT_BUF_SIZE
);
279 comedi_alloc_subdevice_minor(dev
, s
);
282 if (!s
->range_table
&& !s
->range_table_list
)
283 s
->range_table
= &range_unknown
;
285 if (!s
->insn_read
&& s
->insn_bits
)
286 s
->insn_read
= insn_rw_emulate_bits
;
287 if (!s
->insn_write
&& s
->insn_bits
)
288 s
->insn_write
= insn_rw_emulate_bits
;
291 s
->insn_read
= insn_inval
;
293 s
->insn_write
= insn_inval
;
295 s
->insn_bits
= insn_inval
;
297 s
->insn_config
= insn_inval
;
300 s
->poll
= poll_invalid
;
306 /* generic recognize function for drivers
307 * that register their supported board names */
308 static void *comedi_recognize(struct comedi_driver
*driv
, const char *name
)
311 const char *const *name_ptr
= driv
->board_name
;
312 for (i
= 0; i
< driv
->num_names
; i
++) {
313 if (strcmp(*name_ptr
, name
) == 0)
314 return (void *)name_ptr
;
316 (const char *const *)((const char *)name_ptr
+
323 static void comedi_report_boards(struct comedi_driver
*driv
)
326 const char *const *name_ptr
;
328 printk(KERN_INFO
"comedi: valid board names for %s driver are:\n",
331 name_ptr
= driv
->board_name
;
332 for (i
= 0; i
< driv
->num_names
; i
++) {
333 printk(KERN_INFO
" %s\n", *name_ptr
);
334 name_ptr
= (const char **)((char *)name_ptr
+ driv
->offset
);
337 if (driv
->num_names
== 0)
338 printk(KERN_INFO
" %s\n", driv
->driver_name
);
341 static int poll_invalid(struct comedi_device
*dev
, struct comedi_subdevice
*s
)
346 int insn_inval(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
347 struct comedi_insn
*insn
, unsigned int *data
)
352 static int insn_rw_emulate_bits(struct comedi_device
*dev
,
353 struct comedi_subdevice
*s
,
354 struct comedi_insn
*insn
, unsigned int *data
)
356 struct comedi_insn new_insn
;
358 static const unsigned channels_per_bitfield
= 32;
360 unsigned chan
= CR_CHAN(insn
->chanspec
);
361 const unsigned base_bitfield_channel
=
362 (chan
< channels_per_bitfield
) ? 0 : chan
;
363 unsigned int new_data
[2];
364 memset(new_data
, 0, sizeof(new_data
));
365 memset(&new_insn
, 0, sizeof(new_insn
));
366 new_insn
.insn
= INSN_BITS
;
367 new_insn
.chanspec
= base_bitfield_channel
;
369 new_insn
.data
= new_data
;
370 new_insn
.subdev
= insn
->subdev
;
372 if (insn
->insn
== INSN_WRITE
) {
373 if (!(s
->subdev_flags
& SDF_WRITABLE
))
375 new_data
[0] = 1 << (chan
- base_bitfield_channel
); /* mask */
376 new_data
[1] = data
[0] ? (1 << (chan
- base_bitfield_channel
))
380 ret
= s
->insn_bits(dev
, s
, &new_insn
, new_data
);
384 if (insn
->insn
== INSN_READ
)
385 data
[0] = (new_data
[1] >> (chan
- base_bitfield_channel
)) & 1;
390 static inline unsigned long uvirt_to_kva(pgd_t
*pgd
, unsigned long adr
)
392 unsigned long ret
= 0UL;
397 if (!pgd_none(*pgd
)) {
398 pud
= pud_offset(pgd
, adr
);
399 pmd
= pmd_offset(pud
, adr
);
400 if (!pmd_none(*pmd
)) {
401 ptep
= pte_offset_kernel(pmd
, adr
);
403 if (pte_present(pte
)) {
404 ret
= (unsigned long)
405 page_address(pte_page(pte
));
406 ret
|= (adr
& (PAGE_SIZE
- 1));
413 static inline unsigned long kvirt_to_kva(unsigned long adr
)
415 unsigned long va
, kva
;
418 kva
= uvirt_to_kva(pgd_offset_k(va
), va
);
423 int comedi_buf_alloc(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
424 unsigned long new_size
)
426 struct comedi_async
*async
= s
->async
;
428 /* Round up new_size to multiple of PAGE_SIZE */
429 new_size
= (new_size
+ PAGE_SIZE
- 1) & PAGE_MASK
;
431 /* if no change is required, do nothing */
432 if (async
->prealloc_buf
&& async
->prealloc_bufsz
== new_size
)
435 /* deallocate old buffer */
436 if (async
->prealloc_buf
) {
437 vunmap(async
->prealloc_buf
);
438 async
->prealloc_buf
= NULL
;
439 async
->prealloc_bufsz
= 0;
441 if (async
->buf_page_list
) {
443 for (i
= 0; i
< async
->n_buf_pages
; ++i
) {
444 if (async
->buf_page_list
[i
].virt_addr
) {
445 clear_bit(PG_reserved
, &(virt_to_page(async
->buf_page_list
[i
].virt_addr
)->flags
));
446 if (s
->async_dma_dir
!= DMA_NONE
) {
447 dma_free_coherent(dev
->hw_dev
,
456 free_page((unsigned long)
457 async
->buf_page_list
[i
].
462 vfree(async
->buf_page_list
);
463 async
->buf_page_list
= NULL
;
464 async
->n_buf_pages
= 0;
466 /* allocate new buffer */
469 unsigned n_pages
= new_size
>> PAGE_SHIFT
;
470 struct page
**pages
= NULL
;
472 async
->buf_page_list
=
473 vmalloc(sizeof(struct comedi_buf_page
) * n_pages
);
474 if (async
->buf_page_list
) {
475 memset(async
->buf_page_list
, 0,
476 sizeof(struct comedi_buf_page
) * n_pages
);
477 pages
= vmalloc(sizeof(struct page
*) * n_pages
);
480 for (i
= 0; i
< n_pages
; i
++) {
481 if (s
->async_dma_dir
!= DMA_NONE
) {
482 async
->buf_page_list
[i
].virt_addr
=
483 dma_alloc_coherent(dev
->hw_dev
,
491 async
->buf_page_list
[i
].virt_addr
=
493 get_zeroed_page(GFP_KERNEL
);
495 if (async
->buf_page_list
[i
].virt_addr
== NULL
)
499 &(virt_to_page(async
->buf_page_list
[i
].virt_addr
)->flags
));
500 pages
[i
] = virt_to_page(async
->buf_page_list
[i
].virt_addr
);
504 async
->prealloc_buf
=
505 vmap(pages
, n_pages
, VM_MAP
, PAGE_KERNEL_NOCACHE
);
509 if (async
->prealloc_buf
== NULL
) {
510 /* Some allocation failed above. */
511 if (async
->buf_page_list
) {
512 for (i
= 0; i
< n_pages
; i
++) {
513 if (async
->buf_page_list
[i
].virt_addr
==
517 clear_bit(PG_reserved
, &(virt_to_page(async
->buf_page_list
[i
].virt_addr
)->flags
));
518 if (s
->async_dma_dir
!= DMA_NONE
) {
519 dma_free_coherent(dev
->hw_dev
,
528 free_page((unsigned long)
533 vfree(async
->buf_page_list
);
534 async
->buf_page_list
= NULL
;
538 async
->n_buf_pages
= n_pages
;
540 async
->prealloc_bufsz
= new_size
;
545 /* munging is applied to data by core as it passes between user
546 * and kernel space */
547 static unsigned int comedi_buf_munge(struct comedi_async
*async
,
548 unsigned int num_bytes
)
550 struct comedi_subdevice
*s
= async
->subdevice
;
551 unsigned int count
= 0;
552 const unsigned num_sample_bytes
= bytes_per_sample(s
);
554 if (s
->munge
== NULL
|| (async
->cmd
.flags
& CMDF_RAWDATA
)) {
555 async
->munge_count
+= num_bytes
;
556 BUG_ON((int)(async
->munge_count
- async
->buf_write_count
) > 0);
559 /* don't munge partial samples */
560 num_bytes
-= num_bytes
% num_sample_bytes
;
561 while (count
< num_bytes
) {
564 block_size
= num_bytes
- count
;
565 if (block_size
< 0) {
567 "%s: %s: bug! block_size is negative\n",
571 if ((int)(async
->munge_ptr
+ block_size
-
572 async
->prealloc_bufsz
) > 0)
573 block_size
= async
->prealloc_bufsz
- async
->munge_ptr
;
575 s
->munge(s
->device
, s
, async
->prealloc_buf
+ async
->munge_ptr
,
576 block_size
, async
->munge_chan
);
578 smp_wmb(); /* barrier insures data is munged in buffer
579 * before munge_count is incremented */
581 async
->munge_chan
+= block_size
/ num_sample_bytes
;
582 async
->munge_chan
%= async
->cmd
.chanlist_len
;
583 async
->munge_count
+= block_size
;
584 async
->munge_ptr
+= block_size
;
585 async
->munge_ptr
%= async
->prealloc_bufsz
;
588 BUG_ON((int)(async
->munge_count
- async
->buf_write_count
) > 0);
592 unsigned int comedi_buf_write_n_available(struct comedi_async
*async
)
594 unsigned int free_end
;
600 free_end
= async
->buf_read_count
+ async
->prealloc_bufsz
;
601 nbytes
= free_end
- async
->buf_write_alloc_count
;
602 nbytes
-= nbytes
% bytes_per_sample(async
->subdevice
);
603 /* barrier insures the read of buf_read_count in this
604 query occurs before any following writes to the buffer which
605 might be based on the return value from this query.
611 /* allocates chunk for the writer from free buffer space */
612 unsigned int comedi_buf_write_alloc(struct comedi_async
*async
,
615 unsigned int free_end
= async
->buf_read_count
+ async
->prealloc_bufsz
;
617 if ((int)(async
->buf_write_alloc_count
+ nbytes
- free_end
) > 0)
618 nbytes
= free_end
- async
->buf_write_alloc_count
;
620 async
->buf_write_alloc_count
+= nbytes
;
621 /* barrier insures the read of buf_read_count above occurs before
622 we write data to the write-alloc'ed buffer space */
626 EXPORT_SYMBOL(comedi_buf_write_alloc
);
628 /* allocates nothing unless it can completely fulfill the request */
629 unsigned int comedi_buf_write_alloc_strict(struct comedi_async
*async
,
632 unsigned int free_end
= async
->buf_read_count
+ async
->prealloc_bufsz
;
634 if ((int)(async
->buf_write_alloc_count
+ nbytes
- free_end
) > 0)
637 async
->buf_write_alloc_count
+= nbytes
;
638 /* barrier insures the read of buf_read_count above occurs before
639 we write data to the write-alloc'ed buffer space */
644 /* transfers a chunk from writer to filled buffer space */
645 unsigned comedi_buf_write_free(struct comedi_async
*async
, unsigned int nbytes
)
647 if ((int)(async
->buf_write_count
+ nbytes
-
648 async
->buf_write_alloc_count
) > 0) {
650 (KERN_INFO
"comedi: attempted to write-free more bytes than have been write-allocated.\n");
651 nbytes
= async
->buf_write_alloc_count
- async
->buf_write_count
;
653 async
->buf_write_count
+= nbytes
;
654 async
->buf_write_ptr
+= nbytes
;
655 comedi_buf_munge(async
, async
->buf_write_count
- async
->munge_count
);
656 if (async
->buf_write_ptr
>= async
->prealloc_bufsz
)
657 async
->buf_write_ptr
%= async
->prealloc_bufsz
;
661 EXPORT_SYMBOL(comedi_buf_write_free
);
663 /* allocates a chunk for the reader from filled (and munged) buffer space */
664 unsigned comedi_buf_read_alloc(struct comedi_async
*async
, unsigned nbytes
)
666 if ((int)(async
->buf_read_alloc_count
+ nbytes
- async
->munge_count
) >
668 nbytes
= async
->munge_count
- async
->buf_read_alloc_count
;
670 async
->buf_read_alloc_count
+= nbytes
;
671 /* barrier insures read of munge_count occurs before we actually read
672 data out of buffer */
676 EXPORT_SYMBOL(comedi_buf_read_alloc
);
678 /* transfers control of a chunk from reader to free buffer space */
679 unsigned comedi_buf_read_free(struct comedi_async
*async
, unsigned int nbytes
)
681 /* barrier insures data has been read out of
682 * buffer before read count is incremented */
684 if ((int)(async
->buf_read_count
+ nbytes
-
685 async
->buf_read_alloc_count
) > 0) {
687 "comedi: attempted to read-free more bytes than have been read-allocated.\n");
688 nbytes
= async
->buf_read_alloc_count
- async
->buf_read_count
;
690 async
->buf_read_count
+= nbytes
;
691 async
->buf_read_ptr
+= nbytes
;
692 async
->buf_read_ptr
%= async
->prealloc_bufsz
;
695 EXPORT_SYMBOL(comedi_buf_read_free
);
697 void comedi_buf_memcpy_to(struct comedi_async
*async
, unsigned int offset
,
698 const void *data
, unsigned int num_bytes
)
700 unsigned int write_ptr
= async
->buf_write_ptr
+ offset
;
702 if (write_ptr
>= async
->prealloc_bufsz
)
703 write_ptr
%= async
->prealloc_bufsz
;
706 unsigned int block_size
;
708 if (write_ptr
+ num_bytes
> async
->prealloc_bufsz
)
709 block_size
= async
->prealloc_bufsz
- write_ptr
;
711 block_size
= num_bytes
;
713 memcpy(async
->prealloc_buf
+ write_ptr
, data
, block_size
);
716 num_bytes
-= block_size
;
721 EXPORT_SYMBOL(comedi_buf_memcpy_to
);
723 void comedi_buf_memcpy_from(struct comedi_async
*async
, unsigned int offset
,
724 void *dest
, unsigned int nbytes
)
727 unsigned int read_ptr
= async
->buf_read_ptr
+ offset
;
729 if (read_ptr
>= async
->prealloc_bufsz
)
730 read_ptr
%= async
->prealloc_bufsz
;
733 unsigned int block_size
;
735 src
= async
->prealloc_buf
+ read_ptr
;
737 if (nbytes
>= async
->prealloc_bufsz
- read_ptr
)
738 block_size
= async
->prealloc_bufsz
- read_ptr
;
742 memcpy(dest
, src
, block_size
);
743 nbytes
-= block_size
;
748 EXPORT_SYMBOL(comedi_buf_memcpy_from
);
750 unsigned int comedi_buf_read_n_available(struct comedi_async
*async
)
756 num_bytes
= async
->munge_count
- async
->buf_read_count
;
757 /* barrier insures the read of munge_count in this
758 query occurs before any following reads of the buffer which
759 might be based on the return value from this query.
764 EXPORT_SYMBOL(comedi_buf_read_n_available
);
766 int comedi_buf_get(struct comedi_async
*async
, short *x
)
768 unsigned int n
= comedi_buf_read_n_available(async
);
770 if (n
< sizeof(short))
772 comedi_buf_read_alloc(async
, sizeof(short));
773 *x
= *(short *)(async
->prealloc_buf
+ async
->buf_read_ptr
);
774 comedi_buf_read_free(async
, sizeof(short));
777 EXPORT_SYMBOL(comedi_buf_get
);
779 int comedi_buf_put(struct comedi_async
*async
, short x
)
781 unsigned int n
= comedi_buf_write_alloc_strict(async
, sizeof(short));
783 if (n
< sizeof(short)) {
784 async
->events
|= COMEDI_CB_ERROR
;
787 *(short *)(async
->prealloc_buf
+ async
->buf_write_ptr
) = x
;
788 comedi_buf_write_free(async
, sizeof(short));
791 EXPORT_SYMBOL(comedi_buf_put
);
793 void comedi_reset_async_buf(struct comedi_async
*async
)
795 async
->buf_write_alloc_count
= 0;
796 async
->buf_write_count
= 0;
797 async
->buf_read_alloc_count
= 0;
798 async
->buf_read_count
= 0;
800 async
->buf_write_ptr
= 0;
801 async
->buf_read_ptr
= 0;
804 async
->scan_progress
= 0;
805 async
->munge_chan
= 0;
806 async
->munge_count
= 0;
807 async
->munge_ptr
= 0;
812 static int comedi_auto_config(struct device
*hardware_device
,
813 const char *board_name
, const int *options
,
814 unsigned num_options
)
816 struct comedi_devconfig it
;
818 struct comedi_device_file_info
*dev_file_info
;
820 unsigned *private_data
= NULL
;
822 if (!comedi_autoconfig
) {
823 dev_set_drvdata(hardware_device
, NULL
);
827 minor
= comedi_alloc_board_minor(hardware_device
);
831 private_data
= kmalloc(sizeof(unsigned), GFP_KERNEL
);
832 if (private_data
== NULL
) {
836 *private_data
= minor
;
837 dev_set_drvdata(hardware_device
, private_data
);
839 dev_file_info
= comedi_get_device_file_info(minor
);
841 memset(&it
, 0, sizeof(it
));
842 strncpy(it
.board_name
, board_name
, COMEDI_NAMELEN
);
843 it
.board_name
[COMEDI_NAMELEN
- 1] = '\0';
844 BUG_ON(num_options
> COMEDI_NDEVCONFOPTS
);
845 memcpy(it
.options
, options
, num_options
* sizeof(int));
847 mutex_lock(&dev_file_info
->device
->mutex
);
848 retval
= comedi_device_attach(dev_file_info
->device
, &it
);
849 mutex_unlock(&dev_file_info
->device
->mutex
);
854 comedi_free_board_minor(minor
);
859 static void comedi_auto_unconfig(struct device
*hardware_device
)
861 unsigned *minor
= (unsigned *)dev_get_drvdata(hardware_device
);
865 BUG_ON(*minor
>= COMEDI_NUM_BOARD_MINORS
);
867 comedi_free_board_minor(*minor
);
868 dev_set_drvdata(hardware_device
, NULL
);
872 int comedi_pci_auto_config(struct pci_dev
*pcidev
, const char *board_name
)
877 options
[0] = pcidev
->bus
->number
;
879 options
[1] = PCI_SLOT(pcidev
->devfn
);
881 return comedi_auto_config(&pcidev
->dev
, board_name
,
882 options
, ARRAY_SIZE(options
));
884 EXPORT_SYMBOL_GPL(comedi_pci_auto_config
);
886 void comedi_pci_auto_unconfig(struct pci_dev
*pcidev
)
888 comedi_auto_unconfig(&pcidev
->dev
);
890 EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig
);
892 int comedi_usb_auto_config(struct usb_device
*usbdev
, const char *board_name
)
894 BUG_ON(usbdev
== NULL
);
895 return comedi_auto_config(&usbdev
->dev
, board_name
, NULL
, 0);
897 EXPORT_SYMBOL_GPL(comedi_usb_auto_config
);
899 void comedi_usb_auto_unconfig(struct usb_device
*usbdev
)
901 BUG_ON(usbdev
== NULL
);
902 comedi_auto_unconfig(&usbdev
->dev
);
904 EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig
);