Ok, there's a test13-pre6 out there now, which does a partial sync with
[davej-history.git] / Documentation / DocBook / parportbook.tmpl
blobef8c07d337606125eae4344bbf0d6e7a092068c4
1 <!-- -*- sgml -*- -->
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V3.1//EN"[]>
4 <book id="ParportGuide">
5  <bookinfo>
6   <title>The Linux 2.4 Parallel Port Subsystem</title>
8   <authorgroup>
9    <author>
10     <firstname>Tim</firstname>
11     <surname>Waugh</surname>
12     <affiliation>
13      <address>
14       <email>twaugh@redhat.com</email>
15      </address>
16     </affiliation>
17    </author>
18   </authorgroup>
20   <copyright>
21    <year>1999-2000</year>
22    <holder>Tim Waugh</holder>
23   </copyright>
25   <legalnotice>
26    <para>
27     Permission is granted to copy, distribute and/or modify this
28     document under the terms of the GNU Free Documentation License,
29     Version 1.1 or any later version published by the Free Software
30     Foundation; with no Invariant Sections, with no Front-Cover Texts,
31     and with no Back-Cover Texts.  A copy of the license is included
32     in the section entitled "GNU Free Documentation License".
33    </para>
34   </legalnotice>
35  </bookinfo>
37  <toc></toc>
39  <chapter id="design">
40   <title>Design goals</title>
42   <sect1>
43    <title>The problems</title>
45    <para>
46     The first parallel port support for Linux came with the line
47     printer driver, <literal>lp</literal>.  The printer driver is a
48     character special device, and (in Linux 2.0) had support for
49     writing, via <function>write</function>, and configuration and
50     statistics reporting via <function>ioctl</function>.
51    </para>
53    <para>
54     The printer driver could be used on any computer that had an IBM
55     PC-compatible parallel port.  Because some architectures have
56     parallel ports that aren't really the same as PC-style ports,
57     other variants of the printer driver were written in order to
58     support Amiga and Atari parallel ports.
59    </para>
61    <para>
62     When the Iomega Zip drive was released, and a driver written for
63     it, a problem became apparent.  The Zip drive is a parallel port
64     device that provides a parallel port of its own---it is designed
65     to sit between a computer and an attached printer, with the
66     printer plugged into the Zip drive, and the Zip drive plugged into
67     the computer.
68    </para>
70    <para>
71     The problem was that, although printers and Zip drives were both
72     supported, for any given port only one could be used at a time.
73     Only one of the two drivers could be present in the kernel at
74     once.  This was because of the fact that both drivers wanted to
75     drive the same hardware---the parallel port.  When the printer
76     driver initialised, it would call the
77     <function>check_region</function> function to make sure that the
78     IO region associated with the parallel port was free, and then it
79     would call <function>request_region</function> to allocate it.
80     The Zip drive used the same mechanism.  Whichever driver
81     initialised first would gain exclusive control of the parallel
82     port.
83    </para>
85    <para>
86     The only way around this problem at the time was to make sure that
87     both drivers were available as loadable kernel modules.  To use
88     the printer, load the printer driver module; then for the Zip
89     drive, unload the printer driver module and load the Zip driver
90     module.
91    </para>
93    <para>
94     The net effect was that printing a document that was stored on a
95     Zip drive was a bit of an ordeal, at least if the Zip drive and
96     printer shared a parallel port.  A better solution was
97     needed.
98    </para>
100    <para>
101     Zip drives are not the only devices that presented problems for
102     Linux.  There are other devices with pass-through ports, for
103     example parallel port CD-ROM drives.  There are also printers that
104     report their status textually rather than using simple error pins:
105     sending a command to the printer can cause it to report the number
106     of pages that it has ever printed, or how much free memory it has,
107     or whether it is running out of toner, and so on.  The printer
108     driver didn't originally offer any facility for reading back this
109     information (although Carsten Gross added nibble mode readback
110     support for kernel 2.2).
111    </para>
113    <para>
114     The IEEE has issued a standards document called IEEE 1284, which
115     documents existing practice for parallel port communications in a
116     variety of modes.  Those modes are: <quote>compatibility</quote>,
117     reverse nibble, reverse byte, ECP and EPP.  Newer devices often
118     use the more advanced modes of transfer (ECP and EPP).  In Linux
119     2.0, the printer driver only supported <quote>compatibility
120     mode</quote> (i.e. normal printer protocol) and reverse nibble
121     mode.
122    </para>
124   </sect1>
126   <sect1>
127    <title>The solutions</title>
129 <!-- How they are addressed
130      - sharing model
131      - overview of structure (i.e. port drivers) in 2.2 and 2.3.
132      - IEEE 1284 stuff
133      - whether or not 'platform independence' goal was met
134   -->
136    <para>
137     The <literal>parport</literal> code in Linux 2.2 was designed to
138     meet these problems of architectural differences in parallel
139     ports, of port-sharing between devices with pass-through ports,
140     and of lack of support for IEEE 1284 transfer modes.
141    </para>
143    <!-- platform differences -->
145    <para>
146     There are two layers to the <literal>parport</literal>
147     subsystem, only one of which deals directly with the hardware.
148     The other layer deals with sharing and IEEE 1284 transfer modes.
149     In this way, parallel support for a particular architecture comes
150     in the form of a module which registers itself with the generic
151     sharing layer.
152    </para>
154    <!-- sharing model -->
156    <para>
157     The sharing model provided by the <literal>parport</literal>
158     subsystem is one of exclusive access.  A device driver, such as
159     the printer driver, must ask the <literal>parport</literal>
160     layer for access to the port, and can only use the port once
161     access has been granted.  When it has finished a
162     <quote>transaction</quote>, it can tell the
163     <literal>parport</literal> layer that it may release the port
164     for other device drivers to use.
165    </para>
167    <!-- talk a bit about how drivers can share devices on the same port -->
169    <para>
170     Devices with pass-through ports all manage to share a parallel
171     port with other devices in generally the same way.  The device has
172     a latch for each of the pins on its pass-through port.  The normal
173     state of affairs is pass-through mode, with the device copying the
174     signal lines between its host port and its pass-through port.
175     When the device sees a special signal from the host port, it
176     latches the pass-through port so that devices further downstream
177     don't get confused by the pass-through device's conversation with
178     the host parallel port: the device connected to the pass-through
179     port (and any devices connected in turn to it) are effectively cut
180     off from the computer.  When the pass-through device has completed
181     its transaction with the computer, it enables the pass-through
182     port again.
183    </para>
185    <mediaobject>
186     <imageobject>
187      <imagedata fileref="parport-share.eps" format=ps>
188     </imageobject>
189     <imageobject>
190      <imagedata fileref="parport-share.jpeg" format=jpeg>
191     </imageobject>
192    </mediaobject>
194    <para>
195     This technique relies on certain <quote>special signals</quote>
196     being invisible to devices that aren't watching for them.  This
197     tends to mean only changing the data signals and leaving the
198     control signals alone.  IEEE 1284.3 documents a standard protocol
199     for daisy-chaining devices together with parallel ports.
200    </para>
202    <!-- transfer modes -->
204    <para>
205     Support for standard transfer modes are provided as operations
206     that can be performed on a port, along with operations for setting
207     the data lines, or the control lines, or reading the status lines.
208     These operations appear to the device driver as function pointers;
209     more later.
210    </para>
212   </sect1>
214  </chapter>
216  <chapter id="transfermodes">
217   <title>Standard transfer modes</title>
219   <!-- Defined by IEEE, but in common use (even though there are widely -->
220   <!-- varying implementations). -->
222   <para>
223    The <quote>standard</quote> transfer modes in use over the parallel
224    port are <quote>defined</quote> by a document called IEEE 1284.  It
225    really just codifies existing practice and documents protocols (and
226    variations on protocols) that have been in common use for quite
227    some time.
228   </para>
230   <para>
231    The original definitions of which pin did what were set out by
232    Centronics Data Computer Corporation, but only the printer-side
233    interface signals were specified.
234   </para>
236   <para>
237    By the early 1980s, IBM's host-side implementation had become the
238    most widely used.  New printers emerged that claimed Centronics
239    compatibility, but although compatible with Centronics they
240    differed from one another in a number of ways.
241   </para>
243   <para>
244    As a result of this, when IEEE 1284 was published in 1994, all that
245    it could really do was document the various protocols that are used
246    for printers (there are about six variations on a theme).
247   </para>
249   <para>
250    In addition to the protocol used to talk to Centronics-compatible
251    printers, IEEE 1284 defined other protocols that are used for
252    unidirectional peripheral-to-host transfers (reverse nibble and
253    reverse byte) and for fast bidirectional transfers (ECP and
254    EPP).
255   </para>
257  </chapter>
259  <chapter id="structure">
260   <title>Structure</title>
262 <!-- Main structure
263      - sharing core
264      - parports and their IEEE 1284 overrides
265        - IEEE 1284 transfer modes for generic ports
266        - maybe mention muxes here
267      - pardevices
268      - IEEE 1284.3 API
269   -->
271   <mediaobject>
272    <imageobject>
273     <imagedata format=eps fileref="parport-structure.eps">
274    </imageobject>
275    <imageobject>
276     <imagedata format=jpeg fileref="parport-structure.jpeg">
277    </imageobject>
278   </mediaobject>
280   <sect1>
281    <title>Sharing core</title>
283    <para>
284     At the core of the <literal>parport</literal> subsystem is the
285     sharing mechanism (see
286     <filename>drivers/parport/share.c</filename>).  This module,
287     <literal>parport</literal>, is responsible for keeping track of
288     which ports there are in the system, which device drivers might be
289     interested in new ports, and whether or not each port is available
290     for use (or if not, which driver is currently using it).
291    </para>
293   </sect1>
295   <sect1>
296    <title>Parports and their overrides</title>
298    <para>
299     The generic <literal>parport</literal> sharing code doesn't
300     directly handle the parallel port hardware.  That is done instead
301     by <quote>low-level</quote> <literal>parport</literal> drivers.
302     The function of a low-level <literal>parport</literal> driver is
303     to detect parallel ports, register them with the sharing code, and
304     provide a list of access functions for each port.
305    </para>
307    <para>
308     The most basic access functions that must be provided are ones for
309     examining the status lines, for setting the control lines, and for
310     setting the data lines.  There are also access functions for
311     setting the direction of the data lines; normally they are in the
312     <quote>forward</quote> direction (that is, the computer drives
313     them), but some ports allow switching to <quote>reverse</quote>
314     mode (driven by the peripheral).  There is an access function for
315     examining the data lines once in reverse mode.
316    </para>
318   </sect1>
320   <sect1>
321    <title>IEEE 1284 transfer modes</title>
323    <para>
324     Stacked on top of the sharing mechanism, but still in the
325     <literal>parport</literal> module, are functions for
326     transferring data.  They are provided for the device drivers to
327     use, and are very much like library routines.  Since these
328     transfer functions are provided by the generic
329     <literal>parport</literal> core they must use the <quote>lowest
330     common denominator</quote> set of access functions: they can set
331     the control lines, examine the status lines, and use the data
332     lines.  With some parallel ports the data lines can only be set
333     and not examined, and with other ports accessing the data register
334     causes control line activity; with these types of situations, the
335     IEEE 1284 transfer functions make a best effort attempt to do the
336     right thing.  In some cases, it is not physically possible to use
337     particular IEEE 1284 transfer modes.
338    </para>
340    <para>
341     The low-level <literal>parport</literal> drivers also provide
342     IEEE 1284 transfer functions, as names in the access function
343     list.  The low-level driver can just name the generic IEEE 1284
344     transfer functions for this.  Some parallel ports can do IEEE 1284
345     transfers in hardware; for those ports, the low-level driver can
346     provide functions to utilise that feature.
347    </para>
349   </sect1>
351   <!-- muxes? -->
353   <sect1>
354    <title>Pardevices and parport_drivers</title>
356    <para>
357     When a parallel port device driver (such as
358     <literal>lp</literal>) initialises it tells the sharing layer
359     about itself using <function>parport_register_driver</function>.
360     The information is put into a <structname>struct
361     parport_driver</structname>, which is put into a linked list.  The
362     information in a <structname>struct parport_driver</structname>
363     really just amounts to some function pointers to callbacks in the
364     parallel port device driver.
365    </para>
367    <para>
368     During its initialisation, a low-level port driver tells the
369     sharing layer about all the ports that it has found (using
370     <function>parport_register_port</function>), and the sharing layer
371     creates a <structname>struct parport</structname> for each of
372     them.  Each <structname>struct parport</structname> contains
373     (among other things) a pointer to a <structname>struct
374     parport_operations</structname>, which is a list of function
375     pointers for the various operations that can be performed on a
376     port.  You can think of a <structname>struct parport</structname>
377     as a parallel port <quote>object</quote>, if
378     <quote>object-orientated</quote> programming is your thing.  The
379     <structname>parport</structname> structures are chained in a
380     linked list, whose head is <varname>portlist</varname> (in
381     <filename>drivers/parport/share.c</filename>).
382    </para>
384    <para>
385     Once the port has been registered, the low-level port driver
386     announces it.  The <function>parport_announce_port</function>
387     function walks down the list of parallel port device drivers
388     (<structname>struct parport_driver</structname>s) calling the
389     <function>attach</function> function of each (which may block).
390    </para>
392    <para>
393     Similarly, a low-level port driver can undo the effect of
394     registering a port with the
395     <function>parport_unregister_port</function> function, and device
396     drivers are notified using the <function>detach</function>
397     callback (which may not block).
398    </para>
400    <para>
401     Device drivers can undo the effect of registering themselves with
402     the <function>parport_unregister_driver</function>
403     function.
404    </para>
406   </sect1>
408   <!-- IEEE 1284.3 API -->
410   <sect1>
411    <title>The IEEE 1284.3 API</title>
413    <para>
414     The ability to daisy-chain devices is very useful, but if every
415     device does it in a different way it could lead to lots of
416     complications for device driver writers.  Fortunately, the IEEE
417     are standardising it in IEEE 1284.3, which covers daisy-chain
418     devices and port multiplexors.
419    </para>
421    <para>
422     At the time of writing, IEEE 1284.3 has not been published, but
423     the draft specifies the on-the-wire protocol for daisy-chaining
424     and multiplexing, and also suggests a programming interface for
425     using it.  That interface (or most of it) has been implemented in
426     the <literal>parport</literal> code in Linux.
427    </para>
429    <para>
430     At initialisation of the parallel port <quote>bus</quote>,
431     daisy-chained devices are assigned addresses starting from zero.
432     There can only be four devices with daisy-chain addresses, plus
433     one device on the end that doesn't know about daisy-chaining and
434     thinks it's connected directly to a computer.
435    </para>
437    <para>
438     Another way of connecting more parallel port devices is to use a
439     multiplexor.  The idea is to have a device that is connected
440     directly to a parallel port on a computer, but has a number of
441     parallel ports on the other side for other peripherals to connect
442     to (two or four ports are allowed).  The multiplexor switches
443     control to different ports under software control---it is, in
444     effect, a programmable printer switch.
445    </para>
447    <para>
448     Combining the ability of daisy-chaining five devices together with
449     the ability to multiplex one parallel port between four gives the
450     potential to have twenty peripherals connected to the same
451     parallel port!
452    </para>
454    <para>
455     In addition, of course, a single computer can have multiple
456     parallel ports.  So, each parallel port peripheral in the system
457     can be identified with three numbers, or co-ordinates: the
458     parallel port, the multiplexed port, and the daisy-chain
459     address.
460    </para>
462    <mediaobject>
463     <imageobject>
464      <imagedata format=eps fileref="parport-multi.eps">
465     </imageobject>
466     <imageobject>
467      <imagedata format=jpeg fileref="parport-multi.jpeg">
468     </imageobject>
469    </mediaobject>
471    <para>
472     Each device in the system is numbered at initialisation (by
473     <function>parport_daisy_init</function>).  You can convert between
474     this device number and its co-ordinates with
475     <function>parport_device_num</function> and
476     <function>parport_device_coords</function>.
477    </para>
479    <funcsynopsis>
480     <funcsynopsisinfo>
481 #include &lt;parport.h&gt;
482     </funcsynopsisinfo>
483     <funcprototype>
484      <funcdef>int <function>parport_device_num</function></funcdef>
485      <paramdef>int <parameter>parport</parameter></paramdef>
486      <paramdef>int <parameter>mux</parameter></paramdef>
487      <paramdef>int <parameter>daisy</parameter></paramdef>
488     </funcprototype>
489    </funcsynopsis>
491    <funcsynopsis>
492     <funcprototype>
493      <funcdef>int <function>parport_device_coords</function></funcdef>
494      <paramdef>int <parameter>devnum</parameter></paramdef>
495      <paramdef>int *<parameter>parport</parameter></paramdef>
496      <paramdef>int *<parameter>mux</parameter></paramdef>
497      <paramdef>int *<parameter>daisy</parameter></paramdef>
498     </funcprototype>
499    </funcsynopsis>
501    <para>
502     Any parallel port peripheral will be connected directly or
503     indirectly to a parallel port on the system, but it won't have a
504     daisy-chain address if it does not know about daisy-chaining, and
505     it won't be connected through a multiplexor port if there is no
506     multiplexor.  The special co-ordinate value
507     <constant>-1</constant> is used to indicate these cases.
508    </para>
510    <para>
511     Two functions are provided for finding devices based on their IEEE
512     1284 Device ID: <function>parport_find_device</function> and
513     <function>parport_find_class</function>.
514    </para>
516    <funcsynopsis>
517     <funcsynopsisinfo>
518 #include &lt;parport.h&gt;
519     </funcsynopsisinfo>
520     <funcprototype>
521      <funcdef>int <function>parport_find_device</function></funcdef>
522      <paramdef>const char *<parameter>mfg</parameter></paramdef>
523      <paramdef>const char *<parameter>mdl</parameter></paramdef>
524      <paramdef>int <parameter>from</parameter></paramdef>
525     </funcprototype>
526    </funcsynopsis>
528    <funcsynopsis>
529     <funcprototype>
530      <funcdef>int <function>parport_find_class</function></funcdef>
531      <paramdef>parport_device_class <parameter>cls</parameter></paramdef>
532      <paramdef>int <parameter>from</parameter></paramdef>
533     </funcprototype>
534    </funcsynopsis>
536    <para>
537     These functions take a device number (in addition to some other
538     things), and return another device number.  They walk through the
539     list of detected devices until they find one that matches the
540     requirements, and then return that device number (or
541     <constant>-1</constant> if there are no more such devices).  They
542     start their search at the device after the one in the list with
543     the number given (at <parameter>from</parameter>+1, in other
544     words).
545    </para>
547   </sect1>
549  </chapter>
551  <chapter id="drivers">
552   <title>Device driver's view</title>
554 <!-- Cover:
555      - sharing interface, preemption, interrupts, wakeups...
556      - IEEE 1284.3 interface
557      - port operations
558        - why can read data but ctr is faked, etc.
559   -->
561 <!-- I should take a look at the kernel hackers' guide bit I wrote, -->
562 <!-- as that deals with a lot of this.  The main complaint with it  -->
563 <!-- was that there weren't enough examples, but 'The printer -->
564 <!-- driver' should deal with that later; might be worth mentioning -->
565 <!-- in the text. -->
567   <para>
568    This section is written from the point of view of the device driver
569    programmer, who might be writing a driver for a printer or a
570    scanner or else anything that plugs into the parallel port.  It
571    explains how to use the <literal>parport</literal> interface to
572    find parallel ports, use them, and share them with other device
573    drivers.
574   </para>
576   <para>
577    We'll start out with a description of the various functions that
578    can be called, and then look at a reasonably simple example of
579    their use: the printer driver.
580   </para>
582   <para>
583    The interactions between the device driver and the
584    <literal>parport</literal> layer are as follows.  First, the
585    device driver registers its existence with
586    <literal>parport</literal>, in order to get told about any
587    parallel ports that have been (or will be) detected.  When it gets
588    told about a parallel port, it then tells
589    <literal>parport</literal> that it wants to drive a device on
590    that port.  Thereafter it can claim exclusive access to the port in
591    order to talk to its device.
592   </para>
594   <para>
595    So, the first thing for the device driver to do is tell
596    <literal>parport</literal> that it wants to know what parallel
597    ports are on the system.  To do this, it uses the
598    <function>parport_register_device</function> function:
599   </para>
601   <funcsynopsis>
602    <funcsynopsisinfo>
603 #include &lt;parport.h&gt;
605 struct parport_driver {
606         const char *name;
607         void (*attach) (struct parport *);
608         void (*detach) (struct parport *);
609         struct parport_driver *next;
611    </funcsynopsisinfo>
613    <funcprototype>
614     <funcdef>int <function>parport_register_driver</function></funcdef>
615     <paramdef>struct parport_driver *<parameter>driver</parameter></paramdef>
616    </funcprototype>
617   </funcsynopsis>
619   <para>
620    In other words, the device driver passes pointers to a couple of
621    functions to <literal>parport</literal>, and
622    <literal>parport</literal> calls <function>attach</function> for
623    each port that's detected (and <function>detach</function> for each
624    port that disappears---yes, this can happen).
625   </para>
627   <para>
628    The next thing that happens is that the device driver tells
629    <literal>parport</literal> that it thinks there's a device on the
630    port that it can drive.  This typically will happen in the driver's
631    <function>attach</function> function, and is done with
632    <function>parport_register_device</function>:
633   </para>
635   <funcsynopsis>
636    <funcsynopsisinfo>
637 #include &lt;parport.h&gt;
638    </funcsynopsisinfo>
639    <funcprototype>
640     <funcdef>struct pardevice *<function>parport_register_device</function></funcdef>
641     <paramdef>struct parport *<parameter>port</parameter></paramdef>
642     <paramdef>const char *<parameter>name</parameter></paramdef>
643     <paramdef>int <parameter>(*pf)</parameter>
644      <funcparams>void *</funcparams></paramdef>
645     <paramdef>void <parameter>(*kf)</parameter>
646      <funcparams>void *</funcparams></paramdef>
647     <paramdef>void <parameter>(*irq_func)</parameter>
648      <funcparams>int, void *, struct pt_regs *</funcparams></paramdef>
649     <paramdef>int <parameter>flags</parameter></paramdef>
650     <paramdef>void *<parameter>handle</parameter></paramdef>
651    </funcprototype>
652   </funcsynopsis>
654   <para>
655    The <parameter>port</parameter> comes from the parameter supplied
656    to the <function>attach</function> function when it is called, or
657    alternatively can be found from the list of detected parallel ports
658    directly with the (now deprecated)
659    <function>parport_enumerate</function> function.  A better way of
660    doing this is with <function>parport_find_number</function> or
661    <function>parport_find_base</function> functions, which find ports
662    by number and by base I/O address respectively.
663   </para>
665   <funcsynopsis>
666    <funcsynopsisinfo>
667 #include &lt;parport.h&gt;
668    </funcsynopsisinfo>
669    <funcprototype>
670     <funcdef>struct parport *<function>parport_find_number</function></funcdef>
671     <paramdef>int <parameter>number</parameter></paramdef>
672    </funcprototype>
673   </funcsynopsis>
674   <funcsynopsis>
675    <funcsynopsisinfo>
676 #include &lt;parport.h&gt;
677    </funcsynopsisinfo>
678    <funcprototype>
679     <funcdef>struct parport *<function>parport_find_base</function></funcdef>
680     <paramdef>unsigned long <parameter>base</parameter></paramdef>
681    </funcprototype>
682   </funcsynopsis>
684   <para>
685    The next three parameters, <parameter>pf</parameter>,
686    <parameter>kf</parameter>, and <parameter>irq_func</parameter>, are
687    more function pointers.  These callback functions get called under
688    various circumstances, and are always given the
689    <parameter>handle</parameter> as one of their parameters.
690   </para>
692   <para>
693    The preemption callback, <parameter>pf</parameter>, is called when
694    the driver has claimed access to the port but another device driver
695    wants access.  If the driver is willing to let the port go, it
696    should return zero and the port will be released on its behalf.
697    There is no need to call <function>parport_release</function>.  If
698    <parameter>pf</parameter> gets called at a bad time for letting the
699    port go, it should return non-zero and no action will be taken.  It
700    is good manners for the driver to try to release the port at the
701    earliest opportunity after its preemption callback is
702    called.
703   </para>
705   <para>
706    The <quote>kick</quote> callback, <parameter>kf</parameter>, is
707    called when the port can be claimed for exclusive access; that is,
708    <function>parport_claim</function> is guaranteed to succeed inside
709    the <quote>kick</quote> callback.  If the driver wants to claim the
710    port it should do so; otherwise, it need not take any
711    action.
712   </para>
714   <para>
715    The <parameter>irq_func</parameter> callback is called,
716    predictably, when a parallel port interrupt is generated.  But it
717    is not the only code that hooks on the interrupt.  The sequence is
718    this: the lowlevel driver is the one that has done
719    <function>request_irq</function>; it then does whatever
720    hardware-specific things it needs to do to the parallel port
721    hardware (for PC-style ports, there is nothing special to do); it
722    then tells the IEEE 1284 code about the interrupt, which may
723    involve reacting to an IEEE 1284 event, depending on the current
724    IEEE 1284 phase; and finally the <parameter>irq_func</parameter>
725    function is called.
726   </para>
728   <para>
729    None of the callback functions are allowed to block.
730   </para>
732   <para>
733    The <parameter>flags</parameter> are for telling
734    <literal>parport</literal> any requirements or hints that are
735    useful.  The only useful value here (other than
736    <constant>0</constant>, which is the usual value) is
737    <constant>PARPORT_DEV_EXCL</constant>.  The point of that flag is
738    to request exclusive access at all times---once a driver has
739    successfully called <function>parport_register_device</function>
740    with that flag, no other device drivers will be able to register
741    devices on that port (until the successful driver deregisters its
742    device, of course).
743   </para>
745   <para>
746    The <constant>PARPORT_DEV_EXCL</constant> flag is for preventing
747    port sharing, and so should only be used when sharing the port with
748    other device drivers is impossible and would lead to incorrect
749    behaviour.  Use it sparingly!
750   </para>
752   <para>
753    Devices can also be registered by device drivers based on their
754    device numbers (the same device numbers as in the previous
755    section).
756   </para>
758   <para>
759    The <function>parport_open</function> function is similar to
760    <function>parport_register_device</function>, and
761    <function>parport_close</function> is the equivalent of
762    <function>parport_unregister_device</function>.  The difference is
763    that <function>parport_open</function> takes a device number rather
764    than a pointer to a <structname>struct parport</structname>.
765   </para>
767   <funcsynopsis>
768    <funcsynopsisinfo>
769 #include &lt;parport.h&gt;
770    </funcsynopsisinfo>
771    <funcprototype>
772     <funcdef>struct pardevice *<function>parport_open</function></funcdef>
773     <paramdef>int <parameter>devnum</parameter></paramdef>
774     <paramdef>int <parameter>(*pf)</parameter>
775      <funcparams>void *</funcparams></paramdef>
776     <paramdef>int <parameter>(*kf)</parameter>
777      <funcparams>void *</funcparams></paramdef>
778     <paramdef>int <parameter>(*irqf)</parameter>
779      <funcparams>int, void *, struct pt_regs *</funcparams></paramdef>
780     <paramdef>int <parameter>flags</parameter></paramdef>
781     <paramdef>void *<parameter>handle</parameter></paramdef>
782    </funcprototype>
783   </funcsynopsis>
785   <funcsynopsis>
786    <funcprototype>
787     <funcdef>void <function>parport_close</function></funcdef>
788     <paramdef>struct pardevice *<parameter>dev</parameter></paramdef>
789    </funcprototype>
790   </funcsynopsis>
792   <funcsynopsis>
793    <funcprototype>
794     <funcdef>struct pardevice *<function>parport_register_device</function></funcdef>
795     <paramdef>struct parport *<parameter>port</parameter></paramdef>
796     <paramdef>const char *<parameter>name</parameter></paramdef>
797     <paramdef>int <parameter>(*pf)</parameter>
798      <funcparams>void *</funcparams></paramdef>
799     <paramdef>int <parameter>(*kf)</parameter>
800      <funcparams>void *</funcparams></paramdef>
801     <paramdef>int <parameter>(*irqf)</parameter>
802      <funcparams>int, void *, struct pt_regs *</funcparams></paramdef>
803     <paramdef>int <parameter>flags</parameter></paramdef>
804     <paramdef>void *<parameter>handle</parameter></paramdef>
805    </funcprototype>
806   </funcsynopsis>
808   <funcsynopsis>
809    <funcprototype>
810     <funcdef>void <function>parport_unregister_device</function></funcdef>
811     <paramdef>struct pardevice *<parameter>dev</parameter></paramdef>
812    </funcprototype>
813   </funcsynopsis>
815   <para>
816    The intended use of these functions is during driver initialisation
817    while the driver looks for devices that it supports, as
818    demonstrated by the following code fragment:
819   </para>
821   <programlisting>
822    <![CDATA[
823 int devnum = -1;
824 while ((devnum = parport_find_class (PARPORT_CLASS_DIGCAM,
825                                      devnum)) != -1) {
826     struct pardevice *dev = parport_open (devnum, ...);
827     ...
829    ]]></programlisting>
831   <para>
832    Once your device driver has registered its device and been handed a
833    pointer to a <structname>struct pardevice</structname>, the next
834    thing you are likely to want to do is communicate with the device
835    you think is there.  To do that you'll need to claim access to the
836    port.
837   </para>
839   <funcsynopsis>
840    <funcsynopsisinfo>
841 #include &lt;parport.h&gt;
842    </funcsynopsisinfo>
843    <funcprototype>
844     <funcdef>int <function>parport_claim</function></funcdef>
845     <paramdef>struct pardevice *<parameter>dev</parameter></paramdef>
846    </funcprototype>
847   </funcsynopsis>
849   <funcsynopsis>
850    <funcprototype>
851     <funcdef>int <function>parport_claim_or_block</function></funcdef>
852     <paramdef>struct pardevice *<parameter>dev</parameter></paramdef>
853    </funcprototype>
854   </funcsynopsis>
856   <funcsynopsis>
857    <funcprototype>
858     <funcdef>void <function>parport_release</function></funcdef>
859     <paramdef>struct pardevice *<parameter>dev</parameter></paramdef>
860    </funcprototype>
861   </funcsynopsis>
863   <para>
864    To claim access to the port, use <function>parport_claim</function>
865    or <function>parport_claim_or_block</function>.  The first of these
866    will not block, and so can be used from interrupt context.  If
867    <function>parport_claim</function> succeeds it will return zero and
868    the port is available to use.  It may fail (returning non-zero) if
869    the port is in use by another driver and that driver is not willing
870    to relinquish control of the port.
871   </para>
873   <para>
874    The other function, <function>parport_claim_or_block</function>,
875    will block if necessary to wait for the port to be free.  If it
876    slept, it returns <constant>1</constant>; if it succeeded without
877    needing to sleep it returns <constant>0</constant>.  If it fails it
878    will return a negative error code.
879   </para>
881   <para>
882    When you have finished communicating with the device, you can give
883    up access to the port so that other drivers can communicate with
884    their devices.  The <function>parport_release</function> function
885    cannot fail, but it should not be called without the port claimed.
886    Similarly, you should not try to claim the port if you already have
887    it claimed.
888   </para>
890   <para>
891    You may find that although there are convenient points for your
892    driver to relinquish the parallel port and allow other drivers to
893    talk to their devices, it would be preferable to keep hold of the
894    port.  The printer driver only needs the port when there is data to
895    print, for example, but a network driver (such as PLIP) could be
896    sent a remote packet at any time.  With PLIP, it is no huge
897    catastrophe if a network packet is dropped, since it will likely be
898    sent again, so it is possible for that kind of driver to share the
899    port with other (pass-through) devices.
900   </para>
902   <para>
903    The <function>parport_yield</function> and
904    <function>parport_yield_blocking</function> functions are for
905    marking points in the driver at which other drivers may claim the
906    port and use their devices.  Yielding the port is similar to
907    releasing it and reclaiming it, but is more efficient because
908    nothing is done if there are no other devices needing the port.  In
909    fact, nothing is done even if there are other devices waiting but
910    the current device is still within its <quote>timeslice</quote>.
911    The default timeslice is half a second, but it can be adjusted via
912    a <filename>/proc</filename> entry.
913   </para>
915   <funcsynopsis>
916    <funcsynopsisinfo>
917 #include &lt;parport.h&gt;
918    </funcsynopsisinfo>
919    <funcprototype>
920     <funcdef>int <function>parport_yield</function></funcdef>
921     <paramdef>struct pardevice *<parameter>dev</parameter></paramdef>
922    </funcprototype>
923   </funcsynopsis>
925   <funcsynopsis>
926    <funcprototype>
927     <funcdef>int <function>parport_yield_blocking</function></funcdef>
928     <paramdef>struct pardevice *<parameter>dev</parameter></paramdef>
929    </funcprototype>
930   </funcsynopsis>
932   <para>
933    The first of these, <function>parport_yield</function>, will not
934    block but as a result may fail.  The return value for
935    <function>parport_yield</function> is the same as for
936    <function>parport_claim</function>.  The blocking version,
937    <function>parport_yield_blocking</function>, has the same return
938    code as <function>parport_claim_or_block</function>.
939   </para>
941   <para>
942    Once the port has been claimed, the device driver can use the
943    functions in the <structname>struct parport_operations</structname>
944    pointer in the <structname>struct parport</structname> it has a
945    pointer to.  For example:
946   </para>
948   <programlisting>
949    <![CDATA[
950 port->ops->write_data (port, d);
951    ]]></programlisting>
953   <para>
954    Some of these operations have <quote>shortcuts</quote>.  For
955    instance, <function>parport_write_data</function> is equivalent to
956    the above, but may be a little bit faster (it's a macro that in
957    some cases can avoid needing to indirect through
958    <varname>port</varname> and <varname>ops</varname>).
959   </para>
961  </chapter>
963  <chapter id="portdrivers">
964   <title>Port drivers</title>
966   <!-- What port drivers are for (i.e. implementing parport objects). -->
968   <para>
969    To recap, then:</para>
971   <itemizedlist spacing=compact>
973    <listitem>
974     <para>
975      The device driver registers itself with <literal>parport</literal>.
976     </para>
977    </listitem>
979    <listitem>
980     <para>
981      A low-level driver finds a parallel port and registers it with
982      <literal>parport</literal> (these first two things can happen
983      in either order).  This registration creates a <structname>struct
984      parport</structname> which is linked onto a list of known ports.
985     </para>
986    </listitem>
988    <listitem>
989     <para>
990      <literal>parport</literal> calls the
991      <function>attach</function> function of each registered device
992      driver, passing it the pointer to the new <structname>struct
993      parport</structname>.
994     </para>
995    </listitem>
997    <listitem>
998     <para>
999      The device driver gets a handle from
1000      <literal>parport</literal>, for use with
1001      <function>parport_claim</function>/<function>release</function>.
1002      This handle takes the form of a pointer to a <structname>struct
1003      pardevice</structname>, representing a particular device on the
1004      parallel port, and is acquired using
1005      <function>parport_register_device</function>.
1006     </para>
1007    </listitem>
1009    <listitem>
1010     <para>
1011      The device driver claims the port using
1012      <function>parport_claim</function> (or
1013      <function>function_claim_or_block</function>).
1014     </para>
1015    </listitem>
1017    <listitem>
1018     <para>
1019      Then it goes ahead and uses the port.  When finished it releases
1020      the port.
1021     </para>
1022    </listitem>
1024   </itemizedlist>
1026   <para>
1027    The purpose of the low-level drivers, then, is to detect parallel
1028    ports and provide methods of accessing them (i.e. implementing the
1029    operations in <structname>struct
1030    parport_operations</structname>).
1031   </para>
1033   <!-- Should DocBookise this -->
1034   <para>
1035    A more complete description of which operation is supposed to do
1036    what is available in
1037    <filename>Documentation/parport-lowlevel.txt</filename>.
1038   </para>
1040  </chapter>
1042  <chapter id="lp">
1043   <title>The printer driver</title>
1045   <!-- Talk the reader through the printer driver. -->
1046   <!-- Could even talk about parallel port console here. -->
1048   <para>
1049    The printer driver, <literal>lp</literal> is a character special
1050    device driver and a <literal>parport</literal> client.  As a
1051    character special device driver it registers a <structname>struct
1052    file_operations</structname> using
1053    <function>register_chrdev</function>, with pointers filled in for
1054    <structfield>write</structfield>, <structfield>ioctl</structfield>,
1055    <structfield>open</structfield> and
1056    <structfield>release</structfield>.  As a client of
1057    <literal>parport</literal>, it registers a <structname>struct
1058    parport_driver</structname> using
1059    <function>parport_register_driver</function>, so that
1060    <literal>parport</literal> knows to call
1061    <function>lp_attach</function> when a new parallel port is
1062    discovered (and <function>lp_detach</function> when it goes
1063    away).
1064   </para>
1066   <para>
1067    The parallel port console functionality is also implemented in
1068    <filename>drivers/char/lp.c</filename>, but that won't be covered
1069    here (it's quite simple though).
1070   </para>
1072   <para>
1073    The initialisation of the driver is quite easy to understand (see
1074    <function>lp_init</function>).  The <varname>lp_table</varname> is
1075    an array of structures that contain information about a specific
1076    device (the <structname>struct pardevice</structname> associated
1077    with it, for example).  That array is initialised to sensible
1078    values first of all.
1079   </para>
1081   <para>
1082    Next, the printer driver calls <function>register_chrdev</function>
1083    passing it a pointer to <varname>lp_fops</varname>, which contains
1084    function pointers for the printer driver's implementation of
1085    <function>open</function>, <function>write</function>, and so on.
1086    This part is the same as for any character special device
1087    driver.
1088   </para>
1090   <para>
1091    After successfully registering itself as a character special device
1092    driver, the printer driver registers itself as a
1093    <literal>parport</literal> client using
1094    <function>parport_register_driver</function>.  It passes a pointer
1095    to this structure:
1096   </para>
1098   <programlisting>
1099    <![CDATA[
1100 static struct parport_driver lp_driver = {
1101         "lp",
1102         lp_attach,
1103         lp_detach,
1104         NULL
1106    ]]></programlisting>
1108   <para>
1109    The <function>lp_detach</function> function is not very interesting
1110    (it does nothing); the interesting bit is
1111    <function>lp_attach</function>.  What goes on here depends on
1112    whether the user supplied any parameters.  The possibilities are:
1113    no parameters supplied, in which case the printer driver uses every
1114    port that is detected; the user supplied the parameter
1115    <quote>auto</quote>, in which case only ports on which the device
1116    ID string indicates a printer is present are used; or the user
1117    supplied a list of parallel port numbers to try, in which case only
1118    those are used.
1119   </para>
1121   <para>
1122    For each port that the printer driver wants to use (see
1123    <function>lp_register</function>), it calls
1124    <function>parport_register_device</function> and stores the
1125    resulting <structname>struct pardevice</structname> pointer in the
1126    <varname>lp_table</varname>.  If the user told it to do so, it then
1127    resets the printer.
1128   </para>
1130   <para>
1131    The other interesting piece of the printer driver, from the point
1132    of view of <literal>parport</literal>, is
1133    <function>lp_write</function>.  In this function, the user space
1134    process has data that it wants printed, and the printer driver
1135    hands it off to the <literal>parport</literal> code to deal with.
1136   </para>
1138   <para>
1139    The <literal>parport</literal> functions it uses that we have not
1140    seen yet are <function>parport_negotiate</function>,
1141    <function>parport_set_timeout</function>, and
1142    <function>parport_write</function>.  These functions are part of
1143    the IEEE 1284 implementation.
1144   </para>
1146   <para>
1147    The way the IEEE 1284 protocol works is that the host tells the
1148    peripheral what transfer mode it would like to use, and the
1149    peripheral either accepts that mode or rejects it; if the mode is
1150    rejected, the host can try again with a different mode.  This is
1151    the negotation phase.  Once the peripheral has accepted a
1152    particular transfer mode, data transfer can begin that mode.
1153   </para>
1155   <para>
1156    The particular transfer mode that the printer driver wants to use
1157    is named in IEEE 1284 as <quote>compatibility</quote> mode, and the
1158    function to request a particular mode is called
1159    <function>parport_negotiate</function>.
1160   </para>
1162   <funcsynopsis>
1163    <funcsynopsisinfo>
1164 #include &lt;parport.h&gt;
1165    </funcsynopsisinfo>
1166    <funcprototype>
1167     <funcdef>int <function>parport_negotiate</function></funcdef>
1168     <paramdef>struct parport *<parameter>port</parameter></paramdef>
1169     <paramdef>int <parameter>mode</parameter></paramdef>
1170    </funcprototype>
1171   </funcsynopsis>
1173   <para>
1174    The <parameter>modes</parameter> parameter is a symbolic constant
1175    representing an IEEE 1284 mode; in this instance, it is
1176    <constant>IEEE1284_MODE_COMPAT</constant>. (Compatibility mode is
1177    slightly different to the other modes---rather than being
1178    specifically requested, it is the default until another mode is
1179    selected.)
1180   </para>
1182   <para>
1183    Back to <function>lp_write</function> then.  First, access to the
1184    parallel port is secured with
1185    <function>parport_claim_or_block</function>.  At this point the
1186    driver might sleep, waiting for another driver (perhaps a Zip drive
1187    driver, for instance) to let the port go.  Next, it goes to
1188    compatibility mode using <function>parport_negotiate</function>.
1189   </para>
1191   <para>
1192    The main work is done in the write-loop.  In particular, the line
1193    that hands the data over to <literal>parport</literal> reads:
1194   </para>
1196 <programlisting>
1197 <![CDATA[
1198         written = parport_write (port, kbuf, copy_size);
1199 ]]></programlisting>
1201   <para>
1202    The <function>parport_write</function> function writes data to the
1203    peripheral using the currently selected transfer mode
1204    (compatibility mode, in this case).  It returns the number of bytes
1205    successfully written:
1206   </para>
1208   <funcsynopsis>
1209    <funcsynopsisinfo>
1210 #include &lt;parport.h&gt;
1211    </funcsynopsisinfo>
1212    <funcprototype>
1213     <funcdef>ssize_t <function>parport_write</function></funcdef>
1214     <paramdef>struct parport *<parameter>port</parameter></paramdef>
1215     <paramdef>const void *<parameter>buf</parameter></paramdef>
1216     <paramdef>size_t <parameter>len</parameter></paramdef>
1217    </funcprototype>
1218   </funcsynopsis>
1220   <funcsynopsis>
1221    <funcprototype>
1222     <funcdef>ssize_t <function>parport_read</function></funcdef>
1223     <paramdef>struct parport *<parameter>port</parameter></paramdef>
1224     <paramdef>void *<parameter>buf</parameter></paramdef>
1225     <paramdef>size_t <parameter>len</parameter></paramdef>
1226    </funcprototype>
1227   </funcsynopsis>
1229   <para>
1230    (<function>parport_read</function> does what it sounds like, but
1231    only works for modes in which reverse transfer is possible.  Of
1232    course, <function>parport_write</function> only works in modes in
1233    which forward transfer is possible, too.)
1234   </para>
1236   <para>
1237    The <parameter>buf</parameter> pointer should be to kernel space
1238    memory, and obviously the <parameter>len</parameter> parameter
1239    specifies the amount of data to transfer.
1240   </para>
1242   <para>
1243    In fact what <function>parport_write</function> does is call the
1244    appropriate block transfer function from the <structname>struct
1245    parport_operations</structname>:
1246   </para>
1248   <programlisting>
1249    <![CDATA[
1250 struct parport_operations {
1251         [...]
1253         /* Block read/write */
1254         size_t (*epp_write_data) (struct parport *port,
1255                                   const void *buf,
1256                                   size_t len, int flags);
1257         size_t (*epp_read_data) (struct parport *port,
1258                                  void *buf, size_t len,
1259                                  int flags);
1260         size_t (*epp_write_addr) (struct parport *port,
1261                                   const void *buf,
1262                                   size_t len, int flags);
1263         size_t (*epp_read_addr) (struct parport *port,
1264                                  void *buf, size_t len,
1265                                  int flags);
1267         size_t (*ecp_write_data) (struct parport *port,
1268                                   const void *buf,
1269                                   size_t len, int flags);
1270         size_t (*ecp_read_data) (struct parport *port,
1271                                  void *buf, size_t len,
1272                                  int flags);
1273         size_t (*ecp_write_addr) (struct parport *port,
1274                                   const void *buf,
1275                                   size_t len, int flags);
1277         size_t (*compat_write_data) (struct parport *port,
1278                                      const void *buf,
1279                                      size_t len, int flags);
1280         size_t (*nibble_read_data) (struct parport *port,
1281                                     void *buf, size_t len,
1282                                     int flags);
1283         size_t (*byte_read_data) (struct parport *port,
1284                                   void *buf, size_t len,
1285                                   int flags);
1287    ]]></programlisting>
1289   <para>
1290    The transfer code in <literal>parport</literal> will tolerate a
1291    data transfer stall only for so long, and this timeout can be
1292    specified with <function>parport_set_timeout</function>, which
1293    returns the previous timeout:
1294   </para>
1296   <funcsynopsis>
1297    <funcsynopsisinfo>
1298 #include &lt;parport.h&gt;
1299    </funcsynopsisinfo>
1300    <funcprototype>
1301     <funcdef>long <function>parport_set_timeout</function></funcdef>
1302     <paramdef>struct pardevice *<parameter>dev</parameter></paramdef>
1303     <paramdef>long <parameter>inactivity</parameter></paramdef>
1304    </funcprototype>
1305   </funcsynopsis>
1307   <para>
1308    This timeout is specific to the device, and is restored on
1309    <function>parport_claim</function>.
1310   </para>
1312   <para>
1313    The next function to look at is the one that allows processes to
1314    read from <filename>/dev/lp0</filename>:
1315    <function>lp_read</function>.  It's short, like
1316    <function>lp_write</function>.
1317   </para>
1319   <para>
1320    The semantics of reading from a line printer device are as follows:
1321   </para>
1323   <itemizedlist>
1324    <listitem>
1325     <para>
1326      Switch to reverse nibble mode.
1327     </para>
1328    </listitem>
1330    <listitem>
1331     <para>
1332      Try to read data from the peripheral using reverse nibble mode,
1333      until either the user-provided buffer is full or the peripheral
1334      indicates that there is no more data.
1335     </para>
1336    </listitem>
1338    <listitem>
1339     <para>
1340      If there was data, stop, and return it.
1341     </para>
1342    </listitem>
1344    <listitem>
1345     <para>
1346      Otherwise, we tried to read data and there was none.  If the user
1347      opened the device node with the <constant>O_NONBLOCK</constant>
1348      flag, return.  Otherwise wait until an interrupt occurs on the
1349      port (or a timeout elapses).
1350     </para>
1351    </listitem>
1352   </itemizedlist>
1354  </chapter>
1356  <chapter id="ppdev">
1357   <title>User-level device drivers</title>
1359   <!-- ppdev -->
1360   <sect1>
1361    <title>Introduction to ppdev</title>
1363    <para>
1364     The printer is accessible through <filename>/dev/lp0</filename>;
1365     in the same way, the parallel port itself is accessible through
1366     <filename>/dev/parport0</filename>.  The difference is in the
1367     level of control that you have over the wires in the parallel port
1368     cable.
1369    </para>
1371    <para>
1372     With the printer driver, a user-space program (such as the printer
1373     spooler) can send bytes in <quote>printer protocol</quote>.
1374     Briefly, this means that for each byte, the eight data lines are
1375     set up, then a <quote>strobe</quote> line tells the printer to
1376     look at the data lines, and the printer sets an
1377     <quote>acknowledgement</quote> line to say that it got the byte.
1378     The printer driver also allows the user-space program to read
1379     bytes in <quote>nibble mode</quote>, which is a way of
1380     transferring data from the peripheral to the computer half a byte
1381     at a time (and so it's quite slow).
1382    </para>
1384    <para>
1385     In contrast, the <literal>ppdev</literal> driver (accessed via
1386     <filename>/dev/parport0</filename>) allows you to:
1387    </para>
1389    <itemizedlist spacing=compact>
1391     <listitem>
1392      <para>
1393       examine status lines,
1394      </para>
1395     </listitem>
1397     <listitem>
1398      <para>
1399       set control lines,
1400      </para>
1401     </listitem>
1403     <listitem>
1404      <para>
1405       set/examine data lines (and control the direction of the data
1406       lines),
1407      </para>
1408     </listitem>
1410     <listitem>
1411      <para>
1412       wait for an interrupt (triggered by one of the status lines),
1413      </para>
1414     </listitem>
1416     <listitem>
1417      <para>
1418       find out how many new interrupts have occurred,
1419      </para>
1420     </listitem>
1422     <listitem>
1423      <para>
1424       set up a response to an interrupt,
1425      </para>
1426     </listitem>
1428     <listitem>
1429      <para>
1430       use IEEE 1284 negotiation (for telling peripheral which transfer
1431       mode, to use)
1432      </para>
1433     </listitem>
1435     <listitem>
1436      <para>
1437       transfer data using a specified IEEE 1284 mode.
1438      </para>
1439     </listitem>
1441    </itemizedlist>
1443   </sect1>
1445   <sect1>
1446    <title>User-level or kernel-level driver?</title>
1448    <para>
1449     The decision of whether to choose to write a kernel-level device
1450     driver or a user-level device driver depends on several factors.
1451     One of the main ones from a practical point of view is speed:
1452     kernel-level device drivers get to run faster because they are not
1453     preemptable, unlike user-level applications.
1454    </para>
1456    <para>
1457     Another factor is ease of development.  It is in general easier to
1458     write a user-level driver because (a) one wrong move does not
1459     result in a crashed machine, (b) you have access to user libraries
1460     (such as the C library), and (c) debugging is easier.
1461    </para>
1463   </sect1>
1465   <sect1>
1466    <title>Programming interface</title>
1468    <para>
1469     The <literal>ppdev</literal> interface is largely the same as that
1470     of other character special devices, in that it supports
1471     <function>open</function>, <function>close</function>,
1472     <function>read</function>, <function>write</function>, and
1473     <function>ioctl</function>.  The constants for the
1474     <function>ioctl</function> commands are in
1475     <filename>include/linux/ppdev.h</filename>.
1476    </para>
1478    <sect2>
1479     <title>
1480      Starting and stopping: <function>open</function> and
1481      <function>close</function>
1482     </title>
1484     <para>
1485      The device node <filename>/dev/parport0</filename> represents any
1486      device that is connected to <filename>parport0</filename>, the
1487      first parallel port in the system.  Each time the device node is
1488      opened, it represents (to the process doing the opening) a
1489      different device.  It can be opened more than once, but only one
1490      instance can actually be in control of the parallel port at any
1491      time.  A process that has opened
1492      <filename>/dev/parport0</filename> shares the parallel port in
1493      the same way as any other device driver.  A user-land driver may
1494      be sharing the parallel port with in-kernel device drivers as
1495      well as other user-land drivers.
1496     </para>
1497    </sect2>
1499    <sect2>
1500     <title>Control: <function>ioctl</function></title>
1502     <para>
1503      Most of the control is done, naturally enough, via the
1504      <function>ioctl</function> call.  Using
1505      <function>ioctl</function>, the user-land driver can control both
1506      the <literal>ppdev</literal> driver in the kernel and the
1507      physical parallel port itself.  The <function>ioctl</function>
1508      call takes as parameters a file descriptor (the one returned from
1509      opening the device node), a command, and optionally (a pointer
1510      to) some data.
1511     </para>
1513     <variablelist>
1514      <varlistentry><term><constant>PPCLAIM</constant></term>
1515       <listitem>
1517        <para>
1518         Claims access to the port.  As a user-land device driver
1519         writer, you will need to do this before you are able to
1520         actually change the state of the parallel port in any way.
1521         Note that some operations only affect the
1522         <literal>ppdev</literal> driver and not the port, such as
1523         <constant>PPSETMODE</constant>; they can be performed while
1524         access to the port is not claimed.
1525        </para>
1527       </listitem></varlistentry>
1529      <varlistentry><term><constant>PPEXCL</constant></term>
1530       <listitem>
1532        <para>
1533         Instructs the kernel driver to forbid any sharing of the port
1534         with other drivers, i.e. it requests exclusivity.  The
1535         <constant>PPEXCL</constant> command is only valid when the
1536         port is not already claimed for use, and it may mean that the
1537         next <constant>PPCLAIM</constant> <function>ioctl</function>
1538         will fail: some other driver may already have registered
1539         itself on that port.
1540        </para>
1542        <para>
1543         Most device drivers don't need exclusive access to the port.
1544         It's only provided in case it is really needed, for example
1545         for devices where access to the port is required for extensive
1546         periods of time (many seconds).
1547        </para>
1549        <para>
1550         Note that the <constant>PPEXCL</constant>
1551         <function>ioctl</function> doesn't actually claim the port
1552         there and then---action is deferred until the
1553         <constant>PPCLAIM</constant> <function>ioctl</function> is
1554         performed.
1555        </para>
1557       </listitem></varlistentry>
1559      <varlistentry><term><constant>PPRELEASE</constant></term>
1560       <listitem>
1562        <para>
1563         Releases the port.  Releasing the port undoes the effect of
1564         claiming the port.  It allows other device drivers to talk to
1565         their devices (assuming that there are any).
1566        </para>
1568       </listitem></varlistentry>
1570      <varlistentry><term><constant>PPYIELD</constant></term>
1571       <listitem>
1573        <para>
1574         Yields the port to another driver.  This
1575         <function>ioctl</function> is a kind of short-hand for
1576         releasing the port and immediately reclaiming it.  It gives
1577         other drivers a chance to talk to their devices, but
1578         afterwards claims the port back.  An example of using this
1579         would be in a user-land printer driver: once a few characters
1580         have been written we could give the port to another device
1581         driver for a while, but if we still have characters to send to
1582         the printer we would want the port back as soon as possible.
1583        </para>
1585        <para>
1586         It is important not to claim the parallel port for too long,
1587         as other device drivers will have no time to service their
1588         devices.  If your device does not allow for parallel port
1589         sharing at all, it is better to claim the parallel port
1590         exclusively (see <constant>PPEXCL</constant>).
1591        </para>
1593       </listitem></varlistentry>
1595      <varlistentry><term><constant>PPNEGOT</constant></term>
1596       <listitem>
1598        <para>
1599         Performs IEEE 1284 negotiation into a particular mode.
1600         Briefly, negotiation is the method by which the host and the
1601         peripheral decide on a protocol to use when transferring data.
1602        </para>
1604        <para>
1605         An IEEE 1284 compliant device will start out in compatibility
1606         mode, and then the host can negotiate to another mode (such as
1607         ECP).
1608        </para>
1610        <para>
1611         The <function>ioctl</function> parameter should be a pointer
1612         to an <type>int</type>; values for this are in
1613         <filename>incluce/linux/parport.h</filename> and include:
1614        </para>
1616        <itemizedlist spacing=compact>
1617         <listitem><para>
1618           <constant>IEEE1284_MODE_COMPAT</constant></para></listitem>
1619         <listitem><para>
1620           <constant>IEEE1284_MODE_NIBBLE</constant></para></listitem>
1621         <listitem><para>
1622           <constant>IEEE1284_MODE_BYTE</constant></para></listitem>
1623         <listitem><para>
1624           <constant>IEEE1284_MODE_EPP</constant></para></listitem>
1625         <listitem><para>
1626           <constant>IEEE1284_MODE_ECP</constant></para></listitem>
1627        </itemizedlist>
1629        <para>
1630         The <constant>PPNEGOT</constant> <function>ioctl</function>
1631         actually does two things: it performs the on-the-wire
1632         negotiation, and it sets the behaviour of subsequent
1633         <function>read</function>/<function>write</function> calls so
1634         that they use that mode (but see
1635         <constant>PPSETMODE</constant>).
1636        </para>
1638       </listitem></varlistentry>
1640      <varlistentry><term><constant>PPSETMODE</constant></term>
1641       <listitem>
1643        <para>
1644         Sets which IEEE 1284 protocol to use for the
1645         <function>read</function> and <function>write</function>
1646         calls.
1647        </para>
1649        <para>
1650         The <function>ioctl</function> parameter should be a pointer
1651         to an <type>int</type>.
1652        </para>
1654       </listitem></varlistentry>
1656      <varlistentry><term><constant>PPGETTIME</constant></term>
1657       <listitem>
1659        <para>
1660         Retrieves the time-out value.  The <function>read</function>
1661         and <function>write</function> calls will time out if the
1662         peripheral doesn't respond quickly enough.  The
1663         <constant>PPGETTIME</constant> <function>ioctl</function>
1664         retrieves the length of time that the peripheral is allowed to
1665         have before giving up.
1666        </para>
1668        <para>
1669         The <function>ioctl</function> parameter should be a pointer
1670         to a <structname>struct timeval</structname>.
1671        </para>
1673       </listitem></varlistentry>
1675      <varlistentry><term><constant>PPSETTIME</constant></term>
1676       <listitem>
1678        <para>
1679         Sets the time-out.  The <function>ioctl</function> parameter
1680         should be a pointer to a <structname>struct
1681         timeval</structname>.
1682        </para>
1684       </listitem></varlistentry>
1686      <varlistentry><term><constant>PPWCONTROL</constant></term>
1687       <listitem>
1689        <para>
1690         Sets the control lines.  The <function>ioctl</function>
1691         parameter is a pointer to an <type>unsigned char</type>, the
1692         bitwise OR of the control line values in
1693         <filename>include/linux/parport.h</filename>.
1694        </para>
1696       </listitem></varlistentry>
1698      <varlistentry><term><constant>PPRCONTROL</constant></term>
1699       <listitem>
1701        <para>
1702         Returns the last value written to the control register, in the
1703         form of an <type>unsigned char</type>: each bit corresponds to
1704         a control line (although some are unused).  The
1705         <function>ioctl</function> parameter should be a pointer to an
1706         <type>unsigned char</type>.
1707        </para>
1709        <para>
1710         This doesn't actually touch the hardware; the last value
1711         written is remembered in software.  This is because some
1712         parallel port hardware does not offer read access to the
1713         control register.
1714        </para>
1716        <para>
1717         The control lines bits are defined in
1718         <filename>include/linux/parport.h</filename>:
1719        </para>
1721        <itemizedlist spacing=compact>
1722         <listitem><para>
1723           <constant>PARPORT_CONTROL_STROBE</constant></para></listitem>
1724           <listitem><para>
1725           <constant>PARPORT_CONTROL_AUTOFD</constant></para></listitem>
1726           <listitem><para>
1727           <constant>PARPORT_CONTROL_SELECT</constant></para></listitem>
1728           <listitem><para>
1729           <constant>PARPORT_CONTROL_INIT</constant></para></listitem>
1730        </itemizedlist>
1732       </listitem></varlistentry>
1734      <varlistentry><term><constant>PPFCONTROL</constant></term>
1735       <listitem>
1737        <para>
1738         Frobs the control lines.  Since a common operation is to
1739         change one of the control signals while leaving the others
1740         alone, it would be quite inefficient for the user-land driver
1741         to have to use <constant>PPRCONTROL</constant>, make the
1742         change, and then use <constant>PPWCONTROL</constant>.  Of
1743         course, each driver could remember what state the control
1744         lines are supposed to be in (they are never changed by
1745         anything else), but in order to provide
1746         <constant>PPRCONTROL</constant>, <literal>ppdev</literal>
1747         must remember the state of the control lines anyway.
1748        </para>
1750        <para>
1751         The <constant>PPFCONTROL</constant> <function>ioctl</function>
1752         is for <quote>frobbing</quote> control lines, and is like
1753         <constant>PPWCONTROL</constant> but acts on a restricted set
1754         of control lines.  The <function>ioctl</function> parameter is
1755         a pointer to a <structname>struct
1756         ppdev_frob_struct</structname>:
1757        </para>
1759        <programlisting>
1760         <![CDATA[
1761 struct ppdev_frob_struct {
1762         unsigned char mask;
1763         unsigned char val;
1765         ]]>
1766        </programlisting>
1768        <para>
1769         The <structfield>mask</structfield> and
1770         <structfield>val</structfield> fields are bitwise ORs of
1771         control line names (such as in
1772         <constant>PPWCONTROL</constant>).  The operation performed by
1773         <constant>PPFCONTROL</constant> is:
1774        </para>
1776        <programlisting>
1777         <![CDATA[
1778         new_ctr = (old_ctr & ~mask) | val;]]>
1779        </programlisting>
1781        <para>
1782         In other words, the signals named in
1783         <structfield>mask</structfield> are set to the values in
1784         <structfield>val</structfield>.
1785        </para>
1787       </listitem></varlistentry>
1789      <varlistentry><term><constant>PPRSTATUS</constant></term>
1790       <listitem>
1792        <para>
1793         Returns an <type>unsigned char</type> containing bits set for
1794         each status line that is set (for instance,
1795         <constant>PARPORT_STATUS_BUSY</constant>).  The
1796         <function>ioctl</function> parameter should be a pointer to an
1797         <type>unsigned char</type>.
1798        </para>
1800       </listitem></varlistentry>
1802      <varlistentry><term><constant>PPDATADIR</constant></term>
1803       <listitem>
1805        <para>
1806         Controls the data line drivers.  Normally the computer's
1807         parallel port will drive the data lines, but for byte-wide
1808         transfers from the peripheral to the host it is useful to turn
1809         off those drivers and let the peripheral drive the
1810         signals. (If the drivers on the computer's parallel port are
1811         left on when this happens, the port might be damaged.)
1812        </para>
1814        <para>
1815         This is only needed in conjunction with
1816         <constant>PPWDATA</constant> or
1817         <constant>PPRDATA</constant>.
1818        </para>
1820        <para>
1821         The <function>ioctl</function> parameter is a pointer to an
1822         <type>int</type>.  If the <type>int</type> is zero, the
1823         drivers are turned on (forward direction); if non-zero, the
1824         drivers are turned off (reverse direction).
1825        </para>
1827       </listitem></varlistentry>
1829      <varlistentry><term><constant>PPWDATA</constant></term>
1830       <listitem>
1832        <para>
1833         Sets the data lines (if in forward mode).  The
1834         <function>ioctl</function> parameter is a pointer to an
1835         <type>unsigned char</type>.
1836        </para>
1838       </listitem></varlistentry>
1840      <varlistentry><term><constant>PPRDATA</constant></term>
1841       <listitem>
1843        <para>
1844         Reads the data lines (if in reverse mode).  The
1845         <function>ioctl</function> parameter is a pointer to an
1846         <type>unsigned char</type>.
1847        </para>
1849       </listitem></varlistentry>
1851      <varlistentry><term><constant>PPCLRIRQ</constant></term>
1852       <listitem>
1854        <para>
1855         Clears the interrupt count.  The <literal>ppdev</literal>
1856         driver keeps a count of interrupts as they are triggered.
1857         <constant>PPCLRIRQ</constant> stores this count in an
1858         <type>int</type>, a pointer to which is passed in as the
1859         <function>ioctl</function> parameter.
1860        </para>
1862        <para>
1863         In addition, the interrupt count is reset to zero.
1864        </para>
1866       </listitem></varlistentry>
1868      <varlistentry><term><constant>PPWCTLONIRQ</constant></term>
1869       <listitem>
1871        <para>
1872         Set a trigger response.  Afterwards when an interrupt is
1873         triggered, the interrupt handler will set the control lines as
1874         requested.  The <function>ioctl</function> parameter is a
1875         pointer to an <type>unsigned char</type>, which is interpreted
1876         in the same way as for <constant>PPWCONTROL</constant>.
1877        </para>
1879        <para>
1880         The reason for this <function>ioctl</function> is simply
1881         speed.  Without this <function>ioctl</function>, responding to
1882         an interrupt would start in the interrupt handler, switch
1883         context to the user-land driver via <function>poll</function>
1884         or <function>select</function>, and then switch context back
1885         to the kernel in order to handle
1886         <constant>PPWCONTROL</constant>.  Doing the whole lot in the
1887         interrupt handler is a lot faster.
1888        </para>
1890       </listitem></varlistentry>
1892      <!-- PPSETPHASE? -->
1894     </variablelist>
1896    </sect2>
1898    <sect2>
1899     <title>Transferring data: <function>read</function> and
1900      <function>write</function></title>
1902     <para>
1903      Transferring data using <function>read</function> and
1904      <function>write</function> is straightforward.  The data is
1905      transferring using the current IEEE 1284 mode (see the
1906      <constant>PPSETMODE</constant> <function>ioctl</function>).  For
1907      modes which can only transfer data in one direction, only the
1908      appropriate function will work, of course.
1909     </para>
1910    </sect2>
1912    <sect2>
1913     <title>Waiting for events: <function>poll</function> and
1914      <function>select</function></title>
1916     <para>
1917      The <literal>ppdev</literal> driver provides user-land device
1918      drivers with the ability to wait for interrupts, and this is done
1919      using <function>poll</function> (and <function>select</function>,
1920      which is implemented in terms of <function>poll</function>).
1921     </para>
1923     <para>
1924      When a user-land device driver wants to wait for an interrupt, it
1925      sleeps with <function>poll</function>.  When the interrupt
1926      arrives, <literal>ppdev</literal> wakes it up (with a
1927      <quote>read</quote> event, although strictly speaking there is
1928      nothing to actually <function>read</function>).
1929     </para>
1931    </sect2>
1933   </sect1>
1935   <sect1>
1936    <title>Examples</title>
1938    <para>
1939     Presented here are two demonstrations of how to write a simple
1940     printer driver for <literal>ppdev</literal>.  Firstly we will
1941     use the <function>write</function> function, and after that we
1942     will drive the control and data lines directly.
1943    </para>
1945    <para>
1946     The first thing to do is to actually open the device.
1947    </para>
1949    <programlisting><![CDATA[
1950 int drive_printer (const char *name)
1952     int fd;
1953     int mode; /* We'll need this later. */
1955     fd = open (name, O_RDWR);
1956     if (fd == -1) {
1957         perror ("open");
1958         return 1;
1959     }
1960     ]]></programlisting>
1962    <para>
1963     Here <varname>name</varname> should be something along the lines
1964     of <filename>"/dev/parport0"</filename>. (If you don't have any
1965     <filename>/dev/parport</filename> files, you can make them with
1966     <command>mknod</command>; they are character special device nodes
1967     with major 99.)
1968    </para>
1970    <para>
1971     In order to do anything with the port we need to claim access to
1972     it.
1973    </para>
1975    <programlisting><![CDATA[
1976     if (ioctl (fd, PPCLAIM)) {
1977         perror ("PPCLAIM");
1978         close (fd);
1979         return 1;
1980     }
1981     ]]></programlisting>
1983    <para>
1984     Our printer driver will copy its input (from
1985     <varname>stdin</varname>) to the printer, and it can do that it
1986     one of two ways.  The first way is to hand it all off to the
1987     kernel driver, with the knowledge that the protocol that the
1988     printer speaks is IEEE 1284's <quote>compatibility</quote>
1989     mode.
1990    </para>
1992    <programlisting><![CDATA[
1993     /* Switch to compatibility mode.  (In fact we don't need
1994      * to do this, since we start off in compatibility mode
1995      * anyway, but this demonstrates PPNEGOT.)
1996     mode = IEEE1284_MODE_COMPAT;
1997     if (ioctl (fd, PPNEGOT, &mode)) {
1998         perror ("PPNEGOT");
1999         close (fd);
2000         return 1;
2001     }
2003     for (;;) {
2004         char buffer[1000];
2005         char *ptr = buffer;
2006         size_t got;
2008         got = read (0 /* stdin */, buffer, 1000);
2009         if (got < 0) {
2010             perror ("read");
2011             close (fd);
2012             return 1;
2013         }
2015         if (got == 0)
2016             /* End of input */
2017             break;
2019         while (got > 0) {
2020             int written = write_printer (fd, ptr, got);
2022             if (written < 0) {
2023                 perror ("write");
2024                 close (fd);
2025                 return 1;
2026             }
2028             ptr += written;
2029             got -= written;
2030         }
2031     }
2032     ]]></programlisting>
2034    <para>
2035     The <function>write_printer</function> function is not pictured
2036     above.  This is because the main loop that is shown can be used
2037     for both methods of driving the printer.  Here is one
2038     implementation of <function>write_printer</function>:
2039    </para>
2041    <programlisting><![CDATA[
2042 ssize_t write_printer (int fd, const void *ptr, size_t count)
2044     return write (fd, ptr, count);
2046     ]]></programlisting>
2048    <para>
2049     We hand the data to the kernel-level driver (using
2050     <function>write</function>) and it handles the printer
2051     protocol.
2052    </para>
2054    <para>
2055     Now let's do it the hard way!  In this particular example there is
2056     no practical reason to do anything other than just call
2057     <function>write</function>, because we know that the printer talks
2058     an IEEE 1284 protocol.  On the other hand, this particular example
2059     does not even need a user-land driver since there is already a
2060     kernel-level one; for the purpose of this discussion, try to
2061     imagine that the printer speaks a protocol that is not already
2062     implemented under Linux.
2063    </para>
2065    <para>
2066     So, here is the alternative implementation of
2067     <function>write_printer</function> (for brevity, error checking
2068     has been omitted):
2069    </para>
2071    <programlisting><![CDATA[
2072 ssize_t write_printer (int fd, const void *ptr, size_t count)
2074     ssize_t wrote = 0;
2076     while (wrote < count) {
2077         unsigned char status, control, data;
2078         unsigned char mask = (PARPORT_STATUS_ERROR
2079                               | PARPORT_STATUS_BUSY);
2080         unsigned char val = (PARPORT_STATUS_ERROR
2081                               | PARPORT_STATUS_BUSY);
2082         struct parport_frob_struct frob;
2083         struct timespec ts;
2085         /* Wait for printer to be ready */
2086         for (;;) {
2087             ioctl (fd, PPRSTATUS, &status);
2089             if ((status & mask) == val)
2090                 break;
2092             ioctl (fd, PPRELEASE);
2093             sleep (1);
2094             ioctl (fd, PPCLAIM);
2095         }
2097         /* Set the data lines */
2098         data = * ((char *) ptr)++;
2099         ioctl (fd, PPWDATA, &data);
2101         /* Delay for a bit */
2102         ts.tv_sec = 0;
2103         ts.tv_nsec = 1000;
2104         nanosleep (&ts, NULL);
2106         /* Pulse strobe */
2107         frob.mask = PARPORT_CONTROL_STROBE;
2108         frob.val = PARPORT_CONTROL_STROBE;
2109         ioctl (fd, PPFCONTROL, &frob);
2110         nanosleep (&ts, NULL);
2112         /* End the pulse */
2113         frob.val = 0;
2114         ioctl (fd, PPFCONTROL, &frob);
2115         nanosleep (&ts, NULL);
2117         wrote++;
2118     }
2120     return wrote;
2122     ]]></programlisting>
2124    <para>
2125     To show a bit more of the <literal>ppdev</literal> interface,
2126     here is a small piece of code that is intended to mimic the
2127     printer's side of printer protocol.
2128    </para>
2130    <programlisting><![CDATA[
2131   for (;;)
2132     {
2133       int irqc;
2134       int busy = nAck | nFault;
2135       int acking = nFault;
2136       int ready = Busy | nAck | nFault;
2137       char ch;
2139       /* Set up the control lines when an interrupt happens. */
2140       ioctl (fd, PPWCTLONIRQ, &busy);
2142       /* Now we're ready. */
2143       ioctl (fd, PPWCONTROL, &ready);
2145       /* Wait for an interrupt. */
2146       {
2147         fd_set rfds;
2148         FD_ZERO (&rfds);
2149         FD_SET (fd, &rfds);
2150         if (!select (fd + 1, &rfds, NULL, NULL, NULL))
2151           /* Caught a signal? */
2152           continue;
2153       }
2155       /* We are now marked as busy. */
2157       /* Fetch the data. */
2158       ioctl (fd, PPRDATA, &ch);
2160       /* Clear the interrupt. */
2161       ioctl (fd, PPCLRIRQ, &irqc);
2162       if (irqc > 1)
2163         fprintf (stderr, "Arghh! Missed %d interrupt%s!\n",
2164          irqc - 1, irqc == 2 ? "s" : "");
2166       /* Ack it. */
2167       ioctl (fd, PPWCONTROL, &acking);
2168       usleep (2);
2169       ioctl (fd, PPWCONTROL, &busy);
2171       putchar (ch);
2172     }
2173     ]]></programlisting>
2175    <para>
2176     And here is an example (with no error checking at all) to show how
2177     to read data from the port, using ECP mode, with optional
2178     negotiation to ECP mode first.
2179    </para>
2181    <programlisting><![CDATA[
2182     {
2183       int fd, mode;
2184       fd = open ("/dev/parport0", O_RDONLY | O_NOCTTY);
2185       ioctl (fd, PPCLAIM);
2186       mode = IEEE1284_MODE_ECP;
2187       if (negotiate_first) {
2188         ioctl (fd, PPNEGOT, &mode);
2189         /* no need for PPSETMODE */
2190       } else {
2191         ioctl (fd, PPSETMODE, &mode);
2192       }
2194       /* Now do whatever we want with fd */
2195       close (0);
2196       dup2 (fd, 0);
2197       if (!fork()) {
2198         /* child */
2199         execlp ("cat", "cat", NULL);
2200         exit (1);
2201       } else {
2202         /* parent */
2203         wait (NULL);
2204       }
2206       /* Okay, finished */
2207       ioctl (fd, PPRELEASE);
2208       close (fd);
2209     }
2210     ]]></programlisting>
2212   </sect1>
2214  </chapter>
2216  <appendix id="api">
2217   <title>
2218    Linux parallel port driver API reference
2219   </title>
2221 !Fdrivers/parport/daisy.c parport_device_num
2222 !Fdrivers/parport/daisy.c parport_device_coords
2223 !Fdrivers/parport/daisy.c parport_find_device
2224 !Fdrivers/parport/daisy.c parport_find_class
2225 !Fdrivers/parport/share.c parport_register_driver
2226 !Fdrivers/parport/share.c parport_unregister_driver
2227 !Fdrivers/parport/share.c parport_get_port
2228 !Fdrivers/parport/share.c parport_put_port
2229 !Fdrivers/parport/share.c parport_find_number parport_find_base
2230 !Fdrivers/parport/share.c parport_register_device
2231 !Fdrivers/parport/share.c parport_unregister_device
2232 !Fdrivers/parport/daisy.c parport_open
2233 !Fdrivers/parport/daisy.c parport_close
2234 !Fdrivers/parport/share.c parport_claim
2235 !Fdrivers/parport/share.c parport_claim_or_block
2236 !Fdrivers/parport/share.c parport_release
2237 !Finclude/linux/parport.h parport_yield
2238 !Finclude/linux/parport.h parport_yield_blocking
2239 !Fdrivers/parport/ieee1284.c parport_negotiate
2240 !Fdrivers/parport/ieee1284.c parport_write
2241 !Fdrivers/parport/ieee1284.c parport_read
2242 !Fdrivers/parport/ieee1284.c parport_set_timeout
2244  </appendix>
2246  <appendix>
2247   <title>
2248    The Linux 2.2 Parallel Port Subsystem
2249   </title>
2251   <para>
2252    Although the interface described in this document is largely new
2253    with the 2.4 kernel, the sharing mechanism is available in the 2.2
2254    kernel as well.  The functions available in 2.2 are:
2255   </para>
2257   <itemizedlist>
2258    <listitem>
2259     <para>
2260      <function>parport_register_device</function>
2261     </para>
2262    </listitem>
2264    <listitem>
2265     <para>
2266      <function>parport_unregister_device</function>
2267     </para>
2268    </listitem>
2270    <listitem>
2271     <para>
2272      <function>parport_claim</function>
2273     </para>
2274    </listitem>
2276    <listitem>
2277     <para>
2278      <function>parport_claim_or_block</function>
2279     </para>
2280    </listitem>
2282    <listitem>
2283     <para>
2284      <function>parport_release</function>
2285     </para>
2286    </listitem>
2288    <listitem>
2289     <para>
2290      <function>parport_yield</function>
2291     </para>
2292    </listitem>
2294    <listitem>
2295     <para>
2296      <function>parport_yield_blocking</function>
2297     </para>
2298    </listitem>
2299   </itemizedlist>
2301   <para>
2302    In addition, negotiation to reverse nibble mode is supported:
2303   </para>
2305   <funcsynopsis>
2306    <funcprototype>
2307      <funcdef>int <function>parport_ieee1284_nibble_mode_ok</function></funcdef>
2308     <paramdef>struct parport *<parameter>port</parameter></paramdef>
2309     <paramdef>unsigned char <parameter>mode</parameter></paramdef>
2310    </funcprototype>
2311   </funcsynopsis>
2313   <para>
2314    The only valid values for <parameter>mode</parameter> are 0 (for
2315    reverse nibble mode) and 4 (for Device ID in reverse nibble mode).
2316   </para>
2318   <para>
2319    This function is obsoleted by
2320    <function>parport_negotiate</function> in Linux 2.4, and has been
2321    removed.
2322   </para>
2323  </appendix>
2325  <appendix id="fdl">
2326   <title>
2327    GNU Free Documentation License
2328   </title>
2330   <literallayout class="monospaced">
2331                 GNU Free Documentation License
2332                    Version 1.1, March 2000
2334  Copyright (C) 2000  Free Software Foundation, Inc.
2335      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2336  Everyone is permitted to copy and distribute verbatim copies
2337  of this license document, but changing it is not allowed.
2340 0. PREAMBLE
2342 The purpose of this License is to make a manual, textbook, or other
2343 written document "free" in the sense of freedom: to assure everyone
2344 the effective freedom to copy and redistribute it, with or without
2345 modifying it, either commercially or noncommercially.  Secondarily,
2346 this License preserves for the author and publisher a way to get
2347 credit for their work, while not being considered responsible for
2348 modifications made by others.
2350 This License is a kind of "copyleft", which means that derivative
2351 works of the document must themselves be free in the same sense.  It
2352 complements the GNU General Public License, which is a copyleft
2353 license designed for free software.
2355 We have designed this License in order to use it for manuals for free
2356 software, because free software needs free documentation: a free
2357 program should come with manuals providing the same freedoms that the
2358 software does.  But this License is not limited to software manuals;
2359 it can be used for any textual work, regardless of subject matter or
2360 whether it is published as a printed book.  We recommend this License
2361 principally for works whose purpose is instruction or reference.
2364 1. APPLICABILITY AND DEFINITIONS
2366 This License applies to any manual or other work that contains a
2367 notice placed by the copyright holder saying it can be distributed
2368 under the terms of this License.  The "Document", below, refers to any
2369 such manual or work.  Any member of the public is a licensee, and is
2370 addressed as "you".
2372 A "Modified Version" of the Document means any work containing the
2373 Document or a portion of it, either copied verbatim, or with
2374 modifications and/or translated into another language.
2376 A "Secondary Section" is a named appendix or a front-matter section of
2377 the Document that deals exclusively with the relationship of the
2378 publishers or authors of the Document to the Document's overall subject
2379 (or to related matters) and contains nothing that could fall directly
2380 within that overall subject.  (For example, if the Document is in part a
2381 textbook of mathematics, a Secondary Section may not explain any
2382 mathematics.)  The relationship could be a matter of historical
2383 connection with the subject or with related matters, or of legal,
2384 commercial, philosophical, ethical or political position regarding
2385 them.
2387 The "Invariant Sections" are certain Secondary Sections whose titles
2388 are designated, as being those of Invariant Sections, in the notice
2389 that says that the Document is released under this License.
2391 The "Cover Texts" are certain short passages of text that are listed,
2392 as Front-Cover Texts or Back-Cover Texts, in the notice that says that
2393 the Document is released under this License.
2395 A "Transparent" copy of the Document means a machine-readable copy,
2396 represented in a format whose specification is available to the
2397 general public, whose contents can be viewed and edited directly and
2398 straightforwardly with generic text editors or (for images composed of
2399 pixels) generic paint programs or (for drawings) some widely available
2400 drawing editor, and that is suitable for input to text formatters or
2401 for automatic translation to a variety of formats suitable for input
2402 to text formatters.  A copy made in an otherwise Transparent file
2403 format whose markup has been designed to thwart or discourage
2404 subsequent modification by readers is not Transparent.  A copy that is
2405 not "Transparent" is called "Opaque".
2407 Examples of suitable formats for Transparent copies include plain
2408 ASCII without markup, Texinfo input format, LaTeX input format, SGML
2409 or XML using a publicly available DTD, and standard-conforming simple
2410 HTML designed for human modification.  Opaque formats include
2411 PostScript, PDF, proprietary formats that can be read and edited only
2412 by proprietary word processors, SGML or XML for which the DTD and/or
2413 processing tools are not generally available, and the
2414 machine-generated HTML produced by some word processors for output
2415 purposes only.
2417 The "Title Page" means, for a printed book, the title page itself,
2418 plus such following pages as are needed to hold, legibly, the material
2419 this License requires to appear in the title page.  For works in
2420 formats which do not have any title page as such, "Title Page" means
2421 the text near the most prominent appearance of the work's title,
2422 preceding the beginning of the body of the text.
2425 2. VERBATIM COPYING
2427 You may copy and distribute the Document in any medium, either
2428 commercially or noncommercially, provided that this License, the
2429 copyright notices, and the license notice saying this License applies
2430 to the Document are reproduced in all copies, and that you add no other
2431 conditions whatsoever to those of this License.  You may not use
2432 technical measures to obstruct or control the reading or further
2433 copying of the copies you make or distribute.  However, you may accept
2434 compensation in exchange for copies.  If you distribute a large enough
2435 number of copies you must also follow the conditions in section 3.
2437 You may also lend copies, under the same conditions stated above, and
2438 you may publicly display copies.
2441 3. COPYING IN QUANTITY
2443 If you publish printed copies of the Document numbering more than 100,
2444 and the Document's license notice requires Cover Texts, you must enclose
2445 the copies in covers that carry, clearly and legibly, all these Cover
2446 Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
2447 the back cover.  Both covers must also clearly and legibly identify
2448 you as the publisher of these copies.  The front cover must present
2449 the full title with all words of the title equally prominent and
2450 visible.  You may add other material on the covers in addition.
2451 Copying with changes limited to the covers, as long as they preserve
2452 the title of the Document and satisfy these conditions, can be treated
2453 as verbatim copying in other respects.
2455 If the required texts for either cover are too voluminous to fit
2456 legibly, you should put the first ones listed (as many as fit
2457 reasonably) on the actual cover, and continue the rest onto adjacent
2458 pages.
2460 If you publish or distribute Opaque copies of the Document numbering
2461 more than 100, you must either include a machine-readable Transparent
2462 copy along with each Opaque copy, or state in or with each Opaque copy
2463 a publicly-accessible computer-network location containing a complete
2464 Transparent copy of the Document, free of added material, which the
2465 general network-using public has access to download anonymously at no
2466 charge using public-standard network protocols.  If you use the latter
2467 option, you must take reasonably prudent steps, when you begin
2468 distribution of Opaque copies in quantity, to ensure that this
2469 Transparent copy will remain thus accessible at the stated location
2470 until at least one year after the last time you distribute an Opaque
2471 copy (directly or through your agents or retailers) of that edition to
2472 the public.
2474 It is requested, but not required, that you contact the authors of the
2475 Document well before redistributing any large number of copies, to give
2476 them a chance to provide you with an updated version of the Document.
2479 4. MODIFICATIONS
2481 You may copy and distribute a Modified Version of the Document under
2482 the conditions of sections 2 and 3 above, provided that you release
2483 the Modified Version under precisely this License, with the Modified
2484 Version filling the role of the Document, thus licensing distribution
2485 and modification of the Modified Version to whoever possesses a copy
2486 of it.  In addition, you must do these things in the Modified Version:
2488 A. Use in the Title Page (and on the covers, if any) a title distinct
2489    from that of the Document, and from those of previous versions
2490    (which should, if there were any, be listed in the History section
2491    of the Document).  You may use the same title as a previous version
2492    if the original publisher of that version gives permission.
2493 B. List on the Title Page, as authors, one or more persons or entities
2494    responsible for authorship of the modifications in the Modified
2495    Version, together with at least five of the principal authors of the
2496    Document (all of its principal authors, if it has less than five).
2497 C. State on the Title page the name of the publisher of the
2498    Modified Version, as the publisher.
2499 D. Preserve all the copyright notices of the Document.
2500 E. Add an appropriate copyright notice for your modifications
2501    adjacent to the other copyright notices.
2502 F. Include, immediately after the copyright notices, a license notice
2503    giving the public permission to use the Modified Version under the
2504    terms of this License, in the form shown in the Addendum below.
2505 G. Preserve in that license notice the full lists of Invariant Sections
2506    and required Cover Texts given in the Document's license notice.
2507 H. Include an unaltered copy of this License.
2508 I. Preserve the section entitled "History", and its title, and add to
2509    it an item stating at least the title, year, new authors, and
2510    publisher of the Modified Version as given on the Title Page.  If
2511    there is no section entitled "History" in the Document, create one
2512    stating the title, year, authors, and publisher of the Document as
2513    given on its Title Page, then add an item describing the Modified
2514    Version as stated in the previous sentence.
2515 J. Preserve the network location, if any, given in the Document for
2516    public access to a Transparent copy of the Document, and likewise
2517    the network locations given in the Document for previous versions
2518    it was based on.  These may be placed in the "History" section.
2519    You may omit a network location for a work that was published at
2520    least four years before the Document itself, or if the original
2521    publisher of the version it refers to gives permission.
2522 K. In any section entitled "Acknowledgements" or "Dedications",
2523    preserve the section's title, and preserve in the section all the
2524    substance and tone of each of the contributor acknowledgements
2525    and/or dedications given therein.
2526 L. Preserve all the Invariant Sections of the Document,
2527    unaltered in their text and in their titles.  Section numbers
2528    or the equivalent are not considered part of the section titles.
2529 M. Delete any section entitled "Endorsements".  Such a section
2530    may not be included in the Modified Version.
2531 N. Do not retitle any existing section as "Endorsements"
2532    or to conflict in title with any Invariant Section.
2534 If the Modified Version includes new front-matter sections or
2535 appendices that qualify as Secondary Sections and contain no material
2536 copied from the Document, you may at your option designate some or all
2537 of these sections as invariant.  To do this, add their titles to the
2538 list of Invariant Sections in the Modified Version's license notice.
2539 These titles must be distinct from any other section titles.
2541 You may add a section entitled "Endorsements", provided it contains
2542 nothing but endorsements of your Modified Version by various
2543 parties--for example, statements of peer review or that the text has
2544 been approved by an organization as the authoritative definition of a
2545 standard.
2547 You may add a passage of up to five words as a Front-Cover Text, and a
2548 passage of up to 25 words as a Back-Cover Text, to the end of the list
2549 of Cover Texts in the Modified Version.  Only one passage of
2550 Front-Cover Text and one of Back-Cover Text may be added by (or
2551 through arrangements made by) any one entity.  If the Document already
2552 includes a cover text for the same cover, previously added by you or
2553 by arrangement made by the same entity you are acting on behalf of,
2554 you may not add another; but you may replace the old one, on explicit
2555 permission from the previous publisher that added the old one.
2557 The author(s) and publisher(s) of the Document do not by this License
2558 give permission to use their names for publicity for or to assert or
2559 imply endorsement of any Modified Version.
2562 5. COMBINING DOCUMENTS
2564 You may combine the Document with other documents released under this
2565 License, under the terms defined in section 4 above for modified
2566 versions, provided that you include in the combination all of the
2567 Invariant Sections of all of the original documents, unmodified, and
2568 list them all as Invariant Sections of your combined work in its
2569 license notice.
2571 The combined work need only contain one copy of this License, and
2572 multiple identical Invariant Sections may be replaced with a single
2573 copy.  If there are multiple Invariant Sections with the same name but
2574 different contents, make the title of each such section unique by
2575 adding at the end of it, in parentheses, the name of the original
2576 author or publisher of that section if known, or else a unique number.
2577 Make the same adjustment to the section titles in the list of
2578 Invariant Sections in the license notice of the combined work.
2580 In the combination, you must combine any sections entitled "History"
2581 in the various original documents, forming one section entitled
2582 "History"; likewise combine any sections entitled "Acknowledgements",
2583 and any sections entitled "Dedications".  You must delete all sections
2584 entitled "Endorsements."
2587 6. COLLECTIONS OF DOCUMENTS
2589 You may make a collection consisting of the Document and other documents
2590 released under this License, and replace the individual copies of this
2591 License in the various documents with a single copy that is included in
2592 the collection, provided that you follow the rules of this License for
2593 verbatim copying of each of the documents in all other respects.
2595 You may extract a single document from such a collection, and distribute
2596 it individually under this License, provided you insert a copy of this
2597 License into the extracted document, and follow this License in all
2598 other respects regarding verbatim copying of that document.
2602 7. AGGREGATION WITH INDEPENDENT WORKS
2604 A compilation of the Document or its derivatives with other separate
2605 and independent documents or works, in or on a volume of a storage or
2606 distribution medium, does not as a whole count as a Modified Version
2607 of the Document, provided no compilation copyright is claimed for the
2608 compilation.  Such a compilation is called an "aggregate", and this
2609 License does not apply to the other self-contained works thus compiled
2610 with the Document, on account of their being thus compiled, if they
2611 are not themselves derivative works of the Document.
2613 If the Cover Text requirement of section 3 is applicable to these
2614 copies of the Document, then if the Document is less than one quarter
2615 of the entire aggregate, the Document's Cover Texts may be placed on
2616 covers that surround only the Document within the aggregate.
2617 Otherwise they must appear on covers around the whole aggregate.
2620 8. TRANSLATION
2622 Translation is considered a kind of modification, so you may
2623 distribute translations of the Document under the terms of section 4.
2624 Replacing Invariant Sections with translations requires special
2625 permission from their copyright holders, but you may include
2626 translations of some or all Invariant Sections in addition to the
2627 original versions of these Invariant Sections.  You may include a
2628 translation of this License provided that you also include the
2629 original English version of this License.  In case of a disagreement
2630 between the translation and the original English version of this
2631 License, the original English version will prevail.
2634 9. TERMINATION
2636 You may not copy, modify, sublicense, or distribute the Document except
2637 as expressly provided for under this License.  Any other attempt to
2638 copy, modify, sublicense or distribute the Document is void, and will
2639 automatically terminate your rights under this License.  However,
2640 parties who have received copies, or rights, from you under this
2641 License will not have their licenses terminated so long as such
2642 parties remain in full compliance.
2645 10. FUTURE REVISIONS OF THIS LICENSE
2647 The Free Software Foundation may publish new, revised versions
2648 of the GNU Free Documentation License from time to time.  Such new
2649 versions will be similar in spirit to the present version, but may
2650 differ in detail to address new problems or concerns. See
2651 http:///www.gnu.org/copyleft/.
2653 Each version of the License is given a distinguishing version number.
2654 If the Document specifies that a particular numbered version of this
2655 License "or any later version" applies to it, you have the option of
2656 following the terms and conditions either of that specified version or
2657 of any later version that has been published (not as a draft) by the
2658 Free Software Foundation.  If the Document does not specify a version
2659 number of this License, you may choose any version ever published (not
2660 as a draft) by the Free Software Foundation.
2663 ADDENDUM: How to use this License for your documents
2665 To use this License in a document you have written, include a copy of
2666 the License in the document and put the following copyright and
2667 license notices just after the title page:
2669       Copyright (c)  YEAR  YOUR NAME.
2670       Permission is granted to copy, distribute and/or modify this document
2671       under the terms of the GNU Free Documentation License, Version 1.1
2672       or any later version published by the Free Software Foundation;
2673       with the Invariant Sections being LIST THEIR TITLES, with the
2674       Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
2675       A copy of the license is included in the section entitled "GNU
2676       Free Documentation License".
2678 If you have no Invariant Sections, write "with no Invariant Sections"
2679 instead of saying which ones are invariant.  If you have no
2680 Front-Cover Texts, write "no Front-Cover Texts" instead of
2681 "Front-Cover Texts being LIST"; likewise for Back-Cover Texts.
2683 If your document contains nontrivial examples of program code, we
2684 recommend releasing these examples in parallel under your choice of
2685 free software license, such as the GNU General Public License,
2686 to permit their use in free software.
2687   </literallayout>
2688  </appendix>
2690 </book>
2692 <!-- Local Variables: -->
2693 <!-- sgml-indent-step: 1 -->
2694 <!-- sgml-indent-data: 1 -->
2695 <!-- End: -->