2 on26.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU General Public License.
5 on26.c is a low-level protocol driver for the
6 OnSpec 90c26 parallel to IDE adapter chip.
12 1.01 GRG 1998.05.06 init_proto, release_proto
13 1.02 GRG 1998.09.23 updates for the -E rev chip
14 1.03 GRG 1998.12.14 fix for slave drives
15 1.04 GRG 1998.12.20 yet another bug fix
19 #define ON26_VERSION "1.04"
21 #include <linux/module.h>
22 #include <linux/delay.h>
23 #include <linux/kernel.h>
24 #include <linux/types.h>
25 #include <linux/wait.h>
30 /* mode codes: 0 nybble reads, 8-bit writes
31 1 8-bit reads and writes
37 #define j44(a,b) (((a>>4)&0x0f)|(b&0xf0))
39 #define P1 w2(5);w2(0xd);w2(5);w2(0xd);w2(5);w2(4);
40 #define P2 w2(5);w2(7);w2(5);w2(4);
42 /* cont = 0 - access the IDE register file
43 cont = 1 - access the IDE command set
46 static int on26_read_regr( PIA *pi, int cont, int regr )
50 r = (regr<<2) + 1 + cont;
54 case 0: w0(1); P1; w0(r); P2; w0(0); P1;
55 w2(6); a = r1(); w2(4);
56 w2(6); b = r1(); w2(4);
57 w2(6); w2(4); w2(6); w2(4);
60 case 1: w0(1); P1; w0(r); P2; w0(0); P1;
61 w2(0x26); a = r0(); w2(4); w2(0x26); w2(4);
66 case 4: w3(1); w3(1); w2(5); w4(r); w2(4);
67 w3(0); w3(0); w2(0x24); a = r4(); w2(4);
68 w2(0x24); r4(); w2(4);
75 static void on26_write_regr( PIA *pi, int cont, int regr, int val )
79 r = (regr<<2) + 1 + cont;
84 case 1: w0(1); P1; w0(r); P2; w0(0); P1;
85 w0(val); P2; w0(val); P2;
90 case 4: w3(1); w3(1); w2(5); w4(r); w2(4);
92 w2(5); w4(val); w2(4);
93 w2(5); w4(val); w2(4);
98 #define CCP(x) w0(0xfe);w0(0xaa);w0(0x55);w0(0);w0(0xff);\
99 w0(0x87);w0(0x78);w0(x);w2(4);w2(5);w2(4);w0(0xff);
101 static void on26_connect ( PIA *pi )
109 x = 8; if (pi->mode) x = 9;
111 w0(2); P1; w0(8); P2;
112 w0(2); P1; w0(x); P2;
115 static void on26_disconnect ( PIA *pi )
117 { if (pi->mode >= 2) { w3(4); w3(4); w3(4); w3(4); }
118 else { w0(4); P1; w0(4); P1; }
124 #define RESET_WAIT 200
126 static int on26_test_port( PIA *pi) /* hard reset */
128 { int i, m, d, x=0, y=0;
142 w0(0xfe);w0(0xaa);w0(0x55);w0(0);w0(0xff);
143 i = ((r1() & 0xf0) << 4); w0(0x87);
144 i |= (r1() & 0xf0); w0(0x78);
145 w0(0x20);w2(4);w2(5);
146 i |= ((r1() & 0xf0) >> 4);
151 w0(2); P1; w0(0); P2;
152 w0(3); P1; w0(0); P2;
153 w0(2); P1; w0(8); P2; udelay(100);
154 w0(2); P1; w0(0xa); P2; udelay(100);
155 w0(2); P1; w0(8); P2; udelay(1000);
157 on26_write_regr(pi,0,6,0xa0);
159 for (i=0;i<RESET_WAIT;i++) {
160 on26_write_regr(pi,0,6,0xa0);
161 x = on26_read_regr(pi,0,7);
162 on26_write_regr(pi,0,6,0xb0);
163 y = on26_read_regr(pi,0,7);
164 if (!((x&0x80)||(y&0x80))) break;
169 printk("on26: Device reset failed (%x,%x)\n",x,y);
171 w0(4); P1; w0(4); P1;
185 static void on26_read_block( PIA *pi, char * buf, int count )
191 case 0: w0(1); P1; w0(1); P2; w0(2); P1; w0(0x18); P2; w0(0); P1;
193 for (k=0;k<count;k++) {
198 w0(2); P1; w0(8); P2;
201 case 1: w0(1); P1; w0(1); P2; w0(2); P1; w0(0x19); P2; w0(0); P1;
203 for (k=0;k<count/2;k++) {
204 w2(0x26); buf[2*k] = r0();
205 w2(0x24); buf[2*k+1] = r0();
207 w0(2); P1; w0(9); P2;
210 case 2: w3(1); w3(1); w2(5); w4(1); w2(4);
211 w3(0); w3(0); w2(0x24);
213 for (k=0;k<count;k++) buf[k] = r4();
217 case 3: w3(1); w3(1); w2(5); w4(1); w2(4);
218 w3(0); w3(0); w2(0x24);
220 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
224 case 4: w3(1); w3(1); w2(5); w4(1); w2(4);
225 w3(0); w3(0); w2(0x24);
227 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
234 static void on26_write_block( PIA *pi, char * buf, int count )
241 case 1: w0(1); P1; w0(1); P2;
242 w0(2); P1; w0(0x18+pi->mode); P2; w0(0); P1;
244 for (k=0;k<count/2;k++) {
246 w2(7); w0(buf[2*k+1]);
249 w0(2); P1; w0(8+pi->mode); P2;
252 case 2: w3(1); w3(1); w2(5); w4(1); w2(4);
253 w3(0); w3(0); w2(0xc5);
255 for (k=0;k<count;k++) w4(buf[k]);
259 case 3: w3(1); w3(1); w2(5); w4(1); w2(4);
260 w3(0); w3(0); w2(0xc5);
262 for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
266 case 4: w3(1); w3(1); w2(5); w4(1); w2(4);
267 w3(0); w3(0); w2(0xc5);
269 for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
277 static void on26_log_adapter( PIA *pi, char * scratch, int verbose )
279 { char *mode_string[5] = {"4-bit","8-bit","EPP-8",
282 printk("%s: on26 %s, OnSpec 90c26 at 0x%x, ",
283 pi->device,ON26_VERSION,pi->port);
284 printk("mode %d (%s), delay %d\n",pi->mode,
285 mode_string[pi->mode],pi->delay);
289 static void on26_init_proto( PIA *pi)
294 static void on26_release_proto( PIA *pi)
299 struct pi_protocol on26 = {"on26",0,5,2,1,1,
317 int init_module(void)
319 { return pi_register( &on26 ) - 1;
322 void cleanup_module(void)
324 { pi_unregister( &on26 );
331 MODULE_LICENSE("GPL");