Parport numbering

Tim Waugh (tim@cyberelk.demon.co.uk)
Sat, 16 May 1998 12:30:29 +0100 (BST)


On Fri, 15 May 1998, Inaky Perez Gonzalez wrote:

> >>>>> "Philip" == Philip Blundell <pb@nexus.co.uk> writes:
>
> Hi, sorry for the delay, pretty busy studying
>
> >> Quite easy. Got two ports, one dedicated to the zip drive and
> >> another one for the printer, right? so I tell lp to use parport1
> >> and zip to use parport0. If they change names on the fly, I'm
> >> screwed off. It's a no-no.
>
> Philip> You _should_ be able to get them to sort out the right ports
> Philip> automatically. If you load ppa first it will grab any port
> Philip> that has a Zip connected; you can then use lp with the `timid'
> Philip> flag to tell it to only claim otherwise-unused ports.
> Philip> Alternatively if your printer is plug-and-play you can turn on
> Philip> the autoprobe and use `lp=auto'.
>
> Well, I cannot govern when the zip drive is going to be used
> and when any of the printers. A user may be wishing to print and in
> then another one may use the zip drive ... the request order is
> something unpredictable.

I don't see the problem with Phil's suggested scheme, i.e. putting
"options lp parport=auto" in your modules.conf, and getting the IEEE probe
to sort it out.

However, I agree that it would be nice if port numbers were re-used. I've
re-implemented your patch a bit more neatly below.

Tim.
*/

--- linux/drivers/misc/parport_share.c~ Tue May 12 21:03:20 1998
+++ linux/drivers/misc/parport_share.c Sat May 16 12:19:43 1998
@@ -37,7 +37,6 @@
#define PARPORT_DEFAULT_TIMESLICE (HZ/5)

static struct parport *portlist = NULL, *portlist_tail = NULL;
-static int portcount = 0;

void (*parport_probe_hook)(struct parport *port) = NULL;

@@ -67,6 +66,7 @@
struct parport_operations *ops)
{
struct parport *tmp;
+ int portnum;

/* Check for a previously registered port.
NOTE: we will ignore irq and dma if we find a previously
@@ -82,6 +82,23 @@
return NULL;
}

+ /* Search for the lowest free parport number. */
+ portnum = 0;
+ for (portnum = 0; ; portnum++) {
+ struct parport *itr = portlist;
+ while (itr) {
+ if (itr->number == portnum)
+ /* No good, already used. */
+ break;
+ else
+ itr = itr->next;
+ }
+
+ if (itr == NULL)
+ /* Got to the end of the list. */
+ break;
+ }
+
/* Init our structure */
memset(tmp, 0, sizeof(struct parport));
tmp->base = base;
@@ -92,7 +109,7 @@
tmp->devices = tmp->cad = NULL;
tmp->flags = 0;
tmp->ops = ops;
- tmp->number = portcount;
+ tmp->number = portnum;
spin_lock_init (&tmp->lock);

tmp->name = kmalloc(15, GFP_KERNEL);
@@ -101,7 +118,7 @@
kfree(tmp);
return NULL;
}
- sprintf(tmp->name, "parport%d", portcount);
+ sprintf(tmp->name, "parport%d", portnum);

/* Chain the entry to our list. */
if (portlist_tail)
@@ -109,8 +126,6 @@
portlist_tail = tmp;
if (!portlist)
portlist = tmp;
-
- portcount++;

tmp->probe_info.class = PARPORT_CLASS_LEGACY; /* assume the worst */
tmp->waithead = tmp->waittail = NULL;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu