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.
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <linux/kernel.h>
14 #include <linux/types.h>
15 #include <linux/wait.h>
17 #include "pata_parport.h"
19 /* mode codes: 0 nybble reads, 8-bit writes
20 1 8-bit reads and writes
26 #define j44(a,b) (((a>>3)&0x07)|((~a>>4)&0x08)|((b<<1)&0x70)|((~b)&0x80))
28 #define P1 w2(5);w2(0xd);w2(5);w2(4);
29 #define P2 w2(5);w2(7);w2(5);w2(4);
30 #define P3 w2(6);w2(4);w2(6);w2(4);
32 /* cont = 0 - access the IDE register file
33 cont = 1 - access the IDE command set
36 static int cont_map[2] = { 0x20, 0x40 };
38 static int dstr_read_regr(struct pi_adapter *pi, int cont, int regr)
42 r = regr + cont_map[cont];
45 if (pi->mode) { w0(0x11); } else { w0(1); }
50 case 0: w2(6); a = r1(); w2(4); w2(6); b = r1(); w2(4);
53 case 1: w0(0); w2(0x26); a = r0(); w2(4);
58 case 4: w2(0x24); a = r4(); w2(4);
65 static void dstr_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
69 r = regr + cont_map[cont];
72 if (pi->mode >= 2) { w0(0x11); } else { w0(1); }
78 case 1: w0(val); w2(5); w2(7); w2(5); w2(4);
88 #define CCP(x) w0(0xff);w2(0xc);w2(4);\
89 w0(0xaa);w0(0x55);w0(0);w0(0xff);w0(0x87);w0(0x78);\
92 static void dstr_connect(struct pi_adapter *pi)
94 { pi->saved_r0 = r0();
96 w2(4); CCP(0xe0); w0(0xff);
99 static void dstr_disconnect(struct pi_adapter *pi)
106 static void dstr_read_block(struct pi_adapter *pi, char *buf, int count)
111 if (pi->mode) { w0(0x19); } else { w0(9); }
112 P2; w0(0x82); P1; P3; w0(0x20); P1;
116 case 0: for (k=0;k<count;k++) {
117 w2(6); a = r1(); w2(4);
118 w2(6); b = r1(); w2(4);
124 for (k=0;k<count;k++) {
125 w2(0x26); buf[k] = r0(); w2(0x24);
131 for (k=0;k<count;k++) buf[k] = r4();
136 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
141 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
148 static void dstr_write_block(struct pi_adapter *pi, char *buf, int count)
153 if (pi->mode) { w0(0x19); } else { w0(9); }
154 P2; w0(0x82); P1; P3; w0(0x20); P1;
159 case 1: for (k=0;k<count;k++) {
160 w2(5); w0(buf[k]); w2(7);
166 for (k=0;k<count;k++) w4(buf[k]);
171 for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
176 for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
184 static void dstr_log_adapter(struct pi_adapter *pi)
186 { char *mode_string[5] = {"4-bit","8-bit","EPP-8",
189 dev_info(&pi->dev, "DataStor EP2000 at 0x%x, mode %d (%s), delay %d\n",
190 pi->port, pi->mode, mode_string[pi->mode], pi->delay);
193 static struct pi_protocol dstr = {
194 .owner = THIS_MODULE,
200 .write_regr = dstr_write_regr,
201 .read_regr = dstr_read_regr,
202 .write_block = dstr_write_block,
203 .read_block = dstr_read_block,
204 .connect = dstr_connect,
205 .disconnect = dstr_disconnect,
206 .log_adapter = dstr_log_adapter,
209 MODULE_LICENSE("GPL");
210 module_pata_parport_driver(dstr);