3 functions for manipulating drivers
5 COMEDI - Linux Control and Measurement Device Interface
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)
49 if (dev->hw_dev != NULL)
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 (s->runflags & COMEDI_SRF_FREE_SPRIV)
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;
144 dev->board_name = NULL;
145 dev->board_ptr = NULL;
149 dev->ioenabled = false;
151 dev->read_subdev = NULL;
152 dev->write_subdev = NULL;
155 comedi_clear_hw_dev(dev);
158 void comedi_device_detach(struct comedi_device *dev)
160 comedi_device_cancel_all(dev);
161 down_write(&dev->attach_lock);
162 dev->attached = false;
165 dev->driver->detach(dev);
166 comedi_device_detach_cleanup(dev);
167 up_write(&dev->attach_lock);
170 static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s)
175 int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
176 struct comedi_insn *insn, unsigned int *data)
182 * comedi_readback_insn_read() - A generic (*insn_read) for subdevice readback.
183 * @dev: comedi_device struct
184 * @s: comedi_subdevice struct
185 * @insn: comedi_insn struct
186 * @data: pointer to return the readback data
188 int comedi_readback_insn_read(struct comedi_device *dev,
189 struct comedi_subdevice *s,
190 struct comedi_insn *insn,
193 unsigned int chan = CR_CHAN(insn->chanspec);
199 for (i = 0; i < insn->n; i++)
200 data[i] = s->readback[chan];
204 EXPORT_SYMBOL_GPL(comedi_readback_insn_read);
207 * comedi_timeout() - busy-wait for a driver condition to occur.
208 * @dev: comedi_device struct
209 * @s: comedi_subdevice struct
210 * @insn: comedi_insn struct
211 * @cb: callback to check for the condition
212 * @context: private context from the driver
214 int comedi_timeout(struct comedi_device *dev,
215 struct comedi_subdevice *s,
216 struct comedi_insn *insn,
217 int (*cb)(struct comedi_device *dev,
218 struct comedi_subdevice *s,
219 struct comedi_insn *insn,
220 unsigned long context),
221 unsigned long context)
223 unsigned long timeout = jiffies + msecs_to_jiffies(COMEDI_TIMEOUT_MS);
226 while (time_before(jiffies, timeout)) {
227 ret = cb(dev, s, insn, context);
229 return ret; /* success (0) or non EBUSY errno */
234 EXPORT_SYMBOL_GPL(comedi_timeout);
237 * comedi_dio_insn_config() - boilerplate (*insn_config) for DIO subdevices.
238 * @dev: comedi_device struct
239 * @s: comedi_subdevice struct
240 * @insn: comedi_insn struct
241 * @data: parameters for the @insn
242 * @mask: io_bits mask for grouped channels
244 int comedi_dio_insn_config(struct comedi_device *dev,
245 struct comedi_subdevice *s,
246 struct comedi_insn *insn,
250 unsigned int chan_mask = 1 << CR_CHAN(insn->chanspec);
256 case INSN_CONFIG_DIO_INPUT:
260 case INSN_CONFIG_DIO_OUTPUT:
264 case INSN_CONFIG_DIO_QUERY:
265 data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT;
274 EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
277 * comedi_dio_update_state() - update the internal state of DIO subdevices.
278 * @s: comedi_subdevice struct
279 * @data: the channel mask and bits to update
281 unsigned int comedi_dio_update_state(struct comedi_subdevice *s,
284 unsigned int chanmask = (s->n_chan < 32) ? ((1 << s->n_chan) - 1)
286 unsigned int mask = data[0] & chanmask;
287 unsigned int bits = data[1];
291 s->state |= (bits & mask);
296 EXPORT_SYMBOL_GPL(comedi_dio_update_state);
299 * comedi_bytes_per_scan - get length of asynchronous command "scan" in bytes
300 * @s: comedi_subdevice struct
302 * Determines the overall scan length according to the subdevice type and the
303 * number of channels in the scan.
305 * For digital input, output or input/output subdevices, samples for multiple
306 * channels are assumed to be packed into one or more unsigned short or
307 * unsigned int values according to the subdevice's SDF_LSAMPL flag. For other
308 * types of subdevice, samples are assumed to occupy a whole unsigned short or
309 * unsigned int according to the SDF_LSAMPL flag.
311 * Returns the overall scan length in bytes.
313 unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s)
315 struct comedi_cmd *cmd = &s->async->cmd;
316 unsigned int num_samples;
317 unsigned int bits_per_sample;
322 case COMEDI_SUBD_DIO:
323 bits_per_sample = 8 * comedi_bytes_per_sample(s);
324 num_samples = DIV_ROUND_UP(cmd->scan_end_arg, bits_per_sample);
327 num_samples = cmd->scan_end_arg;
330 return comedi_samples_to_bytes(s, num_samples);
332 EXPORT_SYMBOL_GPL(comedi_bytes_per_scan);
335 * comedi_nscans_left - return the number of scans left in the command
336 * @s: comedi_subdevice struct
337 * @nscans: the expected number of scans
339 * If nscans is 0, the number of scans available in the async buffer will be
340 * used. Otherwise the expected number of scans will be used.
342 * If the async command has a stop_src of TRIG_COUNT, the nscans will be
343 * checked against the number of scans left in the command.
345 * The return value will then be either the expected number of scans or the
346 * number of scans remaining in the command.
348 unsigned int comedi_nscans_left(struct comedi_subdevice *s,
351 struct comedi_async *async = s->async;
352 struct comedi_cmd *cmd = &async->cmd;
355 unsigned int nbytes = comedi_buf_read_n_available(s);
357 nscans = nbytes / comedi_bytes_per_scan(s);
360 if (cmd->stop_src == TRIG_COUNT) {
361 unsigned int scans_left = 0;
363 if (async->scans_done < cmd->stop_arg)
364 scans_left = cmd->stop_arg - async->scans_done;
366 if (nscans > scans_left)
371 EXPORT_SYMBOL_GPL(comedi_nscans_left);
374 * comedi_nsamples_left - return the number of samples left in the command
375 * @s: comedi_subdevice struct
376 * @nsamples: the expected number of samples
378 * Returns the expected number of samples of the number of samples remaining
381 unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
382 unsigned int nsamples)
384 struct comedi_async *async = s->async;
385 struct comedi_cmd *cmd = &async->cmd;
387 if (cmd->stop_src == TRIG_COUNT) {
388 /* +1 to force comedi_nscans_left() to return the scans left */
389 unsigned int nscans = (nsamples / cmd->scan_end_arg) + 1;
390 unsigned int scans_left = comedi_nscans_left(s, nscans);
391 unsigned int scan_pos =
392 comedi_bytes_to_samples(s, async->scan_progress);
393 unsigned long long samples_left = 0;
396 samples_left = ((unsigned long long)scans_left *
397 cmd->scan_end_arg) - scan_pos;
400 if (samples_left < nsamples)
401 nsamples = samples_left;
405 EXPORT_SYMBOL_GPL(comedi_nsamples_left);
408 * comedi_inc_scan_progress - update scan progress in asynchronous command
409 * @s: comedi_subdevice struct
410 * @num_bytes: amount of data in bytes to increment scan progress
412 * Increments the scan progress by the number of bytes specified by num_bytes.
413 * If the scan progress reaches or exceeds the scan length in bytes, reduce
414 * it modulo the scan length in bytes and set the "end of scan" asynchronous
415 * event flag to be processed later.
417 void comedi_inc_scan_progress(struct comedi_subdevice *s,
418 unsigned int num_bytes)
420 struct comedi_async *async = s->async;
421 struct comedi_cmd *cmd = &async->cmd;
422 unsigned int scan_length = comedi_bytes_per_scan(s);
424 /* track the 'cur_chan' for non-SDF_PACKED subdevices */
425 if (!(s->subdev_flags & SDF_PACKED)) {
426 async->cur_chan += comedi_bytes_to_samples(s, num_bytes);
427 async->cur_chan %= cmd->chanlist_len;
430 async->scan_progress += num_bytes;
431 if (async->scan_progress >= scan_length) {
432 unsigned int nscans = async->scan_progress / scan_length;
434 if (async->scans_done < (UINT_MAX - nscans))
435 async->scans_done += nscans;
437 async->scans_done = UINT_MAX;
439 async->scan_progress %= scan_length;
440 async->events |= COMEDI_CB_EOS;
443 EXPORT_SYMBOL_GPL(comedi_inc_scan_progress);
446 * comedi_handle_events - handle events and possibly stop acquisition
447 * @dev: comedi_device struct
448 * @s: comedi_subdevice struct
450 * Handles outstanding asynchronous acquisition event flags associated
451 * with the subdevice. Call the subdevice's "->cancel()" handler if the
452 * "end of acquisition", "error" or "overflow" event flags are set in order
453 * to stop the acquisition at the driver level.
455 * Calls comedi_event() to further process the event flags, which may mark
456 * the asynchronous command as no longer running, possibly terminated with
457 * an error, and may wake up tasks.
459 * Return a bit-mask of the handled events.
461 unsigned int comedi_handle_events(struct comedi_device *dev,
462 struct comedi_subdevice *s)
464 unsigned int events = s->async->events;
469 if (events & COMEDI_CB_CANCEL_MASK)
472 comedi_event(dev, s);
476 EXPORT_SYMBOL_GPL(comedi_handle_events);
478 static int insn_rw_emulate_bits(struct comedi_device *dev,
479 struct comedi_subdevice *s,
480 struct comedi_insn *insn, unsigned int *data)
482 struct comedi_insn new_insn;
484 static const unsigned channels_per_bitfield = 32;
486 unsigned chan = CR_CHAN(insn->chanspec);
487 const unsigned base_bitfield_channel =
488 (chan < channels_per_bitfield) ? 0 : chan;
489 unsigned int new_data[2];
491 memset(new_data, 0, sizeof(new_data));
492 memset(&new_insn, 0, sizeof(new_insn));
493 new_insn.insn = INSN_BITS;
494 new_insn.chanspec = base_bitfield_channel;
496 new_insn.subdev = insn->subdev;
498 if (insn->insn == INSN_WRITE) {
499 if (!(s->subdev_flags & SDF_WRITABLE))
501 new_data[0] = 1 << (chan - base_bitfield_channel); /* mask */
502 new_data[1] = data[0] ? (1 << (chan - base_bitfield_channel))
506 ret = s->insn_bits(dev, s, &new_insn, new_data);
510 if (insn->insn == INSN_READ)
511 data[0] = (new_data[1] >> (chan - base_bitfield_channel)) & 1;
516 static int __comedi_device_postconfig_async(struct comedi_device *dev,
517 struct comedi_subdevice *s)
519 struct comedi_async *async;
520 unsigned int buf_size;
523 if ((s->subdev_flags & (SDF_CMD_READ | SDF_CMD_WRITE)) == 0) {
524 dev_warn(dev->class_dev,
525 "async subdevices must support SDF_CMD_READ or SDF_CMD_WRITE\n");
528 if (!s->do_cmdtest) {
529 dev_warn(dev->class_dev,
530 "async subdevices must have a do_cmdtest() function\n");
534 async = kzalloc(sizeof(*async), GFP_KERNEL);
538 init_waitqueue_head(&async->wait_head);
541 async->max_bufsize = comedi_default_buf_maxsize_kb * 1024;
542 buf_size = comedi_default_buf_size_kb * 1024;
543 if (buf_size > async->max_bufsize)
544 buf_size = async->max_bufsize;
546 if (comedi_buf_alloc(dev, s, buf_size) < 0) {
547 dev_warn(dev->class_dev, "Buffer allocation failed\n");
551 ret = s->buf_change(dev, s);
556 comedi_alloc_subdevice_minor(s);
561 static int __comedi_device_postconfig(struct comedi_device *dev)
563 struct comedi_subdevice *s;
567 for (i = 0; i < dev->n_subdevices; i++) {
568 s = &dev->subdevices[i];
570 if (s->type == COMEDI_SUBD_UNUSED)
573 if (s->type == COMEDI_SUBD_DO) {
575 s->io_bits = (1 << s->n_chan) - 1;
577 s->io_bits = 0xffffffff;
580 if (s->len_chanlist == 0)
584 ret = __comedi_device_postconfig_async(dev, s);
589 if (!s->range_table && !s->range_table_list)
590 s->range_table = &range_unknown;
592 if (!s->insn_read && s->insn_bits)
593 s->insn_read = insn_rw_emulate_bits;
594 if (!s->insn_write && s->insn_bits)
595 s->insn_write = insn_rw_emulate_bits;
598 s->insn_read = insn_inval;
600 s->insn_write = insn_inval;
602 s->insn_bits = insn_inval;
604 s->insn_config = insn_inval;
607 s->poll = poll_invalid;
613 /* do a little post-config cleanup */
614 static int comedi_device_postconfig(struct comedi_device *dev)
618 ret = __comedi_device_postconfig(dev);
621 down_write(&dev->attach_lock);
622 dev->attached = true;
623 up_write(&dev->attach_lock);
628 * Generic recognize function for drivers that register their supported
631 * 'driv->board_name' points to a 'const char *' member within the
632 * zeroth element of an array of some private board information
633 * structure, say 'struct foo_board' containing a member 'const char
634 * *board_name' that is initialized to point to a board name string that
635 * is one of the candidates matched against this function's 'name'
638 * 'driv->offset' is the size of the private board information
639 * structure, say 'sizeof(struct foo_board)', and 'driv->num_names' is
640 * the length of the array of private board information structures.
642 * If one of the board names in the array of private board information
643 * structures matches the name supplied to this function, the function
644 * returns a pointer to the pointer to the board name, otherwise it
645 * returns NULL. The return value ends up in the 'board_ptr' member of
646 * a 'struct comedi_device' that the low-level comedi driver's
647 * 'attach()' hook can convert to a point to a particular element of its
648 * array of private board information structures by subtracting the
649 * offset of the member that points to the board name. (No subtraction
650 * is required if the board name pointer is the first member of the
651 * private board information structure, which is generally the case.)
653 static void *comedi_recognize(struct comedi_driver *driv, const char *name)
655 char **name_ptr = (char **)driv->board_name;
658 for (i = 0; i < driv->num_names; i++) {
659 if (strcmp(*name_ptr, name) == 0)
661 name_ptr = (void *)name_ptr + driv->offset;
667 static void comedi_report_boards(struct comedi_driver *driv)
670 const char *const *name_ptr;
672 pr_info("comedi: valid board names for %s driver are:\n",
675 name_ptr = driv->board_name;
676 for (i = 0; i < driv->num_names; i++) {
677 pr_info(" %s\n", *name_ptr);
678 name_ptr = (const char **)((char *)name_ptr + driv->offset);
681 if (driv->num_names == 0)
682 pr_info(" %s\n", driv->driver_name);
686 * comedi_load_firmware() - Request and load firmware for a device.
687 * @dev: comedi_device struct
688 * @hw_device: device struct for the comedi_device
689 * @name: the name of the firmware image
690 * @cb: callback to the upload the firmware image
691 * @context: private context from the driver
693 int comedi_load_firmware(struct comedi_device *dev,
694 struct device *device,
696 int (*cb)(struct comedi_device *dev,
697 const u8 *data, size_t size,
698 unsigned long context),
699 unsigned long context)
701 const struct firmware *fw;
707 ret = request_firmware(&fw, name, device);
709 ret = cb(dev, fw->data, fw->size, context);
710 release_firmware(fw);
713 return ret < 0 ? ret : 0;
715 EXPORT_SYMBOL_GPL(comedi_load_firmware);
718 * __comedi_request_region() - Request an I/O reqion for a legacy driver.
719 * @dev: comedi_device struct
720 * @start: base address of the I/O reqion
721 * @len: length of the I/O region
723 int __comedi_request_region(struct comedi_device *dev,
724 unsigned long start, unsigned long len)
727 dev_warn(dev->class_dev,
728 "%s: a I/O base address must be specified\n",
733 if (!request_region(start, len, dev->board_name)) {
734 dev_warn(dev->class_dev, "%s: I/O port conflict (%#lx,%lu)\n",
735 dev->board_name, start, len);
741 EXPORT_SYMBOL_GPL(__comedi_request_region);
744 * comedi_request_region() - Request an I/O reqion for a legacy driver.
745 * @dev: comedi_device struct
746 * @start: base address of the I/O reqion
747 * @len: length of the I/O region
749 int comedi_request_region(struct comedi_device *dev,
750 unsigned long start, unsigned long len)
754 ret = __comedi_request_region(dev, start, len);
762 EXPORT_SYMBOL_GPL(comedi_request_region);
765 * comedi_legacy_detach() - A generic (*detach) function for legacy drivers.
766 * @dev: comedi_device struct
768 void comedi_legacy_detach(struct comedi_device *dev)
771 free_irq(dev->irq, dev);
774 if (dev->iobase && dev->iolen) {
775 release_region(dev->iobase, dev->iolen);
780 EXPORT_SYMBOL_GPL(comedi_legacy_detach);
782 int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
784 struct comedi_driver *driv;
790 mutex_lock(&comedi_drivers_list_lock);
791 for (driv = comedi_drivers; driv; driv = driv->next) {
792 if (!try_module_get(driv->module))
794 if (driv->num_names) {
795 dev->board_ptr = comedi_recognize(driv, it->board_name);
798 } else if (strcmp(driv->driver_name, it->board_name) == 0) {
801 module_put(driv->module);
804 /* recognize has failed if we get here */
805 /* report valid board names before returning error */
806 for (driv = comedi_drivers; driv; driv = driv->next) {
807 if (!try_module_get(driv->module))
809 comedi_report_boards(driv);
810 module_put(driv->module);
815 if (driv->attach == NULL) {
816 /* driver does not support manual configuration */
817 dev_warn(dev->class_dev,
818 "driver '%s' does not support attach using comedi_config\n",
820 module_put(driv->module);
825 dev->board_name = dev->board_ptr ? *(const char **)dev->board_ptr
826 : dev->driver->driver_name;
827 ret = driv->attach(dev, it);
829 ret = comedi_device_postconfig(dev);
831 comedi_device_detach(dev);
832 module_put(driv->module);
834 /* On success, the driver module count has been incremented. */
836 mutex_unlock(&comedi_drivers_list_lock);
840 int comedi_auto_config(struct device *hardware_device,
841 struct comedi_driver *driver, unsigned long context)
843 struct comedi_device *dev;
846 if (!hardware_device) {
847 pr_warn("BUG! comedi_auto_config called with NULL hardware_device\n");
851 dev_warn(hardware_device,
852 "BUG! comedi_auto_config called with NULL comedi driver\n");
856 if (!driver->auto_attach) {
857 dev_warn(hardware_device,
858 "BUG! comedi driver '%s' has no auto_attach handler\n",
859 driver->driver_name);
863 dev = comedi_alloc_board_minor(hardware_device);
865 dev_warn(hardware_device,
866 "driver '%s' could not create device.\n",
867 driver->driver_name);
870 /* Note: comedi_alloc_board_minor() locked dev->mutex. */
872 dev->driver = driver;
873 dev->board_name = dev->driver->driver_name;
874 ret = driver->auto_attach(dev, context);
876 ret = comedi_device_postconfig(dev);
877 mutex_unlock(&dev->mutex);
880 dev_warn(hardware_device,
881 "driver '%s' failed to auto-configure device.\n",
882 driver->driver_name);
883 comedi_release_hardware_device(hardware_device);
886 * class_dev should be set properly here
887 * after a successful auto config
889 dev_info(dev->class_dev,
890 "driver '%s' has successfully auto-configured '%s'.\n",
891 driver->driver_name, dev->board_name);
895 EXPORT_SYMBOL_GPL(comedi_auto_config);
897 void comedi_auto_unconfig(struct device *hardware_device)
899 if (hardware_device == NULL)
901 comedi_release_hardware_device(hardware_device);
903 EXPORT_SYMBOL_GPL(comedi_auto_unconfig);
905 int comedi_driver_register(struct comedi_driver *driver)
907 mutex_lock(&comedi_drivers_list_lock);
908 driver->next = comedi_drivers;
909 comedi_drivers = driver;
910 mutex_unlock(&comedi_drivers_list_lock);
914 EXPORT_SYMBOL_GPL(comedi_driver_register);
916 void comedi_driver_unregister(struct comedi_driver *driver)
918 struct comedi_driver *prev;
921 /* unlink the driver */
922 mutex_lock(&comedi_drivers_list_lock);
923 if (comedi_drivers == driver) {
924 comedi_drivers = driver->next;
926 for (prev = comedi_drivers; prev->next; prev = prev->next) {
927 if (prev->next == driver) {
928 prev->next = driver->next;
933 mutex_unlock(&comedi_drivers_list_lock);
935 /* check for devices using this driver */
936 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
937 struct comedi_device *dev = comedi_dev_get_from_minor(i);
942 mutex_lock(&dev->mutex);
943 if (dev->attached && dev->driver == driver) {
945 dev_warn(dev->class_dev,
946 "BUG! detaching device with use_count=%d\n",
948 comedi_device_detach(dev);
950 mutex_unlock(&dev->mutex);
954 EXPORT_SYMBOL_GPL(comedi_driver_unregister);