/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1987, 1991 by John E. Lloyd.			    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

#ifndef _PIODRIVER_H_
#define _PIODRIVER_H_

#define PIO_CSR0        0x0008  /* CSR bit 0 (to user dev) */
#define PIO_CSR1        0x0004  /* CSR bit 1 (to user dev) */
#define PIO_REQA        0x0001  /* REQ A line from user dev */
#define PIO_REQB        0x0002  /* REQ B line from user dev */

#define PIO_LISTEN		0x1234
#define PIO_READ_READY		0x1111
#define PIO_WRITE_READY		0x2222
#define PIO_SIGNAL_ACK		0x3333

#define PIO_SIGOUT		PIO_CSR1
#define PIO_SIGIN		PIO_REQB

#define PIO_DEFAULT_BLOCKTIME	100	/* 100 milliseconds */

struct pioreg {
	unsigned short csr;	/* general csr */
#define GCR_MODE_UNI_8_BIT 	0x00
#define GCR_H34_ENA 		0x20
#define GCR_H12_ENA 		0x10
#define GCR_H4_ACTIVE_HIGH 	0x08
#define GCR_H3_ACTIVE_HIGH 	0x04
#define GCR_H2_ACTIVE_HIGH 	0x02
#define GCR_H1_ACTIVE_HIGH 	0x01

	unsigned short srr;	/* service request register */
	unsigned short ddrA;	/* data direction port A */
	unsigned short ddrB;	/* data direction port B */
	unsigned short ddrC;	/* data direction port C */
	unsigned short ivr;	/* interrupt vector register */
	unsigned short crA;	/* control register A */
#define CR_SUBMODE_OUTPUT	0x40
#define CR_SUBMODE_INPUT	0x00
#define CR_H_MODE_NEGATED 	0x20
#define CR_H_MODE_ASSERTED 	0x28
#define CR_H_MODE_INTERLOCK 	0x30
#define CR_H_MODE_PULSED 	0x38
#define INTR_ENABLE 		CR_H_MODE_NEGATED
#define INTR_DISABLE 		CR_H_MODE_ASSERTED

	unsigned short crB;	/* control register B */
	unsigned short obuf;	/* output buffer (port A) */
	unsigned short ibuf;	/* input buffer (port B) */
	unsigned char unused1[4];
	unsigned char pbuf;	/* protocol buffer (port C) */
	unsigned char unused2[1];
	unsigned short status;	/* port status register */
	unsigned char unused3[4];
	unsigned short tcr;	/* timer csr */
};

/* location of the interrupt vector registers, as byte offsets from
   the main csr */

#define VECT_REG_A_OFFSET	(-0x41)
#define VECT_REG_B_OFFSET	(-1)

#define DUPLICATE_BYTES(x)	(unsigned short)((x)|((x)<<8))

extern pioRead();
extern pioTestRead();
extern pioWrite();
extern pioTestWrite();

extern pioProbe();
extern pioAttach();
extern pioDetach();
extern pioSignal();

extern pioIoctl();

extern pioIntrAttach();
extern pioIntrHandler();

#endif
