ia64/kvm: compilation fix. export account_system_vtime.
[pv_ops_mirror.git] / drivers / block / paride / dstr.c
blobaccc5c777cbba7efa0aca7ea09ba0cfa08df0b48
1 /*
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.
8 */
10 /* Changes:
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>
24 #include <asm/io.h>
26 #include "paride.h"
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
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 )
49 { int a, b, r;
51 r = regr + cont_map[cont];
53 w0(0x81); P1;
54 if (pi->mode) { w0(0x11); } else { w0(1); }
55 P2; w0(r); P1;
57 switch (pi->mode) {
59 case 0: w2(6); a = r1(); w2(4); w2(6); b = r1(); w2(4);
60 return j44(a,b);
62 case 1: w0(0); w2(0x26); a = r0(); w2(4);
63 return a;
65 case 2:
66 case 3:
67 case 4: w2(0x24); a = r4(); w2(4);
68 return a;
71 return -1;
74 static void dstr_write_regr( PIA *pi, int cont, int regr, int val )
76 { int r;
78 r = regr + cont_map[cont];
80 w0(0x81); P1;
81 if (pi->mode >= 2) { w0(0x11); } else { w0(1); }
82 P2; w0(r); P1;
84 switch (pi->mode) {
86 case 0:
87 case 1: w0(val); w2(5); w2(7); w2(5); w2(4);
88 break;
90 case 2:
91 case 3:
92 case 4: w4(val);
93 break;
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);
101 static void dstr_connect ( PIA *pi )
103 { pi->saved_r0 = r0();
104 pi->saved_r2 = r2();
105 w2(4); CCP(0xe0); w0(0xff);
108 static void dstr_disconnect ( PIA *pi )
110 { CCP(0x30);
111 w0(pi->saved_r0);
112 w2(pi->saved_r2);
115 static void dstr_read_block( PIA *pi, char * buf, int count )
117 { int k, a, b;
119 w0(0x81); P1;
120 if (pi->mode) { w0(0x19); } else { w0(9); }
121 P2; w0(0x82); P1; P3; w0(0x20); P1;
123 switch (pi->mode) {
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);
130 break;
132 case 1: w0(0);
133 for (k=0;k<count;k++) {
134 w2(0x26); buf[k] = r0(); w2(0x24);
136 w2(4);
137 break;
139 case 2: w2(0x24);
140 for (k=0;k<count;k++) buf[k] = r4();
141 w2(4);
142 break;
144 case 3: w2(0x24);
145 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
146 w2(4);
147 break;
149 case 4: w2(0x24);
150 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
151 w2(4);
152 break;
157 static void dstr_write_block( PIA *pi, char * buf, int count )
159 { int k;
161 w0(0x81); P1;
162 if (pi->mode) { w0(0x19); } else { w0(9); }
163 P2; w0(0x82); P1; P3; w0(0x20); P1;
165 switch (pi->mode) {
167 case 0:
168 case 1: for (k=0;k<count;k++) {
169 w2(5); w0(buf[k]); w2(7);
171 w2(5); w2(4);
172 break;
174 case 2: w2(0xc5);
175 for (k=0;k<count;k++) w4(buf[k]);
176 w2(0xc4);
177 break;
179 case 3: w2(0xc5);
180 for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
181 w2(0xc4);
182 break;
184 case 4: w2(0xc5);
185 for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
186 w2(0xc4);
187 break;
193 static void dstr_log_adapter( PIA *pi, char * scratch, int verbose )
195 { char *mode_string[5] = {"4-bit","8-bit","EPP-8",
196 "EPP-16","EPP-32"};
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,
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,
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)