drivers.c revision d27620669209e3cc87f13449326eeb68229e4bd0
1/* 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 19#include <linux/device.h> 20#include <linux/module.h> 21#include <linux/errno.h> 22#include <linux/kconfig.h> 23#include <linux/kernel.h> 24#include <linux/sched.h> 25#include <linux/fcntl.h> 26#include <linux/ioport.h> 27#include <linux/mm.h> 28#include <linux/slab.h> 29#include <linux/highmem.h> /* for SuSE brokenness */ 30#include <linux/vmalloc.h> 31#include <linux/cdev.h> 32#include <linux/dma-mapping.h> 33#include <linux/io.h> 34#include <linux/interrupt.h> 35#include <linux/firmware.h> 36 37#include "comedidev.h" 38#include "comedi_internal.h" 39 40struct comedi_driver *comedi_drivers; 41/* protects access to comedi_drivers */ 42DEFINE_MUTEX(comedi_drivers_list_lock); 43 44int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev) 45{ 46 if (hw_dev == dev->hw_dev) 47 return 0; 48 if (dev->hw_dev != NULL) 49 return -EEXIST; 50 dev->hw_dev = get_device(hw_dev); 51 return 0; 52} 53EXPORT_SYMBOL_GPL(comedi_set_hw_dev); 54 55static void comedi_clear_hw_dev(struct comedi_device *dev) 56{ 57 put_device(dev->hw_dev); 58 dev->hw_dev = NULL; 59} 60 61/** 62 * comedi_alloc_devpriv() - Allocate memory for the device private data. 63 * @dev: comedi_device struct 64 * @size: size of the memory to allocate 65 */ 66void *comedi_alloc_devpriv(struct comedi_device *dev, size_t size) 67{ 68 dev->private = kzalloc(size, GFP_KERNEL); 69 return dev->private; 70} 71EXPORT_SYMBOL_GPL(comedi_alloc_devpriv); 72 73int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices) 74{ 75 struct comedi_subdevice *s; 76 int i; 77 78 if (num_subdevices < 1) 79 return -EINVAL; 80 81 s = kcalloc(num_subdevices, sizeof(*s), GFP_KERNEL); 82 if (!s) 83 return -ENOMEM; 84 dev->subdevices = s; 85 dev->n_subdevices = num_subdevices; 86 87 for (i = 0; i < num_subdevices; ++i) { 88 s = &dev->subdevices[i]; 89 s->device = dev; 90 s->index = i; 91 s->async_dma_dir = DMA_NONE; 92 spin_lock_init(&s->spin_lock); 93 s->minor = -1; 94 } 95 return 0; 96} 97EXPORT_SYMBOL_GPL(comedi_alloc_subdevices); 98 99/** 100 * comedi_alloc_subdev_readback() - Allocate memory for the subdevice readback. 101 * @s: comedi_subdevice struct 102 */ 103int comedi_alloc_subdev_readback(struct comedi_subdevice *s) 104{ 105 if (!s->n_chan) 106 return -EINVAL; 107 108 s->readback = kcalloc(s->n_chan, sizeof(*s->readback), GFP_KERNEL); 109 if (!s->readback) 110 return -ENOMEM; 111 return 0; 112} 113EXPORT_SYMBOL_GPL(comedi_alloc_subdev_readback); 114 115static void comedi_device_detach_cleanup(struct comedi_device *dev) 116{ 117 int i; 118 struct comedi_subdevice *s; 119 120 if (dev->subdevices) { 121 for (i = 0; i < dev->n_subdevices; i++) { 122 s = &dev->subdevices[i]; 123 if (s->runflags & SRF_FREE_SPRIV) 124 kfree(s->private); 125 comedi_free_subdevice_minor(s); 126 if (s->async) { 127 comedi_buf_alloc(dev, s, 0); 128 kfree(s->async); 129 } 130 kfree(s->readback); 131 } 132 kfree(dev->subdevices); 133 dev->subdevices = NULL; 134 dev->n_subdevices = 0; 135 } 136 kfree(dev->private); 137 dev->private = NULL; 138 dev->driver = NULL; 139 dev->board_name = NULL; 140 dev->board_ptr = NULL; 141 dev->mmio = NULL; 142 dev->iobase = 0; 143 dev->iolen = 0; 144 dev->ioenabled = false; 145 dev->irq = 0; 146 dev->read_subdev = NULL; 147 dev->write_subdev = NULL; 148 dev->open = NULL; 149 dev->close = NULL; 150 comedi_clear_hw_dev(dev); 151} 152 153void comedi_device_detach(struct comedi_device *dev) 154{ 155 comedi_device_cancel_all(dev); 156 down_write(&dev->attach_lock); 157 dev->attached = false; 158 dev->detach_count++; 159 if (dev->driver) 160 dev->driver->detach(dev); 161 comedi_device_detach_cleanup(dev); 162 up_write(&dev->attach_lock); 163} 164 165static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s) 166{ 167 return -EINVAL; 168} 169 170int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s, 171 struct comedi_insn *insn, unsigned int *data) 172{ 173 return -EINVAL; 174} 175 176/** 177 * comedi_readback_insn_read() - A generic (*insn_read) for subdevice readback. 178 * @dev: comedi_device struct 179 * @s: comedi_subdevice struct 180 * @insn: comedi_insn struct 181 * @data: pointer to return the readback data 182 */ 183int comedi_readback_insn_read(struct comedi_device *dev, 184 struct comedi_subdevice *s, 185 struct comedi_insn *insn, 186 unsigned int *data) 187{ 188 unsigned int chan = CR_CHAN(insn->chanspec); 189 int i; 190 191 if (!s->readback) 192 return -EINVAL; 193 194 for (i = 0; i < insn->n; i++) 195 data[i] = s->readback[chan]; 196 197 return insn->n; 198} 199EXPORT_SYMBOL_GPL(comedi_readback_insn_read); 200 201/** 202 * comedi_timeout() - busy-wait for a driver condition to occur. 203 * @dev: comedi_device struct 204 * @s: comedi_subdevice struct 205 * @insn: comedi_insn struct 206 * @cb: callback to check for the condition 207 * @context: private context from the driver 208 */ 209int comedi_timeout(struct comedi_device *dev, 210 struct comedi_subdevice *s, 211 struct comedi_insn *insn, 212 int (*cb)(struct comedi_device *dev, 213 struct comedi_subdevice *s, 214 struct comedi_insn *insn, 215 unsigned long context), 216 unsigned long context) 217{ 218 unsigned long timeout = jiffies + msecs_to_jiffies(COMEDI_TIMEOUT_MS); 219 int ret; 220 221 while (time_before(jiffies, timeout)) { 222 ret = cb(dev, s, insn, context); 223 if (ret != -EBUSY) 224 return ret; /* success (0) or non EBUSY errno */ 225 cpu_relax(); 226 } 227 return -ETIMEDOUT; 228} 229EXPORT_SYMBOL_GPL(comedi_timeout); 230 231/** 232 * comedi_dio_insn_config() - boilerplate (*insn_config) for DIO subdevices. 233 * @dev: comedi_device struct 234 * @s: comedi_subdevice struct 235 * @insn: comedi_insn struct 236 * @data: parameters for the @insn 237 * @mask: io_bits mask for grouped channels 238 */ 239int comedi_dio_insn_config(struct comedi_device *dev, 240 struct comedi_subdevice *s, 241 struct comedi_insn *insn, 242 unsigned int *data, 243 unsigned int mask) 244{ 245 unsigned int chan_mask = 1 << CR_CHAN(insn->chanspec); 246 247 if (!mask) 248 mask = chan_mask; 249 250 switch (data[0]) { 251 case INSN_CONFIG_DIO_INPUT: 252 s->io_bits &= ~mask; 253 break; 254 255 case INSN_CONFIG_DIO_OUTPUT: 256 s->io_bits |= mask; 257 break; 258 259 case INSN_CONFIG_DIO_QUERY: 260 data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT; 261 return insn->n; 262 263 default: 264 return -EINVAL; 265 } 266 267 return 0; 268} 269EXPORT_SYMBOL_GPL(comedi_dio_insn_config); 270 271/** 272 * comedi_dio_update_state() - update the internal state of DIO subdevices. 273 * @s: comedi_subdevice struct 274 * @data: the channel mask and bits to update 275 */ 276unsigned int comedi_dio_update_state(struct comedi_subdevice *s, 277 unsigned int *data) 278{ 279 unsigned int chanmask = (s->n_chan < 32) ? ((1 << s->n_chan) - 1) 280 : 0xffffffff; 281 unsigned int mask = data[0] & chanmask; 282 unsigned int bits = data[1]; 283 284 if (mask) { 285 s->state &= ~mask; 286 s->state |= (bits & mask); 287 } 288 289 return mask; 290} 291EXPORT_SYMBOL_GPL(comedi_dio_update_state); 292 293static int insn_rw_emulate_bits(struct comedi_device *dev, 294 struct comedi_subdevice *s, 295 struct comedi_insn *insn, unsigned int *data) 296{ 297 struct comedi_insn new_insn; 298 int ret; 299 static const unsigned channels_per_bitfield = 32; 300 301 unsigned chan = CR_CHAN(insn->chanspec); 302 const unsigned base_bitfield_channel = 303 (chan < channels_per_bitfield) ? 0 : chan; 304 unsigned int new_data[2]; 305 306 memset(new_data, 0, sizeof(new_data)); 307 memset(&new_insn, 0, sizeof(new_insn)); 308 new_insn.insn = INSN_BITS; 309 new_insn.chanspec = base_bitfield_channel; 310 new_insn.n = 2; 311 new_insn.subdev = insn->subdev; 312 313 if (insn->insn == INSN_WRITE) { 314 if (!(s->subdev_flags & SDF_WRITABLE)) 315 return -EINVAL; 316 new_data[0] = 1 << (chan - base_bitfield_channel); /* mask */ 317 new_data[1] = data[0] ? (1 << (chan - base_bitfield_channel)) 318 : 0; /* bits */ 319 } 320 321 ret = s->insn_bits(dev, s, &new_insn, new_data); 322 if (ret < 0) 323 return ret; 324 325 if (insn->insn == INSN_READ) 326 data[0] = (new_data[1] >> (chan - base_bitfield_channel)) & 1; 327 328 return 1; 329} 330 331static int __comedi_device_postconfig_async(struct comedi_device *dev, 332 struct comedi_subdevice *s) 333{ 334 struct comedi_async *async; 335 unsigned int buf_size; 336 int ret; 337 338 if ((s->subdev_flags & (SDF_CMD_READ | SDF_CMD_WRITE)) == 0) { 339 dev_warn(dev->class_dev, 340 "async subdevices must support SDF_CMD_READ or SDF_CMD_WRITE\n"); 341 return -EINVAL; 342 } 343 if (!s->do_cmdtest) { 344 dev_warn(dev->class_dev, 345 "async subdevices must have a do_cmdtest() function\n"); 346 return -EINVAL; 347 } 348 349 async = kzalloc(sizeof(*async), GFP_KERNEL); 350 if (!async) 351 return -ENOMEM; 352 353 init_waitqueue_head(&async->wait_head); 354 s->async = async; 355 356 async->max_bufsize = comedi_default_buf_maxsize_kb * 1024; 357 buf_size = comedi_default_buf_size_kb * 1024; 358 if (buf_size > async->max_bufsize) 359 buf_size = async->max_bufsize; 360 361 if (comedi_buf_alloc(dev, s, buf_size) < 0) { 362 dev_warn(dev->class_dev, "Buffer allocation failed\n"); 363 return -ENOMEM; 364 } 365 if (s->buf_change) { 366 ret = s->buf_change(dev, s); 367 if (ret < 0) 368 return ret; 369 } 370 371 comedi_alloc_subdevice_minor(s); 372 373 return 0; 374} 375 376static int __comedi_device_postconfig(struct comedi_device *dev) 377{ 378 struct comedi_subdevice *s; 379 int ret; 380 int i; 381 382 for (i = 0; i < dev->n_subdevices; i++) { 383 s = &dev->subdevices[i]; 384 385 if (s->type == COMEDI_SUBD_UNUSED) 386 continue; 387 388 if (s->type == COMEDI_SUBD_DO) { 389 if (s->n_chan < 32) 390 s->io_bits = (1 << s->n_chan) - 1; 391 else 392 s->io_bits = 0xffffffff; 393 } 394 395 if (s->len_chanlist == 0) 396 s->len_chanlist = 1; 397 398 if (s->do_cmd) { 399 ret = __comedi_device_postconfig_async(dev, s); 400 if (ret) 401 return ret; 402 } 403 404 if (!s->range_table && !s->range_table_list) 405 s->range_table = &range_unknown; 406 407 if (!s->insn_read && s->insn_bits) 408 s->insn_read = insn_rw_emulate_bits; 409 if (!s->insn_write && s->insn_bits) 410 s->insn_write = insn_rw_emulate_bits; 411 412 if (!s->insn_read) 413 s->insn_read = insn_inval; 414 if (!s->insn_write) 415 s->insn_write = insn_inval; 416 if (!s->insn_bits) 417 s->insn_bits = insn_inval; 418 if (!s->insn_config) 419 s->insn_config = insn_inval; 420 421 if (!s->poll) 422 s->poll = poll_invalid; 423 } 424 425 return 0; 426} 427 428/* do a little post-config cleanup */ 429static int comedi_device_postconfig(struct comedi_device *dev) 430{ 431 int ret; 432 433 ret = __comedi_device_postconfig(dev); 434 if (ret < 0) 435 return ret; 436 down_write(&dev->attach_lock); 437 dev->attached = true; 438 up_write(&dev->attach_lock); 439 return 0; 440} 441 442/* 443 * Generic recognize function for drivers that register their supported 444 * board names. 445 * 446 * 'driv->board_name' points to a 'const char *' member within the 447 * zeroth element of an array of some private board information 448 * structure, say 'struct foo_board' containing a member 'const char 449 * *board_name' that is initialized to point to a board name string that 450 * is one of the candidates matched against this function's 'name' 451 * parameter. 452 * 453 * 'driv->offset' is the size of the private board information 454 * structure, say 'sizeof(struct foo_board)', and 'driv->num_names' is 455 * the length of the array of private board information structures. 456 * 457 * If one of the board names in the array of private board information 458 * structures matches the name supplied to this function, the function 459 * returns a pointer to the pointer to the board name, otherwise it 460 * returns NULL. The return value ends up in the 'board_ptr' member of 461 * a 'struct comedi_device' that the low-level comedi driver's 462 * 'attach()' hook can convert to a point to a particular element of its 463 * array of private board information structures by subtracting the 464 * offset of the member that points to the board name. (No subtraction 465 * is required if the board name pointer is the first member of the 466 * private board information structure, which is generally the case.) 467 */ 468static void *comedi_recognize(struct comedi_driver *driv, const char *name) 469{ 470 char **name_ptr = (char **)driv->board_name; 471 int i; 472 473 for (i = 0; i < driv->num_names; i++) { 474 if (strcmp(*name_ptr, name) == 0) 475 return name_ptr; 476 name_ptr = (void *)name_ptr + driv->offset; 477 } 478 479 return NULL; 480} 481 482static void comedi_report_boards(struct comedi_driver *driv) 483{ 484 unsigned int i; 485 const char *const *name_ptr; 486 487 pr_info("comedi: valid board names for %s driver are:\n", 488 driv->driver_name); 489 490 name_ptr = driv->board_name; 491 for (i = 0; i < driv->num_names; i++) { 492 pr_info(" %s\n", *name_ptr); 493 name_ptr = (const char **)((char *)name_ptr + driv->offset); 494 } 495 496 if (driv->num_names == 0) 497 pr_info(" %s\n", driv->driver_name); 498} 499 500/** 501 * comedi_load_firmware() - Request and load firmware for a device. 502 * @dev: comedi_device struct 503 * @hw_device: device struct for the comedi_device 504 * @name: the name of the firmware image 505 * @cb: callback to the upload the firmware image 506 * @context: private context from the driver 507 */ 508int comedi_load_firmware(struct comedi_device *dev, 509 struct device *device, 510 const char *name, 511 int (*cb)(struct comedi_device *dev, 512 const u8 *data, size_t size, 513 unsigned long context), 514 unsigned long context) 515{ 516 const struct firmware *fw; 517 int ret; 518 519 if (!cb) 520 return -EINVAL; 521 522 ret = request_firmware(&fw, name, device); 523 if (ret == 0) { 524 ret = cb(dev, fw->data, fw->size, context); 525 release_firmware(fw); 526 } 527 528 return ret < 0 ? ret : 0; 529} 530EXPORT_SYMBOL_GPL(comedi_load_firmware); 531 532/** 533 * __comedi_request_region() - Request an I/O reqion for a legacy driver. 534 * @dev: comedi_device struct 535 * @start: base address of the I/O reqion 536 * @len: length of the I/O region 537 */ 538int __comedi_request_region(struct comedi_device *dev, 539 unsigned long start, unsigned long len) 540{ 541 if (!start) { 542 dev_warn(dev->class_dev, 543 "%s: a I/O base address must be specified\n", 544 dev->board_name); 545 return -EINVAL; 546 } 547 548 if (!request_region(start, len, dev->board_name)) { 549 dev_warn(dev->class_dev, "%s: I/O port conflict (%#lx,%lu)\n", 550 dev->board_name, start, len); 551 return -EIO; 552 } 553 554 return 0; 555} 556EXPORT_SYMBOL_GPL(__comedi_request_region); 557 558/** 559 * comedi_request_region() - Request an I/O reqion for a legacy driver. 560 * @dev: comedi_device struct 561 * @start: base address of the I/O reqion 562 * @len: length of the I/O region 563 */ 564int comedi_request_region(struct comedi_device *dev, 565 unsigned long start, unsigned long len) 566{ 567 int ret; 568 569 ret = __comedi_request_region(dev, start, len); 570 if (ret == 0) { 571 dev->iobase = start; 572 dev->iolen = len; 573 } 574 575 return ret; 576} 577EXPORT_SYMBOL_GPL(comedi_request_region); 578 579/** 580 * comedi_legacy_detach() - A generic (*detach) function for legacy drivers. 581 * @dev: comedi_device struct 582 */ 583void comedi_legacy_detach(struct comedi_device *dev) 584{ 585 if (dev->irq) { 586 free_irq(dev->irq, dev); 587 dev->irq = 0; 588 } 589 if (dev->iobase && dev->iolen) { 590 release_region(dev->iobase, dev->iolen); 591 dev->iobase = 0; 592 dev->iolen = 0; 593 } 594} 595EXPORT_SYMBOL_GPL(comedi_legacy_detach); 596 597int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) 598{ 599 struct comedi_driver *driv; 600 int ret; 601 602 if (dev->attached) 603 return -EBUSY; 604 605 mutex_lock(&comedi_drivers_list_lock); 606 for (driv = comedi_drivers; driv; driv = driv->next) { 607 if (!try_module_get(driv->module)) 608 continue; 609 if (driv->num_names) { 610 dev->board_ptr = comedi_recognize(driv, it->board_name); 611 if (dev->board_ptr) 612 break; 613 } else if (strcmp(driv->driver_name, it->board_name) == 0) { 614 break; 615 } 616 module_put(driv->module); 617 } 618 if (driv == NULL) { 619 /* recognize has failed if we get here */ 620 /* report valid board names before returning error */ 621 for (driv = comedi_drivers; driv; driv = driv->next) { 622 if (!try_module_get(driv->module)) 623 continue; 624 comedi_report_boards(driv); 625 module_put(driv->module); 626 } 627 ret = -EIO; 628 goto out; 629 } 630 if (driv->attach == NULL) { 631 /* driver does not support manual configuration */ 632 dev_warn(dev->class_dev, 633 "driver '%s' does not support attach using comedi_config\n", 634 driv->driver_name); 635 module_put(driv->module); 636 ret = -ENOSYS; 637 goto out; 638 } 639 dev->driver = driv; 640 dev->board_name = dev->board_ptr ? *(const char **)dev->board_ptr 641 : dev->driver->driver_name; 642 ret = driv->attach(dev, it); 643 if (ret >= 0) 644 ret = comedi_device_postconfig(dev); 645 if (ret < 0) { 646 comedi_device_detach(dev); 647 module_put(driv->module); 648 } 649 /* On success, the driver module count has been incremented. */ 650out: 651 mutex_unlock(&comedi_drivers_list_lock); 652 return ret; 653} 654 655int comedi_auto_config(struct device *hardware_device, 656 struct comedi_driver *driver, unsigned long context) 657{ 658 struct comedi_device *dev; 659 int ret; 660 661 if (!hardware_device) { 662 pr_warn("BUG! comedi_auto_config called with NULL hardware_device\n"); 663 return -EINVAL; 664 } 665 if (!driver) { 666 dev_warn(hardware_device, 667 "BUG! comedi_auto_config called with NULL comedi driver\n"); 668 return -EINVAL; 669 } 670 671 if (!driver->auto_attach) { 672 dev_warn(hardware_device, 673 "BUG! comedi driver '%s' has no auto_attach handler\n", 674 driver->driver_name); 675 return -EINVAL; 676 } 677 678 dev = comedi_alloc_board_minor(hardware_device); 679 if (IS_ERR(dev)) { 680 dev_warn(hardware_device, 681 "driver '%s' could not create device.\n", 682 driver->driver_name); 683 return PTR_ERR(dev); 684 } 685 /* Note: comedi_alloc_board_minor() locked dev->mutex. */ 686 687 dev->driver = driver; 688 dev->board_name = dev->driver->driver_name; 689 ret = driver->auto_attach(dev, context); 690 if (ret >= 0) 691 ret = comedi_device_postconfig(dev); 692 mutex_unlock(&dev->mutex); 693 694 if (ret < 0) { 695 dev_warn(hardware_device, 696 "driver '%s' failed to auto-configure device.\n", 697 driver->driver_name); 698 comedi_release_hardware_device(hardware_device); 699 } else { 700 /* 701 * class_dev should be set properly here 702 * after a successful auto config 703 */ 704 dev_info(dev->class_dev, 705 "driver '%s' has successfully auto-configured '%s'.\n", 706 driver->driver_name, dev->board_name); 707 } 708 return ret; 709} 710EXPORT_SYMBOL_GPL(comedi_auto_config); 711 712void comedi_auto_unconfig(struct device *hardware_device) 713{ 714 if (hardware_device == NULL) 715 return; 716 comedi_release_hardware_device(hardware_device); 717} 718EXPORT_SYMBOL_GPL(comedi_auto_unconfig); 719 720int comedi_driver_register(struct comedi_driver *driver) 721{ 722 mutex_lock(&comedi_drivers_list_lock); 723 driver->next = comedi_drivers; 724 comedi_drivers = driver; 725 mutex_unlock(&comedi_drivers_list_lock); 726 727 return 0; 728} 729EXPORT_SYMBOL_GPL(comedi_driver_register); 730 731void comedi_driver_unregister(struct comedi_driver *driver) 732{ 733 struct comedi_driver *prev; 734 int i; 735 736 /* unlink the driver */ 737 mutex_lock(&comedi_drivers_list_lock); 738 if (comedi_drivers == driver) { 739 comedi_drivers = driver->next; 740 } else { 741 for (prev = comedi_drivers; prev->next; prev = prev->next) { 742 if (prev->next == driver) { 743 prev->next = driver->next; 744 break; 745 } 746 } 747 } 748 mutex_unlock(&comedi_drivers_list_lock); 749 750 /* check for devices using this driver */ 751 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { 752 struct comedi_device *dev = comedi_dev_get_from_minor(i); 753 754 if (!dev) 755 continue; 756 757 mutex_lock(&dev->mutex); 758 if (dev->attached && dev->driver == driver) { 759 if (dev->use_count) 760 dev_warn(dev->class_dev, 761 "BUG! detaching device with use_count=%d\n", 762 dev->use_count); 763 comedi_device_detach(dev); 764 } 765 mutex_unlock(&dev->mutex); 766 comedi_dev_put(dev); 767 } 768} 769EXPORT_SYMBOL_GPL(comedi_driver_unregister); 770