1
2
3
4
5
6#ifndef _PARPORT_H_
7#define _PARPORT_H_
8
9
10#include <linux/jiffies.h>
11#include <linux/proc_fs.h>
12#include <linux/spinlock.h>
13#include <linux/wait.h>
14#include <linux/irqreturn.h>
15#include <linux/semaphore.h>
16#include <linux/device.h>
17#include <asm/ptrace.h>
18#include <uapi/linux/parport.h>
19
20
21struct parport;
22struct pardevice;
23
24struct pc_parport_state {
25 unsigned int ctr;
26 unsigned int ecr;
27};
28
29struct ax_parport_state {
30 unsigned int ctr;
31 unsigned int ecr;
32 unsigned int dcsr;
33};
34
35
36struct amiga_parport_state {
37 unsigned char data;
38 unsigned char datadir;
39 unsigned char status;
40 unsigned char statusdir;
41};
42
43struct ax88796_parport_state {
44 unsigned char cpr;
45};
46
47struct ip32_parport_state {
48 unsigned int dcr;
49 unsigned int ecr;
50};
51
52struct parport_state {
53 union {
54 struct pc_parport_state pc;
55
56 struct ax_parport_state ax;
57 struct amiga_parport_state amiga;
58 struct ax88796_parport_state ax88796;
59
60 struct ip32_parport_state ip32;
61 void *misc;
62 } u;
63};
64
65struct parport_operations {
66
67 void (*write_data)(struct parport *, unsigned char);
68 unsigned char (*read_data)(struct parport *);
69
70 void (*write_control)(struct parport *, unsigned char);
71 unsigned char (*read_control)(struct parport *);
72 unsigned char (*frob_control)(struct parport *, unsigned char mask,
73 unsigned char val);
74
75 unsigned char (*read_status)(struct parport *);
76
77
78 void (*enable_irq)(struct parport *);
79 void (*disable_irq)(struct parport *);
80
81
82 void (*data_forward) (struct parport *);
83 void (*data_reverse) (struct parport *);
84
85
86 void (*init_state)(struct pardevice *, struct parport_state *);
87 void (*save_state)(struct parport *, struct parport_state *);
88 void (*restore_state)(struct parport *, struct parport_state *);
89
90
91 size_t (*epp_write_data) (struct parport *port, const void *buf,
92 size_t len, int flags);
93 size_t (*epp_read_data) (struct parport *port, void *buf, size_t len,
94 int flags);
95 size_t (*epp_write_addr) (struct parport *port, const void *buf,
96 size_t len, int flags);
97 size_t (*epp_read_addr) (struct parport *port, void *buf, size_t len,
98 int flags);
99
100 size_t (*ecp_write_data) (struct parport *port, const void *buf,
101 size_t len, int flags);
102 size_t (*ecp_read_data) (struct parport *port, void *buf, size_t len,
103 int flags);
104 size_t (*ecp_write_addr) (struct parport *port, const void *buf,
105 size_t len, int flags);
106
107 size_t (*compat_write_data) (struct parport *port, const void *buf,
108 size_t len, int flags);
109 size_t (*nibble_read_data) (struct parport *port, void *buf,
110 size_t len, int flags);
111 size_t (*byte_read_data) (struct parport *port, void *buf,
112 size_t len, int flags);
113 struct module *owner;
114};
115
116struct parport_device_info {
117 parport_device_class class;
118 const char *class_name;
119 const char *mfr;
120 const char *model;
121 const char *cmdset;
122 const char *description;
123};
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138struct pardevice {
139 const char *name;
140 struct parport *port;
141 int daisy;
142 int (*preempt)(void *);
143 void (*wakeup)(void *);
144 void *private;
145 void (*irq_func)(void *);
146 unsigned int flags;
147 struct pardevice *next;
148 struct pardevice *prev;
149 struct device dev;
150 bool devmodel;
151 struct parport_state *state;
152 wait_queue_head_t wait_q;
153 unsigned long int time;
154 unsigned long int timeslice;
155 volatile long int timeout;
156 unsigned long waiting;
157 struct pardevice *waitprev;
158 struct pardevice *waitnext;
159 void * sysctl_table;
160};
161
162#define to_pardevice(n) container_of(n, struct pardevice, dev)
163
164
165
166
167
168enum ieee1284_phase {
169 IEEE1284_PH_FWD_DATA,
170 IEEE1284_PH_FWD_IDLE,
171 IEEE1284_PH_TERMINATE,
172 IEEE1284_PH_NEGOTIATION,
173 IEEE1284_PH_HBUSY_DNA,
174 IEEE1284_PH_REV_IDLE,
175 IEEE1284_PH_HBUSY_DAVAIL,
176 IEEE1284_PH_REV_DATA,
177 IEEE1284_PH_ECP_SETUP,
178 IEEE1284_PH_ECP_FWD_TO_REV,
179 IEEE1284_PH_ECP_REV_TO_FWD,
180 IEEE1284_PH_ECP_DIR_UNKNOWN,
181};
182struct ieee1284_info {
183 int mode;
184 volatile enum ieee1284_phase phase;
185 struct semaphore irq;
186};
187
188
189struct parport {
190 unsigned long base;
191 unsigned long base_hi;
192 unsigned int size;
193 const char *name;
194 unsigned int modes;
195 int irq;
196 int dma;
197 int muxport;
198 int portnum;
199 struct device *dev;
200
201
202
203 struct device bus_dev;
204 struct parport *physport;
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219 struct pardevice *devices;
220 struct pardevice *cad;
221 int daisy;
222 int muxsel;
223
224 struct pardevice *waithead;
225 struct pardevice *waittail;
226
227 struct list_head list;
228 unsigned int flags;
229
230 void *sysctl_table;
231 struct parport_device_info probe_info[5];
232 struct ieee1284_info ieee1284;
233
234 struct parport_operations *ops;
235 void *private_data;
236
237 int number;
238 spinlock_t pardevice_lock;
239 spinlock_t waitlist_lock;
240 rwlock_t cad_lock;
241
242 int spintime;
243 atomic_t ref_count;
244
245 unsigned long devflags;
246#define PARPORT_DEVPROC_REGISTERED 0
247 struct pardevice *proc_device;
248
249 struct list_head full_list;
250 struct parport *slaves[3];
251};
252
253#define to_parport_dev(n) container_of(n, struct parport, bus_dev)
254
255#define DEFAULT_SPIN_TIME 500
256
257struct parport_driver {
258 const char *name;
259 void (*attach) (struct parport *);
260 void (*detach) (struct parport *);
261 void (*match_port)(struct parport *);
262 int (*probe)(struct pardevice *);
263 struct device_driver driver;
264 bool devmodel;
265 struct list_head list;
266};
267
268#define to_parport_driver(n) container_of(n, struct parport_driver, driver)
269
270int parport_bus_init(void);
271void parport_bus_exit(void);
272
273
274
275
276
277struct parport *parport_register_port(unsigned long base, int irq, int dma,
278 struct parport_operations *ops);
279
280
281
282
283
284
285void parport_announce_port (struct parport *port);
286
287
288extern void parport_remove_port(struct parport *port);
289
290
291
292int __must_check __parport_register_driver(struct parport_driver *,
293 struct module *,
294 const char *mod_name);
295
296
297
298
299#define parport_register_driver(driver) \
300 __parport_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
301
302
303extern void parport_unregister_driver (struct parport_driver *);
304void parport_unregister_driver(struct parport_driver *);
305
306
307
308extern struct parport *parport_find_number (int);
309extern struct parport *parport_find_base (unsigned long);
310
311
312extern irqreturn_t parport_irq_handler(int irq, void *dev_id);
313
314
315extern struct parport *parport_get_port (struct parport *);
316extern void parport_put_port (struct parport *);
317void parport_del_port(struct parport *);
318
319struct pardev_cb {
320 int (*preempt)(void *);
321 void (*wakeup)(void *);
322 void *private;
323 void (*irq_func)(void *);
324 unsigned int flags;
325};
326
327
328
329
330
331
332
333struct pardevice *parport_register_device(struct parport *port,
334 const char *name,
335 int (*pf)(void *), void (*kf)(void *),
336 void (*irq_func)(void *),
337 int flags, void *handle);
338
339struct pardevice *
340parport_register_dev_model(struct parport *port, const char *name,
341 const struct pardev_cb *par_dev_cb, int cnt);
342
343
344extern void parport_unregister_device(struct pardevice *dev);
345
346
347
348
349
350extern int parport_claim(struct pardevice *dev);
351
352
353
354
355extern int parport_claim_or_block(struct pardevice *dev);
356
357
358
359
360
361
362
363
364
365extern void parport_release(struct pardevice *dev);
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387static __inline__ int parport_yield(struct pardevice *dev)
388{
389 unsigned long int timeslip = (jiffies - dev->time);
390 if ((dev->port->waithead == NULL) || (timeslip < dev->timeslice))
391 return 0;
392 parport_release(dev);
393 return parport_claim(dev);
394}
395
396
397
398
399
400
401
402
403
404
405static __inline__ int parport_yield_blocking(struct pardevice *dev)
406{
407 unsigned long int timeslip = (jiffies - dev->time);
408 if ((dev->port->waithead == NULL) || (timeslip < dev->timeslice))
409 return 0;
410 parport_release(dev);
411 return parport_claim_or_block(dev);
412}
413
414
415#define PARPORT_DEV_TRAN 0
416#define PARPORT_DEV_LURK (1<<0)
417#define PARPORT_DEV_EXCL (1<<1)
418
419#define PARPORT_FLAG_EXCL (1<<1)
420
421
422extern void parport_ieee1284_interrupt (void *);
423extern int parport_negotiate (struct parport *, int mode);
424extern ssize_t parport_write (struct parport *, const void *buf, size_t len);
425extern ssize_t parport_read (struct parport *, void *buf, size_t len);
426
427#define PARPORT_INACTIVITY_O_NONBLOCK 1
428extern long parport_set_timeout (struct pardevice *, long inactivity);
429
430extern int parport_wait_event (struct parport *, long timeout);
431extern int parport_wait_peripheral (struct parport *port,
432 unsigned char mask,
433 unsigned char val);
434extern int parport_poll_peripheral (struct parport *port,
435 unsigned char mask,
436 unsigned char val,
437 int usec);
438
439
440extern size_t parport_ieee1284_write_compat (struct parport *,
441 const void *, size_t, int);
442extern size_t parport_ieee1284_read_nibble (struct parport *,
443 void *, size_t, int);
444extern size_t parport_ieee1284_read_byte (struct parport *,
445 void *, size_t, int);
446extern size_t parport_ieee1284_ecp_read_data (struct parport *,
447 void *, size_t, int);
448extern size_t parport_ieee1284_ecp_write_data (struct parport *,
449 const void *, size_t, int);
450extern size_t parport_ieee1284_ecp_write_addr (struct parport *,
451 const void *, size_t, int);
452extern size_t parport_ieee1284_epp_write_data (struct parport *,
453 const void *, size_t, int);
454extern size_t parport_ieee1284_epp_read_data (struct parport *,
455 void *, size_t, int);
456extern size_t parport_ieee1284_epp_write_addr (struct parport *,
457 const void *, size_t, int);
458extern size_t parport_ieee1284_epp_read_addr (struct parport *,
459 void *, size_t, int);
460
461
462extern int parport_daisy_init (struct parport *port);
463extern void parport_daisy_fini (struct parport *port);
464extern struct pardevice *parport_open (int devnum, const char *name);
465extern void parport_close (struct pardevice *dev);
466extern ssize_t parport_device_id (int devnum, char *buffer, size_t len);
467extern void parport_daisy_deselect_all (struct parport *port);
468extern int parport_daisy_select (struct parport *port, int daisy, int mode);
469
470
471static inline void parport_generic_irq(struct parport *port)
472{
473 parport_ieee1284_interrupt (port);
474 read_lock(&port->cad_lock);
475 if (port->cad && port->cad->irq_func)
476 port->cad->irq_func(port->cad->private);
477 read_unlock(&port->cad_lock);
478}
479
480
481extern int parport_proc_register(struct parport *pp);
482extern int parport_proc_unregister(struct parport *pp);
483extern int parport_device_proc_register(struct pardevice *device);
484extern int parport_device_proc_unregister(struct pardevice *device);
485
486
487#if !defined(CONFIG_PARPORT_NOT_PC)
488
489#include <linux/parport_pc.h>
490#define parport_write_data(p,x) parport_pc_write_data(p,x)
491#define parport_read_data(p) parport_pc_read_data(p)
492#define parport_write_control(p,x) parport_pc_write_control(p,x)
493#define parport_read_control(p) parport_pc_read_control(p)
494#define parport_frob_control(p,m,v) parport_pc_frob_control(p,m,v)
495#define parport_read_status(p) parport_pc_read_status(p)
496#define parport_enable_irq(p) parport_pc_enable_irq(p)
497#define parport_disable_irq(p) parport_pc_disable_irq(p)
498#define parport_data_forward(p) parport_pc_data_forward(p)
499#define parport_data_reverse(p) parport_pc_data_reverse(p)
500
501#else
502
503
504#define parport_write_data(p,x) (p)->ops->write_data(p,x)
505#define parport_read_data(p) (p)->ops->read_data(p)
506#define parport_write_control(p,x) (p)->ops->write_control(p,x)
507#define parport_read_control(p) (p)->ops->read_control(p)
508#define parport_frob_control(p,m,v) (p)->ops->frob_control(p,m,v)
509#define parport_read_status(p) (p)->ops->read_status(p)
510#define parport_enable_irq(p) (p)->ops->enable_irq(p)
511#define parport_disable_irq(p) (p)->ops->disable_irq(p)
512#define parport_data_forward(p) (p)->ops->data_forward(p)
513#define parport_data_reverse(p) (p)->ops->data_reverse(p)
514
515#endif
516
517extern unsigned long parport_default_timeslice;
518extern int parport_default_spintime;
519
520#endif
521