1 /* 2 dstr.c (c) 1997-8 Grant R. Guenther <grant@torque.net> 3 Under the terms of the GNU General Public License. 4 5 dstr.c is a low-level protocol driver for the 6 DataStor EP2000 parallel to IDE adapter chip. 7 8 */ 9 10 /* Changes: 11 12 1.01 GRG 1998.05.06 init_proto, release_proto 13 14 */ 15 16 #define DSTR_VERSION "1.01" 17 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> 24 #include <asm/io.h> 25 26 #include <linux/pata_parport.h> 27 28 /* mode codes: 0 nybble reads, 8-bit writes 29 1 8-bit reads and writes 30 2 8-bit EPP mode 31 3 EPP-16 32 4 EPP-32 33 */ 34 35 #define j44(a,b) (((a>>3)&0x07)|((~a>>4)&0x08)|((b<<1)&0x70)|((~b)&0x80)) 36 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); 40 41 /* cont = 0 - access the IDE register file 42 cont = 1 - access the IDE command set 43 */ 44 45 static int cont_map[2] = { 0x20, 0x40 }; 46 47 static int dstr_read_regr( PIA *pi, int cont, int regr ) 48 49 { int a, b, r; 50 51 r = regr + cont_map[cont]; 52 53 w0(0x81); P1; 54 if (pi->mode) { w0(0x11); } else { w0(1); } 55 P2; w0(r); P1; 56 57 switch (pi->mode) { 58 59 case 0: w2(6); a = r1(); w2(4); w2(6); b = r1(); w2(4); 60 return j44(a,b); 61 62 case 1: w0(0); w2(0x26); a = r0(); w2(4); 63 return a; 64 65 case 2: 66 case 3: 67 case 4: w2(0x24); a = r4(); w2(4); 68 return a; 69 70 } 71 return -1; 72 } 73 74 static void dstr_write_regr( PIA *pi, int cont, int regr, int val ) 75 76 { int r; 77 78 r = regr + cont_map[cont]; 79 80 w0(0x81); P1; 81 if (pi->mode >= 2) { w0(0x11); } else { w0(1); } 82 P2; w0(r); P1; 83 84 switch (pi->mode) { 85 86 case 0: 87 case 1: w0(val); w2(5); w2(7); w2(5); w2(4); 88 break; 89 90 case 2: 91 case 3: 92 case 4: w4(val); 93 break; 94 } 95 } 96 97 #define CCP(x) w0(0xff);w2(0xc);w2(4);\ 98 w0(0xaa);w0(0x55);w0(0);w0(0xff);w0(0x87);w0(0x78);\ 99 w0(x);w2(5);w2(4); 100 101 static void dstr_connect ( PIA *pi ) 102 103 { pi->saved_r0 = r0(); 104 pi->saved_r2 = r2(); 105 w2(4); CCP(0xe0); w0(0xff); 106 } 107 108 static void dstr_disconnect ( PIA *pi ) 109 110 { CCP(0x30); 111 w0(pi->saved_r0); 112 w2(pi->saved_r2); 113 } 114 115 static void dstr_read_block( PIA *pi, char * buf, int count ) 116 117 { int k, a, b; 118 119 w0(0x81); P1; 120 if (pi->mode) { w0(0x19); } else { w0(9); } 121 P2; w0(0x82); P1; P3; w0(0x20); P1; 122 123 switch (pi->mode) { 124 125 case 0: for (k=0;k<count;k++) { 126 w2(6); a = r1(); w2(4); 127 w2(6); b = r1(); w2(4); 128 buf[k] = j44(a,b); 129 } 130 break; 131 132 case 1: w0(0); 133 for (k=0;k<count;k++) { 134 w2(0x26); buf[k] = r0(); w2(0x24); 135 } 136 w2(4); 137 break; 138 139 case 2: w2(0x24); 140 for (k=0;k<count;k++) buf[k] = r4(); 141 w2(4); 142 break; 143 144 case 3: w2(0x24); 145 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w(); 146 w2(4); 147 break; 148 149 case 4: w2(0x24); 150 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l(); 151 w2(4); 152 break; 153 154 } 155 } 156 157 static void dstr_write_block( PIA *pi, char * buf, int count ) 158 159 { int k; 160 161 w0(0x81); P1; 162 if (pi->mode) { w0(0x19); } else { w0(9); } 163 P2; w0(0x82); P1; P3; w0(0x20); P1; 164 165 switch (pi->mode) { 166 167 case 0: 168 case 1: for (k=0;k<count;k++) { 169 w2(5); w0(buf[k]); w2(7); 170 } 171 w2(5); w2(4); 172 break; 173 174 case 2: w2(0xc5); 175 for (k=0;k<count;k++) w4(buf[k]); 176 w2(0xc4); 177 break; 178 179 case 3: w2(0xc5); 180 for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]); 181 w2(0xc4); 182 break; 183 184 case 4: w2(0xc5); 185 for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]); 186 w2(0xc4); 187 break; 188 189 } 190 } 191 192 193 static void dstr_log_adapter( PIA *pi, char * scratch, int verbose ) 194 195 { char *mode_string[5] = {"4-bit","8-bit","EPP-8", 196 "EPP-16","EPP-32"}; 197 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); 202 203 } 204 205 static struct pi_protocol dstr = { 206 .owner = THIS_MODULE, 207 .name = "dstr", 208 .max_mode = 5, 209 .epp_first = 2, 210 .default_delay = 1, 211 .max_units = 1, 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, 219 }; 220 221 static int __init dstr_init(void) 222 { 223 return paride_register(&dstr); 224 } 225 226 static void __exit dstr_exit(void) 227 { 228 paride_unregister(&dstr); 229 } 230 231 MODULE_LICENSE("GPL"); 232 module_init(dstr_init) 233 module_exit(dstr_exit) 234