OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [Documentation/] [DocBook/] [parportbook.tmpl] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
2
3
 
4
5
 
6
  The Linux 2.4 Parallel Port Subsystem
7
 
8
  
9
   
10
    Tim
11
    Waugh
12
    
13
     
14
      twaugh@redhat.com
15
     
16
    
17
   
18
  
19
 
20
  
21
   1999-2000
22
   Tim Waugh
23
  
24
 
25
  
26
   
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
   
34
  
35
 
36
 
37
 
38
 
39
 
40
  Design goals
41
 
42
  
43
   The problems
44
 
45
   
46
    The first parallel port support for Linux came with the line
47
    printer driver, lp.  The printer driver is a
48
    character special device, and (in Linux 2.0) had support for
49
    writing, via write, and configuration and
50
    statistics reporting via ioctl.
51
   
52
 
53
   
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
   
60
 
61
   
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
   
69
 
70
   
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
    check_region function to make sure that the
78
    IO region associated with the parallel port was free, and then it
79
    would call request_region 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
   
84
 
85
   
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
   
92
 
93
   
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
   
99
 
100
   
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
   
112
 
113
   
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: compatibility,
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 compatibility
120
    mode (i.e. normal printer protocol) and reverse nibble
121
    mode.
122
   
123
 
124
  
125
 
126
  
127
   The solutions
128
 
129
135
 
136
   
137
    The parport 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
   
142
 
143
   
144
 
145
   
146
    There are two layers to the parport
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
   
153
 
154
   
155
 
156
   
157
    The sharing model provided by the parport
158
    subsystem is one of exclusive access.  A device driver, such as
159
    the printer driver, must ask the parport
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
    transaction, it can tell the
163
    parport layer that it may release the port
164
    for other device drivers to use.
165
   
166
 
167
   
168
 
169
   
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
   
184
 
185
   
186
    
187
     
188
    
189
    
190
     
191
    
192
   
193
 
194
   
195
    This technique relies on certain special signals
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
   
201
 
202
   
203
 
204
   
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
   
211
 
212
  
213
 
214
 
215
 
216
 
217
  Standard transfer modes
218
 
219
  
220
  
221
 
222
  
223
   The standard transfer modes in use over the parallel
224
   port are defined 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
  
229
 
230
  
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
  
235
 
236
  
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
  
242
 
243
  
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
  
248
 
249
  
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
  
256
 
257
 
258
 
259
 
260
  Structure
261
 
262
270
 
271
  
272
   
273
    
274
   
275
   
276
    
277
   
278
  
279
 
280
  
281
   Sharing core
282
 
283
   
284
    At the core of the parport subsystem is the
285
    sharing mechanism (see
286
    drivers/parport/share.c).  This module,
287
    parport, 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
   
292
 
293
  
294
 
295
  
296
   Parports and their overrides
297
 
298
   
299
    The generic parport sharing code doesn't
300
    directly handle the parallel port hardware.  That is done instead
301
    by low-level parport drivers.
302
    The function of a low-level parport 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
   
306
 
307
   
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
    forward direction (that is, the computer drives
313
    them), but some ports allow switching to reverse
314
    mode (driven by the peripheral).  There is an access function for
315
    examining the data lines once in reverse mode.
316
   
317
 
318
  
319
 
320
  
321
   IEEE 1284 transfer modes
322
 
323
   
324
    Stacked on top of the sharing mechanism, but still in the
325
    parport 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
    parport core they must use the lowest
330
    common denominator 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
   
339
 
340
   
341
    The low-level parport 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
   
348
 
349
  
350
 
351
  
352
 
353
  
354
   Pardevices and parport_drivers
355
 
356
   
357
    When a parallel port device driver (such as
358
    lp) initialises it tells the sharing layer
359
    about itself using parport_register_driver.
360
    The information is put into a struct
361
    parport_driver, which is put into a linked list.  The
362
    information in a struct parport_driver
363
    really just amounts to some function pointers to callbacks in the
364
    parallel port device driver.
365
   
366
 
367
   
368
    During its initialisation, a low-level port driver tells the
369
    sharing layer about all the ports that it has found (using
370
    parport_register_port), and the sharing layer
371
    creates a struct parport for each of
372
    them.  Each struct parport contains
373
    (among other things) a pointer to a struct
374
    parport_operations, 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 struct parport
377
    as a parallel port object, if
378
    object-orientated programming is your thing.  The
379
    parport structures are chained in a
380
    linked list, whose head is portlist (in
381
    drivers/parport/share.c).
382
   
383
 
384
   
385
    Once the port has been registered, the low-level port driver
386
    announces it.  The parport_announce_port
387
    function walks down the list of parallel port device drivers
388
    (struct parport_drivers) calling the
389
    attach function of each (which may block).
390
   
391
 
392
   
393
    Similarly, a low-level port driver can undo the effect of
394
    registering a port with the
395
    parport_unregister_port function, and device
396
    drivers are notified using the detach
397
    callback (which may not block).
398
   
399
 
400
   
401
    Device drivers can undo the effect of registering themselves with
402
    the parport_unregister_driver
403
    function.
404
   
405
 
406
  
407
 
408
  
409
 
410
  
411
   The IEEE 1284.3 API
412
 
413
   
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
   
420
 
421
   
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 parport code in Linux.
427
   
428
 
429
   
430
    At initialisation of the parallel port bus,
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
   
436
 
437
   
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
   
446
 
447
   
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
   
453
 
454
   
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
   
461
 
462
   
463
    
464
     
465
    
466
    
467
     
468
    
469
   
470
 
471
   
472
    Each device in the system is numbered at initialisation (by
473
    parport_daisy_init).  You can convert between
474
    this device number and its co-ordinates with
475
    parport_device_num and
476
    parport_device_coords.
477
   
478
 
479
   
480
    
481
#include <parport.h>
482
    
483
    
484
     int parport_device_num
485
     int parport
486
     int mux
487
     int daisy
488
    
489
   
490
 
491
   
492
    
493
     int parport_device_coords
494
     int devnum
495
     int *parport
496
     int *mux
497
     int *daisy
498
    
499
   
500
 
501
   
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
    -1 is used to indicate these cases.
508
   
509
 
510
   
511
    Two functions are provided for finding devices based on their IEEE
512
    1284 Device ID: parport_find_device and
513
    parport_find_class.
514
   
515
 
516
   
517
    
518
#include <parport.h>
519
    
520
    
521
     int parport_find_device
522
     const char *mfg
523
     const char *mdl
524
     int from
525
    
526
   
527
 
528
   
529
    
530
     int parport_find_class
531
     parport_device_class cls
532
     int from
533
    
534
   
535
 
536
   
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
    -1 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 from+1, in other
544
    words).
545
   
546
 
547
  
548
 
549
 
550
 
551
 
552
  Device driver's view
553
 
554
560
 
561
562
563
564
565
566
 
567
  
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 parport interface to
572
   find parallel ports, use them, and share them with other device
573
   drivers.
574
  
575
 
576
  
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
  
581
 
582
  
583
   The interactions between the device driver and the
584
   parport layer are as follows.  First, the
585
   device driver registers its existence with
586
   parport, 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
   parport 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
  
593
 
594
  
595
   So, the first thing for the device driver to do is tell
596
   parport that it wants to know what parallel
597
   ports are on the system.  To do this, it uses the
598
   parport_register_driver function:
599
  
600
 
601
  
602
   
603
#include <parport.h>
604
 
605
struct parport_driver {
606
        const char *name;
607
        void (*attach) (struct parport *);
608
        void (*detach) (struct parport *);
609
        struct parport_driver *next;
610
};
611
   
612
 
613
   
614
    int parport_register_driver
615
    struct parport_driver *driver
616
   
617
  
618
 
619
  
620
   In other words, the device driver passes pointers to a couple of
621
   functions to parport, and
622
   parport calls attach for
623
   each port that's detected (and detach for each
624
   port that disappears---yes, this can happen).
625
  
626
 
627
  
628
   The next thing that happens is that the device driver tells
629
   parport that it thinks there's a device on the
630
   port that it can drive.  This typically will happen in the driver's
631
   attach function, and is done with
632
   parport_register_device:
633
  
634
 
635
  
636
   
637
#include <parport.h>
638
   
639
   
640
    struct pardevice *parport_register_device
641
    struct parport *port
642
    const char *name
643
    int (*pf)
644
     void *
645
    void (*kf)
646
     void *
647
    void (*irq_func)
648
     int, void *, struct pt_regs *
649
    int flags
650
    void *handle
651
   
652
  
653
 
654
  
655
   The port comes from the parameter supplied
656
   to the attach 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
   parport_enumerate function.  A better way of
660
   doing this is with parport_find_number or
661
   parport_find_base functions, which find ports
662
   by number and by base I/O address respectively.
663
  
664
 
665
  
666
   
667
#include <parport.h>
668
   
669
   
670
    struct parport *parport_find_number
671
    int number
672
   
673
  
674
  
675
   
676
#include <parport.h>
677
   
678
   
679
    struct parport *parport_find_base
680
    unsigned long base
681
   
682
  
683
 
684
  
685
   The next three parameters, pf,
686
   kf, and irq_func, are
687
   more function pointers.  These callback functions get called under
688
   various circumstances, and are always given the
689
   handle as one of their parameters.
690
  
691
 
692
  
693
   The preemption callback, pf, 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 parport_release.  If
698
   pf 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
  
704
 
705
  
706
   The kick callback, kf, is
707
   called when the port can be claimed for exclusive access; that is,
708
   parport_claim is guaranteed to succeed inside
709
   the kick callback.  If the driver wants to claim the
710
   port it should do so; otherwise, it need not take any
711
   action.
712
  
713
 
714
  
715
   The irq_func 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
   request_irq; 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 irq_func
725
   function is called.
726
  
727
 
728
  
729
   None of the callback functions are allowed to block.
730
  
731
 
732
  
733
   The flags are for telling
734
   parport any requirements or hints that are
735
   useful.  The only useful value here (other than
736
   0, which is the usual value) is
737
   PARPORT_DEV_EXCL.  The point of that flag is
738
   to request exclusive access at all times---once a driver has
739
   successfully called parport_register_device
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
  
744
 
745
  
746
   The PARPORT_DEV_EXCL 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
  
751
 
752
  
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
  
757
 
758
  
759
   The parport_open function is similar to
760
   parport_register_device, and
761
   parport_close is the equivalent of
762
   parport_unregister_device.  The difference is
763
   that parport_open takes a device number rather
764
   than a pointer to a struct parport.
765
  
766
 
767
  
768
   
769
#include <parport.h>
770
   
771
   
772
    struct pardevice *parport_open
773
    int devnum
774
    const char *name
775
    int (*pf)
776
     void *
777
    int (*kf)
778
     void *
779
    int (*irqf)
780
     int, void *, struct pt_regs *
781
    int flags
782
    void *handle
783
   
784
  
785
 
786
  
787
   
788
    void parport_close
789
    struct pardevice *dev
790
   
791
  
792
 
793
  
794
   
795
    struct pardevice *parport_register_device
796
    struct parport *port
797
    const char *name
798
    int (*pf)
799
     void *
800
    int (*kf)
801
     void *
802
    int (*irqf)
803
     int, void *, struct pt_regs *
804
    int flags
805
    void *handle
806
   
807
  
808
 
809
  
810
   
811
    void parport_unregister_device
812
    struct pardevice *dev
813
   
814
  
815
 
816
  
817
   The intended use of these functions is during driver initialisation
818
   while the driver looks for devices that it supports, as
819
   demonstrated by the following code fragment:
820
  
821
 
822
  
823
   
824
int devnum = -1;
825
while ((devnum = parport_find_class (PARPORT_CLASS_DIGCAM,
826
                                     devnum)) != -1) {
827
    struct pardevice *dev = parport_open (devnum, ...);
828
    ...
829
}
830
   ]]>
831
 
832
  
833
   Once your device driver has registered its device and been handed a
834
   pointer to a struct pardevice, the next
835
   thing you are likely to want to do is communicate with the device
836
   you think is there.  To do that you'll need to claim access to the
837
   port.
838
  
839
 
840
  
841
   
842
#include <parport.h>
843
   
844
   
845
    int parport_claim
846
    struct pardevice *dev
847
   
848
  
849
 
850
  
851
   
852
    int parport_claim_or_block
853
    struct pardevice *dev
854
   
855
  
856
 
857
  
858
   
859
    void parport_release
860
    struct pardevice *dev
861
   
862
  
863
 
864
  
865
   To claim access to the port, use parport_claim
866
   or parport_claim_or_block.  The first of these
867
   will not block, and so can be used from interrupt context.  If
868
   parport_claim succeeds it will return zero and
869
   the port is available to use.  It may fail (returning non-zero) if
870
   the port is in use by another driver and that driver is not willing
871
   to relinquish control of the port.
872
  
873
 
874
  
875
   The other function, parport_claim_or_block,
876
   will block if necessary to wait for the port to be free.  If it
877
   slept, it returns 1; if it succeeded without
878
   needing to sleep it returns 0.  If it fails it
879
   will return a negative error code.
880
  
881
 
882
  
883
   When you have finished communicating with the device, you can give
884
   up access to the port so that other drivers can communicate with
885
   their devices.  The parport_release function
886
   cannot fail, but it should not be called without the port claimed.
887
   Similarly, you should not try to claim the port if you already have
888
   it claimed.
889
  
890
 
891
  
892
   You may find that although there are convenient points for your
893
   driver to relinquish the parallel port and allow other drivers to
894
   talk to their devices, it would be preferable to keep hold of the
895
   port.  The printer driver only needs the port when there is data to
896
   print, for example, but a network driver (such as PLIP) could be
897
   sent a remote packet at any time.  With PLIP, it is no huge
898
   catastrophe if a network packet is dropped, since it will likely be
899
   sent again, so it is possible for that kind of driver to share the
900
   port with other (pass-through) devices.
901
  
902
 
903
  
904
   The parport_yield and
905
   parport_yield_blocking functions are for
906
   marking points in the driver at which other drivers may claim the
907
   port and use their devices.  Yielding the port is similar to
908
   releasing it and reclaiming it, but is more efficient because
909
   nothing is done if there are no other devices needing the port.  In
910
   fact, nothing is done even if there are other devices waiting but
911
   the current device is still within its timeslice.
912
   The default timeslice is half a second, but it can be adjusted via
913
   a /proc entry.
914
  
915
 
916
  
917
   
918
#include <parport.h>
919
   
920
   
921
    int parport_yield
922
    struct pardevice *dev
923
   
924
  
925
 
926
  
927
   
928
    int parport_yield_blocking
929
    struct pardevice *dev
930
   
931
  
932
 
933
  
934
   The first of these, parport_yield, will not
935
   block but as a result may fail.  The return value for
936
   parport_yield is the same as for
937
   parport_claim.  The blocking version,
938
   parport_yield_blocking, has the same return
939
   code as parport_claim_or_block.
940
  
941
 
942
  
943
   Once the port has been claimed, the device driver can use the
944
   functions in the struct parport_operations
945
   pointer in the struct parport it has a
946
   pointer to.  For example:
947
  
948
 
949
  
950
   
951
port->ops->write_data (port, d);
952
   ]]>
953
 
954
  
955
   Some of these operations have shortcuts.  For
956
   instance, parport_write_data is equivalent to
957
   the above, but may be a little bit faster (it's a macro that in
958
   some cases can avoid needing to indirect through
959
   port and ops).
960
  
961
 
962
 
963
 
964
 
965
  Port drivers
966
 
967
  
968
 
969
  
970
   To recap, then:
971
 
972
  
973
 
974
   
975
    
976
     The device driver registers itself with parport.
977
    
978
   
979
 
980
   
981
    
982
     A low-level driver finds a parallel port and registers it with
983
     parport (these first two things can happen
984
     in either order).  This registration creates a struct
985
     parport which is linked onto a list of known ports.
986
    
987
   
988
 
989
   
990
    
991
     parport calls the
992
     attach function of each registered device
993
     driver, passing it the pointer to the new struct
994
     parport.
995
    
996
   
997
 
998
   
999
    
1000
     The device driver gets a handle from
1001
     parport, for use with
1002
     parport_claim/release.
1003
     This handle takes the form of a pointer to a struct
1004
     pardevice, representing a particular device on the
1005
     parallel port, and is acquired using
1006
     parport_register_device.
1007
    
1008
   
1009
 
1010
   
1011
    
1012
     The device driver claims the port using
1013
     parport_claim (or
1014
     function_claim_or_block).
1015
    
1016
   
1017
 
1018
   
1019
    
1020
     Then it goes ahead and uses the port.  When finished it releases
1021
     the port.
1022
    
1023
   
1024
 
1025
  
1026
 
1027
  
1028
   The purpose of the low-level drivers, then, is to detect parallel
1029
   ports and provide methods of accessing them (i.e. implementing the
1030
   operations in struct
1031
   parport_operations).
1032
  
1033
 
1034
  
1035
  
1036
   A more complete description of which operation is supposed to do
1037
   what is available in
1038
   Documentation/parport-lowlevel.txt.
1039
  
1040
 
1041
 
1042
 
1043
 
1044
  The printer driver
1045
 
1046
  
1047
  
1048
 
1049
  
1050
   The printer driver, lp is a character special
1051
   device driver and a parport client.  As a
1052
   character special device driver it registers a struct
1053
   file_operations using
1054
   register_chrdev, with pointers filled in for
1055
   write, ioctl,
1056
   open and
1057
   release.  As a client of
1058
   parport, it registers a struct
1059
   parport_driver using
1060
   parport_register_driver, so that
1061
   parport knows to call
1062
   lp_attach when a new parallel port is
1063
   discovered (and lp_detach when it goes
1064
   away).
1065
  
1066
 
1067
  
1068
   The parallel port console functionality is also implemented in
1069
   drivers/char/lp.c, but that won't be covered
1070
   here (it's quite simple though).
1071
  
1072
 
1073
  
1074
   The initialisation of the driver is quite easy to understand (see
1075
   lp_init).  The lp_table is
1076
   an array of structures that contain information about a specific
1077
   device (the struct pardevice associated
1078
   with it, for example).  That array is initialised to sensible
1079
   values first of all.
1080
  
1081
 
1082
  
1083
   Next, the printer driver calls register_chrdev
1084
   passing it a pointer to lp_fops, which contains
1085
   function pointers for the printer driver's implementation of
1086
   open, write, and so on.
1087
   This part is the same as for any character special device
1088
   driver.
1089
  
1090
 
1091
  
1092
   After successfully registering itself as a character special device
1093
   driver, the printer driver registers itself as a
1094
   parport client using
1095
   parport_register_driver.  It passes a pointer
1096
   to this structure:
1097
  
1098
 
1099
  
1100
   
1101
static struct parport_driver lp_driver = {
1102
        "lp",
1103
        lp_attach,
1104
        lp_detach,
1105
        NULL
1106
};
1107
   ]]>
1108
 
1109
  
1110
   The lp_detach function is not very interesting
1111
   (it does nothing); the interesting bit is
1112
   lp_attach.  What goes on here depends on
1113
   whether the user supplied any parameters.  The possibilities are:
1114
   no parameters supplied, in which case the printer driver uses every
1115
   port that is detected; the user supplied the parameter
1116
   auto, in which case only ports on which the device
1117
   ID string indicates a printer is present are used; or the user
1118
   supplied a list of parallel port numbers to try, in which case only
1119
   those are used.
1120
  
1121
 
1122
  
1123
   For each port that the printer driver wants to use (see
1124
   lp_register), it calls
1125
   parport_register_device and stores the
1126
   resulting struct pardevice pointer in the
1127
   lp_table.  If the user told it to do so, it then
1128
   resets the printer.
1129
  
1130
 
1131
  
1132
   The other interesting piece of the printer driver, from the point
1133
   of view of parport, is
1134
   lp_write.  In this function, the user space
1135
   process has data that it wants printed, and the printer driver
1136
   hands it off to the parport code to deal with.
1137
  
1138
 
1139
  
1140
   The parport functions it uses that we have not
1141
   seen yet are parport_negotiate,
1142
   parport_set_timeout, and
1143
   parport_write.  These functions are part of
1144
   the IEEE 1284 implementation.
1145
  
1146
 
1147
  
1148
   The way the IEEE 1284 protocol works is that the host tells the
1149
   peripheral what transfer mode it would like to use, and the
1150
   peripheral either accepts that mode or rejects it; if the mode is
1151
   rejected, the host can try again with a different mode.  This is
1152
   the negotation phase.  Once the peripheral has accepted a
1153
   particular transfer mode, data transfer can begin that mode.
1154
  
1155
 
1156
  
1157
   The particular transfer mode that the printer driver wants to use
1158
   is named in IEEE 1284 as compatibility mode, and the
1159
   function to request a particular mode is called
1160
   parport_negotiate.
1161
  
1162
 
1163
  
1164
   
1165
#include <parport.h>
1166
   
1167
   
1168
    int parport_negotiate
1169
    struct parport *port
1170
    int mode
1171
   
1172
  
1173
 
1174
  
1175
   The modes parameter is a symbolic constant
1176
   representing an IEEE 1284 mode; in this instance, it is
1177
   IEEE1284_MODE_COMPAT. (Compatibility mode is
1178
   slightly different to the other modes---rather than being
1179
   specifically requested, it is the default until another mode is
1180
   selected.)
1181
  
1182
 
1183
  
1184
   Back to lp_write then.  First, access to the
1185
   parallel port is secured with
1186
   parport_claim_or_block.  At this point the
1187
   driver might sleep, waiting for another driver (perhaps a Zip drive
1188
   driver, for instance) to let the port go.  Next, it goes to
1189
   compatibility mode using parport_negotiate.
1190
  
1191
 
1192
  
1193
   The main work is done in the write-loop.  In particular, the line
1194
   that hands the data over to parport reads:
1195
  
1196
 
1197
1198
1199
        written = parport_write (port, kbuf, copy_size);
1200
]]>
1201
 
1202
  
1203
   The parport_write function writes data to the
1204
   peripheral using the currently selected transfer mode
1205
   (compatibility mode, in this case).  It returns the number of bytes
1206
   successfully written:
1207
  
1208
 
1209
  
1210
   
1211
#include <parport.h>
1212
   
1213
   
1214
    ssize_t parport_write
1215
    struct parport *port
1216
    const void *buf
1217
    size_t len
1218
   
1219
  
1220
 
1221
  
1222
   
1223
    ssize_t parport_read
1224
    struct parport *port
1225
    void *buf
1226
    size_t len
1227
   
1228
  
1229
 
1230
  
1231
   (parport_read does what it sounds like, but
1232
   only works for modes in which reverse transfer is possible.  Of
1233
   course, parport_write only works in modes in
1234
   which forward transfer is possible, too.)
1235
  
1236
 
1237
  
1238
   The buf pointer should be to kernel space
1239
   memory, and obviously the len parameter
1240
   specifies the amount of data to transfer.
1241
  
1242
 
1243
  
1244
   In fact what parport_write does is call the
1245
   appropriate block transfer function from the struct
1246
   parport_operations:
1247
  
1248
 
1249
  
1250
   
1251
struct parport_operations {
1252
        [...]
1253
 
1254
        /* Block read/write */
1255
        size_t (*epp_write_data) (struct parport *port,
1256
                                  const void *buf,
1257
                                  size_t len, int flags);
1258
        size_t (*epp_read_data) (struct parport *port,
1259
                                 void *buf, size_t len,
1260
                                 int flags);
1261
        size_t (*epp_write_addr) (struct parport *port,
1262
                                  const void *buf,
1263
                                  size_t len, int flags);
1264
        size_t (*epp_read_addr) (struct parport *port,
1265
                                 void *buf, size_t len,
1266
                                 int flags);
1267
 
1268
        size_t (*ecp_write_data) (struct parport *port,
1269
                                  const void *buf,
1270
                                  size_t len, int flags);
1271
        size_t (*ecp_read_data) (struct parport *port,
1272
                                 void *buf, size_t len,
1273
                                 int flags);
1274
        size_t (*ecp_write_addr) (struct parport *port,
1275
                                  const void *buf,
1276
                                  size_t len, int flags);
1277
 
1278
        size_t (*compat_write_data) (struct parport *port,
1279
                                     const void *buf,
1280
                                     size_t len, int flags);
1281
        size_t (*nibble_read_data) (struct parport *port,
1282
                                    void *buf, size_t len,
1283
                                    int flags);
1284
        size_t (*byte_read_data) (struct parport *port,
1285
                                  void *buf, size_t len,
1286
                                  int flags);
1287
};
1288
   ]]>
1289
 
1290
  
1291
   The transfer code in parport will tolerate a
1292
   data transfer stall only for so long, and this timeout can be
1293
   specified with parport_set_timeout, which
1294
   returns the previous timeout:
1295
  
1296
 
1297
  
1298
   
1299
#include <parport.h>
1300
   
1301
   
1302
    long parport_set_timeout
1303
    struct pardevice *dev
1304
    long inactivity
1305
   
1306
  
1307
 
1308
  
1309
   This timeout is specific to the device, and is restored on
1310
   parport_claim.
1311
  
1312
 
1313
  
1314
   The next function to look at is the one that allows processes to
1315
   read from /dev/lp0:
1316
   lp_read.  It's short, like
1317
   lp_write.
1318
  
1319
 
1320
  
1321
   The semantics of reading from a line printer device are as follows:
1322
  
1323
 
1324
  
1325
   
1326
    
1327
     Switch to reverse nibble mode.
1328
    
1329
   
1330
 
1331
   
1332
    
1333
     Try to read data from the peripheral using reverse nibble mode,
1334
     until either the user-provided buffer is full or the peripheral
1335
     indicates that there is no more data.
1336
    
1337
   
1338
 
1339
   
1340
    
1341
     If there was data, stop, and return it.
1342
    
1343
   
1344
 
1345
   
1346
    
1347
     Otherwise, we tried to read data and there was none.  If the user
1348
     opened the device node with the O_NONBLOCK
1349
     flag, return.  Otherwise wait until an interrupt occurs on the
1350
     port (or a timeout elapses).
1351
    
1352
   
1353
  
1354
 
1355
 
1356
 
1357
 
1358
  User-level device drivers
1359
 
1360
  
1361
  
1362
   Introduction to ppdev
1363
 
1364
   
1365
    The printer is accessible through /dev/lp0;
1366
    in the same way, the parallel port itself is accessible through
1367
    /dev/parport0.  The difference is in the
1368
    level of control that you have over the wires in the parallel port
1369
    cable.
1370
   
1371
 
1372
   
1373
    With the printer driver, a user-space program (such as the printer
1374
    spooler) can send bytes in printer protocol.
1375
    Briefly, this means that for each byte, the eight data lines are
1376
    set up, then a strobe line tells the printer to
1377
    look at the data lines, and the printer sets an
1378
    acknowledgement line to say that it got the byte.
1379
    The printer driver also allows the user-space program to read
1380
    bytes in nibble mode, which is a way of
1381
    transferring data from the peripheral to the computer half a byte
1382
    at a time (and so it's quite slow).
1383
   
1384
 
1385
   
1386
    In contrast, the ppdev driver (accessed via
1387
    /dev/parport0) allows you to:
1388
   
1389
 
1390
   
1391
 
1392
    
1393
     
1394
      examine status lines,
1395
     
1396
    
1397
 
1398
    
1399
     
1400
      set control lines,
1401
     
1402
    
1403
 
1404
    
1405
     
1406
      set/examine data lines (and control the direction of the data
1407
      lines),
1408
     
1409
    
1410
 
1411
    
1412
     
1413
      wait for an interrupt (triggered by one of the status lines),
1414
     
1415
    
1416
 
1417
    
1418
     
1419
      find out how many new interrupts have occurred,
1420
     
1421
    
1422
 
1423
    
1424
     
1425
      set up a response to an interrupt,
1426
     
1427
    
1428
 
1429
    
1430
     
1431
      use IEEE 1284 negotiation (for telling peripheral which transfer
1432
      mode, to use)
1433
     
1434
    
1435
 
1436
    
1437
     
1438
      transfer data using a specified IEEE 1284 mode.
1439
     
1440
    
1441
 
1442
   
1443
 
1444
  
1445
 
1446
  
1447
   User-level or kernel-level driver?
1448
 
1449
   
1450
    The decision of whether to choose to write a kernel-level device
1451
    driver or a user-level device driver depends on several factors.
1452
    One of the main ones from a practical point of view is speed:
1453
    kernel-level device drivers get to run faster because they are not
1454
    preemptable, unlike user-level applications.
1455
   
1456
 
1457
   
1458
    Another factor is ease of development.  It is in general easier to
1459
    write a user-level driver because (a) one wrong move does not
1460
    result in a crashed machine, (b) you have access to user libraries
1461
    (such as the C library), and (c) debugging is easier.
1462
   
1463
 
1464
  
1465
 
1466
  
1467
   Programming interface
1468
 
1469
   
1470
    The ppdev interface is largely the same as that
1471
    of other character special devices, in that it supports
1472
    open, close,
1473
    read, write, and
1474
    ioctl.  The constants for the
1475
    ioctl commands are in
1476
    include/linux/ppdev.h.
1477
   
1478
 
1479
   
1480
    </code></pre></td>
      </tr>
      <tr valign="middle">
         <td>1481</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>     Starting and stopping: <function>open</function> and</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>1482</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>     <function>close</function></code></pre></td>
      </tr>
      <tr valign="middle">
         <td>1483</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>    
1484
 
1485
    
1486
     The device node /dev/parport0 represents any
1487
     device that is connected to parport0, the
1488
     first parallel port in the system.  Each time the device node is
1489
     opened, it represents (to the process doing the opening) a
1490
     different device.  It can be opened more than once, but only one
1491
     instance can actually be in control of the parallel port at any
1492
     time.  A process that has opened
1493
     /dev/parport0 shares the parallel port in
1494
     the same way as any other device driver.  A user-land driver may
1495
     be sharing the parallel port with in-kernel device drivers as
1496
     well as other user-land drivers.
1497
    
1498
   
1499
 
1500
   
1501
    Control: <function>ioctl</function>
1502
 
1503
    
1504
     Most of the control is done, naturally enough, via the
1505
     ioctl call.  Using
1506
     ioctl, the user-land driver can control both
1507
     the ppdev driver in the kernel and the
1508
     physical parallel port itself.  The ioctl
1509
     call takes as parameters a file descriptor (the one returned from
1510
     opening the device node), a command, and optionally (a pointer
1511
     to) some data.
1512
    
1513
 
1514
    
1515
     PPCLAIM
1516
      
1517
 
1518
       
1519
        Claims access to the port.  As a user-land device driver
1520
        writer, you will need to do this before you are able to
1521
        actually change the state of the parallel port in any way.
1522
        Note that some operations only affect the
1523
        ppdev driver and not the port, such as
1524
        PPSETMODE; they can be performed while
1525
        access to the port is not claimed.
1526
       
1527
 
1528
      
1529
 
1530
     PPEXCL
1531
      
1532
 
1533
       
1534
        Instructs the kernel driver to forbid any sharing of the port
1535
        with other drivers, i.e. it requests exclusivity.  The
1536
        PPEXCL command is only valid when the
1537
        port is not already claimed for use, and it may mean that the
1538
        next PPCLAIM ioctl
1539
        will fail: some other driver may already have registered
1540
        itself on that port.
1541
       
1542
 
1543
       
1544
        Most device drivers don't need exclusive access to the port.
1545
        It's only provided in case it is really needed, for example
1546
        for devices where access to the port is required for extensive
1547
        periods of time (many seconds).
1548
       
1549
 
1550
       
1551
        Note that the PPEXCL
1552
        ioctl doesn't actually claim the port
1553
        there and then---action is deferred until the
1554
        PPCLAIM ioctl is
1555
        performed.
1556
       
1557
 
1558
      
1559
 
1560
     PPRELEASE
1561
      
1562
 
1563
       
1564
        Releases the port.  Releasing the port undoes the effect of
1565
        claiming the port.  It allows other device drivers to talk to
1566
        their devices (assuming that there are any).
1567
       
1568
 
1569
      
1570
 
1571
     PPYIELD
1572
      
1573
 
1574
       
1575
        Yields the port to another driver.  This
1576
        ioctl is a kind of short-hand for
1577
        releasing the port and immediately reclaiming it.  It gives
1578
        other drivers a chance to talk to their devices, but
1579
        afterwards claims the port back.  An example of using this
1580
        would be in a user-land printer driver: once a few characters
1581
        have been written we could give the port to another device
1582
        driver for a while, but if we still have characters to send to
1583
        the printer we would want the port back as soon as possible.
1584
       
1585
 
1586
       
1587
        It is important not to claim the parallel port for too long,
1588
        as other device drivers will have no time to service their
1589
        devices.  If your device does not allow for parallel port
1590
        sharing at all, it is better to claim the parallel port
1591
        exclusively (see PPEXCL).
1592
       
1593
 
1594
      
1595
 
1596
     PPNEGOT
1597
      
1598
 
1599
       
1600
        Performs IEEE 1284 negotiation into a particular mode.
1601
        Briefly, negotiation is the method by which the host and the
1602
        peripheral decide on a protocol to use when transferring data.
1603
       
1604
 
1605
       
1606
        An IEEE 1284 compliant device will start out in compatibility
1607
        mode, and then the host can negotiate to another mode (such as
1608
        ECP).
1609
       
1610
 
1611
       
1612
        The ioctl parameter should be a pointer
1613
        to an int; values for this are in
1614
        incluce/linux/parport.h and include:
1615
       
1616
 
1617
       
1618
        
1619
          IEEE1284_MODE_COMPAT
1620
        
1621
          IEEE1284_MODE_NIBBLE
1622
        
1623
          IEEE1284_MODE_BYTE
1624
        
1625
          IEEE1284_MODE_EPP
1626
        
1627
          IEEE1284_MODE_ECP
1628
       
1629
 
1630
       
1631
        The PPNEGOT ioctl
1632
        actually does two things: it performs the on-the-wire
1633
        negotiation, and it sets the behaviour of subsequent
1634
        read/write calls so
1635
        that they use that mode (but see
1636
        PPSETMODE).
1637
       
1638
 
1639
      
1640
 
1641
     PPSETMODE
1642
      
1643
 
1644
       
1645
        Sets which IEEE 1284 protocol to use for the
1646
        read and write
1647
        calls.
1648
       
1649
 
1650
       
1651
        The ioctl parameter should be a pointer
1652
        to an int.
1653
       
1654
 
1655
      
1656
 
1657
     PPGETMODE
1658
      
1659
 
1660
       
1661
        Retrieves the current IEEE 1284 mode to use for
1662
        read and write.
1663
       
1664
 
1665
      
1666
 
1667
     PPGETTIME
1668
      
1669
 
1670
       
1671
        Retrieves the time-out value.  The read
1672
        and write calls will time out if the
1673
        peripheral doesn't respond quickly enough.  The
1674
        PPGETTIME ioctl
1675
        retrieves the length of time that the peripheral is allowed to
1676
        have before giving up.
1677
       
1678
 
1679
       
1680
        The ioctl parameter should be a pointer
1681
        to a struct timeval.
1682
       
1683
 
1684
      
1685
 
1686
     PPSETTIME
1687
      
1688
 
1689
       
1690
        Sets the time-out.  The ioctl parameter
1691
        should be a pointer to a struct
1692
        timeval.
1693
       
1694
 
1695
      
1696
 
1697
     PPGETMODES
1698
      
1699
 
1700
       
1701
        Retrieves the capabilities of the hardware (i.e. the
1702
        modes field of the
1703
        parport structure).
1704
       
1705
 
1706
      
1707
 
1708
     PPSETFLAGS
1709
      
1710
 
1711
       
1712
        Sets flags on the ppdev device which can
1713
        affect future I/O operations.  Available flags are:
1714
       
1715
 
1716
       
1717
        
1718
          PP_FASTWRITE
1719
        
1720
          PP_FASTREAD
1721
        
1722
          PP_W91284PIC
1723
       
1724
 
1725
      
1726
 
1727
     PPWCONTROL
1728
      
1729
 
1730
       
1731
        Sets the control lines.  The ioctl
1732
        parameter is a pointer to an unsigned char, the
1733
        bitwise OR of the control line values in
1734
        include/linux/parport.h.
1735
       
1736
 
1737
      
1738
 
1739
     PPRCONTROL
1740
      
1741
 
1742
       
1743
        Returns the last value written to the control register, in the
1744
        form of an unsigned char: each bit corresponds to
1745
        a control line (although some are unused).  The
1746
        ioctl parameter should be a pointer to an
1747
        unsigned char.
1748
       
1749
 
1750
       
1751
        This doesn't actually touch the hardware; the last value
1752
        written is remembered in software.  This is because some
1753
        parallel port hardware does not offer read access to the
1754
        control register.
1755
       
1756
 
1757
       
1758
        The control lines bits are defined in
1759
        include/linux/parport.h:
1760
       
1761
 
1762
       
1763
        
1764
          PARPORT_CONTROL_STROBE
1765
          
1766
          PARPORT_CONTROL_AUTOFD
1767
          
1768
          PARPORT_CONTROL_SELECT
1769
          
1770
          PARPORT_CONTROL_INIT
1771
       
1772
 
1773
      
1774
 
1775
     PPFCONTROL
1776
      
1777
 
1778
       
1779
        Frobs the control lines.  Since a common operation is to
1780
        change one of the control signals while leaving the others
1781
        alone, it would be quite inefficient for the user-land driver
1782
        to have to use PPRCONTROL, make the
1783
        change, and then use PPWCONTROL.  Of
1784
        course, each driver could remember what state the control
1785
        lines are supposed to be in (they are never changed by
1786
        anything else), but in order to provide
1787
        PPRCONTROL, ppdev
1788
        must remember the state of the control lines anyway.
1789
       
1790
 
1791
       
1792
        The PPFCONTROL ioctl
1793
        is for frobbing control lines, and is like
1794
        PPWCONTROL but acts on a restricted set
1795
        of control lines.  The ioctl parameter is
1796
        a pointer to a struct
1797
        ppdev_frob_struct:
1798
       
1799
 
1800
       
1801
        
1802
struct ppdev_frob_struct {
1803
        unsigned char mask;
1804
        unsigned char val;
1805
};
1806
        ]]>
1807
       
1808
 
1809
       
1810
        The mask and
1811
        val fields are bitwise ORs of
1812
        control line names (such as in
1813
        PPWCONTROL).  The operation performed by
1814
        PPFCONTROL is:
1815
       
1816
 
1817
       
1818
        
1819
        new_ctr = (old_ctr & ~mask) | val;]]>
1820
       
1821
 
1822
       
1823
        In other words, the signals named in
1824
        mask are set to the values in
1825
        val.
1826
       
1827
 
1828
      
1829
 
1830
     PPRSTATUS
1831
      
1832
 
1833
       
1834
        Returns an unsigned char containing bits set for
1835
        each status line that is set (for instance,
1836
        PARPORT_STATUS_BUSY).  The
1837
        ioctl parameter should be a pointer to an
1838
        unsigned char.
1839
       
1840
 
1841
      
1842
 
1843
     PPDATADIR
1844
      
1845
 
1846
       
1847
        Controls the data line drivers.  Normally the computer's
1848
        parallel port will drive the data lines, but for byte-wide
1849
        transfers from the peripheral to the host it is useful to turn
1850
        off those drivers and let the peripheral drive the
1851
        signals. (If the drivers on the computer's parallel port are
1852
        left on when this happens, the port might be damaged.)
1853
       
1854
 
1855
       
1856
        This is only needed in conjunction with
1857
        PPWDATA or
1858
        PPRDATA.
1859
       
1860
 
1861
       
1862
        The ioctl parameter is a pointer to an
1863
        int.  If the int is zero, the
1864
        drivers are turned on (forward direction); if non-zero, the
1865
        drivers are turned off (reverse direction).
1866
       
1867
 
1868
      
1869
 
1870
     PPWDATA
1871
      
1872
 
1873
       
1874
        Sets the data lines (if in forward mode).  The
1875
        ioctl parameter is a pointer to an
1876
        unsigned char.
1877
       
1878
 
1879
      
1880
 
1881
     PPRDATA
1882
      
1883
 
1884
       
1885
        Reads the data lines (if in reverse mode).  The
1886
        ioctl parameter is a pointer to an
1887
        unsigned char.
1888
       
1889
 
1890
      
1891
 
1892
     PPCLRIRQ
1893
      
1894
 
1895
       
1896
        Clears the interrupt count.  The ppdev
1897
        driver keeps a count of interrupts as they are triggered.
1898
        PPCLRIRQ stores this count in an
1899
        int, a pointer to which is passed in as the
1900
        ioctl parameter.
1901
       
1902
 
1903
       
1904
        In addition, the interrupt count is reset to zero.
1905
       
1906
 
1907
      
1908
 
1909
     PPWCTLONIRQ
1910
      
1911
 
1912
       
1913
        Set a trigger response.  Afterwards when an interrupt is
1914
        triggered, the interrupt handler will set the control lines as
1915
        requested.  The ioctl parameter is a
1916
        pointer to an unsigned char, which is interpreted
1917
        in the same way as for PPWCONTROL.
1918
       
1919
 
1920
       
1921
        The reason for this ioctl is simply
1922
        speed.  Without this ioctl, responding to
1923
        an interrupt would start in the interrupt handler, switch
1924
        context to the user-land driver via poll
1925
        or select, and then switch context back
1926
        to the kernel in order to handle
1927
        PPWCONTROL.  Doing the whole lot in the
1928
        interrupt handler is a lot faster.
1929
       
1930
 
1931
      
1932
 
1933
     
1934
 
1935
    
1936
 
1937
   
1938
 
1939
   
1940
    Transferring data: <function>read</function> and</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>1941</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>     <function>write</function>
1942
 
1943
    
1944
     Transferring data using read and
1945
     write is straightforward.  The data is
1946
     transferring using the current IEEE 1284 mode (see the
1947
     PPSETMODE ioctl).  For
1948
     modes which can only transfer data in one direction, only the
1949
     appropriate function will work, of course.
1950
    
1951
   
1952
 
1953
   
1954
    Waiting for events: <function>poll</function> and</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>1955</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>     <function>select</function>
1956
 
1957
    
1958
     The ppdev driver provides user-land device
1959
     drivers with the ability to wait for interrupts, and this is done
1960
     using poll (and select,
1961
     which is implemented in terms of poll).
1962
    
1963
 
1964
    
1965
     When a user-land device driver wants to wait for an interrupt, it
1966
     sleeps with poll.  When the interrupt
1967
     arrives, ppdev wakes it up (with a
1968
     read event, although strictly speaking there is
1969
     nothing to actually read).
1970
    
1971
 
1972
   
1973
 
1974
  
1975
 
1976
  
1977
   Examples
1978
 
1979
   
1980
    Presented here are two demonstrations of how to write a simple
1981
    printer driver for ppdev.  Firstly we will
1982
    use the write function, and after that we
1983
    will drive the control and data lines directly.
1984
   
1985
 
1986
   
1987
    The first thing to do is to actually open the device.
1988
   
1989
 
1990
   
1991
int drive_printer (const char *name)
1992
{
1993
    int fd;
1994
    int mode; /* We'll need this later. */
1995
 
1996
    fd = open (name, O_RDWR);
1997
    if (fd == -1) {
1998
        perror ("open");
1999
        return 1;
2000
    }
2001
    ]]>
2002
 
2003
   
2004
    Here name should be something along the lines
2005
    of "/dev/parport0". (If you don't have any
2006
    /dev/parport files, you can make them with
2007
    mknod; they are character special device nodes
2008
    with major 99.)
2009
   
2010
 
2011
   
2012
    In order to do anything with the port we need to claim access to
2013
    it.
2014
   
2015
 
2016
   
2017
    if (ioctl (fd, PPCLAIM)) {
2018
        perror ("PPCLAIM");
2019
        close (fd);
2020
        return 1;
2021
    }
2022
    ]]>
2023
 
2024
   
2025
    Our printer driver will copy its input (from
2026
    stdin) to the printer, and it can do that it
2027
    one of two ways.  The first way is to hand it all off to the
2028
    kernel driver, with the knowledge that the protocol that the
2029
    printer speaks is IEEE 1284's compatibility
2030
    mode.
2031
   
2032
 
2033
   
2034
    /* Switch to compatibility mode.  (In fact we don't need
2035
     * to do this, since we start off in compatibility mode
2036
     * anyway, but this demonstrates PPNEGOT.)
2037
    mode = IEEE1284_MODE_COMPAT;
2038
    if (ioctl (fd, PPNEGOT, &mode)) {
2039
        perror ("PPNEGOT");
2040
        close (fd);
2041
        return 1;
2042
    }
2043
 
2044
    for (;;) {
2045
        char buffer[1000];
2046
        char *ptr = buffer;
2047
        size_t got;
2048
 
2049
        got = read (0 /* stdin */, buffer, 1000);
2050
        if (got < 0) {
2051
            perror ("read");
2052
            close (fd);
2053
            return 1;
2054
        }
2055
 
2056
        if (got == 0)
2057
            /* End of input */
2058
            break;
2059
 
2060
        while (got > 0) {
2061
            int written = write_printer (fd, ptr, got);
2062
 
2063
            if (written < 0) {
2064
                perror ("write");
2065
                close (fd);
2066
                return 1;
2067
            }
2068
 
2069
            ptr += written;
2070
            got -= written;
2071
        }
2072
    }
2073
    ]]>
2074
 
2075
   
2076
    The write_printer function is not pictured
2077
    above.  This is because the main loop that is shown can be used
2078
    for both methods of driving the printer.  Here is one
2079
    implementation of write_printer:
2080
   
2081
 
2082
   
2083
ssize_t write_printer (int fd, const void *ptr, size_t count)
2084
{
2085
    return write (fd, ptr, count);
2086
}
2087
    ]]>
2088
 
2089
   
2090
    We hand the data to the kernel-level driver (using
2091
    write) and it handles the printer
2092
    protocol.
2093
   
2094
 
2095
   
2096
    Now let's do it the hard way!  In this particular example there is
2097
    no practical reason to do anything other than just call
2098
    write, because we know that the printer talks
2099
    an IEEE 1284 protocol.  On the other hand, this particular example
2100
    does not even need a user-land driver since there is already a
2101
    kernel-level one; for the purpose of this discussion, try to
2102
    imagine that the printer speaks a protocol that is not already
2103
    implemented under Linux.
2104
   
2105
 
2106
   
2107
    So, here is the alternative implementation of
2108
    write_printer (for brevity, error checking
2109
    has been omitted):
2110
   
2111
 
2112
   
2113
ssize_t write_printer (int fd, const void *ptr, size_t count)
2114
{
2115
    ssize_t wrote = 0;
2116
 
2117
    while (wrote < count) {
2118
        unsigned char status, control, data;
2119
        unsigned char mask = (PARPORT_STATUS_ERROR
2120
                              | PARPORT_STATUS_BUSY);
2121
        unsigned char val = (PARPORT_STATUS_ERROR
2122
                              | PARPORT_STATUS_BUSY);
2123
        struct ppdev_frob_struct frob;
2124
        struct timespec ts;
2125
 
2126
        /* Wait for printer to be ready */
2127
        for (;;) {
2128
            ioctl (fd, PPRSTATUS, &status);
2129
 
2130
            if ((status & mask) == val)
2131
                break;
2132
 
2133
            ioctl (fd, PPRELEASE);
2134
            sleep (1);
2135
            ioctl (fd, PPCLAIM);
2136
        }
2137
 
2138
        /* Set the data lines */
2139
        data = * ((char *) ptr)++;
2140
        ioctl (fd, PPWDATA, &data);
2141
 
2142
        /* Delay for a bit */
2143
        ts.tv_sec = 0;
2144
        ts.tv_nsec = 1000;
2145
        nanosleep (&ts, NULL);
2146
 
2147
        /* Pulse strobe */
2148
        frob.mask = PARPORT_CONTROL_STROBE;
2149
        frob.val = PARPORT_CONTROL_STROBE;
2150
        ioctl (fd, PPFCONTROL, &frob);
2151
        nanosleep (&ts, NULL);
2152
 
2153
        /* End the pulse */
2154
        frob.val = 0;
2155
        ioctl (fd, PPFCONTROL, &frob);
2156
        nanosleep (&ts, NULL);
2157
 
2158
        wrote++;
2159
    }
2160
 
2161
    return wrote;
2162
}
2163
    ]]>
2164
 
2165
   
2166
    To show a bit more of the ppdev interface,
2167
    here is a small piece of code that is intended to mimic the
2168
    printer's side of printer protocol.
2169
   
2170
 
2171
   
2172
  for (;;)
2173
    {
2174
      int irqc;
2175
      int busy = nAck | nFault;
2176
      int acking = nFault;
2177
      int ready = Busy | nAck | nFault;
2178
      char ch;
2179
 
2180
      /* Set up the control lines when an interrupt happens. */
2181
      ioctl (fd, PPWCTLONIRQ, &busy);
2182
 
2183
      /* Now we're ready. */
2184
      ioctl (fd, PPWCONTROL, &ready);
2185
 
2186
      /* Wait for an interrupt. */
2187
      {
2188
        fd_set rfds;
2189
        FD_ZERO (&rfds);
2190
        FD_SET (fd, &rfds);
2191
        if (!select (fd + 1, &rfds, NULL, NULL, NULL))
2192
          /* Caught a signal? */
2193
          continue;
2194
      }
2195
 
2196
      /* We are now marked as busy. */
2197
 
2198
      /* Fetch the data. */
2199
      ioctl (fd, PPRDATA, &ch);
2200
 
2201
      /* Clear the interrupt. */
2202
      ioctl (fd, PPCLRIRQ, &irqc);
2203
      if (irqc > 1)
2204
        fprintf (stderr, "Arghh! Missed %d interrupt%s!\n",
2205
         irqc - 1, irqc == 2 ? "s" : "");
2206
 
2207
      /* Ack it. */
2208
      ioctl (fd, PPWCONTROL, &acking);
2209
      usleep (2);
2210
      ioctl (fd, PPWCONTROL, &busy);
2211
 
2212
      putchar (ch);
2213
    }
2214
    ]]>
2215
 
2216
   
2217
    And here is an example (with no error checking at all) to show how
2218
    to read data from the port, using ECP mode, with optional
2219
    negotiation to ECP mode first.
2220
   
2221
 
2222
   
2223
    {
2224
      int fd, mode;
2225
      fd = open ("/dev/parport0", O_RDONLY | O_NOCTTY);
2226
      ioctl (fd, PPCLAIM);
2227
      mode = IEEE1284_MODE_ECP;
2228
      if (negotiate_first) {
2229
        ioctl (fd, PPNEGOT, &mode);
2230
        /* no need for PPSETMODE */
2231
      } else {
2232
        ioctl (fd, PPSETMODE, &mode);
2233
      }
2234
 
2235
      /* Now do whatever we want with fd */
2236
      close (0);
2237
      dup2 (fd, 0);
2238
      if (!fork()) {
2239
        /* child */
2240
        execlp ("cat", "cat", NULL);
2241
        exit (1);
2242
      } else {
2243
        /* parent */
2244
        wait (NULL);
2245
      }
2246
 
2247
      /* Okay, finished */
2248
      ioctl (fd, PPRELEASE);
2249
      close (fd);
2250
    }
2251
    ]]>
2252
 
2253
  
2254
 
2255
 
2256
 
2257
 
2258
  </code></pre></td>
      </tr>
      <tr valign="middle">
         <td>2259</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>   Linux parallel port driver API reference</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>2260</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  
2261
 
2262
!Fdrivers/parport/daisy.c parport_device_num
2263
!Fdrivers/parport/daisy.c parport_device_coords
2264
!Fdrivers/parport/daisy.c parport_find_device
2265
!Fdrivers/parport/daisy.c parport_find_class
2266
!Fdrivers/parport/share.c parport_register_driver
2267
!Fdrivers/parport/share.c parport_unregister_driver
2268
!Fdrivers/parport/share.c parport_get_port
2269
!Fdrivers/parport/share.c parport_put_port
2270
!Fdrivers/parport/share.c parport_find_number parport_find_base
2271
!Fdrivers/parport/share.c parport_register_device
2272
!Fdrivers/parport/share.c parport_unregister_device
2273
!Fdrivers/parport/daisy.c parport_open
2274
!Fdrivers/parport/daisy.c parport_close
2275
!Fdrivers/parport/share.c parport_claim
2276
!Fdrivers/parport/share.c parport_claim_or_block
2277
!Fdrivers/parport/share.c parport_release
2278
!Finclude/linux/parport.h parport_yield
2279
!Finclude/linux/parport.h parport_yield_blocking
2280
!Fdrivers/parport/ieee1284.c parport_negotiate
2281
!Fdrivers/parport/ieee1284.c parport_write
2282
!Fdrivers/parport/ieee1284.c parport_read
2283
!Fdrivers/parport/ieee1284.c parport_set_timeout
2284
 
2285
 
2286
 
2287
 
2288
  </code></pre></td>
      </tr>
      <tr valign="middle">
         <td>2289</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>   The Linux 2.2 Parallel Port Subsystem</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>2290</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  
2291
 
2292
  
2293
   Although the interface described in this document is largely new
2294
   with the 2.4 kernel, the sharing mechanism is available in the 2.2
2295
   kernel as well.  The functions available in 2.2 are:
2296
  
2297
 
2298
  
2299
   
2300
    
2301
     parport_register_device
2302
    
2303
   
2304
 
2305
   
2306
    
2307
     parport_unregister_device
2308
    
2309
   
2310
 
2311
   
2312
    
2313
     parport_claim
2314
    
2315
   
2316
 
2317
   
2318
    
2319
     parport_claim_or_block
2320
    
2321
   
2322
 
2323
   
2324
    
2325
     parport_release
2326
    
2327
   
2328
 
2329
   
2330
    
2331
     parport_yield
2332
    
2333
   
2334
 
2335
   
2336
    
2337
     parport_yield_blocking
2338
    
2339
   
2340
  
2341
 
2342
  
2343
   In addition, negotiation to reverse nibble mode is supported:
2344
  
2345
 
2346
  
2347
   
2348
     int parport_ieee1284_nibble_mode_ok
2349
    struct parport *port
2350
    unsigned char mode
2351
   
2352
  
2353
 
2354
  
2355
   The only valid values for mode are 0 (for
2356
   reverse nibble mode) and 4 (for Device ID in reverse nibble mode).
2357
  
2358
 
2359
  
2360
   This function is obsoleted by
2361
   parport_negotiate in Linux 2.4, and has been
2362
   removed.
2363
  
2364
 
2365
 
2366
 
2367
  </code></pre></td>
      </tr>
      <tr valign="middle">
         <td>2368</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>   GNU Free Documentation License</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>2369</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  
2370
 
2371
  
2372
                GNU Free Documentation License
2373
                   Version 1.1, March 2000
2374
 
2375
 Copyright (C) 2000  Free Software Foundation, Inc.
2376
     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2377
 Everyone is permitted to copy and distribute verbatim copies
2378
 of this license document, but changing it is not allowed.
2379
 
2380
 
2381
0. PREAMBLE
2382
 
2383
The purpose of this License is to make a manual, textbook, or other
2384
written document "free" in the sense of freedom: to assure everyone
2385
the effective freedom to copy and redistribute it, with or without
2386
modifying it, either commercially or noncommercially.  Secondarily,
2387
this License preserves for the author and publisher a way to get
2388
credit for their work, while not being considered responsible for
2389
modifications made by others.
2390
 
2391
This License is a kind of "copyleft", which means that derivative
2392
works of the document must themselves be free in the same sense.  It
2393
complements the GNU General Public License, which is a copyleft
2394
license designed for free software.
2395
 
2396
We have designed this License in order to use it for manuals for free
2397
software, because free software needs free documentation: a free
2398
program should come with manuals providing the same freedoms that the
2399
software does.  But this License is not limited to software manuals;
2400
it can be used for any textual work, regardless of subject matter or
2401
whether it is published as a printed book.  We recommend this License
2402
principally for works whose purpose is instruction or reference.
2403
 
2404
 
2405
1. APPLICABILITY AND DEFINITIONS
2406
 
2407
This License applies to any manual or other work that contains a
2408
notice placed by the copyright holder saying it can be distributed
2409
under the terms of this License.  The "Document", below, refers to any
2410
such manual or work.  Any member of the public is a licensee, and is
2411
addressed as "you".
2412
 
2413
A "Modified Version" of the Document means any work containing the
2414
Document or a portion of it, either copied verbatim, or with
2415
modifications and/or translated into another language.
2416
 
2417
A "Secondary Section" is a named appendix or a front-matter section of
2418
the Document that deals exclusively with the relationship of the
2419
publishers or authors of the Document to the Document's overall subject
2420
(or to related matters) and contains nothing that could fall directly
2421
within that overall subject.  (For example, if the Document is in part a
2422
textbook of mathematics, a Secondary Section may not explain any
2423
mathematics.)  The relationship could be a matter of historical
2424
connection with the subject or with related matters, or of legal,
2425
commercial, philosophical, ethical or political position regarding
2426
them.
2427
 
2428
The "Invariant Sections" are certain Secondary Sections whose titles
2429
are designated, as being those of Invariant Sections, in the notice
2430
that says that the Document is released under this License.
2431
 
2432
The "Cover Texts" are certain short passages of text that are listed,
2433
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
2434
the Document is released under this License.
2435
 
2436
A "Transparent" copy of the Document means a machine-readable copy,
2437
represented in a format whose specification is available to the
2438
general public, whose contents can be viewed and edited directly and
2439
straightforwardly with generic text editors or (for images composed of
2440
pixels) generic paint programs or (for drawings) some widely available
2441
drawing editor, and that is suitable for input to text formatters or
2442
for automatic translation to a variety of formats suitable for input
2443
to text formatters.  A copy made in an otherwise Transparent file
2444
format whose markup has been designed to thwart or discourage
2445
subsequent modification by readers is not Transparent.  A copy that is
2446
not "Transparent" is called "Opaque".
2447
 
2448
Examples of suitable formats for Transparent copies include plain
2449
ASCII without markup, Texinfo input format, LaTeX input format, SGML
2450
or XML using a publicly available DTD, and standard-conforming simple
2451
HTML designed for human modification.  Opaque formats include
2452
PostScript, PDF, proprietary formats that can be read and edited only
2453
by proprietary word processors, SGML or XML for which the DTD and/or
2454
processing tools are not generally available, and the
2455
machine-generated HTML produced by some word processors for output
2456
purposes only.
2457
 
2458
The "Title Page" means, for a printed book, the title page itself,
2459
plus such following pages as are needed to hold, legibly, the material
2460
this License requires to appear in the title page.  For works in
2461
formats which do not have any title page as such, "Title Page" means
2462
the text near the most prominent appearance of the work's title,
2463
preceding the beginning of the body of the text.
2464
 
2465
 
2466
2. VERBATIM COPYING
2467
 
2468
You may copy and distribute the Document in any medium, either
2469
commercially or noncommercially, provided that this License, the
2470
copyright notices, and the license notice saying this License applies
2471
to the Document are reproduced in all copies, and that you add no other
2472
conditions whatsoever to those of this License.  You may not use
2473
technical measures to obstruct or control the reading or further
2474
copying of the copies you make or distribute.  However, you may accept
2475
compensation in exchange for copies.  If you distribute a large enough
2476
number of copies you must also follow the conditions in section 3.
2477
 
2478
You may also lend copies, under the same conditions stated above, and
2479
you may publicly display copies.
2480
 
2481
 
2482
3. COPYING IN QUANTITY
2483
 
2484
If you publish printed copies of the Document numbering more than 100,
2485
and the Document's license notice requires Cover Texts, you must enclose
2486
the copies in covers that carry, clearly and legibly, all these Cover
2487
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
2488
the back cover.  Both covers must also clearly and legibly identify
2489
you as the publisher of these copies.  The front cover must present
2490
the full title with all words of the title equally prominent and
2491
visible.  You may add other material on the covers in addition.
2492
Copying with changes limited to the covers, as long as they preserve
2493
the title of the Document and satisfy these conditions, can be treated
2494
as verbatim copying in other respects.
2495
 
2496
If the required texts for either cover are too voluminous to fit
2497
legibly, you should put the first ones listed (as many as fit
2498
reasonably) on the actual cover, and continue the rest onto adjacent
2499
pages.
2500
 
2501
If you publish or distribute Opaque copies of the Document numbering
2502
more than 100, you must either include a machine-readable Transparent
2503
copy along with each Opaque copy, or state in or with each Opaque copy
2504
a publicly-accessible computer-network location containing a complete
2505
Transparent copy of the Document, free of added material, which the
2506
general network-using public has access to download anonymously at no
2507
charge using public-standard network protocols.  If you use the latter
2508
option, you must take reasonably prudent steps, when you begin
2509
distribution of Opaque copies in quantity, to ensure that this
2510
Transparent copy will remain thus accessible at the stated location
2511
until at least one year after the last time you distribute an Opaque
2512
copy (directly or through your agents or retailers) of that edition to
2513
the public.
2514
 
2515
It is requested, but not required, that you contact the authors of the
2516
Document well before redistributing any large number of copies, to give
2517
them a chance to provide you with an updated version of the Document.
2518
 
2519
 
2520
4. MODIFICATIONS
2521
 
2522
You may copy and distribute a Modified Version of the Document under
2523
the conditions of sections 2 and 3 above, provided that you release
2524
the Modified Version under precisely this License, with the Modified
2525
Version filling the role of the Document, thus licensing distribution
2526
and modification of the Modified Version to whoever possesses a copy
2527
of it.  In addition, you must do these things in the Modified Version:
2528
 
2529
A. Use in the Title Page (and on the covers, if any) a title distinct
2530
   from that of the Document, and from those of previous versions
2531
   (which should, if there were any, be listed in the History section
2532
   of the Document).  You may use the same title as a previous version
2533
   if the original publisher of that version gives permission.
2534
B. List on the Title Page, as authors, one or more persons or entities
2535
   responsible for authorship of the modifications in the Modified
2536
   Version, together with at least five of the principal authors of the
2537
   Document (all of its principal authors, if it has less than five).
2538
C. State on the Title page the name of the publisher of the
2539
   Modified Version, as the publisher.
2540
D. Preserve all the copyright notices of the Document.
2541
E. Add an appropriate copyright notice for your modifications
2542
   adjacent to the other copyright notices.
2543
F. Include, immediately after the copyright notices, a license notice
2544
   giving the public permission to use the Modified Version under the
2545
   terms of this License, in the form shown in the Addendum below.
2546
G. Preserve in that license notice the full lists of Invariant Sections
2547
   and required Cover Texts given in the Document's license notice.
2548
H. Include an unaltered copy of this License.
2549
I. Preserve the section entitled "History", and its title, and add to
2550
   it an item stating at least the title, year, new authors, and
2551
   publisher of the Modified Version as given on the Title Page.  If
2552
   there is no section entitled "History" in the Document, create one
2553
   stating the title, year, authors, and publisher of the Document as
2554
   given on its Title Page, then add an item describing the Modified
2555
   Version as stated in the previous sentence.
2556
J. Preserve the network location, if any, given in the Document for
2557
   public access to a Transparent copy of the Document, and likewise
2558
   the network locations given in the Document for previous versions
2559
   it was based on.  These may be placed in the "History" section.
2560
   You may omit a network location for a work that was published at
2561
   least four years before the Document itself, or if the original
2562
   publisher of the version it refers to gives permission.
2563
K. In any section entitled "Acknowledgements" or "Dedications",
2564
   preserve the section's title, and preserve in the section all the
2565
   substance and tone of each of the contributor acknowledgements
2566
   and/or dedications given therein.
2567
L. Preserve all the Invariant Sections of the Document,
2568
   unaltered in their text and in their titles.  Section numbers
2569
   or the equivalent are not considered part of the section titles.
2570
M. Delete any section entitled "Endorsements".  Such a section
2571
   may not be included in the Modified Version.
2572
N. Do not retitle any existing section as "Endorsements"
2573
   or to conflict in title with any Invariant Section.
2574
 
2575
If the Modified Version includes new front-matter sections or
2576
appendices that qualify as Secondary Sections and contain no material
2577
copied from the Document, you may at your option designate some or all
2578
of these sections as invariant.  To do this, add their titles to the
2579
list of Invariant Sections in the Modified Version's license notice.
2580
These titles must be distinct from any other section titles.
2581
 
2582
You may add a section entitled "Endorsements", provided it contains
2583
nothing but endorsements of your Modified Version by various
2584
parties--for example, statements of peer review or that the text has
2585
been approved by an organization as the authoritative definition of a
2586
standard.
2587
 
2588
You may add a passage of up to five words as a Front-Cover Text, and a
2589
passage of up to 25 words as a Back-Cover Text, to the end of the list
2590
of Cover Texts in the Modified Version.  Only one passage of
2591
Front-Cover Text and one of Back-Cover Text may be added by (or
2592
through arrangements made by) any one entity.  If the Document already
2593
includes a cover text for the same cover, previously added by you or
2594
by arrangement made by the same entity you are acting on behalf of,
2595
you may not add another; but you may replace the old one, on explicit
2596
permission from the previous publisher that added the old one.
2597
 
2598
The author(s) and publisher(s) of the Document do not by this License
2599
give permission to use their names for publicity for or to assert or
2600
imply endorsement of any Modified Version.
2601
 
2602
 
2603
5. COMBINING DOCUMENTS
2604
 
2605
You may combine the Document with other documents released under this
2606
License, under the terms defined in section 4 above for modified
2607
versions, provided that you include in the combination all of the
2608
Invariant Sections of all of the original documents, unmodified, and
2609
list them all as Invariant Sections of your combined work in its
2610
license notice.
2611
 
2612
The combined work need only contain one copy of this License, and
2613
multiple identical Invariant Sections may be replaced with a single
2614
copy.  If there are multiple Invariant Sections with the same name but
2615
different contents, make the title of each such section unique by
2616
adding at the end of it, in parentheses, the name of the original
2617
author or publisher of that section if known, or else a unique number.
2618
Make the same adjustment to the section titles in the list of
2619
Invariant Sections in the license notice of the combined work.
2620
 
2621
In the combination, you must combine any sections entitled "History"
2622
in the various original documents, forming one section entitled
2623
"History"; likewise combine any sections entitled "Acknowledgements",
2624
and any sections entitled "Dedications".  You must delete all sections
2625
entitled "Endorsements."
2626
 
2627
 
2628
6. COLLECTIONS OF DOCUMENTS
2629
 
2630
You may make a collection consisting of the Document and other documents
2631
released under this License, and replace the individual copies of this
2632
License in the various documents with a single copy that is included in
2633
the collection, provided that you follow the rules of this License for
2634
verbatim copying of each of the documents in all other respects.
2635
 
2636
You may extract a single document from such a collection, and distribute
2637
it individually under this License, provided you insert a copy of this
2638
License into the extracted document, and follow this License in all
2639
other respects regarding verbatim copying of that document.
2640
 
2641
 
2642
 
2643
7. AGGREGATION WITH INDEPENDENT WORKS
2644
 
2645
A compilation of the Document or its derivatives with other separate
2646
and independent documents or works, in or on a volume of a storage or
2647
distribution medium, does not as a whole count as a Modified Version
2648
of the Document, provided no compilation copyright is claimed for the
2649
compilation.  Such a compilation is called an "aggregate", and this
2650
License does not apply to the other self-contained works thus compiled
2651
with the Document, on account of their being thus compiled, if they
2652
are not themselves derivative works of the Document.
2653
 
2654
If the Cover Text requirement of section 3 is applicable to these
2655
copies of the Document, then if the Document is less than one quarter
2656
of the entire aggregate, the Document's Cover Texts may be placed on
2657
covers that surround only the Document within the aggregate.
2658
Otherwise they must appear on covers around the whole aggregate.
2659
 
2660
 
2661
8. TRANSLATION
2662
 
2663
Translation is considered a kind of modification, so you may
2664
distribute translations of the Document under the terms of section 4.
2665
Replacing Invariant Sections with translations requires special
2666
permission from their copyright holders, but you may include
2667
translations of some or all Invariant Sections in addition to the
2668
original versions of these Invariant Sections.  You may include a
2669
translation of this License provided that you also include the
2670
original English version of this License.  In case of a disagreement
2671
between the translation and the original English version of this
2672
License, the original English version will prevail.
2673
 
2674
 
2675
9. TERMINATION
2676
 
2677
You may not copy, modify, sublicense, or distribute the Document except
2678
as expressly provided for under this License.  Any other attempt to
2679
copy, modify, sublicense or distribute the Document is void, and will
2680
automatically terminate your rights under this License.  However,
2681
parties who have received copies, or rights, from you under this
2682
License will not have their licenses terminated so long as such
2683
parties remain in full compliance.
2684
 
2685
 
2686
10. FUTURE REVISIONS OF THIS LICENSE
2687
 
2688
The Free Software Foundation may publish new, revised versions
2689
of the GNU Free Documentation License from time to time.  Such new
2690
versions will be similar in spirit to the present version, but may
2691
differ in detail to address new problems or concerns. See
2692
http:///www.gnu.org/copyleft/.
2693
 
2694
Each version of the License is given a distinguishing version number.
2695
If the Document specifies that a particular numbered version of this
2696
License "or any later version" applies to it, you have the option of
2697
following the terms and conditions either of that specified version or
2698
of any later version that has been published (not as a draft) by the
2699
Free Software Foundation.  If the Document does not specify a version
2700
number of this License, you may choose any version ever published (not
2701
as a draft) by the Free Software Foundation.
2702
 
2703
 
2704
ADDENDUM: How to use this License for your documents
2705
 
2706
To use this License in a document you have written, include a copy of
2707
the License in the document and put the following copyright and
2708
license notices just after the title page:
2709
 
2710
      Copyright (c)  YEAR  YOUR NAME.
2711
      Permission is granted to copy, distribute and/or modify this document
2712
      under the terms of the GNU Free Documentation License, Version 1.1
2713
      or any later version published by the Free Software Foundation;
2714
      with the Invariant Sections being LIST THEIR TITLES, with the
2715
      Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
2716
      A copy of the license is included in the section entitled "GNU
2717
      Free Documentation License".
2718
 
2719
If you have no Invariant Sections, write "with no Invariant Sections"
2720
instead of saying which ones are invariant.  If you have no
2721
Front-Cover Texts, write "no Front-Cover Texts" instead of
2722
"Front-Cover Texts being LIST"; likewise for Back-Cover Texts.
2723
 
2724
If your document contains nontrivial examples of program code, we
2725
recommend releasing these examples in parallel under your choice of
2726
free software license, such as the GNU General Public License,
2727
to permit their use in free software.
2728
  
2729
 
2730
 
2731
2732
 
2733
2734
2735
2736

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.