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/init.h>
23 #include <linux/delay.h>
24 #include <linux/kernel.h>
25 #include <linux/types.h>
26 #include <linux/wait.h>
31 /* mode codes: 0 nybble reads, 8-bit writes
32 1 8-bit reads and writes
38 #define j44(a,b) (((a>>4)&0x0f)|(b&0xf0))
40 #define P1 w2(5);w2(0xd);w2(5);w2(0xd);w2(5);w2(4);
41 #define P2 w2(5);w2(7);w2(5);w2(4);
43 /* cont = 0 - access the IDE register file
44 cont = 1 - access the IDE command set
47 static int on26_read_regr( PIA *pi, int cont, int regr )
51 r = (regr<<2) + 1 + cont;
55 case 0: w0(1); P1; w0(r); P2; w0(0); P1;
56 w2(6); a = r1(); w2(4);
57 w2(6); b = r1(); w2(4);
58 w2(6); w2(4); w2(6); w2(4);
61 case 1: w0(1); P1; w0(r); P2; w0(0); P1;
62 w2(0x26); a = r0(); w2(4); w2(0x26); w2(4);
67 case 4: w3(1); w3(1); w2(5); w4(r); w2(4);
68 w3(0); w3(0); w2(0x24); a = r4(); w2(4);
69 w2(0x24); (void)r4(); w2(4);
76 static void on26_write_regr( PIA *pi, int cont, int regr, int val )
80 r = (regr<<2) + 1 + cont;
85 case 1: w0(1); P1; w0(r); P2; w0(0); P1;
86 w0(val); P2; w0(val); P2;
91 case 4: w3(1); w3(1); w2(5); w4(r); w2(4);
93 w2(5); w4(val); w2(4);
94 w2(5); w4(val); w2(4);
99 #define CCP(x) w0(0xfe);w0(0xaa);w0(0x55);w0(0);w0(0xff);\
100 w0(0x87);w0(0x78);w0(x);w2(4);w2(5);w2(4);w0(0xff);
102 static void on26_connect ( PIA *pi )
110 x = 8; if (pi->mode) x = 9;
112 w0(2); P1; w0(8); P2;
113 w0(2); P1; w0(x); P2;
116 static void on26_disconnect ( PIA *pi )
118 { if (pi->mode >= 2) { w3(4); w3(4); w3(4); w3(4); }
119 else { w0(4); P1; w0(4); P1; }
125 #define RESET_WAIT 200
127 static int on26_test_port( PIA *pi) /* hard reset */
129 { int i, m, d, x=0, y=0;
143 w0(0xfe);w0(0xaa);w0(0x55);w0(0);w0(0xff);
144 i = ((r1() & 0xf0) << 4); w0(0x87);
145 i |= (r1() & 0xf0); w0(0x78);
146 w0(0x20);w2(4);w2(5);
147 i |= ((r1() & 0xf0) >> 4);
152 w0(2); P1; w0(0); P2;
153 w0(3); P1; w0(0); P2;
154 w0(2); P1; w0(8); P2; udelay(100);
155 w0(2); P1; w0(0xa); P2; udelay(100);
156 w0(2); P1; w0(8); P2; udelay(1000);
158 on26_write_regr(pi,0,6,0xa0);
160 for (i=0;i<RESET_WAIT;i++) {
161 on26_write_regr(pi,0,6,0xa0);
162 x = on26_read_regr(pi,0,7);
163 on26_write_regr(pi,0,6,0xb0);
164 y = on26_read_regr(pi,0,7);
165 if (!((x&0x80)||(y&0x80))) break;
170 printk("on26: Device reset failed (%x,%x)\n",x,y);
172 w0(4); P1; w0(4); P1;
186 static void on26_read_block( PIA *pi, char * buf, int count )
192 case 0: w0(1); P1; w0(1); P2; w0(2); P1; w0(0x18); P2; w0(0); P1;
194 for (k=0;k<count;k++) {
199 w0(2); P1; w0(8); P2;
202 case 1: w0(1); P1; w0(1); P2; w0(2); P1; w0(0x19); P2; w0(0); P1;
204 for (k=0;k<count/2;k++) {
205 w2(0x26); buf[2*k] = r0();
206 w2(0x24); buf[2*k+1] = r0();
208 w0(2); P1; w0(9); P2;
211 case 2: w3(1); w3(1); w2(5); w4(1); w2(4);
212 w3(0); w3(0); w2(0x24);
214 for (k=0;k<count;k++) buf[k] = r4();
218 case 3: w3(1); w3(1); w2(5); w4(1); w2(4);
219 w3(0); w3(0); w2(0x24);
221 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
225 case 4: w3(1); w3(1); w2(5); w4(1); w2(4);
226 w3(0); w3(0); w2(0x24);
228 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
235 static void on26_write_block( PIA *pi, char * buf, int count )
242 case 1: w0(1); P1; w0(1); P2;
243 w0(2); P1; w0(0x18+pi->mode); P2; w0(0); P1;
245 for (k=0;k<count/2;k++) {
247 w2(7); w0(buf[2*k+1]);
250 w0(2); P1; w0(8+pi->mode); P2;
253 case 2: w3(1); w3(1); w2(5); w4(1); w2(4);
254 w3(0); w3(0); w2(0xc5);
256 for (k=0;k<count;k++) w4(buf[k]);
260 case 3: w3(1); w3(1); w2(5); w4(1); w2(4);
261 w3(0); w3(0); w2(0xc5);
263 for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
267 case 4: w3(1); w3(1); w2(5); w4(1); w2(4);
268 w3(0); w3(0); w2(0xc5);
270 for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
278 static void on26_log_adapter( PIA *pi, char * scratch, int verbose )
280 { char *mode_string[5] = {"4-bit","8-bit","EPP-8",
283 printk("%s: on26 %s, OnSpec 90c26 at 0x%x, ",
284 pi->device,ON26_VERSION,pi->port);
285 printk("mode %d (%s), delay %d\n",pi->mode,
286 mode_string[pi->mode],pi->delay);
290 static struct pi_protocol on26 = {
291 .owner = THIS_MODULE,
297 .write_regr = on26_write_regr,
298 .read_regr = on26_read_regr,
299 .write_block = on26_write_block,
300 .read_block = on26_read_block,
301 .connect = on26_connect,
302 .disconnect = on26_disconnect,
303 .test_port = on26_test_port,
304 .log_adapter = on26_log_adapter,
307 static int __init on26_init(void)
309 return paride_register(&on26);
312 static void __exit on26_exit(void)
314 paride_unregister(&on26);
317 MODULE_LICENSE("GPL");
318 module_init(on26_init)
319 module_exit(on26_exit)