2 dstr.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU General Public License.
5 dstr.c is a low-level protocol driver for the
6 DataStor EP2000 parallel to IDE adapter chip.
12 1.01 GRG 1998.05.06 init_proto, release_proto
16 #define DSTR_VERSION "1.01"
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/delay.h>
21 #include <linux/kernel.h>
22 #include <linux/types.h>
23 #include <linux/wait.h>
28 /* mode codes: 0 nybble reads, 8-bit writes
29 1 8-bit reads and writes
35 #define j44(a,b) (((a>>3)&0x07)|((~a>>4)&0x08)|((b<<1)&0x70)|((~b)&0x80))
37 #define P1 w2(5);w2(0xd);w2(5);w2(4);
38 #define P2 w2(5);w2(7);w2(5);w2(4);
39 #define P3 w2(6);w2(4);w2(6);w2(4);
41 /* cont = 0 - access the IDE register file
42 cont = 1 - access the IDE command set
45 static int cont_map[2] = { 0x20, 0x40 };
47 static int dstr_read_regr( PIA *pi, int cont, int regr )
51 r = regr + cont_map[cont];
54 if (pi->mode) { w0(0x11); } else { w0(1); }
59 case 0: w2(6); a = r1(); w2(4); w2(6); b = r1(); w2(4);
62 case 1: w0(0); w2(0x26); a = r0(); w2(4);
67 case 4: w2(0x24); a = r4(); w2(4);
74 static void dstr_write_regr( PIA *pi, int cont, int regr, int val )
78 r = regr + cont_map[cont];
81 if (pi->mode >= 2) { w0(0x11); } else { w0(1); }
87 case 1: w0(val); w2(5); w2(7); w2(5); w2(4);
97 #define CCP(x) w0(0xff);w2(0xc);w2(4);\
98 w0(0xaa);w0(0x55);w0(0);w0(0xff);w0(0x87);w0(0x78);\
101 static void dstr_connect ( PIA *pi )
103 { pi->saved_r0 = r0();
105 w2(4); CCP(0xe0); w0(0xff);
108 static void dstr_disconnect ( PIA *pi )
115 static void dstr_read_block( PIA *pi, char * buf, int count )
120 if (pi->mode) { w0(0x19); } else { w0(9); }
121 P2; w0(0x82); P1; P3; w0(0x20); P1;
125 case 0: for (k=0;k<count;k++) {
126 w2(6); a = r1(); w2(4);
127 w2(6); b = r1(); w2(4);
133 for (k=0;k<count;k++) {
134 w2(0x26); buf[k] = r0(); w2(0x24);
140 for (k=0;k<count;k++) buf[k] = r4();
145 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
150 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
157 static void dstr_write_block( PIA *pi, char * buf, int count )
162 if (pi->mode) { w0(0x19); } else { w0(9); }
163 P2; w0(0x82); P1; P3; w0(0x20); P1;
168 case 1: for (k=0;k<count;k++) {
169 w2(5); w0(buf[k]); w2(7);
175 for (k=0;k<count;k++) w4(buf[k]);
180 for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
185 for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
193 static void dstr_log_adapter( PIA *pi, char * scratch, int verbose )
195 { char *mode_string[5] = {"4-bit","8-bit","EPP-8",
198 printk("%s: dstr %s, DataStor EP2000 at 0x%x, ",
199 pi->device,DSTR_VERSION,pi->port);
200 printk("mode %d (%s), delay %d\n",pi->mode,
201 mode_string[pi->mode],pi->delay);
205 static struct pi_protocol dstr = {
206 .owner = THIS_MODULE,
212 .write_regr = dstr_write_regr,
213 .read_regr = dstr_read_regr,
214 .write_block = dstr_write_block,
215 .read_block = dstr_read_block,
216 .connect = dstr_connect,
217 .disconnect = dstr_disconnect,
218 .log_adapter = dstr_log_adapter,
221 static int __init dstr_init(void)
223 return paride_register(&dstr);
226 static void __exit dstr_exit(void)
228 paride_unregister(&dstr);
231 MODULE_LICENSE("GPL");
232 module_init(dstr_init)
233 module_exit(dstr_exit)