18 #undef PARPORT_DEBUG_SHARING
20 #include <linux/module.h>
21 #include <linux/string.h>
23 #include <linux/parport.h>
25 #include <linux/errno.h>
28 #include <linux/kernel.h>
29 #include <linux/slab.h>
30 #include <linux/sched.h>
37 #undef PARPORT_PARANOID
39 #define PARPORT_DEFAULT_TIMESLICE (HZ/5)
56 static void dead_write_lines (
struct parport *
p,
unsigned char b){}
57 static unsigned char dead_read_lines (
struct parport *
p) {
return 0; }
58 static unsigned char dead_frob_lines (
struct parport *
p,
unsigned char b,
59 unsigned char c) {
return 0; }
60 static void dead_onearg (
struct parport *
p){}
63 static size_t dead_write (
struct parport *
p,
const void *
b,
size_t l,
int f)
65 static size_t dead_read (
struct parport *
p,
void *
b,
size_t l,
int f)
68 .write_data = dead_write_lines,
69 .read_data = dead_read_lines,
71 .write_control = dead_write_lines,
72 .read_control = dead_read_lines,
73 .frob_control = dead_frob_lines,
75 .read_status = dead_read_lines,
77 .enable_irq = dead_onearg,
78 .disable_irq = dead_onearg,
80 .data_forward = dead_onearg,
81 .data_reverse = dead_onearg,
83 .init_state = dead_initstate,
84 .save_state = dead_state,
85 .restore_state = dead_state,
87 .epp_write_data = dead_write,
88 .epp_read_data = dead_read,
89 .epp_write_addr = dead_write,
90 .epp_read_addr = dead_read,
92 .ecp_write_data = dead_write,
93 .ecp_read_data = dead_read,
94 .ecp_write_addr = dead_write,
96 .compat_write_data = dead_write,
97 .nibble_read_data = dead_read,
98 .byte_read_data = dead_read,
104 static void attach_driver_chain(
struct parport *
port)
122 static
void get_lowlevel_driver (
void)
126 request_module (
"parport_lowlevel");
158 if (list_empty(&portlist))
159 get_lowlevel_driver ();
164 list_add(&drv->
list, &drivers);
192 list_del_init(&drv->
list);
198 static void free_port (
struct parport *port)
201 spin_lock(&full_list_lock);
203 spin_unlock(&full_list_lock);
204 for (d = 0; d < 5; d++) {
298 INIT_LIST_HEAD(&tmp->
list);
322 spin_lock(&full_list_lock);
323 for (l = all_ports.
next, num = 0; l != &all_ports; l = l->
next, num++) {
330 spin_unlock(&full_list_lock);
338 for (device = 0; device < 5; device++)
363 #ifdef CONFIG_PARPORT_1284
370 "no-device port driver!\n",
375 spin_lock_irq(&parportlist_lock);
377 for (i = 1; i < 3; i++) {
382 spin_unlock_irq(&parportlist_lock);
385 attach_driver_chain (port);
386 for (i = 1; i < 3; i++) {
389 attach_driver_chain(slave);
420 detach_driver_chain (port);
422 #ifdef CONFIG_PARPORT_1284
425 for (i = 1; i < 3; i++) {
429 detach_driver_chain(slave);
434 port->
ops = &dead_ops;
435 spin_lock(&parportlist_lock);
436 list_del_init(&port->
list);
437 for (i = 1; i < 3; i++) {
440 list_del_init(&slave->
list);
442 spin_unlock(&parportlist_lock);
448 for (i = 1; i < 3; i++) {
526 int (*
pf)(
void *),
void (*kf)(
void *),
541 printk(
KERN_INFO "%s: refused to register lurking device (%s) without callbacks\n", port->
name, name);
551 if (!try_module_get(port->
ops->owner)) {
566 goto out_free_pardevice;
586 spin_lock(&port->
physport->pardevice_lock);
590 spin_unlock (&port->
physport->pardevice_lock);
592 "%s: cannot grant exclusive access for "
593 "device %s\n", port->
name, name);
606 spin_unlock(&port->
physport->pardevice_lock);
616 port->
ops->init_state(tmp, tmp->
state);
629 module_put(port->
ops->owner);
645 #ifdef PARPORT_PARANOID
652 port = dev->
port->physport;
660 if (port->
cad == dev) {
697 module_put(port->
ops->owner);
717 if (list_empty(&portlist))
718 get_lowlevel_driver ();
720 spin_lock (&parportlist_lock);
722 if (port->
number == number) {
727 spin_unlock (&parportlist_lock);
747 if (list_empty(&portlist))
748 get_lowlevel_driver ();
750 spin_lock (&parportlist_lock);
752 if (port->
base == base) {
757 spin_unlock (&parportlist_lock);
779 if (port->
cad == dev) {
787 if ((oldcad = port->
cad) !=
NULL) {
791 port->
ops->save_state(port, dev->
state);
795 if (port->
cad != oldcad) {
799 "%s: %s released port when preempted!\n",
827 #ifdef CONFIG_PARPORT_1284
829 if (dev->
port->muxport >= 0) {
835 if (dev->
daisy >= 0) {
844 port->
ops->restore_state(port, dev->
state);
894 #ifdef PARPORT_DEBUG_SHARING
910 if (signal_pending (
current)) {
916 #ifdef PARPORT_DEBUG_SHARING
922 #ifdef PARPORT_DEBUG_SHARING
923 if (dev->
port->physport->cad != dev)
925 "but %s owns port!\n", dev->
name,
926 dev->
port->physport->cad ?
927 dev->
port->physport->cad->name:
"nobody");
951 if (port->
cad != dev) {
954 "when not owner\n", port->
name, dev->
name);
958 #ifdef CONFIG_PARPORT_1284
960 if (dev->
port->muxport >= 0) {
966 if (dev->
daisy >= 0) {
976 port->
ops->save_state(port, dev->
state);
984 if (waitqueue_active(&pd->
wait_q))
1000 if (pd->
wakeup && pd != dev)
1009 parport_generic_irq(port);