More Makefile cleanups, otherwise mainly noticeable are the netfilter fix
[davej-history.git] / include / linux / parport.h
blob71fc1398b7998650048b9e1de7c65c3c837a5c6e
1 /* $Id: parport.h,v 1.1 1998/05/17 10:57:52 andrea Exp andrea $ */
3 /*
4 * Any part of this program may be used in documents licensed under
5 * the GNU Free Documentation License, Version 1.1 or any later version
6 * published by the Free Software Foundation.
7 */
9 #ifndef _PARPORT_H_
10 #define _PARPORT_H_
12 /* Start off with user-visible constants */
14 /* Maximum of 8 ports per machine */
15 #define PARPORT_MAX 8
17 /* Magic numbers */
18 #define PARPORT_IRQ_NONE -1
19 #define PARPORT_DMA_NONE -1
20 #define PARPORT_IRQ_AUTO -2
21 #define PARPORT_DMA_AUTO -2
22 #define PARPORT_DMA_NOFIFO -3
23 #define PARPORT_DISABLE -2
24 #define PARPORT_IRQ_PROBEONLY -3
26 #define PARPORT_CONTROL_STROBE 0x1
27 #define PARPORT_CONTROL_AUTOFD 0x2
28 #define PARPORT_CONTROL_INIT 0x4
29 #define PARPORT_CONTROL_SELECT 0x8
31 #define PARPORT_STATUS_ERROR 0x8
32 #define PARPORT_STATUS_SELECT 0x10
33 #define PARPORT_STATUS_PAPEROUT 0x20
34 #define PARPORT_STATUS_ACK 0x40
35 #define PARPORT_STATUS_BUSY 0x80
37 /* Type classes for Plug-and-Play probe. */
38 typedef enum {
39 PARPORT_CLASS_LEGACY = 0, /* Non-IEEE1284 device */
40 PARPORT_CLASS_PRINTER,
41 PARPORT_CLASS_MODEM,
42 PARPORT_CLASS_NET,
43 PARPORT_CLASS_HDC, /* Hard disk controller */
44 PARPORT_CLASS_PCMCIA,
45 PARPORT_CLASS_MEDIA, /* Multimedia device */
46 PARPORT_CLASS_FDC, /* Floppy disk controller */
47 PARPORT_CLASS_PORTS,
48 PARPORT_CLASS_SCANNER,
49 PARPORT_CLASS_DIGCAM,
50 PARPORT_CLASS_OTHER, /* Anything else */
51 PARPORT_CLASS_UNSPEC, /* No CLS field in ID */
52 PARPORT_CLASS_SCSIADAPTER
53 } parport_device_class;
55 /* The "modes" entry in parport is a bit field representing the
56 capabilities of the hardware. */
57 #define PARPORT_MODE_PCSPP (1<<0) /* IBM PC registers available. */
58 #define PARPORT_MODE_TRISTATE (1<<1) /* Can tristate. */
59 #define PARPORT_MODE_EPP (1<<2) /* Hardware EPP. */
60 #define PARPORT_MODE_ECP (1<<3) /* Hardware ECP. */
61 #define PARPORT_MODE_COMPAT (1<<4) /* Hardware 'printer protocol'. */
62 #define PARPORT_MODE_DMA (1<<5) /* Hardware can DMA. */
63 #define PARPORT_MODE_SAFEININT (1<<6) /* SPP registers accessible in IRQ. */
65 /* IEEE1284 modes:
66 Nibble mode, byte mode, ECP, ECPRLE and EPP are their own
67 'extensibility request' values. Others are special.
68 'Real' ECP modes must have the IEEE1284_MODE_ECP bit set. */
69 #define IEEE1284_MODE_NIBBLE 0
70 #define IEEE1284_MODE_BYTE (1<<0)
71 #define IEEE1284_MODE_COMPAT (1<<8)
72 #define IEEE1284_MODE_BECP (1<<9) /* Bounded ECP mode */
73 #define IEEE1284_MODE_ECP (1<<4)
74 #define IEEE1284_MODE_ECPRLE (IEEE1284_MODE_ECP | (1<<5))
75 #define IEEE1284_MODE_ECPSWE (1<<10) /* Software-emulated */
76 #define IEEE1284_MODE_EPP (1<<6)
77 #define IEEE1284_MODE_EPPSL (1<<11) /* EPP 1.7 */
78 #define IEEE1284_MODE_EPPSWE (1<<12) /* Software-emulated */
79 #define IEEE1284_DEVICEID (1<<2) /* This is a flag */
80 #define IEEE1284_EXT_LINK (1<<14) /* This flag causes the
81 * extensibility link to
82 * be requested, using
83 * bits 0-6. */
85 /* For the benefit of parport_read/write, you can use these with
86 * parport_negotiate to use address operations. They have no effect
87 * other than to make parport_read/write use address transfers. */
88 #define IEEE1284_ADDR (1<<13) /* This is a flag */
89 #define IEEE1284_DATA 0 /* So is this */
91 /* Flags for block transfer operations. */
92 #define PARPORT_EPP_FAST (1<<0) /* Unreliable counts. */
94 /* The rest is for the kernel only */
95 #ifdef __KERNEL__
97 #include <linux/wait.h>
98 #include <linux/spinlock.h>
99 #include <asm/system.h>
100 #include <asm/ptrace.h>
101 #include <asm/semaphore.h>
102 #include <linux/proc_fs.h>
103 #include <linux/config.h>
105 #define PARPORT_NEED_GENERIC_OPS
107 /* Define this later. */
108 struct parport;
109 struct pardevice;
111 struct pc_parport_state {
112 unsigned int ctr;
113 unsigned int ecr;
116 struct ax_parport_state {
117 unsigned int ctr;
118 unsigned int ecr;
119 unsigned int dcsr;
122 /* used by both parport_amiga and parport_mfc3 */
123 struct amiga_parport_state {
124 unsigned char data; /* ciaa.prb */
125 unsigned char datadir; /* ciaa.ddrb */
126 unsigned char status; /* ciab.pra & 7 */
127 unsigned char statusdir;/* ciab.ddrb & 7 */
130 struct parport_state {
131 union {
132 struct pc_parport_state pc;
133 /* ARC has no state. */
134 struct ax_parport_state ax;
135 struct amiga_parport_state amiga;
136 /* Atari has not state. */
137 void *misc;
138 } u;
141 struct parport_operations {
142 /* IBM PC-style virtual registers. */
143 void (*write_data)(struct parport *, unsigned char);
144 unsigned char (*read_data)(struct parport *);
146 void (*write_control)(struct parport *, unsigned char);
147 unsigned char (*read_control)(struct parport *);
148 unsigned char (*frob_control)(struct parport *, unsigned char mask,
149 unsigned char val);
151 unsigned char (*read_status)(struct parport *);
153 /* IRQs. */
154 void (*enable_irq)(struct parport *);
155 void (*disable_irq)(struct parport *);
157 /* Data direction. */
158 void (*data_forward) (struct parport *);
159 void (*data_reverse) (struct parport *);
161 /* For core parport code. */
162 void (*init_state)(struct pardevice *, struct parport_state *);
163 void (*save_state)(struct parport *, struct parport_state *);
164 void (*restore_state)(struct parport *, struct parport_state *);
166 void (*inc_use_count)(void);
167 void (*dec_use_count)(void);
169 /* Block read/write */
170 size_t (*epp_write_data) (struct parport *port, const void *buf,
171 size_t len, int flags);
172 size_t (*epp_read_data) (struct parport *port, void *buf, size_t len,
173 int flags);
174 size_t (*epp_write_addr) (struct parport *port, const void *buf,
175 size_t len, int flags);
176 size_t (*epp_read_addr) (struct parport *port, void *buf, size_t len,
177 int flags);
179 size_t (*ecp_write_data) (struct parport *port, const void *buf,
180 size_t len, int flags);
181 size_t (*ecp_read_data) (struct parport *port, void *buf, size_t len,
182 int flags);
183 size_t (*ecp_write_addr) (struct parport *port, const void *buf,
184 size_t len, int flags);
186 size_t (*compat_write_data) (struct parport *port, const void *buf,
187 size_t len, int flags);
188 size_t (*nibble_read_data) (struct parport *port, void *buf,
189 size_t len, int flags);
190 size_t (*byte_read_data) (struct parport *port, void *buf,
191 size_t len, int flags);
194 struct parport_device_info {
195 parport_device_class class;
196 const char *class_name;
197 const char *mfr;
198 const char *model;
199 const char *cmdset;
200 const char *description;
203 /* Each device can have two callback functions:
204 * 1) a preemption function, called by the resource manager to request
205 * that the driver relinquish control of the port. The driver should
206 * return zero if it agrees to release the port, and nonzero if it
207 * refuses. Do not call parport_release() - the kernel will do this
208 * implicitly.
210 * 2) a wake-up function, called by the resource manager to tell drivers
211 * that the port is available to be claimed. If a driver wants to use
212 * the port, it should call parport_claim() here.
215 /* A parallel port device */
216 struct pardevice {
217 const char *name;
218 struct parport *port;
219 int daisy;
220 int (*preempt)(void *);
221 void (*wakeup)(void *);
222 void *private;
223 void (*irq_func)(int, void *, struct pt_regs *);
224 unsigned int flags;
225 struct pardevice *next;
226 struct pardevice *prev;
227 struct parport_state *state; /* saved status over preemption */
228 wait_queue_head_t wait_q;
229 unsigned long int time;
230 unsigned long int timeslice;
231 volatile long int timeout;
232 unsigned int waiting;
233 struct pardevice *waitprev;
234 struct pardevice *waitnext;
235 void * sysctl_table;
238 /* IEEE1284 information */
240 /* IEEE1284 phases */
241 enum ieee1284_phase {
242 IEEE1284_PH_FWD_DATA,
243 IEEE1284_PH_FWD_IDLE,
244 IEEE1284_PH_TERMINATE,
245 IEEE1284_PH_NEGOTIATION,
246 IEEE1284_PH_HBUSY_DNA,
247 IEEE1284_PH_REV_IDLE,
248 IEEE1284_PH_HBUSY_DAVAIL,
249 IEEE1284_PH_REV_DATA,
250 IEEE1284_PH_ECP_SETUP,
251 IEEE1284_PH_ECP_FWD_TO_REV,
252 IEEE1284_PH_ECP_REV_TO_FWD
254 struct ieee1284_info {
255 int mode;
256 volatile enum ieee1284_phase phase;
257 struct semaphore irq;
260 /* A parallel port */
261 struct parport {
262 unsigned long base; /* base address */
263 unsigned long base_hi; /* base address (hi - ECR) */
264 unsigned int size; /* IO extent */
265 const char *name;
266 unsigned int modes;
267 int irq; /* interrupt (or -1 for none) */
268 int dma;
269 int muxport; /* which muxport (if any) this is */
270 int portnum; /* which physical parallel port (not mux) */
272 struct parport *physport;
273 /* If this is a non-default mux
274 parport, i.e. we're a clone of a real
275 physical port, this is a pointer to that
276 port. The locking is only done in the
277 real port. For a clone port, the
278 following structure members are
279 meaningless: devices, cad, muxsel,
280 waithead, waittail, flags, pdir,
281 ieee1284, *_lock.
283 It this is a default mux parport, or
284 there is no mux involved, this points to
285 ourself. */
287 struct pardevice *devices;
288 struct pardevice *cad; /* port owner */
289 int daisy; /* currently selected daisy addr */
290 int muxsel; /* currently selected mux port */
292 struct pardevice *waithead;
293 struct pardevice *waittail;
295 struct parport *next;
296 unsigned int flags;
298 void *sysctl_table;
299 struct parport_device_info probe_info[5]; /* 0-3 + non-IEEE1284.3 */
300 struct ieee1284_info ieee1284;
302 struct parport_operations *ops;
303 void *private_data; /* for lowlevel driver */
305 int number; /* port index - the `n' in `parportn' */
306 spinlock_t pardevice_lock;
307 spinlock_t waitlist_lock;
308 rwlock_t cad_lock;
310 int spintime;
311 atomic_t ref_count;
314 #define DEFAULT_SPIN_TIME 500 /* us */
316 struct parport_driver {
317 const char *name;
318 void (*attach) (struct parport *);
319 void (*detach) (struct parport *);
320 struct parport_driver *next;
323 /* parport_register_port registers a new parallel port at the given
324 address (if one does not already exist) and returns a pointer to it.
325 This entails claiming the I/O region, IRQ and DMA. NULL is returned
326 if initialisation fails. */
327 struct parport *parport_register_port(unsigned long base, int irq, int dma,
328 struct parport_operations *ops);
330 /* Once a registered port is ready for high-level drivers to use, the
331 low-level driver that registered it should announce it. This will
332 call the high-level drivers' attach() functions (after things like
333 determining the IEEE 1284.3 topology of the port and collecting
334 DeviceIDs). */
335 void parport_announce_port (struct parport *port);
337 /* Unregister a port. */
338 extern void parport_unregister_port(struct parport *port);
340 /* parport_enumerate returns a pointer to the linked list of all the
341 ports in this machine. DON'T USE THIS. Use
342 parport_register_driver instead. */
343 struct parport *parport_enumerate(void);
345 /* Register a new high-level driver. */
346 extern int parport_register_driver (struct parport_driver *);
348 /* Unregister a high-level driver. */
349 extern void parport_unregister_driver (struct parport_driver *);
351 /* If parport_register_driver doesn't fit your needs, perhaps
352 * parport_find_xxx does. */
353 extern struct parport *parport_find_number (int);
354 extern struct parport *parport_find_base (unsigned long);
356 /* Reference counting for ports. */
357 extern struct parport *parport_get_port (struct parport *);
358 extern void parport_put_port (struct parport *);
360 /* parport_register_device declares that a device is connected to a
361 port, and tells the kernel all it needs to know.
362 - pf is the preemption function (may be NULL for no callback)
363 - kf is the wake-up function (may be NULL for no callback)
364 - irq_func is the interrupt handler (may be NULL for no interrupts)
365 - handle is a user pointer that gets handed to callback functions. */
366 struct pardevice *parport_register_device(struct parport *port,
367 const char *name,
368 int (*pf)(void *), void (*kf)(void *),
369 void (*irq_func)(int, void *, struct pt_regs *),
370 int flags, void *handle);
372 /* parport_unregister unlinks a device from the chain. */
373 extern void parport_unregister_device(struct pardevice *dev);
375 /* parport_claim tries to gain ownership of the port for a particular
376 driver. This may fail (return non-zero) if another driver is busy.
377 If this driver has registered an interrupt handler, it will be
378 enabled. */
379 extern int parport_claim(struct pardevice *dev);
381 /* parport_claim_or_block is the same, but sleeps if the port cannot
382 be claimed. Return value is 1 if it slept, 0 normally and -errno
383 on error. */
384 extern int parport_claim_or_block(struct pardevice *dev);
386 /* parport_release reverses a previous parport_claim. This can never
387 fail, though the effects are undefined (except that they are bad)
388 if you didn't previously own the port. Once you have released the
389 port you should make sure that neither your code nor the hardware
390 on the port tries to initiate any communication without first
391 re-claiming the port. If you mess with the port state (enabling
392 ECP for example) you should clean up before releasing the port. */
394 extern void parport_release(struct pardevice *dev);
397 * parport_yield - relinquish a parallel port temporarily
398 * @dev: a device on the parallel port
400 * This function relinquishes the port if it would be helpful to other
401 * drivers to do so. Afterwards it tries to reclaim the port using
402 * parport_claim(), and the return value is the same as for
403 * parport_claim(). If it fails, the port is left unclaimed and it is
404 * the driver's responsibility to reclaim the port.
406 * The parport_yield() and parport_yield_blocking() functions are for
407 * marking points in the driver at which other drivers may claim the
408 * port and use their devices. Yielding the port is similar to
409 * releasing it and reclaiming it, but is more efficient because no
410 * action is taken if there are no other devices needing the port. In
411 * fact, nothing is done even if there are other devices waiting but
412 * the current device is still within its "timeslice". The default
413 * timeslice is half a second, but it can be adjusted via the /proc
414 * interface.
416 extern __inline__ int parport_yield(struct pardevice *dev)
418 unsigned long int timeslip = (jiffies - dev->time);
419 if ((dev->port->waithead == NULL) || (timeslip < dev->timeslice))
420 return 0;
421 parport_release(dev);
422 return parport_claim(dev);
426 * parport_yield_blocking - relinquish a parallel port temporarily
427 * @dev: a device on the parallel port
429 * This function relinquishes the port if it would be helpful to other
430 * drivers to do so. Afterwards it tries to reclaim the port using
431 * parport_claim_or_block(), and the return value is the same as for
432 * parport_claim_or_block().
434 extern __inline__ int parport_yield_blocking(struct pardevice *dev)
436 unsigned long int timeslip = (jiffies - dev->time);
437 if ((dev->port->waithead == NULL) || (timeslip < dev->timeslice))
438 return 0;
439 parport_release(dev);
440 return parport_claim_or_block(dev);
443 /* Flags used to identify what a device does. */
444 #define PARPORT_DEV_TRAN 0 /* WARNING !! DEPRECATED !! */
445 #define PARPORT_DEV_LURK (1<<0) /* WARNING !! DEPRECATED !! */
446 #define PARPORT_DEV_EXCL (1<<1) /* Need exclusive access. */
448 #define PARPORT_FLAG_EXCL (1<<1) /* EXCL driver registered. */
450 extern int parport_parse_irqs(int, const char *[], int irqval[]);
451 extern int parport_parse_dmas(int, const char *[], int dmaval[]);
453 /* IEEE1284 functions */
454 extern void parport_ieee1284_interrupt (int, void *, struct pt_regs *);
455 extern int parport_negotiate (struct parport *, int mode);
456 extern ssize_t parport_write (struct parport *, const void *buf, size_t len);
457 extern ssize_t parport_read (struct parport *, void *buf, size_t len);
458 extern long parport_set_timeout (struct pardevice *, long inactivity);
459 extern int parport_wait_event (struct parport *, long timeout);
460 extern int parport_wait_peripheral (struct parport *port,
461 unsigned char mask,
462 unsigned char val);
463 extern int parport_poll_peripheral (struct parport *port,
464 unsigned char mask,
465 unsigned char val,
466 int usec);
468 /* For architectural drivers */
469 extern void parport_ieee1284_wakeup (struct parport *port);
470 extern size_t parport_ieee1284_write_compat (struct parport *,
471 const void *, size_t, int);
472 extern size_t parport_ieee1284_read_nibble (struct parport *,
473 void *, size_t, int);
474 extern size_t parport_ieee1284_read_byte (struct parport *,
475 void *, size_t, int);
476 extern size_t parport_ieee1284_ecp_read_data (struct parport *,
477 void *, size_t, int);
478 extern size_t parport_ieee1284_ecp_write_data (struct parport *,
479 const void *, size_t, int);
480 extern size_t parport_ieee1284_ecp_write_addr (struct parport *,
481 const void *, size_t, int);
482 extern size_t parport_ieee1284_epp_write_data (struct parport *,
483 const void *, size_t, int);
484 extern size_t parport_ieee1284_epp_read_data (struct parport *,
485 void *, size_t, int);
486 extern size_t parport_ieee1284_epp_write_addr (struct parport *,
487 const void *, size_t, int);
488 extern size_t parport_ieee1284_epp_read_addr (struct parport *,
489 void *, size_t, int);
491 /* IEEE1284.3 functions */
492 extern int parport_daisy_init (struct parport *port);
493 extern void parport_daisy_fini (struct parport *port);
494 extern struct pardevice *parport_open (int devnum, const char *name,
495 int (*pf) (void *),
496 void (*kf) (void *),
497 void (*irqf) (int, void *,
498 struct pt_regs *),
499 int flags, void *handle);
500 extern void parport_close (struct pardevice *dev);
501 extern ssize_t parport_device_id (int devnum, char *buffer, size_t len);
502 extern int parport_device_num (int parport, int mux, int daisy);
503 extern int parport_device_coords (int devnum, int *parport, int *mux,
504 int *daisy);
505 extern void parport_daisy_deselect_all (struct parport *port);
506 extern int parport_daisy_select (struct parport *port, int daisy, int mode);
508 /* For finding devices based on their device ID. Example usage:
509 int devnum = -1;
510 while ((devnum = parport_find_class (PARPORT_CLASS_DIGCAM, devnum)) != -1) {
511 struct pardevice *dev = parport_open (devnum, ...);
515 extern int parport_find_device (const char *mfg, const char *mdl, int from);
516 extern int parport_find_class (parport_device_class cls, int from);
518 /* Lowlevel drivers _can_ call this support function to handle irqs. */
519 extern __inline__ void parport_generic_irq(int irq, struct parport *port,
520 struct pt_regs *regs)
522 parport_ieee1284_interrupt (irq, port, regs);
523 read_lock(&port->cad_lock);
524 if (port->cad && port->cad->irq_func)
525 port->cad->irq_func(irq, port->cad->private, regs);
526 read_unlock(&port->cad_lock);
529 /* Prototypes from parport_procfs */
530 extern int parport_proc_register(struct parport *pp);
531 extern int parport_proc_unregister(struct parport *pp);
532 extern int parport_device_proc_register(struct pardevice *device);
533 extern int parport_device_proc_unregister(struct pardevice *device);
534 extern int parport_default_proc_register(void);
535 extern int parport_default_proc_unregister(void);
537 extern void dec_parport_count(void);
538 extern void inc_parport_count(void);
540 /* If PC hardware is the only type supported, we can optimise a bit. */
541 #if (defined(CONFIG_PARPORT_PC) || defined(CONFIG_PARPORT_PC_MODULE)) && !(defined(CONFIG_PARPORT_ARC) || defined(CONFIG_PARPORT_ARC_MODULE)) && !(defined(CONFIG_PARPORT_AMIGA) || defined(CONFIG_PARPORT_AMIGA_MODULE)) && !(defined(CONFIG_PARPORT_MFC3) || defined(CONFIG_PARPORT_MFC3_MODULE)) && !(defined(CONFIG_PARPORT_ATARI) || defined(CONFIG_PARPORT_ATARI_MODULE)) && !(defined(CONFIG_USB_USS720) || defined(CONFIG_USB_USS720_MODULE)) && !(defined(CONFIG_PARPORT_SUNBPP) || defined(CONFIG_PARPORT_SUNBPP_MODULE)) && !defined(CONFIG_PARPORT_OTHER)
543 #undef PARPORT_NEED_GENERIC_OPS
544 #include <linux/parport_pc.h>
545 #define parport_write_data(p,x) parport_pc_write_data(p,x)
546 #define parport_read_data(p) parport_pc_read_data(p)
547 #define parport_write_control(p,x) parport_pc_write_control(p,x)
548 #define parport_read_control(p) parport_pc_read_control(p)
549 #define parport_frob_control(p,m,v) parport_pc_frob_control(p,m,v)
550 #define parport_read_status(p) parport_pc_read_status(p)
551 #define parport_enable_irq(p) parport_pc_enable_irq(p)
552 #define parport_disable_irq(p) parport_pc_disable_irq(p)
553 #define parport_data_forward(p) parport_pc_data_forward(p)
554 #define parport_data_reverse(p) parport_pc_data_reverse(p)
555 #endif
557 #ifdef PARPORT_NEED_GENERIC_OPS
558 /* Generic operations vector through the dispatch table. */
559 #define parport_write_data(p,x) (p)->ops->write_data(p,x)
560 #define parport_read_data(p) (p)->ops->read_data(p)
561 #define parport_write_control(p,x) (p)->ops->write_control(p,x)
562 #define parport_read_control(p) (p)->ops->read_control(p)
563 #define parport_frob_control(p,m,v) (p)->ops->frob_control(p,m,v)
564 #define parport_read_status(p) (p)->ops->read_status(p)
565 #define parport_enable_irq(p) (p)->ops->enable_irq(p)
566 #define parport_disable_irq(p) (p)->ops->disable_irq(p)
567 #define parport_data_forward(p) (p)->ops->data_forward(p)
568 #define parport_data_reverse(p) (p)->ops->data_reverse(p)
569 #endif
571 #endif /* __KERNEL__ */
572 #endif /* _PARPORT_H_ */