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