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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [block/] [paride/] [kbic.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
        kbic.c    (c) 1997-8  Grant R. Guenther <grant@torque.net>
3
                              Under the terms of the GNU public license.
4
 
5
        This is a low-level driver for the KBIC-951A and KBIC-971A
6
        parallel to IDE adapter chips from KingByte Information Systems.
7
 
8
        The chips are almost identical, however, the wakeup code
9
        required for the 971A interferes with the correct operation of
10
        the 951A, so this driver registers itself twice, once for
11
        each chip.
12
 
13
*/
14
 
15
/* Changes:
16
 
17
        1.01    GRG 1998.05.06 init_proto, release_proto
18
 
19
*/
20
 
21
#define KBIC_VERSION      "1.01"
22
 
23
#include <linux/module.h>
24
#include <linux/delay.h>
25
#include <linux/kernel.h>
26
#include <linux/types.h>
27
#include <asm/io.h>
28
 
29
#include "paride.h"
30
 
31
#define r12w()                  (delay_p,inw(pi->port+1)&0xffff) 
32
 
33
#define j44(a,b)                ((((a>>4)&0x0f)|(b&0xf0))^0x88)
34
#define j53(w)                  (((w>>3)&0x1f)|((w>>4)&0xe0))
35
 
36
 
37
/* cont = 0 - access the IDE register file
38
   cont = 1 - access the IDE command set
39
*/
40
 
41
static int  cont_map[2] = { 0x80, 0x40 };
42
 
43
static int kbic_read_regr( PIA *pi, int cont, int regr )
44
 
45
{       int     a, b, s;
46
 
47
        s = cont_map[cont];
48
 
49
        switch (pi->mode) {
50
 
51
        case 0: w0(regr|0x18|s); w2(4); w2(6); w2(4); w2(1); w0(8);
52
                a = r1(); w0(0x28); b = r1(); w2(4);
53
                return j44(a,b);
54
 
55
        case 1: w0(regr|0x38|s); w2(4); w2(6); w2(4); w2(5); w0(8);
56
                a = r12w(); w2(4);
57
                return j53(a);
58
 
59
        case 2: w0(regr|0x08|s); w2(4); w2(6); w2(4); w2(0xa5); w2(0xa1);
60
                a = r0(); w2(4);
61
                return a;
62
 
63
        case 3:
64
        case 4:
65
        case 5: w0(0x20|s); w2(4); w2(6); w2(4); w3(regr);
66
                a = r4(); b = r4(); w2(4); w2(0); w2(4);
67
                return a;
68
 
69
        }
70
        return -1;
71
}
72
 
73
static void  kbic_write_regr( PIA *pi, int cont, int regr, int val)
74
 
75
{       int  s;
76
 
77
        s = cont_map[cont];
78
 
79
        switch (pi->mode) {
80
 
81
        case 0:
82
        case 1:
83
        case 2: w0(regr|0x10|s); w2(4); w2(6); w2(4);
84
                w0(val); w2(5); w2(4);
85
                break;
86
 
87
        case 3:
88
        case 4:
89
        case 5: w0(0x20|s); w2(4); w2(6); w2(4); w3(regr);
90
                w4(val); w4(val);
91
                w2(4); w2(0); w2(4);
92
                break;
93
 
94
        }
95
}
96
 
97
static void k951_connect ( PIA *pi  )
98
 
99
{       pi->saved_r0 = r0();
100
        pi->saved_r2 = r2();
101
        w2(4);
102
}
103
 
104
static void k951_disconnect ( PIA *pi )
105
 
106
{       w0(pi->saved_r0);
107
        w2(pi->saved_r2);
108
}
109
 
110
#define CCP(x)  w2(0xc4);w0(0xaa);w0(0x55);w0(0);w0(0xff);w0(0x87);\
111
                w0(0x78);w0(x);w2(0xc5);w2(0xc4);w0(0xff);
112
 
113
static void k971_connect ( PIA *pi  )
114
 
115
{       pi->saved_r0 = r0();
116
        pi->saved_r2 = r2();
117
        CCP(0x20);
118
        w2(4);
119
}
120
 
121
static void k971_disconnect ( PIA *pi )
122
 
123
{       CCP(0x30);
124
        w0(pi->saved_r0);
125
        w2(pi->saved_r2);
126
}
127
 
128
/* counts must be congruent to 0 MOD 4, but all known applications
129
   have this property.
130
*/
131
 
132
static void kbic_read_block( PIA *pi, char * buf, int count )
133
 
134
{       int     k, a, b;
135
 
136
        switch (pi->mode) {
137
 
138
        case 0: w0(0x98); w2(4); w2(6); w2(4);
139
                for (k=0;k<count/2;k++) {
140
                        w2(1); w0(8);    a = r1();
141
                               w0(0x28); b = r1();
142
                        buf[2*k]   = j44(a,b);
143
                        w2(5);           b = r1();
144
                               w0(8);    a = r1();
145
                        buf[2*k+1] = j44(a,b);
146
                        w2(4);
147
                }
148
                break;
149
 
150
        case 1: w0(0xb8); w2(4); w2(6); w2(4);
151
                for (k=0;k<count/4;k++) {
152
                        w0(0xb8);
153
                        w2(4); w2(5);
154
                        w0(8);    buf[4*k]   = j53(r12w());
155
                        w0(0xb8); buf[4*k+1] = j53(r12w());
156
                        w2(4); w2(5);
157
                                  buf[4*k+3] = j53(r12w());
158
                        w0(8);    buf[4*k+2] = j53(r12w());
159
                }
160
                w2(4);
161
                break;
162
 
163
        case 2: w0(0x88); w2(4); w2(6); w2(4);
164
                for (k=0;k<count/2;k++) {
165
                        w2(0xa0); w2(0xa1); buf[2*k] = r0();
166
                        w2(0xa5); buf[2*k+1] = r0();
167
                }
168
                w2(4);
169
                break;
170
 
171
        case 3: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
172
                for (k=0;k<count;k++) buf[k] = r4();
173
                w2(4); w2(0); w2(4);
174
                break;
175
 
176
        case 4: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
177
                for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
178
                w2(4); w2(0); w2(4);
179
                break;
180
 
181
        case 5: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
182
                for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
183
                w2(4); w2(0); w2(4);
184
                break;
185
 
186
 
187
        }
188
}
189
 
190
static void kbic_write_block( PIA *pi, char * buf, int count )
191
 
192
{       int     k;
193
 
194
        switch (pi->mode) {
195
 
196
        case 0:
197
        case 1:
198
        case 2: w0(0x90); w2(4); w2(6); w2(4);
199
                for(k=0;k<count/2;k++) {
200
                        w0(buf[2*k+1]); w2(0); w2(4);
201
                        w0(buf[2*k]);   w2(5); w2(4);
202
                }
203
                break;
204
 
205
        case 3: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
206
                for(k=0;k<count/2;k++) {
207
                        w4(buf[2*k+1]);
208
                        w4(buf[2*k]);
209
                }
210
                w2(4); w2(0); w2(4);
211
                break;
212
 
213
        case 4: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
214
                for(k=0;k<count/2;k++) w4w(pi_swab16(buf,k));
215
                w2(4); w2(0); w2(4);
216
                break;
217
 
218
        case 5: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
219
                for(k=0;k<count/4;k++) w4l(pi_swab32(buf,k));
220
                w2(4); w2(0); w2(4);
221
                break;
222
 
223
        }
224
 
225
}
226
 
227
static void kbic_log_adapter( PIA *pi, char * scratch,
228
                              int verbose, char * chip )
229
 
230
{       char    *mode_string[6] = {"4-bit","5/3","8-bit",
231
                                   "EPP-8","EPP_16","EPP-32"};
232
 
233
        printk("%s: kbic %s, KingByte %s at 0x%x, ",
234
                pi->device,KBIC_VERSION,chip,pi->port);
235
        printk("mode %d (%s), delay %d\n",pi->mode,
236
                mode_string[pi->mode],pi->delay);
237
 
238
}
239
 
240
static void k951_log_adapter( PIA *pi, char * scratch, int verbose )
241
 
242
{       kbic_log_adapter(pi,scratch,verbose,"KBIC-951A");
243
}
244
 
245
static void k971_log_adapter( PIA *pi, char * scratch, int verbose )
246
 
247
{       kbic_log_adapter(pi,scratch,verbose,"KBIC-971A");
248
}
249
 
250
static void kbic_init_proto( PIA *pi)
251
 
252
{       MOD_INC_USE_COUNT;
253
}
254
 
255
static void kbic_release_proto( PIA *pi)
256
 
257
{       MOD_DEC_USE_COUNT;
258
}
259
 
260
struct pi_protocol k951 = {"k951",0,6,3,1,1,
261
                           kbic_write_regr,
262
                           kbic_read_regr,
263
                           kbic_write_block,
264
                           kbic_read_block,
265
                           k951_connect,
266
                           k951_disconnect,
267
                           0,
268
                           0,
269
                           0,
270
                           k951_log_adapter,
271
                           kbic_init_proto,
272
                           kbic_release_proto
273
                          };
274
 
275
 
276
struct pi_protocol k971 = {"k971",0,6,3,1,1,
277
                           kbic_write_regr,
278
                           kbic_read_regr,
279
                           kbic_write_block,
280
                           kbic_read_block,
281
                           k971_connect,
282
                           k971_disconnect,
283
                           0,
284
                           0,
285
                           0,
286
                           k971_log_adapter,
287
                           kbic_init_proto,
288
                           kbic_release_proto
289
                          };
290
 
291
#ifdef MODULE
292
 
293
int     init_module(void)
294
 
295
{       int s5,s7;
296
 
297
        s5 = pi_register(&k951);
298
        s7 = pi_register(&k971);
299
 
300
        return (s5 || s7) - 1;
301
}
302
 
303
void    cleanup_module(void)
304
 
305
{       pi_unregister( &k951 );
306
        pi_unregister( &k971 );
307
}
308
 
309
#endif
310
 
311
/* end of kbic.c */

powered by: WebSVN 2.1.0

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