xref: /OK3568_Linux_fs/kernel/drivers/block/paride/paride.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun #ifndef __DRIVERS_PARIDE_H__
2*4882a593Smuzhiyun #define __DRIVERS_PARIDE_H__
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun /*
5*4882a593Smuzhiyun 	paride.h	(c) 1997-8  Grant R. Guenther <grant@torque.net>
6*4882a593Smuzhiyun    		                    Under the terms of the GPL.
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun    This file defines the interface between the high-level parallel
9*4882a593Smuzhiyun    IDE device drivers (pd, pf, pcd, pt) and the adapter chips.
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun /* Changes:
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun 	1.01	GRG 1998.05.05	init_proto, release_proto
16*4882a593Smuzhiyun */
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #define PARIDE_H_VERSION 	"1.01"
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun /* Some adapters need to know what kind of device they are in
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun    Values for devtype:
23*4882a593Smuzhiyun */
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #define	PI_PD	0	/* IDE disk */
26*4882a593Smuzhiyun #define PI_PCD	1	/* ATAPI CDrom */
27*4882a593Smuzhiyun #define PI_PF   2	/* ATAPI disk */
28*4882a593Smuzhiyun #define PI_PT	3	/* ATAPI tape */
29*4882a593Smuzhiyun #define PI_PG   4       /* ATAPI generic */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /* The paride module contains no state, instead the drivers allocate
32*4882a593Smuzhiyun    a pi_adapter data structure and pass it to paride in every operation.
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun */
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun struct pi_adapter  {
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun 	struct pi_protocol *proto;   /* adapter protocol */
39*4882a593Smuzhiyun 	int	port;		     /* base address of parallel port */
40*4882a593Smuzhiyun 	int	mode;		     /* transfer mode in use */
41*4882a593Smuzhiyun 	int     delay;		     /* adapter delay setting */
42*4882a593Smuzhiyun 	int	devtype;	     /* device type: PI_PD etc. */
43*4882a593Smuzhiyun 	char    *device;	     /* name of driver */
44*4882a593Smuzhiyun 	int     unit;		     /* unit number for chained adapters */
45*4882a593Smuzhiyun 	int	saved_r0;	     /* saved port state */
46*4882a593Smuzhiyun 	int	saved_r2;	     /* saved port state */
47*4882a593Smuzhiyun 	int	reserved;	     /* number of ports reserved */
48*4882a593Smuzhiyun 	unsigned long	private;     /* for protocol module */
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun 	wait_queue_head_t parq;     /* semaphore for parport sharing */
51*4882a593Smuzhiyun 	void	*pardev;	     /* pointer to pardevice */
52*4882a593Smuzhiyun 	char	*parname;	     /* parport name */
53*4882a593Smuzhiyun 	int	claimed;	     /* parport has already been claimed */
54*4882a593Smuzhiyun 	void (*claim_cont)(void);    /* continuation for parport wait */
55*4882a593Smuzhiyun };
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun typedef struct pi_adapter PIA;
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun /* functions exported by paride to the high level drivers */
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun extern int pi_init(PIA *pi,
62*4882a593Smuzhiyun 	int autoprobe,		/* 1 to autoprobe */
63*4882a593Smuzhiyun 	int port, 		/* base port address */
64*4882a593Smuzhiyun 	int mode, 		/* -1 for autoprobe */
65*4882a593Smuzhiyun 	int unit,		/* unit number, if supported */
66*4882a593Smuzhiyun 	int protocol, 		/* protocol to use */
67*4882a593Smuzhiyun 	int delay, 		/* -1 to use adapter specific default */
68*4882a593Smuzhiyun 	char * scratch, 	/* address of 512 byte buffer */
69*4882a593Smuzhiyun 	int devtype,		/* device type: PI_PD, PI_PCD, etc ... */
70*4882a593Smuzhiyun 	int verbose,		/* log verbose data while probing */
71*4882a593Smuzhiyun 	char *device		/* name of the driver */
72*4882a593Smuzhiyun 	);			/* returns 0 on failure, 1 on success */
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun extern void pi_release(PIA *pi);
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun /* registers are addressed as (cont,regr)
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun        	cont: 0 for command register file, 1 for control register(s)
79*4882a593Smuzhiyun 	regr: 0-7 for register number.
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun */
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun extern void pi_write_regr(PIA *pi, int cont, int regr, int val);
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun extern int pi_read_regr(PIA *pi, int cont, int regr);
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun extern void pi_write_block(PIA *pi, char * buf, int count);
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun extern void pi_read_block(PIA *pi, char * buf, int count);
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun extern void pi_connect(PIA *pi);
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun extern void pi_disconnect(PIA *pi);
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun extern void pi_do_claimed(PIA *pi, void (*cont)(void));
96*4882a593Smuzhiyun extern int pi_schedule_claimed(PIA *pi, void (*cont)(void));
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun /* macros and functions exported to the protocol modules */
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun #define delay_p			(pi->delay?udelay(pi->delay):(void)0)
101*4882a593Smuzhiyun #define out_p(offs,byte)	outb(byte,pi->port+offs); delay_p;
102*4882a593Smuzhiyun #define in_p(offs)		(delay_p,inb(pi->port+offs))
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun #define w0(byte)                {out_p(0,byte);}
105*4882a593Smuzhiyun #define r0()                    (in_p(0) & 0xff)
106*4882a593Smuzhiyun #define w1(byte)                {out_p(1,byte);}
107*4882a593Smuzhiyun #define r1()                    (in_p(1) & 0xff)
108*4882a593Smuzhiyun #define w2(byte)                {out_p(2,byte);}
109*4882a593Smuzhiyun #define r2()                    (in_p(2) & 0xff)
110*4882a593Smuzhiyun #define w3(byte)                {out_p(3,byte);}
111*4882a593Smuzhiyun #define w4(byte)                {out_p(4,byte);}
112*4882a593Smuzhiyun #define r4()                    (in_p(4) & 0xff)
113*4882a593Smuzhiyun #define w4w(data)     		{outw(data,pi->port+4); delay_p;}
114*4882a593Smuzhiyun #define w4l(data)     		{outl(data,pi->port+4); delay_p;}
115*4882a593Smuzhiyun #define r4w()         		(delay_p,inw(pi->port+4)&0xffff)
116*4882a593Smuzhiyun #define r4l()         		(delay_p,inl(pi->port+4)&0xffffffff)
117*4882a593Smuzhiyun 
pi_swab16(char * b,int k)118*4882a593Smuzhiyun static inline u16 pi_swab16( char *b, int k)
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun { 	union { u16 u; char t[2]; } r;
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 	r.t[0]=b[2*k+1]; r.t[1]=b[2*k];
123*4882a593Smuzhiyun         return r.u;
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun 
pi_swab32(char * b,int k)126*4882a593Smuzhiyun static inline u32 pi_swab32( char *b, int k)
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun { 	union { u32 u; char f[4]; } r;
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun 	r.f[0]=b[4*k+1]; r.f[1]=b[4*k];
131*4882a593Smuzhiyun 	r.f[2]=b[4*k+3]; r.f[3]=b[4*k+2];
132*4882a593Smuzhiyun         return r.u;
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun struct pi_protocol {
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun 	char	name[8];	/* name for this protocol */
138*4882a593Smuzhiyun 	int	index;		/* index into protocol table */
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 	int	max_mode;	/* max mode number */
141*4882a593Smuzhiyun 	int	epp_first;	/* modes >= this use 8 ports */
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun 	int	default_delay;  /* delay parameter if not specified */
144*4882a593Smuzhiyun 	int	max_units;	/* max chained units probed for */
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 	void (*write_regr)(PIA *,int,int,int);
147*4882a593Smuzhiyun 	int  (*read_regr)(PIA *,int,int);
148*4882a593Smuzhiyun 	void (*write_block)(PIA *,char *,int);
149*4882a593Smuzhiyun 	void (*read_block)(PIA *,char *,int);
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun 	void (*connect)(PIA *);
152*4882a593Smuzhiyun 	void (*disconnect)(PIA *);
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun 	int  (*test_port)(PIA *);
155*4882a593Smuzhiyun 	int  (*probe_unit)(PIA *);
156*4882a593Smuzhiyun 	int  (*test_proto)(PIA *,char *,int);
157*4882a593Smuzhiyun 	void (*log_adapter)(PIA *,char *,int);
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	int (*init_proto)(PIA *);
160*4882a593Smuzhiyun 	void (*release_proto)(PIA *);
161*4882a593Smuzhiyun 	struct module *owner;
162*4882a593Smuzhiyun };
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun typedef struct pi_protocol PIP;
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun extern int paride_register( PIP * );
167*4882a593Smuzhiyun extern void paride_unregister ( PIP * );
168*4882a593Smuzhiyun void *pi_register_driver(char *);
169*4882a593Smuzhiyun void pi_unregister_driver(void *);
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun #endif /* __DRIVERS_PARIDE_H__ */
172*4882a593Smuzhiyun /* end of paride.h */
173