Import 2.3.18pre1
[davej-history.git] / include / linux / parport.h
blob50256a87d8825951f032a588708d390b07ac1d36
1 /* $Id: parport.h,v 1.1 1998/05/17 10:57:52 andrea Exp andrea $ */
3 #ifndef _PARPORT_H_
4 #define _PARPORT_H_
6 /* Start off with user-visible constants */
8 /* Maximum of 8 ports per machine */
9 #define PARPORT_MAX 8
11 /* Magic numbers */
12 #define PARPORT_IRQ_NONE -1
13 #define PARPORT_DMA_NONE -1
14 #define PARPORT_IRQ_AUTO -2
15 #define PARPORT_DMA_AUTO -2
16 #define PARPORT_DISABLE -2
17 #define PARPORT_IRQ_PROBEONLY -3
19 #define PARPORT_CONTROL_STROBE 0x1
20 #define PARPORT_CONTROL_AUTOFD 0x2
21 #define PARPORT_CONTROL_INIT 0x4
22 #define PARPORT_CONTROL_SELECT 0x8
24 #define PARPORT_STATUS_ERROR 0x8
25 #define PARPORT_STATUS_SELECT 0x10
26 #define PARPORT_STATUS_PAPEROUT 0x20
27 #define PARPORT_STATUS_ACK 0x40
28 #define PARPORT_STATUS_BUSY 0x80
30 /* Type classes for Plug-and-Play probe. */
31 typedef enum {
32 PARPORT_CLASS_LEGACY = 0, /* Non-IEEE1284 device */
33 PARPORT_CLASS_PRINTER,
34 PARPORT_CLASS_MODEM,
35 PARPORT_CLASS_NET,
36 PARPORT_CLASS_HDC, /* Hard disk controller */
37 PARPORT_CLASS_PCMCIA,
38 PARPORT_CLASS_MEDIA, /* Multimedia device */
39 PARPORT_CLASS_FDC, /* Floppy disk controller */
40 PARPORT_CLASS_PORTS,
41 PARPORT_CLASS_SCANNER,
42 PARPORT_CLASS_DIGCAM,
43 PARPORT_CLASS_OTHER, /* Anything else */
44 PARPORT_CLASS_UNSPEC, /* No CLS field in ID */
45 PARPORT_CLASS_SCSIADAPTER
46 } parport_device_class;
48 /* The "modes" entry in parport is a bit field representing the
49 capabilities of the hardware. */
50 #define PARPORT_MODE_PCSPP (1<<0) /* IBM PC registers available. */
51 #define PARPORT_MODE_TRISTATE (1<<1) /* Can tristate. */
52 #define PARPORT_MODE_EPP (1<<2) /* Hardware EPP. */
53 #define PARPORT_MODE_ECP (1<<3) /* Hardware ECP. */
54 #define PARPORT_MODE_COMPAT (1<<4) /* Hardware 'printer protocol'. */
55 #define PARPORT_MODE_DMA (1<<5) /* Hardware can DMA. */
56 #define PARPORT_MODE_SAFEININT (1<<6) /* SPP registers accessible in IRQ. */
58 /* IEEE1284 modes:
59 Nibble mode, byte mode, ECP, ECPRLE and EPP are their own
60 'extensibility request' values. Others are special.
61 'Real' ECP modes must have the IEEE1284_MODE_ECP bit set. */
62 #define IEEE1284_MODE_NIBBLE 0
63 #define IEEE1284_MODE_BYTE (1<<0)
64 #define IEEE1284_MODE_COMPAT (1<<8)
65 #define IEEE1284_MODE_BECP (1<<9) /* Bounded ECP mode */
66 #define IEEE1284_MODE_ECP (1<<4)
67 #define IEEE1284_MODE_ECPRLE (IEEE1284_MODE_ECP | (1<<5))
68 #define IEEE1284_MODE_ECPSWE (1<<10) /* Software-emulated */
69 #define IEEE1284_MODE_EPP (1<<6)
70 #define IEEE1284_MODE_EPPSL (1<<11) /* EPP 1.7 */
71 #define IEEE1284_MODE_EPPSWE (1<<12) /* Software-emulated */
72 #define IEEE1284_DEVICEID (1<<2) /* This is a flag */
74 /* For the benefit of parport_read/write, you can use these with
75 * parport_negotiate to use address operations. They have no effect
76 * other than to make parport_read/write use address transfers. */
77 #define IEEE1284_ADDR (1<<13) /* This is a flag */
78 #define IEEE1284_DATA 0 /* So is this */
80 /* Flags for block transfer operations. */
81 #define PARPORT_EPP_FAST (1<<0) /* Unreliable counts. */
83 /* The rest is for the kernel only */
84 #ifdef __KERNEL__
86 #include <linux/wait.h>
87 #include <linux/spinlock.h>
88 #include <asm/system.h>
89 #include <asm/ptrace.h>
90 #include <asm/semaphore.h>
91 #include <linux/proc_fs.h>
92 #include <linux/config.h>
94 #define PARPORT_NEED_GENERIC_OPS
96 /* Define this later. */
97 struct parport;
98 struct pardevice;
100 struct pc_parport_state {
101 unsigned int ctr;
102 unsigned int ecr;
105 struct ax_parport_state {
106 unsigned int ctr;
107 unsigned int ecr;
108 unsigned int dcsr;
111 /* used by both parport_amiga and parport_mfc3 */
112 struct amiga_parport_state {
113 unsigned char data; /* ciaa.prb */
114 unsigned char datadir; /* ciaa.ddrb */
115 unsigned char status; /* ciab.pra & 7 */
116 unsigned char statusdir;/* ciab.ddrb & 7 */
119 struct parport_state {
120 union {
121 struct pc_parport_state pc;
122 /* ARC has no state. */
123 struct ax_parport_state ax;
124 struct amiga_parport_state amiga;
125 /* Atari has not state. */
126 void *misc;
127 } u;
130 struct parport_operations {
131 /* IBM PC-style virtual registers. */
132 void (*write_data)(struct parport *, unsigned char);
133 unsigned char (*read_data)(struct parport *);
135 void (*write_control)(struct parport *, unsigned char);
136 unsigned char (*read_control)(struct parport *);
137 unsigned char (*frob_control)(struct parport *, unsigned char mask,
138 unsigned char val);
140 unsigned char (*read_status)(struct parport *);
142 /* IRQs. */
143 void (*enable_irq)(struct parport *);
144 void (*disable_irq)(struct parport *);
146 /* Data direction. */
147 void (*data_forward) (struct parport *);
148 void (*data_reverse) (struct parport *);
150 /* For core parport code. */
151 void (*init_state)(struct pardevice *, struct parport_state *);
152 void (*save_state)(struct parport *, struct parport_state *);
153 void (*restore_state)(struct parport *, struct parport_state *);
155 void (*inc_use_count)(void);
156 void (*dec_use_count)(void);
158 /* Block read/write */
159 size_t (*epp_write_data) (struct parport *port, const void *buf,
160 size_t len, int flags);
161 size_t (*epp_read_data) (struct parport *port, void *buf, size_t len,
162 int flags);
163 size_t (*epp_write_addr) (struct parport *port, const void *buf,
164 size_t len, int flags);
165 size_t (*epp_read_addr) (struct parport *port, void *buf, size_t len,
166 int flags);
168 size_t (*ecp_write_data) (struct parport *port, const void *buf,
169 size_t len, int flags);
170 size_t (*ecp_read_data) (struct parport *port, void *buf, size_t len,
171 int flags);
172 size_t (*ecp_write_addr) (struct parport *port, const void *buf,
173 size_t len, int flags);
175 size_t (*compat_write_data) (struct parport *port, const void *buf,
176 size_t len, int flags);
177 size_t (*nibble_read_data) (struct parport *port, void *buf,
178 size_t len, int flags);
179 size_t (*byte_read_data) (struct parport *port, void *buf,
180 size_t len, int flags);
183 struct parport_device_info {
184 parport_device_class class;
185 const char *class_name;
186 const char *mfr;
187 const char *model;
188 const char *cmdset;
189 const char *description;
192 /* Each device can have two callback functions:
193 * 1) a preemption function, called by the resource manager to request
194 * that the driver relinquish control of the port. The driver should
195 * return zero if it agrees to release the port, and nonzero if it
196 * refuses. Do not call parport_release() - the kernel will do this
197 * implicitly.
199 * 2) a wake-up function, called by the resource manager to tell drivers
200 * that the port is available to be claimed. If a driver wants to use
201 * the port, it should call parport_claim() here.
204 /* A parallel port device */
205 struct pardevice {
206 const char *name;
207 struct parport *port;
208 int daisy;
209 int (*preempt)(void *);
210 void (*wakeup)(void *);
211 void *private;
212 void (*irq_func)(int, void *, struct pt_regs *);
213 unsigned int flags;
214 struct pardevice *next;
215 struct pardevice *prev;
216 struct parport_state *state; /* saved status over preemption */
217 wait_queue_head_t wait_q;
218 unsigned long int time;
219 unsigned long int timeslice;
220 volatile long int timeout;
221 unsigned int waiting;
222 struct pardevice *waitprev;
223 struct pardevice *waitnext;
224 void * sysctl_table;
227 /* IEEE1284 information */
229 /* IEEE1284 phases */
230 enum ieee1284_phase {
231 IEEE1284_PH_FWD_DATA,
232 IEEE1284_PH_FWD_IDLE,
233 IEEE1284_PH_TERMINATE,
234 IEEE1284_PH_NEGOTIATION,
235 IEEE1284_PH_HBUSY_DNA,
236 IEEE1284_PH_REV_IDLE,
237 IEEE1284_PH_HBUSY_DAVAIL,
238 IEEE1284_PH_REV_DATA,
239 IEEE1284_PH_ECP_SETUP,
240 IEEE1284_PH_ECP_FWD_TO_REV,
241 IEEE1284_PH_ECP_REV_TO_FWD
243 struct ieee1284_info {
244 int mode;
245 volatile enum ieee1284_phase phase;
246 struct semaphore irq;
249 /* A parallel port */
250 struct parport {
251 unsigned long base; /* base address */
252 unsigned long base_hi; /* base address (hi - ECR) */
253 unsigned int size; /* IO extent */
254 const char *name;
255 unsigned int modes;
256 int irq; /* interrupt (or -1 for none) */
257 int dma;
258 int muxport; /* which muxport (if any) this is */
259 int portnum; /* which physical parallel port (not mux) */
261 struct parport *physport;
262 /* If this is a non-default mux
263 parport, i.e. we're a clone of a real
264 physical port, this is a pointer to that
265 port. The locking is only done in the
266 real port. For a clone port, the
267 following structure members are
268 meaningless: devices, cad, muxsel,
269 waithead, waittail, flags, pdir,
270 ieee1284, *_lock.
272 It this is a default mux parport, or
273 there is no mux involved, this points to
274 ourself. */
276 struct pardevice *devices;
277 struct pardevice *cad; /* port owner */
278 int daisy; /* currently selected daisy addr */
279 int muxsel; /* currently selected mux port */
281 struct pardevice *waithead;
282 struct pardevice *waittail;
284 struct parport *next;
285 unsigned int flags;
287 void *sysctl_table;
288 struct parport_device_info probe_info[5]; /* 0-3 + non-IEEE1284.3 */
289 struct ieee1284_info ieee1284;
291 struct parport_operations *ops;
292 void *private_data; /* for lowlevel driver */
294 int number; /* port index - the `n' in `parportn' */
295 spinlock_t pardevice_lock;
296 spinlock_t waitlist_lock;
297 rwlock_t cad_lock;
299 int spintime;
302 #define DEFAULT_SPIN_TIME 500 /* us */
304 struct parport_driver {
305 const char *name;
306 void (*attach) (struct parport *);
307 void (*detach) (struct parport *);
308 struct parport_driver *next;
311 /* parport_register_port registers a new parallel port at the given
312 address (if one does not already exist) and returns a pointer to it.
313 This entails claiming the I/O region, IRQ and DMA. NULL is returned
314 if initialisation fails. */
315 struct parport *parport_register_port(unsigned long base, int irq, int dma,
316 struct parport_operations *ops);
318 /* Once a registered port is ready for high-level drivers to use, the
319 low-level driver that registered it should announce it. This will
320 call the high-level drivers' attach() functions (after things like
321 determining the IEEE 1284.3 topology of the port and collecting
322 DeviceIDs). */
323 void parport_announce_port (struct parport *port);
325 /* Unregister a port. */
326 extern void parport_unregister_port(struct parport *port);
328 /* parport_in_use returns nonzero if there are devices attached to a
329 port. */
330 #define parport_in_use(x) ((x)->devices != NULL)
332 /* parport_enumerate returns a pointer to the linked list of all the
333 ports in this machine. */
334 struct parport *parport_enumerate(void);
336 /* Register a new high-level driver. */
337 extern int parport_register_driver (struct parport_driver *);
339 /* Unregister a high-level driver. */
340 extern void parport_unregister_driver (struct parport_driver *);
342 /* parport_register_device declares that a device is connected to a
343 port, and tells the kernel all it needs to know. pf is the
344 preemption function (may be NULL for no callback) kf is the wake-up
345 function (may be NULL for no callback) irq_func is the interrupt
346 handler (may be NULL for no interrupts) handle is a user pointer
347 that gets handed to callback functions. */
348 struct pardevice *parport_register_device(struct parport *port,
349 const char *name,
350 int (*pf)(void *), void (*kf)(void *),
351 void (*irq_func)(int, void *, struct pt_regs *),
352 int flags, void *handle);
354 /* parport_unregister unlinks a device from the chain. */
355 extern void parport_unregister_device(struct pardevice *dev);
357 /* parport_claim tries to gain ownership of the port for a particular
358 driver. This may fail (return non-zero) if another driver is busy.
359 If this driver has registered an interrupt handler, it will be
360 enabled. */
361 extern int parport_claim(struct pardevice *dev);
363 /* parport_claim_or_block is the same, but sleeps if the port cannot
364 be claimed. Return value is 1 if it slept, 0 normally and -errno
365 on error. */
366 extern int parport_claim_or_block(struct pardevice *dev);
368 /* parport_release reverses a previous parport_claim. This can never
369 fail, though the effects are undefined (except that they are bad)
370 if you didn't previously own the port. Once you have released the
371 port you should make sure that neither your code nor the hardware
372 on the port tries to initiate any communication without first
373 re-claiming the port. If you mess with the port state (enabling
374 ECP for example) you should clean up before releasing the port. */
376 extern void parport_release(struct pardevice *dev);
378 /* parport_yield relinquishes the port if it would be helpful to other
379 drivers. The return value is the same as for parport_claim. */
380 extern __inline__ int parport_yield(struct pardevice *dev)
382 unsigned long int timeslip = (jiffies - dev->time);
383 if ((dev->port->waithead == NULL) || (timeslip < dev->timeslice))
384 return 0;
385 parport_release(dev);
386 return parport_claim(dev);
389 /* parport_yield_blocking is the same but uses parport_claim_or_block
390 instead of parport_claim. */
391 extern __inline__ int parport_yield_blocking(struct pardevice *dev)
393 unsigned long int timeslip = (jiffies - dev->time);
394 if ((dev->port->waithead == NULL) || (timeslip < dev->timeslice))
395 return 0;
396 parport_release(dev);
397 return parport_claim_or_block(dev);
400 /* Flags used to identify what a device does. */
401 #define PARPORT_DEV_TRAN 0 /* WARNING !! DEPRECATED !! */
402 #define PARPORT_DEV_LURK (1<<0) /* WARNING !! DEPRECATED !! */
403 #define PARPORT_DEV_EXCL (1<<1) /* Need exclusive access. */
405 #define PARPORT_FLAG_EXCL (1<<1) /* EXCL driver registered. */
407 extern int parport_parse_irqs(int, const char *[], int irqval[]);
408 extern int parport_parse_dmas(int, const char *[], int dmaval[]);
410 /* IEEE1284 functions */
411 extern void parport_ieee1284_interrupt (int, void *, struct pt_regs *);
412 extern int parport_negotiate (struct parport *, int mode);
413 extern ssize_t parport_write (struct parport *, const void *buf, size_t len);
414 extern ssize_t parport_read (struct parport *, void *buf, size_t len);
415 extern long parport_set_timeout (struct pardevice *, long inactivity);
416 extern int parport_wait_event (struct parport *, long timeout);
417 extern int parport_wait_peripheral (struct parport *port,
418 unsigned char mask,
419 unsigned char val);
421 /* For architectural drivers */
422 extern void parport_ieee1284_wakeup (struct parport *port);
423 extern size_t parport_ieee1284_write_compat (struct parport *,
424 const void *, size_t, int);
425 extern size_t parport_ieee1284_read_nibble (struct parport *,
426 void *, size_t, int);
427 extern size_t parport_ieee1284_read_byte (struct parport *,
428 void *, size_t, int);
429 extern size_t parport_ieee1284_ecp_read_data (struct parport *,
430 void *, size_t, int);
431 extern size_t parport_ieee1284_ecp_write_data (struct parport *,
432 const void *, size_t, int);
433 extern size_t parport_ieee1284_ecp_write_addr (struct parport *,
434 const void *, size_t, int);
435 extern size_t parport_ieee1284_epp_write_data (struct parport *,
436 const void *, size_t, int);
437 extern size_t parport_ieee1284_epp_read_data (struct parport *,
438 void *, size_t, int);
439 extern size_t parport_ieee1284_epp_write_addr (struct parport *,
440 const void *, size_t, int);
441 extern size_t parport_ieee1284_epp_read_addr (struct parport *,
442 void *, size_t, int);
444 /* IEEE1284.3 functions */
445 extern int parport_daisy_init (struct parport *port);
446 extern void parport_daisy_fini (struct parport *port);
447 extern struct pardevice *parport_open (int devnum, const char *name,
448 int (*pf) (void *),
449 void (*kf) (void *),
450 void (*irqf) (int, void *,
451 struct pt_regs *),
452 int flags, void *handle);
453 extern void parport_close (struct pardevice *dev);
454 extern ssize_t parport_device_id (int devnum, char *buffer, size_t len);
455 extern int parport_device_num (int parport, int mux, int daisy);
456 extern int parport_device_coords (int devnum, int *parport, int *mux,
457 int *daisy);
458 extern void parport_daisy_deselect_all (struct parport *port);
459 extern int parport_daisy_select (struct parport *port, int daisy, int mode);
461 /* For finding devices based on their device ID. Example usage:
462 int devnum = -1;
463 while ((devnum = parport_find_class (PARPORT_CLASS_DIGCAM, devnum)) != -1) {
464 struct pardevice *dev = parport_open (devnum, ...);
468 extern int parport_find_device (const char *mfg, const char *mdl, int from);
469 extern int parport_find_class (parport_device_class cls, int from);
471 /* Lowlevel drivers _can_ call this support function to handle irqs. */
472 extern __inline__ void parport_generic_irq(int irq, struct parport *port,
473 struct pt_regs *regs)
475 parport_ieee1284_interrupt (irq, port, regs);
476 read_lock(&port->cad_lock);
477 if (port->cad && port->cad->irq_func)
478 port->cad->irq_func(irq, port->cad->private, regs);
479 read_unlock(&port->cad_lock);
482 /* Prototypes from parport_procfs */
483 extern int parport_proc_register(struct parport *pp);
484 extern int parport_proc_unregister(struct parport *pp);
485 extern int parport_device_proc_register(struct pardevice *device);
486 extern int parport_device_proc_unregister(struct pardevice *device);
487 extern int parport_default_proc_register(void);
488 extern int parport_default_proc_unregister(void);
490 extern void dec_parport_count(void);
491 extern void inc_parport_count(void);
493 /* If PC hardware is the only type supported, we can optimise a bit. */
494 #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)
496 #undef PARPORT_NEED_GENERIC_OPS
497 #include <linux/parport_pc.h>
498 #define parport_write_data(p,x) parport_pc_write_data(p,x)
499 #define parport_read_data(p) parport_pc_read_data(p)
500 #define parport_write_control(p,x) parport_pc_write_control(p,x)
501 #define parport_read_control(p) parport_pc_read_control(p)
502 #define parport_frob_control(p,m,v) parport_pc_frob_control(p,m,v)
503 #define parport_read_status(p) parport_pc_read_status(p)
504 #define parport_enable_irq(p) parport_pc_enable_irq(p)
505 #define parport_disable_irq(p) parport_pc_disable_irq(p)
506 #define parport_data_forward(p) parport_pc_data_forward(p)
507 #define parport_data_reverse(p) parport_pc_data_reverse(p)
508 #endif
510 #ifdef PARPORT_NEED_GENERIC_OPS
511 /* Generic operations vector through the dispatch table. */
512 #define parport_write_data(p,x) (p)->ops->write_data(p,x)
513 #define parport_read_data(p) (p)->ops->read_data(p)
514 #define parport_write_control(p,x) (p)->ops->write_control(p,x)
515 #define parport_read_control(p) (p)->ops->read_control(p)
516 #define parport_frob_control(p,m,v) (p)->ops->frob_control(p,m,v)
517 #define parport_read_status(p) (p)->ops->read_status(p)
518 #define parport_enable_irq(p) (p)->ops->enable_irq(p)
519 #define parport_disable_irq(p) (p)->ops->disable_irq(p)
520 #define parport_data_forward(p) (p)->ops->data_forward(p)
521 #define parport_data_reverse(p) (p)->ops->data_reverse(p)
522 #endif
524 #endif /* __KERNEL__ */
525 #endif /* _PARPORT_H_ */