.. | .. |
---|
278 | 278 | int __parport_register_driver(struct parport_driver *drv, struct module *owner, |
---|
279 | 279 | const char *mod_name) |
---|
280 | 280 | { |
---|
281 | | - if (list_empty(&portlist)) |
---|
| 281 | + /* using device model */ |
---|
| 282 | + int ret; |
---|
| 283 | + |
---|
| 284 | + /* initialize common driver fields */ |
---|
| 285 | + drv->driver.name = drv->name; |
---|
| 286 | + drv->driver.bus = &parport_bus_type; |
---|
| 287 | + drv->driver.owner = owner; |
---|
| 288 | + drv->driver.mod_name = mod_name; |
---|
| 289 | + ret = driver_register(&drv->driver); |
---|
| 290 | + if (ret) |
---|
| 291 | + return ret; |
---|
| 292 | + |
---|
| 293 | + /* |
---|
| 294 | + * check if bus has any parallel port registered, if |
---|
| 295 | + * none is found then load the lowlevel driver. |
---|
| 296 | + */ |
---|
| 297 | + ret = bus_for_each_dev(&parport_bus_type, NULL, NULL, |
---|
| 298 | + port_detect); |
---|
| 299 | + if (!ret) |
---|
282 | 300 | get_lowlevel_driver(); |
---|
283 | 301 | |
---|
284 | | - if (drv->devmodel) { |
---|
285 | | - /* using device model */ |
---|
286 | | - int ret; |
---|
287 | | - |
---|
288 | | - /* initialize common driver fields */ |
---|
289 | | - drv->driver.name = drv->name; |
---|
290 | | - drv->driver.bus = &parport_bus_type; |
---|
291 | | - drv->driver.owner = owner; |
---|
292 | | - drv->driver.mod_name = mod_name; |
---|
293 | | - ret = driver_register(&drv->driver); |
---|
294 | | - if (ret) |
---|
295 | | - return ret; |
---|
296 | | - |
---|
297 | | - /* |
---|
298 | | - * check if bus has any parallel port registered, if |
---|
299 | | - * none is found then load the lowlevel driver. |
---|
300 | | - */ |
---|
301 | | - ret = bus_for_each_dev(&parport_bus_type, NULL, NULL, |
---|
302 | | - port_detect); |
---|
303 | | - if (!ret) |
---|
304 | | - get_lowlevel_driver(); |
---|
305 | | - |
---|
306 | | - mutex_lock(®istration_lock); |
---|
307 | | - if (drv->match_port) |
---|
308 | | - bus_for_each_dev(&parport_bus_type, NULL, drv, |
---|
309 | | - port_check); |
---|
310 | | - mutex_unlock(®istration_lock); |
---|
311 | | - } else { |
---|
312 | | - struct parport *port; |
---|
313 | | - |
---|
314 | | - drv->devmodel = false; |
---|
315 | | - |
---|
316 | | - mutex_lock(®istration_lock); |
---|
317 | | - list_for_each_entry(port, &portlist, list) |
---|
318 | | - drv->attach(port); |
---|
319 | | - list_add(&drv->list, &drivers); |
---|
320 | | - mutex_unlock(®istration_lock); |
---|
321 | | - } |
---|
| 302 | + mutex_lock(®istration_lock); |
---|
| 303 | + if (drv->match_port) |
---|
| 304 | + bus_for_each_dev(&parport_bus_type, NULL, drv, |
---|
| 305 | + port_check); |
---|
| 306 | + mutex_unlock(®istration_lock); |
---|
322 | 307 | |
---|
323 | 308 | return 0; |
---|
324 | 309 | } |
---|
.. | .. |
---|
353 | 338 | |
---|
354 | 339 | void parport_unregister_driver(struct parport_driver *drv) |
---|
355 | 340 | { |
---|
356 | | - struct parport *port; |
---|
357 | | - |
---|
358 | 341 | mutex_lock(®istration_lock); |
---|
359 | | - if (drv->devmodel) { |
---|
360 | | - bus_for_each_dev(&parport_bus_type, NULL, drv, port_detach); |
---|
361 | | - driver_unregister(&drv->driver); |
---|
362 | | - } else { |
---|
363 | | - list_del_init(&drv->list); |
---|
364 | | - list_for_each_entry(port, &portlist, list) |
---|
365 | | - drv->detach(port); |
---|
366 | | - } |
---|
| 342 | + bus_for_each_dev(&parport_bus_type, NULL, drv, port_detach); |
---|
| 343 | + driver_unregister(&drv->driver); |
---|
367 | 344 | mutex_unlock(®istration_lock); |
---|
368 | 345 | } |
---|
369 | 346 | EXPORT_SYMBOL(parport_unregister_driver); |
---|
.. | .. |
---|
555 | 532 | #endif |
---|
556 | 533 | |
---|
557 | 534 | if (!port->dev) |
---|
558 | | - printk(KERN_WARNING "%s: fix this legacy no-device port driver!\n", |
---|
559 | | - port->name); |
---|
| 535 | + pr_warn("%s: fix this legacy no-device port driver!\n", |
---|
| 536 | + port->name); |
---|
560 | 537 | |
---|
561 | 538 | parport_proc_register(port); |
---|
562 | 539 | mutex_lock(®istration_lock); |
---|
.. | .. |
---|
642 | 619 | } |
---|
643 | 620 | EXPORT_SYMBOL(parport_remove_port); |
---|
644 | 621 | |
---|
| 622 | +static void free_pardevice(struct device *dev) |
---|
| 623 | +{ |
---|
| 624 | + struct pardevice *par_dev = to_pardevice(dev); |
---|
| 625 | + |
---|
| 626 | + kfree(par_dev->name); |
---|
| 627 | + kfree(par_dev); |
---|
| 628 | +} |
---|
| 629 | + |
---|
645 | 630 | /** |
---|
646 | | - * parport_register_device - register a device on a parallel port |
---|
| 631 | + * parport_register_dev_model - register a device on a parallel port |
---|
647 | 632 | * @port: port to which the device is attached |
---|
648 | 633 | * @name: a name to refer to the device |
---|
649 | | - * @pf: preemption callback |
---|
650 | | - * @kf: kick callback (wake-up) |
---|
651 | | - * @irq_func: interrupt handler |
---|
652 | | - * @flags: registration flags |
---|
653 | | - * @handle: data for callback functions |
---|
| 634 | + * @par_dev_cb: struct containing callbacks |
---|
| 635 | + * @id: device number to be given to the device |
---|
654 | 636 | * |
---|
655 | 637 | * This function, called by parallel port device drivers, |
---|
656 | 638 | * declares that a device is connected to a port, and tells the |
---|
657 | 639 | * system all it needs to know. |
---|
658 | 640 | * |
---|
659 | | - * The @name is allocated by the caller and must not be |
---|
660 | | - * deallocated until the caller calls @parport_unregister_device |
---|
661 | | - * for that device. |
---|
| 641 | + * The struct pardev_cb contains pointer to callbacks. preemption |
---|
| 642 | + * callback function, @preempt, is called when this device driver |
---|
| 643 | + * has claimed access to the port but another device driver wants |
---|
| 644 | + * to use it. It is given, @private, as its parameter, and should |
---|
| 645 | + * return zero if it is willing for the system to release the port |
---|
| 646 | + * to another driver on its behalf. If it wants to keep control of |
---|
| 647 | + * the port it should return non-zero, and no action will be taken. |
---|
| 648 | + * It is good manners for the driver to try to release the port at |
---|
| 649 | + * the earliest opportunity after its preemption callback rejects a |
---|
| 650 | + * preemption attempt. Note that if a preemption callback is happy |
---|
| 651 | + * for preemption to go ahead, there is no need to release the |
---|
| 652 | + * port; it is done automatically. This function may not block, as |
---|
| 653 | + * it may be called from interrupt context. If the device driver |
---|
| 654 | + * does not support preemption, @preempt can be %NULL. |
---|
662 | 655 | * |
---|
663 | | - * The preemption callback function, @pf, is called when this |
---|
664 | | - * device driver has claimed access to the port but another |
---|
665 | | - * device driver wants to use it. It is given @handle as its |
---|
666 | | - * parameter, and should return zero if it is willing for the |
---|
667 | | - * system to release the port to another driver on its behalf. |
---|
668 | | - * If it wants to keep control of the port it should return |
---|
669 | | - * non-zero, and no action will be taken. It is good manners for |
---|
670 | | - * the driver to try to release the port at the earliest |
---|
671 | | - * opportunity after its preemption callback rejects a preemption |
---|
672 | | - * attempt. Note that if a preemption callback is happy for |
---|
673 | | - * preemption to go ahead, there is no need to release the port; |
---|
674 | | - * it is done automatically. This function may not block, as it |
---|
675 | | - * may be called from interrupt context. If the device driver |
---|
676 | | - * does not support preemption, @pf can be %NULL. |
---|
677 | | - * |
---|
678 | | - * The wake-up ("kick") callback function, @kf, is called when |
---|
| 656 | + * The wake-up ("kick") callback function, @wakeup, is called when |
---|
679 | 657 | * the port is available to be claimed for exclusive access; that |
---|
680 | 658 | * is, parport_claim() is guaranteed to succeed when called from |
---|
681 | 659 | * inside the wake-up callback function. If the driver wants to |
---|
682 | 660 | * claim the port it should do so; otherwise, it need not take |
---|
683 | 661 | * any action. This function may not block, as it may be called |
---|
684 | 662 | * from interrupt context. If the device driver does not want to |
---|
685 | | - * be explicitly invited to claim the port in this way, @kf can |
---|
| 663 | + * be explicitly invited to claim the port in this way, @wakeup can |
---|
686 | 664 | * be %NULL. |
---|
687 | 665 | * |
---|
688 | 666 | * The interrupt handler, @irq_func, is called when an interrupt |
---|
.. | .. |
---|
710 | 688 | * the device on the port, or %NULL if there is not enough memory |
---|
711 | 689 | * to allocate space for that structure. |
---|
712 | 690 | **/ |
---|
713 | | - |
---|
714 | | -struct pardevice * |
---|
715 | | -parport_register_device(struct parport *port, const char *name, |
---|
716 | | - int (*pf)(void *), void (*kf)(void *), |
---|
717 | | - void (*irq_func)(void *), |
---|
718 | | - int flags, void *handle) |
---|
719 | | -{ |
---|
720 | | - struct pardevice *tmp; |
---|
721 | | - |
---|
722 | | - if (port->physport->flags & PARPORT_FLAG_EXCL) { |
---|
723 | | - /* An exclusive device is registered. */ |
---|
724 | | - printk(KERN_DEBUG "%s: no more devices allowed\n", |
---|
725 | | - port->name); |
---|
726 | | - return NULL; |
---|
727 | | - } |
---|
728 | | - |
---|
729 | | - if (flags & PARPORT_DEV_LURK) { |
---|
730 | | - if (!pf || !kf) { |
---|
731 | | - printk(KERN_INFO "%s: refused to register lurking device (%s) without callbacks\n", port->name, name); |
---|
732 | | - return NULL; |
---|
733 | | - } |
---|
734 | | - } |
---|
735 | | - |
---|
736 | | - if (flags & PARPORT_DEV_EXCL) { |
---|
737 | | - if (port->physport->devices) { |
---|
738 | | - /* |
---|
739 | | - * If a device is already registered and this new |
---|
740 | | - * device wants exclusive access, then no need to |
---|
741 | | - * continue as we can not grant exclusive access to |
---|
742 | | - * this device. |
---|
743 | | - */ |
---|
744 | | - pr_err("%s: cannot grant exclusive access for device %s\n", |
---|
745 | | - port->name, name); |
---|
746 | | - return NULL; |
---|
747 | | - } |
---|
748 | | - } |
---|
749 | | - |
---|
750 | | - /* |
---|
751 | | - * We up our own module reference count, and that of the port |
---|
752 | | - * on which a device is to be registered, to ensure that |
---|
753 | | - * neither of us gets unloaded while we sleep in (e.g.) |
---|
754 | | - * kmalloc. |
---|
755 | | - */ |
---|
756 | | - if (!try_module_get(port->ops->owner)) |
---|
757 | | - return NULL; |
---|
758 | | - |
---|
759 | | - parport_get_port(port); |
---|
760 | | - |
---|
761 | | - tmp = kmalloc(sizeof(struct pardevice), GFP_KERNEL); |
---|
762 | | - if (!tmp) |
---|
763 | | - goto out; |
---|
764 | | - |
---|
765 | | - tmp->state = kmalloc(sizeof(struct parport_state), GFP_KERNEL); |
---|
766 | | - if (!tmp->state) |
---|
767 | | - goto out_free_pardevice; |
---|
768 | | - |
---|
769 | | - tmp->name = name; |
---|
770 | | - tmp->port = port; |
---|
771 | | - tmp->daisy = -1; |
---|
772 | | - tmp->preempt = pf; |
---|
773 | | - tmp->wakeup = kf; |
---|
774 | | - tmp->private = handle; |
---|
775 | | - tmp->flags = flags; |
---|
776 | | - tmp->irq_func = irq_func; |
---|
777 | | - tmp->waiting = 0; |
---|
778 | | - tmp->timeout = 5 * HZ; |
---|
779 | | - tmp->devmodel = false; |
---|
780 | | - |
---|
781 | | - /* Chain this onto the list */ |
---|
782 | | - tmp->prev = NULL; |
---|
783 | | - /* |
---|
784 | | - * This function must not run from an irq handler so we don' t need |
---|
785 | | - * to clear irq on the local CPU. -arca |
---|
786 | | - */ |
---|
787 | | - spin_lock(&port->physport->pardevice_lock); |
---|
788 | | - |
---|
789 | | - if (flags & PARPORT_DEV_EXCL) { |
---|
790 | | - if (port->physport->devices) { |
---|
791 | | - spin_unlock(&port->physport->pardevice_lock); |
---|
792 | | - printk(KERN_DEBUG |
---|
793 | | - "%s: cannot grant exclusive access for device %s\n", |
---|
794 | | - port->name, name); |
---|
795 | | - goto out_free_all; |
---|
796 | | - } |
---|
797 | | - port->flags |= PARPORT_FLAG_EXCL; |
---|
798 | | - } |
---|
799 | | - |
---|
800 | | - tmp->next = port->physport->devices; |
---|
801 | | - wmb(); /* |
---|
802 | | - * Make sure that tmp->next is written before it's |
---|
803 | | - * added to the list; see comments marked 'no locking |
---|
804 | | - * required' |
---|
805 | | - */ |
---|
806 | | - if (port->physport->devices) |
---|
807 | | - port->physport->devices->prev = tmp; |
---|
808 | | - port->physport->devices = tmp; |
---|
809 | | - spin_unlock(&port->physport->pardevice_lock); |
---|
810 | | - |
---|
811 | | - init_waitqueue_head(&tmp->wait_q); |
---|
812 | | - tmp->timeslice = parport_default_timeslice; |
---|
813 | | - tmp->waitnext = tmp->waitprev = NULL; |
---|
814 | | - |
---|
815 | | - /* |
---|
816 | | - * This has to be run as last thing since init_state may need other |
---|
817 | | - * pardevice fields. -arca |
---|
818 | | - */ |
---|
819 | | - port->ops->init_state(tmp, tmp->state); |
---|
820 | | - if (!test_and_set_bit(PARPORT_DEVPROC_REGISTERED, &port->devflags)) { |
---|
821 | | - port->proc_device = tmp; |
---|
822 | | - parport_device_proc_register(tmp); |
---|
823 | | - } |
---|
824 | | - return tmp; |
---|
825 | | - |
---|
826 | | - out_free_all: |
---|
827 | | - kfree(tmp->state); |
---|
828 | | - out_free_pardevice: |
---|
829 | | - kfree(tmp); |
---|
830 | | - out: |
---|
831 | | - parport_put_port(port); |
---|
832 | | - module_put(port->ops->owner); |
---|
833 | | - |
---|
834 | | - return NULL; |
---|
835 | | -} |
---|
836 | | -EXPORT_SYMBOL(parport_register_device); |
---|
837 | | - |
---|
838 | | -static void free_pardevice(struct device *dev) |
---|
839 | | -{ |
---|
840 | | - struct pardevice *par_dev = to_pardevice(dev); |
---|
841 | | - |
---|
842 | | - kfree(par_dev->name); |
---|
843 | | - kfree(par_dev); |
---|
844 | | -} |
---|
845 | 691 | |
---|
846 | 692 | struct pardevice * |
---|
847 | 693 | parport_register_dev_model(struct parport *port, const char *name, |
---|
.. | .. |
---|
997 | 843 | |
---|
998 | 844 | #ifdef PARPORT_PARANOID |
---|
999 | 845 | if (!dev) { |
---|
1000 | | - printk(KERN_ERR "parport_unregister_device: passed NULL\n"); |
---|
| 846 | + pr_err("%s: passed NULL\n", __func__); |
---|
1001 | 847 | return; |
---|
1002 | 848 | } |
---|
1003 | 849 | #endif |
---|
.. | .. |
---|
1047 | 893 | spin_unlock_irq(&port->waitlist_lock); |
---|
1048 | 894 | |
---|
1049 | 895 | kfree(dev->state); |
---|
1050 | | - if (dev->devmodel) |
---|
1051 | | - device_unregister(&dev->dev); |
---|
1052 | | - else |
---|
1053 | | - kfree(dev); |
---|
| 896 | + device_unregister(&dev->dev); |
---|
1054 | 897 | |
---|
1055 | 898 | module_put(port->ops->owner); |
---|
1056 | 899 | parport_put_port(port); |
---|
.. | .. |
---|
1138 | 981 | unsigned long flags; |
---|
1139 | 982 | |
---|
1140 | 983 | if (port->cad == dev) { |
---|
1141 | | - printk(KERN_INFO "%s: %s already owner\n", |
---|
1142 | | - dev->port->name,dev->name); |
---|
| 984 | + pr_info("%s: %s already owner\n", dev->port->name, dev->name); |
---|
1143 | 985 | return 0; |
---|
1144 | 986 | } |
---|
1145 | 987 | |
---|
.. | .. |
---|
1159 | 1001 | * I think we'll actually deadlock rather than |
---|
1160 | 1002 | * get here, but just in case.. |
---|
1161 | 1003 | */ |
---|
1162 | | - printk(KERN_WARNING |
---|
1163 | | - "%s: %s released port when preempted!\n", |
---|
1164 | | - port->name, oldcad->name); |
---|
| 1004 | + pr_warn("%s: %s released port when preempted!\n", |
---|
| 1005 | + port->name, oldcad->name); |
---|
1165 | 1006 | if (port->cad) |
---|
1166 | 1007 | goto blocked; |
---|
1167 | 1008 | } |
---|
.. | .. |
---|
1261 | 1102 | r = parport_claim(dev); |
---|
1262 | 1103 | if (r == -EAGAIN) { |
---|
1263 | 1104 | #ifdef PARPORT_DEBUG_SHARING |
---|
1264 | | - printk(KERN_DEBUG "%s: parport_claim() returned -EAGAIN\n", dev->name); |
---|
| 1105 | + printk(KERN_DEBUG "%s: parport_claim() returned -EAGAIN\n", |
---|
| 1106 | + dev->name); |
---|
1265 | 1107 | #endif |
---|
1266 | 1108 | /* |
---|
1267 | 1109 | * FIXME!!! Use the proper locking for dev->waiting, |
---|
.. | .. |
---|
1294 | 1136 | if (dev->port->physport->cad != dev) |
---|
1295 | 1137 | printk(KERN_DEBUG "%s: exiting parport_claim_or_block but %s owns port!\n", |
---|
1296 | 1138 | dev->name, dev->port->physport->cad ? |
---|
1297 | | - dev->port->physport->cad->name:"nobody"); |
---|
| 1139 | + dev->port->physport->cad->name : "nobody"); |
---|
1298 | 1140 | #endif |
---|
1299 | 1141 | } |
---|
1300 | 1142 | dev->waiting = 0; |
---|
.. | .. |
---|
1321 | 1163 | write_lock_irqsave(&port->cad_lock, flags); |
---|
1322 | 1164 | if (port->cad != dev) { |
---|
1323 | 1165 | write_unlock_irqrestore(&port->cad_lock, flags); |
---|
1324 | | - printk(KERN_WARNING "%s: %s tried to release parport when not owner\n", |
---|
1325 | | - port->name, dev->name); |
---|
| 1166 | + pr_warn("%s: %s tried to release parport when not owner\n", |
---|
| 1167 | + port->name, dev->name); |
---|
1326 | 1168 | return; |
---|
1327 | 1169 | } |
---|
1328 | 1170 | |
---|
.. | .. |
---|
1362 | 1204 | if (dev->port->cad) /* racy but no matter */ |
---|
1363 | 1205 | return; |
---|
1364 | 1206 | } else { |
---|
1365 | | - printk(KERN_ERR "%s: don't know how to wake %s\n", port->name, pd->name); |
---|
| 1207 | + pr_err("%s: don't know how to wake %s\n", |
---|
| 1208 | + port->name, pd->name); |
---|
1366 | 1209 | } |
---|
1367 | 1210 | } |
---|
1368 | 1211 | |
---|