1 /* $Id: parport.h,v 1.1 1998/05/17 10:57:52 andrea Exp andrea $ */
6 /* Start off with user-visible constants */
8 /* Maximum of 8 ports per machine */
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
23 #define PARPORT_CONTROL_INTEN 0x10
24 #define PARPORT_CONTROL_DIRECTION 0x20
26 #define PARPORT_STATUS_ERROR 0x8
27 #define PARPORT_STATUS_SELECT 0x10
28 #define PARPORT_STATUS_PAPEROUT 0x20
29 #define PARPORT_STATUS_ACK 0x40
30 #define PARPORT_STATUS_BUSY 0x80
32 /* Type classes for Plug-and-Play probe. */
34 PARPORT_CLASS_LEGACY
= 0, /* Non-IEEE1284 device */
35 PARPORT_CLASS_PRINTER
,
38 PARPORT_CLASS_HDC
, /* Hard disk controller */
40 PARPORT_CLASS_MEDIA
, /* Multimedia device */
41 PARPORT_CLASS_FDC
, /* Floppy disk controller */
43 PARPORT_CLASS_SCANNER
,
45 PARPORT_CLASS_OTHER
, /* Anything else */
46 PARPORT_CLASS_UNSPEC
/* No CLS field in ID */
47 } parport_device_class
;
49 /* The "modes" entry in parport is a bit field representing the following
51 * Note that PARPORT_MODE_PCECPEPP is for the SMC EPP+ECP mode which is NOT
52 * 100% compatible with EPP.
54 #define PARPORT_MODE_PCSPP 0x0001
55 #define PARPORT_MODE_PCPS2 0x0002
56 #define PARPORT_MODE_PCEPP 0x0004
57 #define PARPORT_MODE_PCECP 0x0008
58 #define PARPORT_MODE_PCECPEPP 0x0010
59 #define PARPORT_MODE_PCECR 0x0020 /* ECR Register Exists */
60 #define PARPORT_MODE_PCECPPS2 0x0040
62 /* The rest is for the kernel only */
65 #include <asm/system.h>
66 #include <asm/ptrace.h>
67 #include <asm/spinlock.h>
68 #include <linux/proc_fs.h>
69 #include <linux/config.h>
71 #define PARPORT_NEED_GENERIC_OPS
73 /* Define this later. */
76 struct pc_parport_state
{
81 struct parport_state
{
83 struct pc_parport_state pc
;
84 /* ARC has no state. */
85 /* AX uses same state information as PC */
90 struct parport_operations
{
91 void (*write_data
)(struct parport
*, unsigned char);
92 unsigned char (*read_data
)(struct parport
*);
93 void (*write_control
)(struct parport
*, unsigned char);
94 unsigned char (*read_control
)(struct parport
*);
95 unsigned char (*frob_control
)(struct parport
*, unsigned char mask
, unsigned char val
);
96 void (*write_econtrol
)(struct parport
*, unsigned char);
97 unsigned char (*read_econtrol
)(struct parport
*);
98 unsigned char (*frob_econtrol
)(struct parport
*, unsigned char mask
, unsigned char val
);
99 void (*write_status
)(struct parport
*, unsigned char);
100 unsigned char (*read_status
)(struct parport
*);
101 void (*write_fifo
)(struct parport
*, unsigned char);
102 unsigned char (*read_fifo
)(struct parport
*);
104 void (*change_mode
)(struct parport
*, int);
106 void (*epp_write_data
)(struct parport
*, unsigned char);
107 unsigned char (*epp_read_data
)(struct parport
*);
108 void (*epp_write_addr
)(struct parport
*, unsigned char);
109 unsigned char (*epp_read_addr
)(struct parport
*);
110 int (*epp_check_timeout
)(struct parport
*);
111 size_t (*epp_write_block
)(struct parport
*, void *, size_t);
112 size_t (*epp_read_block
)(struct parport
*, void *, size_t);
114 int (*ecp_write_block
)(struct parport
*, void *, size_t, void (*fn
)(struct parport
*, void *, size_t), void *);
115 int (*ecp_read_block
)(struct parport
*, void *, size_t, void (*fn
)(struct parport
*, void *, size_t), void *);
117 void (*init_state
)(struct parport_state
*);
118 void (*save_state
)(struct parport
*, struct parport_state
*);
119 void (*restore_state
)(struct parport
*, struct parport_state
*);
121 void (*enable_irq
)(struct parport
*);
122 void (*disable_irq
)(struct parport
*);
123 void (*interrupt
)(int, void *, struct pt_regs
*);
125 void (*inc_use_count
)(void);
126 void (*dec_use_count
)(void);
127 void (*fill_inode
)(struct inode
*inode
, int fill
);
130 struct parport_device_info
{
131 parport_device_class
class;
132 const char *class_name
;
136 const char *description
;
139 /* Each device can have two callback functions:
140 * 1) a preemption function, called by the resource manager to request
141 * that the driver relinquish control of the port. The driver should
142 * return zero if it agrees to release the port, and nonzero if it
143 * refuses. Do not call parport_release() - the kernel will do this
146 * 2) a wake-up function, called by the resource manager to tell drivers
147 * that the port is available to be claimed. If a driver wants to use
148 * the port, it should call parport_claim() here.
151 /* A parallel port device */
154 struct parport
*port
;
155 int (*preempt
)(void *);
156 void (*wakeup
)(void *);
158 void (*irq_func
)(int, void *, struct pt_regs
*);
160 struct pardevice
*next
;
161 struct pardevice
*prev
;
162 struct parport_state
*state
; /* saved status over preemption */
163 wait_queue_head_t wait_q
;
164 unsigned long int time
;
165 unsigned long int timeslice
;
166 unsigned int waiting
;
167 struct pardevice
*waitprev
;
168 struct pardevice
*waitnext
;
172 /* Directory information for the /proc interface */
174 struct proc_dir_entry
*entry
; /* Directory /proc/parport/X */
175 struct proc_dir_entry
*irq
; /* .../irq */
176 struct proc_dir_entry
*devices
; /* .../devices */
177 struct proc_dir_entry
*hardware
; /* .../hardware */
178 struct proc_dir_entry
*probe
; /* .../autoprobe */
182 /* A parallel port */
184 unsigned long base
; /* base address */
185 unsigned long base_hi
; /* base address (ECR) */
186 unsigned int size
; /* IO extent */
188 int irq
; /* interrupt (or -1 for none) */
192 struct pardevice
*devices
;
193 struct pardevice
*cad
; /* port owner */
195 struct pardevice
*waithead
;
196 struct pardevice
*waittail
;
198 struct parport
*next
;
201 struct parport_dir pdir
;
202 struct parport_device_info probe_info
;
204 struct parport_operations
*ops
;
205 void *private_data
; /* for lowlevel driver */
207 int number
; /* port index - the `n' in `parportn' */
208 spinlock_t pardevice_lock
;
209 spinlock_t waitlist_lock
;
214 struct parport_driver
{
216 void (*attach
) (struct parport
*);
217 void (*detach
) (struct parport
*);
218 struct parport_driver
*next
;
221 /* parport_register_port registers a new parallel port at the given address (if
222 * one does not already exist) and returns a pointer to it. This entails
223 * claiming the I/O region, IRQ and DMA.
224 * NULL is returned if initialisation fails.
226 struct parport
*parport_register_port(unsigned long base
, int irq
, int dma
,
227 struct parport_operations
*ops
);
229 /* Once a registered port is ready for high-level drivers to use, the
230 low-level driver that registered it should announce it. This will
231 call the high-level drivers' attach() functions (after things like
232 determining the IEEE 1284.3 topology of the port and collecting
234 void parport_announce_port (struct parport
*port
);
236 /* Unregister a port. */
237 extern void parport_unregister_port(struct parport
*port
);
239 /* parport_in_use returns nonzero if there are devices attached to a port. */
240 #define parport_in_use(x) ((x)->devices != NULL)
242 /* parport_enumerate returns a pointer to the linked list of all the ports
245 struct parport
*parport_enumerate(void);
247 /* Register a new high-level driver. */
248 extern int parport_register_driver (struct parport_driver
*);
250 /* Unregister a high-level driver. */
251 extern void parport_unregister_driver (struct parport_driver
*);
253 /* parport_register_device declares that a device is connected to a port, and
254 * tells the kernel all it needs to know.
255 * pf is the preemption function (may be NULL for no callback)
256 * kf is the wake-up function (may be NULL for no callback)
257 * irq_func is the interrupt handler (may be NULL for no interrupts)
258 * handle is a user pointer that gets handed to callback functions.
260 struct pardevice
*parport_register_device(struct parport
*port
,
262 int (*pf
)(void *), void (*kf
)(void *),
263 void (*irq_func
)(int, void *, struct pt_regs
*),
264 int flags
, void *handle
);
266 /* parport_unregister unlinks a device from the chain. */
267 extern void parport_unregister_device(struct pardevice
*dev
);
269 /* parport_claim tries to gain ownership of the port for a particular driver.
270 * This may fail (return non-zero) if another driver is busy. If this
271 * driver has registered an interrupt handler, it will be enabled.
273 extern int parport_claim(struct pardevice
*dev
);
275 /* parport_claim_or_block is the same, but sleeps if the port cannot be
276 claimed. Return value is 1 if it slept, 0 normally and -errno on error. */
277 extern int parport_claim_or_block(struct pardevice
*dev
);
279 /* parport_release reverses a previous parport_claim. This can never fail,
280 * though the effects are undefined (except that they are bad) if you didn't
281 * previously own the port. Once you have released the port you should make
282 * sure that neither your code nor the hardware on the port tries to initiate
283 * any communication without first re-claiming the port.
284 * If you mess with the port state (enabling ECP for example) you should
285 * clean up before releasing the port.
288 extern void parport_release(struct pardevice
*dev
);
290 /* parport_yield relinquishes the port if it would be helpful to other
291 * drivers. The return value is the same as for parport_claim.
293 extern __inline__
int parport_yield(struct pardevice
*dev
)
295 unsigned long int timeslip
= (jiffies
- dev
->time
);
296 if ((dev
->port
->waithead
== NULL
) || (timeslip
< dev
->timeslice
))
298 parport_release(dev
);
299 return parport_claim(dev
);
302 /* parport_yield_blocking is the same but uses parport_claim_or_block
303 * instead of parport_claim.
305 extern __inline__
int parport_yield_blocking(struct pardevice
*dev
)
307 unsigned long int timeslip
= (jiffies
- dev
->time
);
308 if ((dev
->port
->waithead
== NULL
) || (timeslip
< dev
->timeslice
))
310 parport_release(dev
);
311 return parport_claim_or_block(dev
);
315 * Lowlevel drivers _can_ call this support function to handle irqs.
317 extern __inline__
void parport_generic_irq(int irq
, struct parport
*port
,
318 struct pt_regs
*regs
)
320 read_lock(&port
->cad_lock
);
323 if (port
->cad
->irq_func
)
324 port
->cad
->irq_func(irq
, port
->cad
->private, regs
);
326 printk(KERN_ERR
"%s: irq%d happened with irq_func NULL "
327 "with %s as cad!\n", port
->name
, irq
, port
->cad
->name
);
329 read_unlock(&port
->cad_lock
);
332 /* Flags used to identify what a device does. */
333 #define PARPORT_DEV_TRAN 0 /* WARNING !! DEPRECATED !! */
334 #define PARPORT_DEV_LURK (1<<0) /* WARNING !! DEPRECATED !! */
335 #define PARPORT_DEV_EXCL (1<<1) /* Need exclusive access. */
337 #define PARPORT_FLAG_COMA_ (1<<0) /* No longer used. */
338 #define PARPORT_FLAG_EXCL (1<<1) /* EXCL driver registered. */
340 extern int parport_parse_irqs(int, const char *[], int irqval
[]);
341 extern int parport_parse_dmas(int, const char *[], int irqval
[]);
342 extern int parport_ieee1284_nibble_mode_ok(struct parport
*, unsigned char);
343 extern int parport_wait_peripheral(struct parport
*, unsigned char, unsigned
346 /* Prototypes from parport_procfs */
347 extern int parport_proc_register(struct parport
*pp
);
348 extern int parport_proc_unregister(struct parport
*pp
);
349 extern int parport_device_proc_register(struct pardevice
*device
);
350 extern int parport_device_proc_unregister(struct pardevice
*device
);
351 extern int parport_default_proc_register(void);
352 extern int parport_default_proc_unregister(void);
354 extern void dec_parport_count(void);
355 extern void inc_parport_count(void);
357 extern int parport_probe(struct parport
*port
, char *buffer
, int len
);
358 extern void parport_probe_one(struct parport
*port
);
359 extern void (*parport_probe_hook
)(struct parport
*port
);
361 /* If PC hardware is the only type supported, we can optimise a bit. */
362 #if (defined(CONFIG_PARPORT_PC) || defined(CONFIG_PARPORT_PC_MODULE)) && !(defined(CONFIG_PARPORT_AX) || defined(CONFIG_PARPORT_AX_MODULE)) && !(defined(CONFIG_PARPORT_ARC) || defined(CONFIG_PARPORT_ARC_MODULE)) && !defined(CONFIG_PARPORT_OTHER)
363 #undef PARPORT_NEED_GENERIC_OPS
364 #include <linux/parport_pc.h>
365 #define parport_write_data(p,x) parport_pc_write_data(p,x)
366 #define parport_read_data(p) parport_pc_read_data(p)
367 #define parport_write_control(p,x) parport_pc_write_control(p,x)
368 #define parport_read_control(p) parport_pc_read_control(p)
369 #define parport_frob_control(p,m,v) parport_pc_frob_control(p,m,v)
370 #define parport_write_econtrol(p,x) parport_pc_write_econtrol(p,x)
371 #define parport_read_econtrol(p) parport_pc_read_econtrol(p)
372 #define parport_frob_econtrol(p,m,v) parport_pc_frob_econtrol(p,m,v)
373 #define parport_write_status(p,v) parport_pc_write_status(p,v)
374 #define parport_read_status(p) parport_pc_read_status(p)
375 #define parport_write_fifo(p,v) parport_pc_write_fifo(p,v)
376 #define parport_read_fifo(p) parport_pc_read_fifo(p)
377 #define parport_change_mode(p,m) parport_pc_change_mode(p,m)
378 #define parport_release_resources(p) parport_pc_release_resources(p)
379 #define parport_claim_resources(p) parport_pc_claim_resources(p)
380 #define parport_epp_write_data(p,x) parport_pc_write_epp(p,x)
381 #define parport_epp_read_data(p) parport_pc_read_epp(p)
382 #define parport_epp_write_addr(p,x) parport_pc_write_epp_addr(p,x)
383 #define parport_epp_read_addr(p) parport_pc_read_epp_addr(p)
384 #define parport_epp_check_timeout(p) parport_pc_check_epp_timeout(p)
387 #ifdef PARPORT_NEED_GENERIC_OPS
388 /* Generic operations vector through the dispatch table. */
389 #define parport_write_data(p,x) (p)->ops->write_data(p,x)
390 #define parport_read_data(p) (p)->ops->read_data(p)
391 #define parport_write_control(p,x) (p)->ops->write_control(p,x)
392 #define parport_read_control(p) (p)->ops->read_control(p)
393 #define parport_frob_control(p,m,v) (p)->ops->frob_control(p,m,v)
394 #define parport_write_econtrol(p,x) (p)->ops->write_econtrol(p,x)
395 #define parport_read_econtrol(p) (p)->ops->read_econtrol(p)
396 #define parport_frob_econtrol(p,m,v) (p)->ops->frob_econtrol(p,m,v)
397 #define parport_write_status(p,v) (p)->ops->write_status(p,v)
398 #define parport_read_status(p) (p)->ops->read_status(p)
399 #define parport_write_fifo(p,v) (p)->ops->write_fifo(p,v)
400 #define parport_read_fifo(p) (p)->ops->read_fifo(p)
401 #define parport_change_mode(p,m) (p)->ops->change_mode(p,m)
402 #define parport_release_resources(p) (p)->ops->release_resources(p)
403 #define parport_claim_resources(p) (p)->ops->claim_resources(p)
404 #define parport_epp_write_data(p,x) (p)->ops->epp_write_data(p,x)
405 #define parport_epp_read_data(p) (p)->ops->epp_read_data(p)
406 #define parport_epp_write_addr(p,x) (p)->ops->epp_write_addr(p,x)
407 #define parport_epp_read_addr(p) (p)->ops->epp_read_addr(p)
408 #define parport_epp_check_timeout(p) (p)->ops->epp_check_timeout(p)
411 #endif /* __KERNEL__ */
412 #endif /* _PARPORT_H_ */