linux/include/linux/parport.h

/*
 * Any part of this program may be used in documents licensed under
 * the GNU Free Documentation License, Version 1.1 or any later version
 * published by the Free Software Foundation.
 */
#ifndef _PARPORT_H_
#define _PARPORT_H_


#include <linux/jiffies.h>
#include <linux/proc_fs.h>
#include <linux/spinlock.h>
#include <linux/wait.h>
#include <linux/irqreturn.h>
#include <linux/semaphore.h>
#include <linux/device.h>
#include <asm/ptrace.h>
#include <uapi/linux/parport.h>

/* Define this later. */
struct parport;
struct pardevice;

struct pc_parport_state {};

struct ax_parport_state {};

/* used by both parport_amiga and parport_mfc3 */
struct amiga_parport_state {};

struct ip32_parport_state {};

struct parport_state {};

struct parport_operations {};

struct parport_device_info {};

/* Each device can have two callback functions:
 *  1) a preemption function, called by the resource manager to request
 *     that the driver relinquish control of the port.  The driver should
 *     return zero if it agrees to release the port, and nonzero if it 
 *     refuses.  Do not call parport_release() - the kernel will do this
 *     implicitly.
 *
 *  2) a wake-up function, called by the resource manager to tell drivers
 *     that the port is available to be claimed.  If a driver wants to use
 *     the port, it should call parport_claim() here.
 */

/* A parallel port device */
struct pardevice {};

#define to_pardevice(n)

/* IEEE1284 information */

/* IEEE1284 phases. These are exposed to userland through ppdev IOCTL
 * PP[GS]ETPHASE, so do not change existing values. */
enum ieee1284_phase {};
struct ieee1284_info {};

/* A parallel port */
struct parport {};

#define to_parport_dev(n)

#define DEFAULT_SPIN_TIME

struct parport_driver {};

#define to_parport_driver(n)

int parport_bus_init(void);
void parport_bus_exit(void);

/* parport_register_port registers a new parallel port at the given
   address (if one does not already exist) and returns a pointer to it.
   This entails claiming the I/O region, IRQ and DMA.  NULL is returned
   if initialisation fails. */
struct parport *parport_register_port(unsigned long base, int irq, int dma,
				      struct parport_operations *ops);

/* Once a registered port is ready for high-level drivers to use, the
   low-level driver that registered it should announce it.  This will
   call the high-level drivers' attach() functions (after things like
   determining the IEEE 1284.3 topology of the port and collecting
   DeviceIDs). */
void parport_announce_port (struct parport *port);

/* Unregister a port. */
extern void parport_remove_port(struct parport *port);

/* Register a new high-level driver. */

int __must_check __parport_register_driver(struct parport_driver *,
					   struct module *,
					   const char *mod_name);
/*
 * parport_register_driver must be a macro so that KBUILD_MODNAME can
 * be expanded
 */

/**
 *	parport_register_driver - register a parallel port device driver
 *	@driver: structure describing the driver
 *
 *	This can be called by a parallel port device driver in order
 *	to receive notifications about ports being found in the
 *	system, as well as ports no longer available.
 *
 *	The @driver structure is allocated by the caller and must not be
 *	deallocated until after calling parport_unregister_driver().
 *
 *	If using the non device model:
 *	The driver's attach() function may block.  The port that
 *	attach() is given will be valid for the duration of the
 *	callback, but if the driver wants to take a copy of the
 *	pointer it must call parport_get_port() to do so.  Calling
 *	parport_register_device() on that port will do this for you.
 *
 *	The driver's detach() function may block.  The port that
 *	detach() is given will be valid for the duration of the
 *	callback, but if the driver wants to take a copy of the
 *	pointer it must call parport_get_port() to do so.
 *
 *
 *	Returns 0 on success. The non device model will always succeeds.
 *	but the new device model can fail and will return the error code.
 **/
#define parport_register_driver(driver)

/* Unregister a high-level driver. */
void parport_unregister_driver(struct parport_driver *);

/**
 * module_parport_driver() - Helper macro for registering a modular parport driver
 * @__parport_driver: struct parport_driver to be used
 *
 * Helper macro for parport drivers which do not do anything special in module
 * init and exit. This eliminates a lot of boilerplate. Each module may only
 * use this macro once, and calling it replaces module_init() and module_exit().
 */
#define module_parport_driver(__parport_driver)

/* If parport_register_driver doesn't fit your needs, perhaps
 * parport_find_xxx does. */
extern struct parport *parport_find_number (int);
extern struct parport *parport_find_base (unsigned long);

/* generic irq handler, if it suits your needs */
extern irqreturn_t parport_irq_handler(int irq, void *dev_id);

/* Reference counting for ports. */
extern struct parport *parport_get_port (struct parport *);
extern void parport_put_port (struct parport *);
void parport_del_port(struct parport *);

struct pardev_cb {};

/*
 * parport_register_dev_model declares that a device is connected to a
 * port, and tells the kernel all it needs to know.
 */
struct pardevice *
parport_register_dev_model(struct parport *port, const char *name,
			   const struct pardev_cb *par_dev_cb, int cnt);

/* parport_unregister unlinks a device from the chain. */
extern void parport_unregister_device(struct pardevice *dev);

/* parport_claim tries to gain ownership of the port for a particular
   driver.  This may fail (return non-zero) if another driver is busy.
   If this driver has registered an interrupt handler, it will be
   enabled.  */
extern int parport_claim(struct pardevice *dev);

/* parport_claim_or_block is the same, but sleeps if the port cannot
   be claimed.  Return value is 1 if it slept, 0 normally and -errno
   on error.  */
extern int parport_claim_or_block(struct pardevice *dev);

/* parport_release reverses a previous parport_claim.  This can never
   fail, though the effects are undefined (except that they are bad)
   if you didn't previously own the port.  Once you have released the
   port you should make sure that neither your code nor the hardware
   on the port tries to initiate any communication without first
   re-claiming the port.  If you mess with the port state (enabling
   ECP for example) you should clean up before releasing the port. */

extern void parport_release(struct pardevice *dev);

/**
 * parport_yield - relinquish a parallel port temporarily
 * @dev: a device on the parallel port
 *
 * This function relinquishes the port if it would be helpful to other
 * drivers to do so.  Afterwards it tries to reclaim the port using
 * parport_claim(), and the return value is the same as for
 * parport_claim().  If it fails, the port is left unclaimed and it is
 * the driver's responsibility to reclaim the port.
 *
 * The parport_yield() and parport_yield_blocking() functions are for
 * marking points in the driver at which other drivers may claim the
 * port and use their devices.  Yielding the port is similar to
 * releasing it and reclaiming it, but is more efficient because no
 * action is taken if there are no other devices needing the port.  In
 * fact, nothing is done even if there are other devices waiting but
 * the current device is still within its "timeslice".  The default
 * timeslice is half a second, but it can be adjusted via the /proc
 * interface.
 **/
static __inline__ int parport_yield(struct pardevice *dev)
{}

/**
 * parport_yield_blocking - relinquish a parallel port temporarily
 * @dev: a device on the parallel port
 *
 * This function relinquishes the port if it would be helpful to other
 * drivers to do so.  Afterwards it tries to reclaim the port using
 * parport_claim_or_block(), and the return value is the same as for
 * parport_claim_or_block().
 **/
static __inline__ int parport_yield_blocking(struct pardevice *dev)
{}

/* Flags used to identify what a device does. */
#define PARPORT_DEV_TRAN
#define PARPORT_DEV_LURK
#define PARPORT_DEV_EXCL

#define PARPORT_FLAG_EXCL

/* IEEE1284 functions */
extern void parport_ieee1284_interrupt (void *);
extern int parport_negotiate (struct parport *, int mode);
extern ssize_t parport_write (struct parport *, const void *buf, size_t len);
extern ssize_t parport_read (struct parport *, void *buf, size_t len);

#define PARPORT_INACTIVITY_O_NONBLOCK
extern long parport_set_timeout (struct pardevice *, long inactivity);

extern int parport_wait_event (struct parport *, long timeout);
extern int parport_wait_peripheral (struct parport *port,
				    unsigned char mask,
				    unsigned char val);
extern int parport_poll_peripheral (struct parport *port,
				    unsigned char mask,
				    unsigned char val,
				    int usec);

/* For architectural drivers */
extern size_t parport_ieee1284_write_compat (struct parport *,
					     const void *, size_t, int);
extern size_t parport_ieee1284_read_nibble (struct parport *,
					    void *, size_t, int);
extern size_t parport_ieee1284_read_byte (struct parport *,
					  void *, size_t, int);
extern size_t parport_ieee1284_ecp_read_data (struct parport *,
					      void *, size_t, int);
extern size_t parport_ieee1284_ecp_write_data (struct parport *,
					       const void *, size_t, int);
extern size_t parport_ieee1284_ecp_write_addr (struct parport *,
					       const void *, size_t, int);
extern size_t parport_ieee1284_epp_write_data (struct parport *,
					       const void *, size_t, int);
extern size_t parport_ieee1284_epp_read_data (struct parport *,
					      void *, size_t, int);
extern size_t parport_ieee1284_epp_write_addr (struct parport *,
					       const void *, size_t, int);
extern size_t parport_ieee1284_epp_read_addr (struct parport *,
					      void *, size_t, int);

/* IEEE1284.3 functions */
#define daisy_dev_name
extern int parport_daisy_init (struct parport *port);
extern void parport_daisy_fini (struct parport *port);
extern struct pardevice *parport_open (int devnum, const char *name);
extern void parport_close (struct pardevice *dev);
extern ssize_t parport_device_id (int devnum, char *buffer, size_t len);
extern void parport_daisy_deselect_all (struct parport *port);
extern int parport_daisy_select (struct parport *port, int daisy, int mode);

/* Lowlevel drivers _can_ call this support function to handle irqs.  */
static inline void parport_generic_irq(struct parport *port)
{}

/* Prototypes from parport_procfs */
extern int parport_proc_register(struct parport *pp);
extern int parport_proc_unregister(struct parport *pp);
extern int parport_device_proc_register(struct pardevice *device);
extern int parport_device_proc_unregister(struct pardevice *device);

/* If PC hardware is the only type supported, we can optimise a bit.  */
#if !defined(CONFIG_PARPORT_NOT_PC) && defined(CONFIG_PARPORT_PC)

#include <linux/parport_pc.h>
#define parport_write_data
#define parport_read_data
#define parport_write_control
#define parport_read_control
#define parport_frob_control
#define parport_read_status
#define parport_enable_irq
#define parport_disable_irq
#define parport_data_forward
#define parport_data_reverse

#else  /*  !CONFIG_PARPORT_NOT_PC  */

/* Generic operations vector through the dispatch table. */
#define parport_write_data(p,x)
#define parport_read_data(p)
#define parport_write_control(p,x)
#define parport_read_control(p)
#define parport_frob_control(p,m,v)
#define parport_read_status(p)
#define parport_enable_irq(p)
#define parport_disable_irq(p)
#define parport_data_forward(p)
#define parport_data_reverse(p)

#endif /*  !CONFIG_PARPORT_NOT_PC  */

extern unsigned long parport_default_timeslice;
extern int parport_default_spintime;

#endif /* _PARPORT_H_ */