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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [block/] [paride/] [dstr.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
        dstr.c    (c) 1997-8  Grant R. Guenther <grant@torque.net>
3
                              Under the terms of the GNU 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/delay.h>
20
#include <linux/kernel.h>
21
#include <linux/types.h>
22
#include <asm/io.h>
23
 
24
#include "paride.h"
25
 
26
/* mode codes:  0  nybble reads, 8-bit writes
27
                1  8-bit reads and writes
28
                2  8-bit EPP mode
29
                3  EPP-16
30
                4  EPP-32
31
*/
32
 
33
#define j44(a,b)  (((a>>3)&0x07)|((~a>>4)&0x08)|((b<<1)&0x70)|((~b)&0x80))
34
 
35
#define P1      w2(5);w2(0xd);w2(5);w2(4);
36
#define P2      w2(5);w2(7);w2(5);w2(4);
37
#define P3      w2(6);w2(4);w2(6);w2(4);
38
 
39
/* cont = 0 - access the IDE register file
40
   cont = 1 - access the IDE command set
41
*/
42
 
43
static int  cont_map[2] = { 0x20, 0x40 };
44
 
45
static int dstr_read_regr( PIA *pi, int cont, int regr )
46
 
47
{       int     a, b, r;
48
 
49
        r = regr + cont_map[cont];
50
 
51
        w0(0x81); P1;
52
        if (pi->mode) { w0(0x11); } else { w0(1); }
53
        P2; w0(r); P1;
54
 
55
        switch (pi->mode)  {
56
 
57
        case 0: w2(6); a = r1(); w2(4); w2(6); b = r1(); w2(4);
58
                return j44(a,b);
59
 
60
        case 1: w0(0); w2(0x26); a = r0(); w2(4);
61
                return a;
62
 
63
        case 2:
64
        case 3:
65
        case 4: w2(0x24); a = r4(); w2(4);
66
                return a;
67
 
68
        }
69
        return -1;
70
}
71
 
72
static void dstr_write_regr(  PIA *pi, int cont, int regr, int val )
73
 
74
{       int  r;
75
 
76
        r = regr + cont_map[cont];
77
 
78
        w0(0x81); P1;
79
        if (pi->mode >= 2) { w0(0x11); } else { w0(1); }
80
        P2; w0(r); P1;
81
 
82
        switch (pi->mode)  {
83
 
84
        case 0:
85
        case 1: w0(val); w2(5); w2(7); w2(5); w2(4);
86
                break;
87
 
88
        case 2:
89
        case 3:
90
        case 4: w4(val);
91
                break;
92
        }
93
}
94
 
95
#define  CCP(x)  w0(0xff);w2(0xc);w2(4);\
96
                 w0(0xaa);w0(0x55);w0(0);w0(0xff);w0(0x87);w0(0x78);\
97
                 w0(x);w2(5);w2(4);
98
 
99
static void dstr_connect ( PIA *pi  )
100
 
101
{       pi->saved_r0 = r0();
102
        pi->saved_r2 = r2();
103
        w2(4); CCP(0xe0); w0(0xff);
104
}
105
 
106
static void dstr_disconnect ( PIA *pi )
107
 
108
{       CCP(0x30);
109
        w0(pi->saved_r0);
110
        w2(pi->saved_r2);
111
}
112
 
113
static void dstr_read_block( PIA *pi, char * buf, int count )
114
 
115
{       int     k, a, b;
116
 
117
        w0(0x81); P1;
118
        if (pi->mode) { w0(0x19); } else { w0(9); }
119
        P2; w0(0x82); P1; P3; w0(0x20); P1;
120
 
121
        switch (pi->mode) {
122
 
123
        case 0: for (k=0;k<count;k++) {
124
                        w2(6); a = r1(); w2(4);
125
                        w2(6); b = r1(); w2(4);
126
                        buf[k] = j44(a,b);
127
                }
128
                break;
129
 
130
        case 1: w0(0);
131
                for (k=0;k<count;k++) {
132
                        w2(0x26); buf[k] = r0(); w2(0x24);
133
                }
134
                w2(4);
135
                break;
136
 
137
        case 2: w2(0x24);
138
                for (k=0;k<count;k++) buf[k] = r4();
139
                w2(4);
140
                break;
141
 
142
        case 3: w2(0x24);
143
                for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
144
                w2(4);
145
                break;
146
 
147
        case 4: w2(0x24);
148
                for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
149
                w2(4);
150
                break;
151
 
152
        }
153
}
154
 
155
static void dstr_write_block( PIA *pi, char * buf, int count )
156
 
157
{       int     k;
158
 
159
        w0(0x81); P1;
160
        if (pi->mode) { w0(0x19); } else { w0(9); }
161
        P2; w0(0x82); P1; P3; w0(0x20); P1;
162
 
163
        switch (pi->mode) {
164
 
165
        case 0:
166
        case 1: for (k=0;k<count;k++) {
167
                        w2(5); w0(buf[k]); w2(7);
168
                }
169
                w2(5); w2(4);
170
                break;
171
 
172
        case 2: w2(0xc5);
173
                for (k=0;k<count;k++) w4(buf[k]);
174
                w2(0xc4);
175
                break;
176
 
177
        case 3: w2(0xc5);
178
                for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
179
                w2(0xc4);
180
                break;
181
 
182
        case 4: w2(0xc5);
183
                for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
184
                w2(0xc4);
185
                break;
186
 
187
        }
188
}
189
 
190
 
191
static void dstr_log_adapter( PIA *pi, char * scratch, int verbose )
192
 
193
{       char    *mode_string[5] = {"4-bit","8-bit","EPP-8",
194
                                   "EPP-16","EPP-32"};
195
 
196
        printk("%s: dstr %s, DataStor EP2000 at 0x%x, ",
197
                pi->device,DSTR_VERSION,pi->port);
198
        printk("mode %d (%s), delay %d\n",pi->mode,
199
                mode_string[pi->mode],pi->delay);
200
 
201
}
202
 
203
static void dstr_init_proto( PIA *pi)
204
 
205
{       MOD_INC_USE_COUNT;
206
}
207
 
208
static void dstr_release_proto( PIA *pi)
209
 
210
{       MOD_DEC_USE_COUNT;
211
}
212
 
213
struct pi_protocol dstr = {"dstr",0,5,2,1,1,
214
                           dstr_write_regr,
215
                           dstr_read_regr,
216
                           dstr_write_block,
217
                           dstr_read_block,
218
                           dstr_connect,
219
                           dstr_disconnect,
220
                           0,
221
                           0,
222
                           0,
223
                           dstr_log_adapter,
224
                           dstr_init_proto,
225
                           dstr_release_proto
226
                          };
227
 
228
 
229
#ifdef MODULE
230
 
231
int     init_module(void)
232
 
233
{       return pi_register( &dstr ) - 1;
234
}
235
 
236
void    cleanup_module(void)
237
 
238
{       pi_unregister( &dstr );
239
}
240
 
241
#endif
242
 
243
/* end of dstr.c */

powered by: WebSVN 2.1.0

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