OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [drivers/] [block/] [paride/] [epat.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
        epat.c  (c) 1997-8  Grant R. Guenther <grant@torque.net>
3
                            Under the terms of the GNU public license.
4
 
5
        This is the low level protocol driver for the EPAT parallel
6
        to IDE adapter from Shuttle Technologies.  This adapter is
7
        used in many popular parallel port disk products such as the
8
        SyQuest EZ drives, the Avatar Shark and the Imation SuperDisk.
9
 
10
*/
11
 
12
/* Changes:
13
 
14
        1.01    GRG 1998.05.06 init_proto, release_proto
15
 
16
*/
17
 
18
#define EPAT_VERSION      "1.01"
19
 
20
#include <linux/module.h>
21
#include <linux/delay.h>
22
#include <linux/kernel.h>
23
#include <linux/types.h>
24
#include <asm/io.h>
25
 
26
#include "paride.h"
27
 
28
#define j44(a,b)                (((a>>4)&0x0f)+(b&0xf0))
29
#define j53(a,b)                (((a>>3)&0x1f)+((b<<4)&0xe0))
30
 
31
/* cont =  0   IDE register file
32
   cont =  1   IDE control registers
33
   cont =  2   internal EPAT registers
34
*/
35
 
36
static int cont_map[3] = { 0x18, 0x10, 0 };
37
 
38
static void epat_write_regr( PIA *pi, int cont, int regr, int val)
39
 
40
{       int r;
41
 
42
        r = regr + cont_map[cont];
43
 
44
        switch (pi->mode) {
45
 
46
        case 0:
47
        case 1:
48
        case 2: w0(0x60+r); w2(1); w0(val); w2(4);
49
                break;
50
 
51
        case 3:
52
        case 4:
53
        case 5: w3(0x40+r); w4(val);
54
                break;
55
 
56
        }
57
}
58
 
59
static int epat_read_regr( PIA *pi, int cont, int regr )
60
 
61
{       int  a, b, r;
62
 
63
        r = regr + cont_map[cont];
64
 
65
        switch (pi->mode) {
66
 
67
        case 0:  w0(r); w2(1); w2(3);
68
                a = r1(); w2(4); b = r1();
69
                return j44(a,b);
70
 
71
        case 1: w0(0x40+r); w2(1); w2(4);
72
                a = r1(); b = r2(); w0(0xff);
73
                return j53(a,b);
74
 
75
        case 2: w0(0x20+r); w2(1); w2(0x25);
76
                a = r0(); w2(4);
77
                return a;
78
 
79
        case 3:
80
        case 4:
81
        case 5: w3(r); w2(0x24); a = r4(); w2(4);
82
                return a;
83
 
84
        }
85
        return -1;      /* never gets here */
86
}
87
 
88
static void epat_read_block( PIA *pi, char * buf, int count )
89
 
90
{       int  k, ph, a, b;
91
 
92
        switch (pi->mode) {
93
 
94
        case 0:  w0(7); w2(1); w2(3); w0(0xff);
95
                ph = 0;
96
                for(k=0;k<count;k++) {
97
                        if (k == count-1) w0(0xfd);
98
                        w2(6+ph); a = r1();
99
                        if (a & 8) b = a;
100
                          else { w2(4+ph); b = r1(); }
101
                        buf[k] = j44(a,b);
102
                        ph =  1 - ph;
103
                }
104
                w0(0); w2(4);
105
                break;
106
 
107
        case 1: w0(0x47); w2(1); w2(5); w0(0xff);
108
                ph = 0;
109
                for(k=0;k<count;k++) {
110
                        if (k == count-1) w0(0xfd);
111
                        w2(4+ph);
112
                        a = r1(); b = r2();
113
                        buf[k] = j53(a,b);
114
                        ph = 1 - ph;
115
                }
116
                w0(0); w2(4);
117
                break;
118
 
119
        case 2: w0(0x27); w2(1); w2(0x25); w0(0);
120
                ph = 0;
121
                for(k=0;k<count-1;k++) {
122
                        w2(0x24+ph);
123
                        buf[k] = r0();
124
                        ph = 1 - ph;
125
                }
126
                w2(0x26); w2(0x27); buf[count-1] = r0();
127
                w2(0x25); w2(4);
128
                break;
129
 
130
        case 3: w3(0x80); w2(0x24);
131
                for(k=0;k<count-1;k++) buf[k] = r4();
132
                w2(4); w3(0xa0); w2(0x24); buf[count-1] = r4();
133
                w2(4);
134
                break;
135
 
136
        case 4: w3(0x80); w2(0x24);
137
                for(k=0;k<(count/2)-1;k++) ((u16 *)buf)[k] = r4w();
138
                buf[count-2] = r4();
139
                w2(4); w3(0xa0); w2(0x24); buf[count-1] = r4();
140
                w2(4);
141
                break;
142
 
143
        case 5: w3(0x80); w2(0x24);
144
                for(k=0;k<(count/4)-1;k++) ((u32 *)buf)[k] = r4l();
145
                for(k=count-4;k<count-1;k++) buf[k] = r4();
146
                w2(4); w3(0xa0); w2(0x24); buf[count-1] = r4();
147
                w2(4);
148
                break;
149
 
150
        }
151
}
152
 
153
static void epat_write_block( PIA *pi, char * buf, int count )
154
 
155
{       int ph, k;
156
 
157
        switch (pi->mode) {
158
 
159
        case 0:
160
        case 1:
161
        case 2: w0(0x67); w2(1); w2(5);
162
                ph = 0;
163
                for(k=0;k<count;k++) {
164
                        w0(buf[k]);
165
                        w2(4+ph);
166
                        ph = 1 - ph;
167
                }
168
                w2(7); w2(4);
169
                break;
170
 
171
        case 3: w3(0xc0);
172
                for(k=0;k<count;k++) w4(buf[k]);
173
                w2(4);
174
                break;
175
 
176
        case 4: w3(0xc0);
177
                for(k=0;k<(count/2);k++) w4w(((u16 *)buf)[k]);
178
                w2(4);
179
                break;
180
 
181
        case 5: w3(0xc0);
182
                for(k=0;k<(count/4);k++) w4l(((u32 *)buf)[k]);
183
                w2(4);
184
                break;
185
 
186
        }
187
}
188
 
189
/* these macros access the EPAT registers in native addressing */
190
 
191
#define WR(r,v)         epat_write_regr(pi,2,r,v)
192
#define RR(r)           (epat_read_regr(pi,2,r))
193
 
194
/* and these access the IDE task file */
195
 
196
#define WRi(r,v)         epat_write_regr(pi,0,r,v)
197
#define RRi(r)           (epat_read_regr(pi,0,r))
198
 
199
/* FIXME:  the CCP stuff should be fixed to handle multiple EPATs on a chain */
200
 
201
#define CCP(x)  w2(4);w0(0x22);w0(0xaa);w0(0x55);w0(0);w0(0xff);\
202
                w0(0x87);w0(0x78);w0(x);w2(4);w2(5);w2(4);w0(0xff);
203
 
204
static void epat_connect ( PIA *pi )
205
 
206
{       pi->saved_r0 = r0();
207
        pi->saved_r2 = r2();
208
        CCP(0); CCP(0xe0);
209
        w0(0); w2(1); w2(4);
210
        if (pi->mode >= 3) {
211
                w0(0); w2(1); w2(4); w2(0xc);
212
                w0(0x40); w2(6); w2(7); w2(4); w2(0xc); w2(4);
213
        }
214
        WR(8,0x10); WR(0xc,0x14); WR(0xa,0x38); WR(0x12,0x10);
215
}
216
 
217
static void epat_disconnect ( PIA *pi )
218
 
219
{       CCP(0x30);
220
        w0(pi->saved_r0);
221
        w2(pi->saved_r2);
222
}
223
 
224
static int epat_test_proto( PIA *pi, char * scratch, int verbose )
225
 
226
{       int     k, j, f, cc;
227
        int     e[2] = {0,0};
228
 
229
        epat_connect(pi);
230
        cc = RR(0xd);
231
        epat_disconnect(pi);
232
 
233
        epat_connect(pi);
234
        for (j=0;j<2;j++) {
235
            WRi(6,0xa0+j*0x10);
236
            for (k=0;k<256;k++) {
237
                WRi(2,k^0xaa);
238
                WRi(3,k^0x55);
239
                if (RRi(2) != (k^0xaa)) e[j]++;
240
                }
241
            }
242
        epat_disconnect(pi);
243
 
244
        f = 0;
245
        epat_connect(pi);
246
        WR(0x13,1); WR(0x13,0); WR(0xa,0x11);
247
        epat_read_block(pi,scratch,512);
248
 
249
        for (k=0;k<256;k++) {
250
            if ((scratch[2*k] & 0xff) != k) f++;
251
            if ((scratch[2*k+1] & 0xff) != (0xff-k)) f++;
252
        }
253
        epat_disconnect(pi);
254
 
255
        if (verbose)  {
256
            printk("%s: epat: port 0x%x, mode %d, ccr %x, test=(%d,%d,%d)\n",
257
                   pi->device,pi->port,pi->mode,cc,e[0],e[1],f);
258
        }
259
 
260
        return (e[0] && e[1]) || f;
261
}
262
 
263
static void epat_log_adapter( PIA *pi, char * scratch, int verbose )
264
 
265
{       int     ver;
266
        char    *mode_string[6] =
267
                   {"4-bit","5/3","8-bit","EPP-8","EPP-16","EPP-32"};
268
 
269
        epat_connect(pi);
270
        WR(0xa,0x38);           /* read the version code */
271
        ver = RR(0xb);
272
        epat_disconnect(pi);
273
 
274
        printk("%s: epat %s, Shuttle EPAT chip %x at 0x%x, ",
275
                pi->device,EPAT_VERSION,ver,pi->port);
276
        printk("mode %d (%s), delay %d\n",pi->mode,
277
                mode_string[pi->mode],pi->delay);
278
 
279
}
280
 
281
static void epat_init_proto( PIA *pi)
282
 
283
{       MOD_INC_USE_COUNT;
284
}
285
 
286
static void epat_release_proto( PIA *pi)
287
 
288
{       MOD_DEC_USE_COUNT;
289
}
290
 
291
struct pi_protocol epat = {"epat",0,6,3,1,1,
292
                           epat_write_regr,
293
                           epat_read_regr,
294
                           epat_write_block,
295
                           epat_read_block,
296
                           epat_connect,
297
                           epat_disconnect,
298
                           0,
299
                           0,
300
                           epat_test_proto,
301
                           epat_log_adapter,
302
                           epat_init_proto,
303
                           epat_release_proto
304
                          };
305
 
306
 
307
#ifdef MODULE
308
 
309
int     init_module(void)
310
 
311
{       return pi_register( &epat) - 1;
312
}
313
 
314
void    cleanup_module(void)
315
 
316
{       pi_unregister( &epat);
317
}
318
 
319
#endif
320
 
321
/* end of epat.c */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.