1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
|
/* $Id: parport.h,v 1.1 1998/05/17 10:57:52 andrea Exp andrea $ */
/*
* Any part of this program may be used in documents licensed under
* the GNU Free Documentation License, Version 1.1 or any later version
* published by the Free Software Foundation.
*/
#ifndef _PARPORT_H_
#define _PARPORT_H_
/* Start off with user-visible constants */
/* Maximum of 16 ports per machine */
#define PARPORT_MAX 16
/* Magic numbers */
#define PARPORT_IRQ_NONE -1
#define PARPORT_DMA_NONE -1
#define PARPORT_IRQ_AUTO -2
#define PARPORT_DMA_AUTO -2
#define PARPORT_DMA_NOFIFO -3
#define PARPORT_DISABLE -2
#define PARPORT_IRQ_PROBEONLY -3
#define PARPORT_IOHI_AUTO -1
#define PARPORT_CONTROL_STROBE 0x1
#define PARPORT_CONTROL_AUTOFD 0x2
#define PARPORT_CONTROL_INIT 0x4
#define PARPORT_CONTROL_SELECT 0x8
#define PARPORT_STATUS_ERROR 0x8
#define PARPORT_STATUS_SELECT 0x10
#define PARPORT_STATUS_PAPEROUT 0x20
#define PARPORT_STATUS_ACK 0x40
#define PARPORT_STATUS_BUSY 0x80
/* Type classes for Plug-and-Play probe. */
typedef enum {
PARPORT_CLASS_LEGACY = 0, /* Non-IEEE1284 device */
PARPORT_CLASS_PRINTER,
PARPORT_CLASS_MODEM,
PARPORT_CLASS_NET,
PARPORT_CLASS_HDC, /* Hard disk controller */
PARPORT_CLASS_PCMCIA,
PARPORT_CLASS_MEDIA, /* Multimedia device */
PARPORT_CLASS_FDC, /* Floppy disk controller */
PARPORT_CLASS_PORTS,
PARPORT_CLASS_SCANNER,
PARPORT_CLASS_DIGCAM,
PARPORT_CLASS_OTHER, /* Anything else */
PARPORT_CLASS_UNSPEC, /* No CLS field in ID */
PARPORT_CLASS_SCSIADAPTER
} parport_device_class;
/* The "modes" entry in parport is a bit field representing the
capabilities of the hardware. */
#define PARPORT_MODE_PCSPP (1<<0) /* IBM PC registers available. */
#define PARPORT_MODE_TRISTATE (1<<1) /* Can tristate. */
#define PARPORT_MODE_EPP (1<<2) /* Hardware EPP. */
#define PARPORT_MODE_ECP (1<<3) /* Hardware ECP. */
#define PARPORT_MODE_COMPAT (1<<4) /* Hardware 'printer protocol'. */
#define PARPORT_MODE_DMA (1<<5) /* Hardware can DMA. */
#define PARPORT_MODE_SAFEININT (1<<6) /* SPP registers accessible in IRQ. */
/* IEEE1284 modes:
Nibble mode, byte mode, ECP, ECPRLE and EPP are their own
'extensibility request' values. Others are special.
'Real' ECP modes must have the IEEE1284_MODE_ECP bit set. */
#define IEEE1284_MODE_NIBBLE 0
#define IEEE1284_MODE_BYTE (1<<0)
#define IEEE1284_MODE_COMPAT (1<<8)
#define IEEE1284_MODE_BECP (1<<9) /* Bounded ECP mode */
#define IEEE1284_MODE_ECP (1<<4)
#define IEEE1284_MODE_ECPRLE (IEEE1284_MODE_ECP | (1<<5))
#define IEEE1284_MODE_ECPSWE (1<<10) /* Software-emulated */
#define IEEE1284_MODE_EPP (1<<6)
#define IEEE1284_MODE_EPPSL (1<<11) /* EPP 1.7 */
#define IEEE1284_MODE_EPPSWE (1<<12) /* Software-emulated */
#define IEEE1284_DEVICEID (1<<2) /* This is a flag */
#define IEEE1284_EXT_LINK (1<<14) /* This flag causes the
* extensibility link to
* be requested, using
* bits 0-6. */
/* For the benefit of parport_read/write, you can use these with
* parport_negotiate to use address operations. They have no effect
* other than to make parport_read/write use address transfers. */
#define IEEE1284_ADDR (1<<13) /* This is a flag */
#define IEEE1284_DATA 0 /* So is this */
/* Flags for block transfer operations. */
#define PARPORT_EPP_FAST (1<<0) /* Unreliable counts. */
#define PARPORT_W91284PIC (1<<1) /* have a Warp9 w91284pic in the device */
/* The rest is for the kernel only */
#ifdef __KERNEL__
#include <linux/jiffies.h>
#include <linux/proc_fs.h>
#include <linux/spinlock.h>
#include <linux/wait.h>
#include <asm/system.h>
#include <asm/ptrace.h>
#include <asm/semaphore.h>
/* Define this later. */
struct parport;
struct pardevice;
struct pc_parport_state {
unsigned int ctr;
unsigned int ecr;
};
struct ax_parport_state {
unsigned int ctr;
unsigned int ecr;
unsigned int dcsr;
};
/* used by both parport_amiga and parport_mfc3 */
struct amiga_parport_state {
unsigned char data; /* ciaa.prb */
unsigned char datadir; /* ciaa.ddrb */
unsigned char status; /* ciab.pra & 7 */
unsigned char statusdir;/* ciab.ddrb & 7 */
};
struct ax88796_parport_state {
unsigned char cpr;
};
struct ip32_parport_state {
unsigned int dcr;
unsigned int ecr;
};
struct parport_state {
union {
struct pc_parport_state pc;
/* ARC has no state. */
struct ax_parport_state ax;
struct amiga_parport_state amiga;
struct ax88796_parport_state ax88796;
/* Atari has not state. */
struct ip32_parport_state ip32;
void *misc;
} u;
};
struct parport_operations {
/* IBM PC-style virtual registers. */
void (*write_data)(struct parport *, unsigned char);
unsigned char (*read_data)(struct parport *);
void (*write_control)(struct parport *, unsigned char);
unsigned char (*read_control)(struct parport *);
unsigned char (*frob_control)(struct parport *, unsigned char mask,
unsigned char val);
unsigned char (*read_status)(struct parport *);
/* IRQs. */
void (*enable_irq)(struct parport *);
void (*disable_irq)(struct parport *);
/* Data direction. */
void (*data_forward) (struct parport *);
void (*data_reverse) (struct parport *);
/* For core parport code. */
void (*init_state)(struct pardevice *, struct parport_state *);
void (*save_state)(struct parport *, struct parport_state *);
void (*restore_state)(struct parport *, struct parport_state *);
/* Block read/write */
size_t (*epp_write_data) (struct parport *port, const void *buf,
size_t len, int flags);
size_t (*epp_read_data) (struct parport *port, void *buf, size_t len,
int flags);
size_t (*epp_write_addr) (struct parport *port, const void *buf,
size_t len, int flags);
size_t (*epp_read_addr) (struct parport *port, void *buf, size_t len,
int flags);
size_t (*ecp_write_data) (struct parport *port, const void *buf,
size_t len, int flags);
size_t (*ecp_read_data) (struct parport *port, void *buf, size_t len,
int flags);
size_t (*ecp_write_addr) (struct parport *port, const void *buf,
size_t len, int flags);
size_t (*compat_write_data) (struct parport *port, const void *buf,
size_t len, int flags);
size_t (*nibble_read_data) (struct parport *port, void *buf,
size_t len, int flags);
size_t (*byte_read_data) (struct parport *port, void *buf,
size_t len, int flags);
struct module *owner;
};
struct parport_device_info {
parport_device_class class;
const char *class_name;
const char *mfr;
const char *model;
const char *cmdset;
const char *description;
};
/* Each device can have two callback functions:
* 1) a preemption function, called by the resource manager to request
* that the driver relinquish control of the port. The driver should
* return zero if it agrees to release the port, and nonzero if it
* refuses. Do not call parport_release() - the kernel will do this
* implicitly.
*
* 2) a wake-up function, called by the resource manager to tell drivers
* that the port is available to be claimed. If a driver wants to use
* the port, it should call parport_claim() here.
*/
/* A parallel port device */
struct pardevice {
const char *name;
struct parport *port;
int daisy;
int (*preempt)(void *);
void (*wakeup)(void *);
void *private;
void (*irq_func)(int, void *, struct pt_regs *);
unsigned int flags;
struct pardevice *next;
struct pardevice *prev;
struct parport_state *state; /* saved status over preemption */
wait_queue_head_t wait_q;
unsigned long int time;
unsigned long int timeslice;
volatile long int timeout;
unsigned long waiting; /* long req'd for set_bit --RR */
struct pardevice *waitprev;
struct pardevice *waitnext;
void * sysctl_table;
};
/* IEEE1284 information */
/* IEEE1284 phases. These are exposed to userland through ppdev IOCTL
* PP[GS]ETPHASE, so do not change existing values. */
enum ieee1284_phase {
IEEE1284_PH_FWD_DATA,
IEEE1284_PH_FWD_IDLE,
IEEE1284_PH_TERMINATE,
IEEE1284_PH_NEGOTIATION,
IEEE1284_PH_HBUSY_DNA,
IEEE1284_PH_REV_IDLE,
IEEE1284_PH_HBUSY_DAVAIL,
IEEE1284_PH_REV_DATA,
IEEE1284_PH_ECP_SETUP,
IEEE1284_PH_ECP_FWD_TO_REV,
IEEE1284_PH_ECP_REV_TO_FWD,
IEEE1284_PH_ECP_DIR_UNKNOWN,
};
struct ieee1284_info {
int mode;
volatile enum ieee1284_phase phase;
struct semaphore irq;
};
/* A parallel port */
struct parport {
|