3 functions for manipulating drivers
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 Copyright (C) 2002 Frank Mori Hess <fmhess@users.sourceforge.net>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
20 #include <linux/device.h>
21 #include <linux/module.h>
22 #include <linux/errno.h>
23 #include <linux/kconfig.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
26 #include <linux/fcntl.h>
27 #include <linux/ioport.h>
29 #include <linux/slab.h>
30 #include <linux/highmem.h> /* for SuSE brokenness */
31 #include <linux/vmalloc.h>
32 #include <linux/cdev.h>
33 #include <linux/dma-mapping.h>
35 #include <linux/interrupt.h>
36 #include <linux/firmware.h>
38 #include "comedidev.h"
39 #include "comedi_internal.h"
41 struct comedi_driver *comedi_drivers;
42 /* protects access to comedi_drivers */
43 DEFINE_MUTEX(comedi_drivers_list_lock);
45 int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev)
47 if (hw_dev == dev->hw_dev)
51 dev->hw_dev = get_device(hw_dev);
54 EXPORT_SYMBOL_GPL(comedi_set_hw_dev);
56 static void comedi_clear_hw_dev(struct comedi_device *dev)
58 put_device(dev->hw_dev);
63 * comedi_alloc_devpriv() - Allocate memory for the device private data.
64 * @dev: comedi_device struct
65 * @size: size of the memory to allocate
67 void *comedi_alloc_devpriv(struct comedi_device *dev, size_t size)
69 dev->private = kzalloc(size, GFP_KERNEL);
72 EXPORT_SYMBOL_GPL(comedi_alloc_devpriv);
74 int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices)
76 struct comedi_subdevice *s;
79 if (num_subdevices < 1)
82 s = kcalloc(num_subdevices, sizeof(*s), GFP_KERNEL);
86 dev->n_subdevices = num_subdevices;
88 for (i = 0; i < num_subdevices; ++i) {
89 s = &dev->subdevices[i];
92 s->async_dma_dir = DMA_NONE;
93 spin_lock_init(&s->spin_lock);
98 EXPORT_SYMBOL_GPL(comedi_alloc_subdevices);
101 * comedi_alloc_subdev_readback() - Allocate memory for the subdevice readback.
102 * @s: comedi_subdevice struct
104 int comedi_alloc_subdev_readback(struct comedi_subdevice *s)
109 s->readback = kcalloc(s->n_chan, sizeof(*s->readback), GFP_KERNEL);
114 s->insn_read = comedi_readback_insn_read;
118 EXPORT_SYMBOL_GPL(comedi_alloc_subdev_readback);
120 static void comedi_device_detach_cleanup(struct comedi_device *dev)
123 struct comedi_subdevice *s;
125 if (dev->subdevices) {
126 for (i = 0; i < dev->n_subdevices; i++) {
127 s = &dev->subdevices[i];
128 if (comedi_can_auto_free_spriv(s))
130 comedi_free_subdevice_minor(s);
132 comedi_buf_alloc(dev, s, 0);
137 kfree(dev->subdevices);
138 dev->subdevices = NULL;
139 dev->n_subdevices = 0;
146 dev->board_name = NULL;
147 dev->board_ptr = NULL;
151 dev->ioenabled = false;
153 dev->read_subdev = NULL;
154 dev->write_subdev = NULL;
157 comedi_clear_hw_dev(dev);
160 void comedi_device_detach(struct comedi_device *dev)
162 comedi_device_cancel_all(dev);
163 down_write(&dev->attach_lock);
164 dev->attached = false;
167 dev->driver->detach(dev);
168 comedi_device_detach_cleanup(dev);
169 up_write(&dev->attach_lock);
172 static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s)
177 int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
178 struct comedi_insn *insn, unsigned int *data)
184 * comedi_readback_insn_read() - A generic (*insn_read) for subdevice readback.
185 * @dev: comedi_device struct
186 * @s: comedi_subdevice struct
187 * @insn: comedi_insn struct
188 * @data: pointer to return the readback data
190 int comedi_readback_insn_read(struct comedi_device *dev,
191 struct comedi_subdevice *s,
192 struct comedi_insn *insn,
195 unsigned int chan = CR_CHAN(insn->chanspec);
201 for (i = 0; i < insn->n; i++)
202 data[i] = s->readback[chan];
206 EXPORT_SYMBOL_GPL(comedi_readback_insn_read);
209 * comedi_timeout() - busy-wait for a driver condition to occur.
210 * @dev: comedi_device struct
211 * @s: comedi_subdevice struct
212 * @insn: comedi_insn struct
213 * @cb: callback to check for the condition
214 * @context: private context from the driver
216 int comedi_timeout(struct comedi_device *dev,
217 struct comedi_subdevice *s,
218 struct comedi_insn *insn,
219 int (*cb)(struct comedi_device *dev,
220 struct comedi_subdevice *s,
221 struct comedi_insn *insn,
222 unsigned long context),
223 unsigned long context)
225 unsigned long timeout = jiffies + msecs_to_jiffies(COMEDI_TIMEOUT_MS);
228 while (time_before(jiffies, timeout)) {
229 ret = cb(dev, s, insn, context);
231 return ret; /* success (0) or non EBUSY errno */
236 EXPORT_SYMBOL_GPL(comedi_timeout);
239 * comedi_dio_insn_config() - boilerplate (*insn_config) for DIO subdevices.
240 * @dev: comedi_device struct
241 * @s: comedi_subdevice struct
242 * @insn: comedi_insn struct
243 * @data: parameters for the @insn
244 * @mask: io_bits mask for grouped channels
246 int comedi_dio_insn_config(struct comedi_device *dev,
247 struct comedi_subdevice *s,
248 struct comedi_insn *insn,
252 unsigned int chan_mask = 1 << CR_CHAN(insn->chanspec);
258 case INSN_CONFIG_DIO_INPUT:
262 case INSN_CONFIG_DIO_OUTPUT:
266 case INSN_CONFIG_DIO_QUERY:
267 data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT;
276 EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
279 * comedi_dio_update_state() - update the internal state of DIO subdevices.
280 * @s: comedi_subdevice struct
281 * @data: the channel mask and bits to update
283 unsigned int comedi_dio_update_state(struct comedi_subdevice *s,
286 unsigned int chanmask = (s->n_chan < 32) ? ((1 << s->n_chan) - 1)
288 unsigned int mask = data[0] & chanmask;
289 unsigned int bits = data[1];
293 s->state |= (bits & mask);
298 EXPORT_SYMBOL_GPL(comedi_dio_update_state);
301 * comedi_bytes_per_scan - get length of asynchronous command "scan" in bytes
302 * @s: comedi_subdevice struct
304 * Determines the overall scan length according to the subdevice type and the
305 * number of channels in the scan.
307 * For digital input, output or input/output subdevices, samples for multiple
308 * channels are assumed to be packed into one or more unsigned short or
309 * unsigned int values according to the subdevice's SDF_LSAMPL flag. For other
310 * types of subdevice, samples are assumed to occupy a whole unsigned short or
311 * unsigned int according to the SDF_LSAMPL flag.
313 * Returns the overall scan length in bytes.
315 unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s)
317 struct comedi_cmd *cmd = &s->async->cmd;
318 unsigned int num_samples;
319 unsigned int bits_per_sample;
324 case COMEDI_SUBD_DIO:
325 bits_per_sample = 8 * comedi_bytes_per_sample(s);
326 num_samples = DIV_ROUND_UP(cmd->scan_end_arg, bits_per_sample);
329 num_samples = cmd->scan_end_arg;
332 return comedi_samples_to_bytes(s, num_samples);
334 EXPORT_SYMBOL_GPL(comedi_bytes_per_scan);
337 * comedi_nscans_left - return the number of scans left in the command
338 * @s: comedi_subdevice struct
339 * @nscans: the expected number of scans
341 * If nscans is 0, the number of scans available in the async buffer will be
342 * used. Otherwise the expected number of scans will be used.
344 * If the async command has a stop_src of TRIG_COUNT, the nscans will be
345 * checked against the number of scans left in the command.
347 * The return value will then be either the expected number of scans or the
348 * number of scans remaining in the command.
350 unsigned int comedi_nscans_left(struct comedi_subdevice *s,
353 struct comedi_async *async = s->async;
354 struct comedi_cmd *cmd = &async->cmd;
357 unsigned int nbytes = comedi_buf_read_n_available(s);
359 nscans = nbytes / comedi_bytes_per_scan(s);
362 if (cmd->stop_src == TRIG_COUNT) {
363 unsigned int scans_left = 0;
365 if (async->scans_done < cmd->stop_arg)
366 scans_left = cmd->stop_arg - async->scans_done;
368 if (nscans > scans_left)
373 EXPORT_SYMBOL_GPL(comedi_nscans_left);
376 * comedi_nsamples_left - return the number of samples left in the command
377 * @s: comedi_subdevice struct
378 * @nsamples: the expected number of samples
380 * Returns the expected number of samples of the number of samples remaining
383 unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
384 unsigned int nsamples)
386 struct comedi_async *async = s->async;
387 struct comedi_cmd *cmd = &async->cmd;
389 if (cmd->stop_src == TRIG_COUNT) {
390 /* +1 to force comedi_nscans_left() to return the scans left */
391 unsigned int nscans = (nsamples / cmd->scan_end_arg) + 1;
392 unsigned int scans_left = comedi_nscans_left(s, nscans);
393 unsigned int scan_pos =
394 comedi_bytes_to_samples(s, async->scan_progress);
395 unsigned long long samples_left = 0;
398 samples_left = ((unsigned long long)scans_left *
399 cmd->scan_end_arg) - scan_pos;
402 if (samples_left < nsamples)
403 nsamples = samples_left;
407 EXPORT_SYMBOL_GPL(comedi_nsamples_left);
410 * comedi_inc_scan_progress - update scan progress in asynchronous command
411 * @s: comedi_subdevice struct
412 * @num_bytes: amount of data in bytes to increment scan progress
414 * Increments the scan progress by the number of bytes specified by num_bytes.
415 * If the scan progress reaches or exceeds the scan length in bytes, reduce
416 * it modulo the scan length in bytes and set the "end of scan" asynchronous
417 * event flag to be processed later.
419 void comedi_inc_scan_progress(struct comedi_subdevice *s,
420 unsigned int num_bytes)
422 struct comedi_async *async = s->async;
423 struct comedi_cmd *cmd = &async->cmd;
424 unsigned int scan_length = comedi_bytes_per_scan(s);
426 /* track the 'cur_chan' for non-SDF_PACKED subdevices */
427 if (!(s->subdev_flags & SDF_PACKED)) {
428 async->cur_chan += comedi_bytes_to_samples(s, num_bytes);
429 async->cur_chan %= cmd->chanlist_len;
432 async->scan_progress += num_bytes;
433 if (async->scan_progress >= scan_length) {
434 unsigned int nscans = async->scan_progress / scan_length;
436 if (async->scans_done < (UINT_MAX - nscans))
437 async->scans_done += nscans;
439 async->scans_done = UINT_MAX;
441 async->scan_progress %= scan_length;
442 async->events |= COMEDI_CB_EOS;
445 EXPORT_SYMBOL_GPL(comedi_inc_scan_progress);
448 * comedi_handle_events - handle events and possibly stop acquisition
449 * @dev: comedi_device struct
450 * @s: comedi_subdevice struct
452 * Handles outstanding asynchronous acquisition event flags associated
453 * with the subdevice. Call the subdevice's "->cancel()" handler if the
454 * "end of acquisition", "error" or "overflow" event flags are set in order
455 * to stop the acquisition at the driver level.
457 * Calls comedi_event() to further process the event flags, which may mark
458 * the asynchronous command as no longer running, possibly terminated with
459 * an error, and may wake up tasks.
461 * Return a bit-mask of the handled events.
463 unsigned int comedi_handle_events(struct comedi_device *dev,
464 struct comedi_subdevice *s)
466 unsigned int events = s->async->events;
471 if (events & COMEDI_CB_CANCEL_MASK)
474 comedi_event(dev, s);
478 EXPORT_SYMBOL_GPL(comedi_handle_events);
480 static int insn_rw_emulate_bits(struct comedi_device *dev,
481 struct comedi_subdevice *s,
482 struct comedi_insn *insn, unsigned int *data)
484 struct comedi_insn new_insn;
486 static const unsigned channels_per_bitfield = 32;
488 unsigned chan = CR_CHAN(insn->chanspec);
489 const unsigned base_bitfield_channel =
490 (chan < channels_per_bitfield) ? 0 : chan;
491 unsigned int new_data[2];
493 memset(new_data, 0, sizeof(new_data));
494 memset(&new_insn, 0, sizeof(new_insn));
495 new_insn.insn = INSN_BITS;
496 new_insn.chanspec = base_bitfield_channel;
498 new_insn.subdev = insn->subdev;
500 if (insn->insn == INSN_WRITE) {
501 if (!(s->subdev_flags & SDF_WRITABLE))
503 new_data[0] = 1 << (chan - base_bitfield_channel); /* mask */
504 new_data[1] = data[0] ? (1 << (chan - base_bitfield_channel))
508 ret = s->insn_bits(dev, s, &new_insn, new_data);
512 if (insn->insn == INSN_READ)
513 data[0] = (new_data[1] >> (chan - base_bitfield_channel)) & 1;
518 static int __comedi_device_postconfig_async(struct comedi_device *dev,
519 struct comedi_subdevice *s)
521 struct comedi_async *async;
522 unsigned int buf_size;
525 if ((s->subdev_flags & (SDF_CMD_READ | SDF_CMD_WRITE)) == 0) {
526 dev_warn(dev->class_dev,
527 "async subdevices must support SDF_CMD_READ or SDF_CMD_WRITE\n");
530 if (!s->do_cmdtest) {
531 dev_warn(dev->class_dev,
532 "async subdevices must have a do_cmdtest() function\n");
536 async = kzalloc(sizeof(*async), GFP_KERNEL);
540 init_waitqueue_head(&async->wait_head);
543 async->max_bufsize = comedi_default_buf_maxsize_kb * 1024;
544 buf_size = comedi_default_buf_size_kb * 1024;
545 if (buf_size > async->max_bufsize)
546 buf_size = async->max_bufsize;
548 if (comedi_buf_alloc(dev, s, buf_size) < 0) {
549 dev_warn(dev->class_dev, "Buffer allocation failed\n");
553 ret = s->buf_change(dev, s);
558 comedi_alloc_subdevice_minor(s);
563 static int __comedi_device_postconfig(struct comedi_device *dev)
565 struct comedi_subdevice *s;
569 for (i = 0; i < dev->n_subdevices; i++) {
570 s = &dev->subdevices[i];
572 if (s->type == COMEDI_SUBD_UNUSED)
575 if (s->type == COMEDI_SUBD_DO) {
577 s->io_bits = (1 << s->n_chan) - 1;
579 s->io_bits = 0xffffffff;
582 if (s->len_chanlist == 0)
586 ret = __comedi_device_postconfig_async(dev, s);
591 if (!s->range_table && !s->range_table_list)
592 s->range_table = &range_unknown;
594 if (!s->insn_read && s->insn_bits)
595 s->insn_read = insn_rw_emulate_bits;
596 if (!s->insn_write && s->insn_bits)
597 s->insn_write = insn_rw_emulate_bits;
600 s->insn_read = insn_inval;
602 s->insn_write = insn_inval;
604 s->insn_bits = insn_inval;
606 s->insn_config = insn_inval;
609 s->poll = poll_invalid;
615 /* do a little post-config cleanup */
616 static int comedi_device_postconfig(struct comedi_device *dev)
620 ret = __comedi_device_postconfig(dev);
623 down_write(&dev->attach_lock);
624 dev->attached = true;
625 up_write(&dev->attach_lock);
630 * Generic recognize function for drivers that register their supported
633 * 'driv->board_name' points to a 'const char *' member within the
634 * zeroth element of an array of some private board information
635 * structure, say 'struct foo_board' containing a member 'const char
636 * *board_name' that is initialized to point to a board name string that
637 * is one of the candidates matched against this function's 'name'
640 * 'driv->offset' is the size of the private board information
641 * structure, say 'sizeof(struct foo_board)', and 'driv->num_names' is
642 * the length of the array of private board information structures.
644 * If one of the board names in the array of private board information
645 * structures matches the name supplied to this function, the function
646 * returns a pointer to the pointer to the board name, otherwise it
647 * returns NULL. The return value ends up in the 'board_ptr' member of
648 * a 'struct comedi_device' that the low-level comedi driver's
649 * 'attach()' hook can convert to a point to a particular element of its
650 * array of private board information structures by subtracting the
651 * offset of the member that points to the board name. (No subtraction
652 * is required if the board name pointer is the first member of the
653 * private board information structure, which is generally the case.)
655 static void *comedi_recognize(struct comedi_driver *driv, const char *name)
657 char **name_ptr = (char **)driv->board_name;
660 for (i = 0; i < driv->num_names; i++) {
661 if (strcmp(*name_ptr, name) == 0)
663 name_ptr = (void *)name_ptr + driv->offset;
669 static void comedi_report_boards(struct comedi_driver *driv)
672 const char *const *name_ptr;
674 pr_info("comedi: valid board names for %s driver are:\n",
677 name_ptr = driv->board_name;
678 for (i = 0; i < driv->num_names; i++) {
679 pr_info(" %s\n", *name_ptr);
680 name_ptr = (const char **)((char *)name_ptr + driv->offset);
683 if (driv->num_names == 0)
684 pr_info(" %s\n", driv->driver_name);
688 * comedi_load_firmware() - Request and load firmware for a device.
689 * @dev: comedi_device struct
690 * @hw_device: device struct for the comedi_device
691 * @name: the name of the firmware image
692 * @cb: callback to the upload the firmware image
693 * @context: private context from the driver
695 int comedi_load_firmware(struct comedi_device *dev,
696 struct device *device,
698 int (*cb)(struct comedi_device *dev,
699 const u8 *data, size_t size,
700 unsigned long context),
701 unsigned long context)
703 const struct firmware *fw;
709 ret = request_firmware(&fw, name, device);
711 ret = cb(dev, fw->data, fw->size, context);
712 release_firmware(fw);
715 return ret < 0 ? ret : 0;
717 EXPORT_SYMBOL_GPL(comedi_load_firmware);
720 * __comedi_request_region() - Request an I/O reqion for a legacy driver.
721 * @dev: comedi_device struct
722 * @start: base address of the I/O reqion
723 * @len: length of the I/O region
725 int __comedi_request_region(struct comedi_device *dev,
726 unsigned long start, unsigned long len)
729 dev_warn(dev->class_dev,
730 "%s: a I/O base address must be specified\n",
735 if (!request_region(start, len, dev->board_name)) {
736 dev_warn(dev->class_dev, "%s: I/O port conflict (%#lx,%lu)\n",
737 dev->board_name, start, len);
743 EXPORT_SYMBOL_GPL(__comedi_request_region);
746 * comedi_request_region() - Request an I/O reqion for a legacy driver.
747 * @dev: comedi_device struct
748 * @start: base address of the I/O reqion
749 * @len: length of the I/O region
751 int comedi_request_region(struct comedi_device *dev,
752 unsigned long start, unsigned long len)
756 ret = __comedi_request_region(dev, start, len);
764 EXPORT_SYMBOL_GPL(comedi_request_region);
767 * comedi_legacy_detach() - A generic (*detach) function for legacy drivers.
768 * @dev: comedi_device struct
770 void comedi_legacy_detach(struct comedi_device *dev)
773 free_irq(dev->irq, dev);
776 if (dev->iobase && dev->iolen) {
777 release_region(dev->iobase, dev->iolen);
782 EXPORT_SYMBOL_GPL(comedi_legacy_detach);
784 int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
786 struct comedi_driver *driv;
792 mutex_lock(&comedi_drivers_list_lock);
793 for (driv = comedi_drivers; driv; driv = driv->next) {
794 if (!try_module_get(driv->module))
796 if (driv->num_names) {
797 dev->board_ptr = comedi_recognize(driv, it->board_name);
800 } else if (strcmp(driv->driver_name, it->board_name) == 0) {
803 module_put(driv->module);
806 /* recognize has failed if we get here */
807 /* report valid board names before returning error */
808 for (driv = comedi_drivers; driv; driv = driv->next) {
809 if (!try_module_get(driv->module))
811 comedi_report_boards(driv);
812 module_put(driv->module);
818 /* driver does not support manual configuration */
819 dev_warn(dev->class_dev,
820 "driver '%s' does not support attach using comedi_config\n",
822 module_put(driv->module);
827 dev->board_name = dev->board_ptr ? *(const char **)dev->board_ptr
828 : dev->driver->driver_name;
829 ret = driv->attach(dev, it);
831 ret = comedi_device_postconfig(dev);
833 comedi_device_detach(dev);
834 module_put(driv->module);
836 /* On success, the driver module count has been incremented. */
838 mutex_unlock(&comedi_drivers_list_lock);
842 int comedi_auto_config(struct device *hardware_device,
843 struct comedi_driver *driver, unsigned long context)
845 struct comedi_device *dev;
848 if (!hardware_device) {
849 pr_warn("BUG! comedi_auto_config called with NULL hardware_device\n");
853 dev_warn(hardware_device,
854 "BUG! comedi_auto_config called with NULL comedi driver\n");
858 if (!driver->auto_attach) {
859 dev_warn(hardware_device,
860 "BUG! comedi driver '%s' has no auto_attach handler\n",
861 driver->driver_name);
865 dev = comedi_alloc_board_minor(hardware_device);
867 dev_warn(hardware_device,
868 "driver '%s' could not create device.\n",
869 driver->driver_name);
872 /* Note: comedi_alloc_board_minor() locked dev->mutex. */
874 dev->driver = driver;
875 dev->board_name = dev->driver->driver_name;
876 ret = driver->auto_attach(dev, context);
878 ret = comedi_device_postconfig(dev);
879 mutex_unlock(&dev->mutex);
882 dev_warn(hardware_device,
883 "driver '%s' failed to auto-configure device.\n",
884 driver->driver_name);
885 comedi_release_hardware_device(hardware_device);
888 * class_dev should be set properly here
889 * after a successful auto config
891 dev_info(dev->class_dev,
892 "driver '%s' has successfully auto-configured '%s'.\n",
893 driver->driver_name, dev->board_name);
897 EXPORT_SYMBOL_GPL(comedi_auto_config);
899 void comedi_auto_unconfig(struct device *hardware_device)
901 if (!hardware_device)
903 comedi_release_hardware_device(hardware_device);
905 EXPORT_SYMBOL_GPL(comedi_auto_unconfig);
907 int comedi_driver_register(struct comedi_driver *driver)
909 mutex_lock(&comedi_drivers_list_lock);
910 driver->next = comedi_drivers;
911 comedi_drivers = driver;
912 mutex_unlock(&comedi_drivers_list_lock);
916 EXPORT_SYMBOL_GPL(comedi_driver_register);
918 void comedi_driver_unregister(struct comedi_driver *driver)
920 struct comedi_driver *prev;
923 /* unlink the driver */
924 mutex_lock(&comedi_drivers_list_lock);
925 if (comedi_drivers == driver) {
926 comedi_drivers = driver->next;
928 for (prev = comedi_drivers; prev->next; prev = prev->next) {
929 if (prev->next == driver) {
930 prev->next = driver->next;
935 mutex_unlock(&comedi_drivers_list_lock);
937 /* check for devices using this driver */
938 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
939 struct comedi_device *dev = comedi_dev_get_from_minor(i);
944 mutex_lock(&dev->mutex);
945 if (dev->attached && dev->driver == driver) {
947 dev_warn(dev->class_dev,
948 "BUG! detaching device with use_count=%d\n",
950 comedi_device_detach(dev);
952 mutex_unlock(&dev->mutex);
956 EXPORT_SYMBOL_GPL(comedi_driver_unregister);