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