18c2ecf20Sopenharmony_ci#ifndef __DRIVERS_PARIDE_H__
28c2ecf20Sopenharmony_ci#define __DRIVERS_PARIDE_H__
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci/*
58c2ecf20Sopenharmony_ci	paride.h	(c) 1997-8  Grant R. Guenther <grant@torque.net>
68c2ecf20Sopenharmony_ci   		                    Under the terms of the GPL.
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci   This file defines the interface between the high-level parallel
98c2ecf20Sopenharmony_ci   IDE device drivers (pd, pf, pcd, pt) and the adapter chips.
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci*/
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* Changes:
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci	1.01	GRG 1998.05.05	init_proto, release_proto
168c2ecf20Sopenharmony_ci*/
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define PARIDE_H_VERSION 	"1.01"
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/* Some adapters need to know what kind of device they are in
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci   Values for devtype:
238c2ecf20Sopenharmony_ci*/
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define	PI_PD	0	/* IDE disk */
268c2ecf20Sopenharmony_ci#define PI_PCD	1	/* ATAPI CDrom */
278c2ecf20Sopenharmony_ci#define PI_PF   2	/* ATAPI disk */
288c2ecf20Sopenharmony_ci#define PI_PT	3	/* ATAPI tape */
298c2ecf20Sopenharmony_ci#define PI_PG   4       /* ATAPI generic */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/* The paride module contains no state, instead the drivers allocate
328c2ecf20Sopenharmony_ci   a pi_adapter data structure and pass it to paride in every operation.
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci*/
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistruct pi_adapter  {
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	struct pi_protocol *proto;   /* adapter protocol */
398c2ecf20Sopenharmony_ci	int	port;		     /* base address of parallel port */
408c2ecf20Sopenharmony_ci	int	mode;		     /* transfer mode in use */
418c2ecf20Sopenharmony_ci	int     delay;		     /* adapter delay setting */
428c2ecf20Sopenharmony_ci	int	devtype;	     /* device type: PI_PD etc. */
438c2ecf20Sopenharmony_ci	char    *device;	     /* name of driver */
448c2ecf20Sopenharmony_ci	int     unit;		     /* unit number for chained adapters */
458c2ecf20Sopenharmony_ci	int	saved_r0;	     /* saved port state */
468c2ecf20Sopenharmony_ci	int	saved_r2;	     /* saved port state */
478c2ecf20Sopenharmony_ci	int	reserved;	     /* number of ports reserved */
488c2ecf20Sopenharmony_ci	unsigned long	private;     /* for protocol module */
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	wait_queue_head_t parq;     /* semaphore for parport sharing */
518c2ecf20Sopenharmony_ci	void	*pardev;	     /* pointer to pardevice */
528c2ecf20Sopenharmony_ci	char	*parname;	     /* parport name */
538c2ecf20Sopenharmony_ci	int	claimed;	     /* parport has already been claimed */
548c2ecf20Sopenharmony_ci	void (*claim_cont)(void);    /* continuation for parport wait */
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_citypedef struct pi_adapter PIA;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/* functions exported by paride to the high level drivers */
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciextern int pi_init(PIA *pi,
628c2ecf20Sopenharmony_ci	int autoprobe,		/* 1 to autoprobe */
638c2ecf20Sopenharmony_ci	int port, 		/* base port address */
648c2ecf20Sopenharmony_ci	int mode, 		/* -1 for autoprobe */
658c2ecf20Sopenharmony_ci	int unit,		/* unit number, if supported */
668c2ecf20Sopenharmony_ci	int protocol, 		/* protocol to use */
678c2ecf20Sopenharmony_ci	int delay, 		/* -1 to use adapter specific default */
688c2ecf20Sopenharmony_ci	char * scratch, 	/* address of 512 byte buffer */
698c2ecf20Sopenharmony_ci	int devtype,		/* device type: PI_PD, PI_PCD, etc ... */
708c2ecf20Sopenharmony_ci	int verbose,		/* log verbose data while probing */
718c2ecf20Sopenharmony_ci	char *device		/* name of the driver */
728c2ecf20Sopenharmony_ci	);			/* returns 0 on failure, 1 on success */
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ciextern void pi_release(PIA *pi);
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/* registers are addressed as (cont,regr)
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci       	cont: 0 for command register file, 1 for control register(s)
798c2ecf20Sopenharmony_ci	regr: 0-7 for register number.
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci*/
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ciextern void pi_write_regr(PIA *pi, int cont, int regr, int val);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ciextern int pi_read_regr(PIA *pi, int cont, int regr);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ciextern void pi_write_block(PIA *pi, char * buf, int count);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ciextern void pi_read_block(PIA *pi, char * buf, int count);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ciextern void pi_connect(PIA *pi);
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ciextern void pi_disconnect(PIA *pi);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ciextern void pi_do_claimed(PIA *pi, void (*cont)(void));
968c2ecf20Sopenharmony_ciextern int pi_schedule_claimed(PIA *pi, void (*cont)(void));
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/* macros and functions exported to the protocol modules */
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define delay_p			(pi->delay?udelay(pi->delay):(void)0)
1018c2ecf20Sopenharmony_ci#define out_p(offs,byte)	outb(byte,pi->port+offs); delay_p;
1028c2ecf20Sopenharmony_ci#define in_p(offs)		(delay_p,inb(pi->port+offs))
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#define w0(byte)                {out_p(0,byte);}
1058c2ecf20Sopenharmony_ci#define r0()                    (in_p(0) & 0xff)
1068c2ecf20Sopenharmony_ci#define w1(byte)                {out_p(1,byte);}
1078c2ecf20Sopenharmony_ci#define r1()                    (in_p(1) & 0xff)
1088c2ecf20Sopenharmony_ci#define w2(byte)                {out_p(2,byte);}
1098c2ecf20Sopenharmony_ci#define r2()                    (in_p(2) & 0xff)
1108c2ecf20Sopenharmony_ci#define w3(byte)                {out_p(3,byte);}
1118c2ecf20Sopenharmony_ci#define w4(byte)                {out_p(4,byte);}
1128c2ecf20Sopenharmony_ci#define r4()                    (in_p(4) & 0xff)
1138c2ecf20Sopenharmony_ci#define w4w(data)     		{outw(data,pi->port+4); delay_p;}
1148c2ecf20Sopenharmony_ci#define w4l(data)     		{outl(data,pi->port+4); delay_p;}
1158c2ecf20Sopenharmony_ci#define r4w()         		(delay_p,inw(pi->port+4)&0xffff)
1168c2ecf20Sopenharmony_ci#define r4l()         		(delay_p,inl(pi->port+4)&0xffffffff)
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_cistatic inline u16 pi_swab16( char *b, int k)
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci{ 	union { u16 u; char t[2]; } r;
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	r.t[0]=b[2*k+1]; r.t[1]=b[2*k];
1238c2ecf20Sopenharmony_ci        return r.u;
1248c2ecf20Sopenharmony_ci}
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistatic inline u32 pi_swab32( char *b, int k)
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci{ 	union { u32 u; char f[4]; } r;
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci	r.f[0]=b[4*k+1]; r.f[1]=b[4*k];
1318c2ecf20Sopenharmony_ci	r.f[2]=b[4*k+3]; r.f[3]=b[4*k+2];
1328c2ecf20Sopenharmony_ci        return r.u;
1338c2ecf20Sopenharmony_ci}
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_cistruct pi_protocol {
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	char	name[8];	/* name for this protocol */
1388c2ecf20Sopenharmony_ci	int	index;		/* index into protocol table */
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	int	max_mode;	/* max mode number */
1418c2ecf20Sopenharmony_ci	int	epp_first;	/* modes >= this use 8 ports */
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci	int	default_delay;  /* delay parameter if not specified */
1448c2ecf20Sopenharmony_ci	int	max_units;	/* max chained units probed for */
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	void (*write_regr)(PIA *,int,int,int);
1478c2ecf20Sopenharmony_ci	int  (*read_regr)(PIA *,int,int);
1488c2ecf20Sopenharmony_ci	void (*write_block)(PIA *,char *,int);
1498c2ecf20Sopenharmony_ci	void (*read_block)(PIA *,char *,int);
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	void (*connect)(PIA *);
1528c2ecf20Sopenharmony_ci	void (*disconnect)(PIA *);
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	int  (*test_port)(PIA *);
1558c2ecf20Sopenharmony_ci	int  (*probe_unit)(PIA *);
1568c2ecf20Sopenharmony_ci	int  (*test_proto)(PIA *,char *,int);
1578c2ecf20Sopenharmony_ci	void (*log_adapter)(PIA *,char *,int);
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	int (*init_proto)(PIA *);
1608c2ecf20Sopenharmony_ci	void (*release_proto)(PIA *);
1618c2ecf20Sopenharmony_ci	struct module *owner;
1628c2ecf20Sopenharmony_ci};
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_citypedef struct pi_protocol PIP;
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ciextern int paride_register( PIP * );
1678c2ecf20Sopenharmony_ciextern void paride_unregister ( PIP * );
1688c2ecf20Sopenharmony_civoid *pi_register_driver(char *);
1698c2ecf20Sopenharmony_civoid pi_unregister_driver(void *);
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci#endif /* __DRIVERS_PARIDE_H__ */
1728c2ecf20Sopenharmony_ci/* end of paride.h */
173