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/] [comm.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
        comm.c    (c) 1997-8  Grant R. Guenther <grant@torque.net>
3
                              Under the terms of the GNU public license.
4
 
5
        comm.c is a low-level protocol driver for some older models
6
        of the DataStor "Commuter" parallel to IDE adapter.  Some of
7
        the parallel port devices marketed by Arista currently
8
        use this adapter.
9
*/
10
 
11
/* Changes:
12
 
13
        1.01    GRG 1998.05.05  init_proto, release_proto
14
 
15
*/
16
 
17
#define COMM_VERSION      "1.01"
18
 
19
#include <linux/module.h>
20
#include <linux/delay.h>
21
#include <linux/kernel.h>
22
#include <linux/types.h>
23
#include <asm/io.h>
24
 
25
#include "paride.h"
26
 
27
/* mode codes:  0  nybble reads, 8-bit writes
28
                1  8-bit reads and writes
29
                2  8-bit EPP mode
30
*/
31
 
32
#define j44(a,b)        (((a>>3)&0x0f)|((b<<1)&0xf0))
33
 
34
#define P1      w2(5);w2(0xd);w2(0xd);w2(5);w2(4);
35
#define P2      w2(5);w2(7);w2(7);w2(5);w2(4);
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] = { 0x08, 0x10 };
42
 
43
static int comm_read_regr( PIA *pi, int cont, int regr )
44
 
45
{       int     l, h, r;
46
 
47
        r = regr + cont_map[cont];
48
 
49
        switch (pi->mode)  {
50
 
51
        case 0: w0(r); P1; w0(0);
52
                w2(6); l = r1(); w0(0x80); h = r1(); w2(4);
53
                return j44(l,h);
54
 
55
        case 1: w0(r+0x20); P1;
56
                w0(0); w2(0x26); h = r0(); w2(4);
57
                return h;
58
 
59
        case 2:
60
        case 3:
61
        case 4: w3(r+0x20); r1();
62
                w2(0x24); h = r4(); w2(4);
63
                return h;
64
 
65
        }
66
        return -1;
67
}
68
 
69
static void comm_write_regr( PIA *pi, int cont, int regr, int val )
70
 
71
{       int  r;
72
 
73
        r = regr + cont_map[cont];
74
 
75
        switch (pi->mode)  {
76
 
77
        case 0:
78
        case 1: w0(r); P1; w0(val); P2;
79
                break;
80
 
81
        case 2:
82
        case 3:
83
        case 4: w3(r); r1(); w4(val);
84
                break;
85
        }
86
}
87
 
88
static void comm_connect ( PIA *pi  )
89
 
90
{       pi->saved_r0 = r0();
91
        pi->saved_r2 = r2();
92
        w2(4); w0(0xff); w2(6);
93
        w2(4); w0(0xaa); w2(6);
94
        w2(4); w0(0x00); w2(6);
95
        w2(4); w0(0x87); w2(6);
96
        w2(4); w0(0xe0); w2(0xc); w2(0xc); w2(4);
97
}
98
 
99
static void comm_disconnect ( PIA *pi )
100
 
101
{       w2(0); w2(0); w2(0); w2(4);
102
        w0(pi->saved_r0);
103
        w2(pi->saved_r2);
104
}
105
 
106
static void comm_read_block( PIA *pi, char * buf, int count )
107
 
108
{       int     i, l, h;
109
 
110
        switch (pi->mode) {
111
 
112
        case 0: w0(0x48); P1;
113
                for(i=0;i<count;i++) {
114
                        w0(0); w2(6); l = r1();
115
                        w0(0x80); h = r1(); w2(4);
116
                        buf[i] = j44(l,h);
117
                }
118
                break;
119
 
120
        case 1: w0(0x68); P1; w0(0);
121
                for(i=0;i<count;i++) {
122
                        w2(0x26); buf[i] = r0(); w2(0x24);
123
                }
124
                w2(4);
125
                break;
126
 
127
        case 2: w3(0x68); r1(); w2(0x24);
128
                for (i=0;i<count;i++) buf[i] = r4();
129
                w2(4);
130
                break;
131
 
132
        case 3: w3(0x68); r1(); w2(0x24);
133
                for (i=0;i<count/2;i++) ((u16 *)buf)[i] = r4w();
134
                w2(4);
135
                break;
136
 
137
        case 4: w3(0x68); r1(); w2(0x24);
138
                for (i=0;i<count/4;i++) ((u32 *)buf)[i] = r4l();
139
                w2(4);
140
                break;
141
 
142
        }
143
}
144
 
145
/* NB: Watch out for the byte swapped writes ! */
146
 
147
static void comm_write_block( PIA *pi, char * buf, int count )
148
 
149
{       int     k;
150
 
151
        switch (pi->mode) {
152
 
153
        case 0:
154
        case 1: w0(0x68); P1;
155
                for (k=0;k<count;k++) {
156
                        w2(5); w0(buf[k^1]); w2(7);
157
                }
158
                w2(5); w2(4);
159
                break;
160
 
161
        case 2: w3(0x48); r1();
162
                for (k=0;k<count;k++) w4(buf[k^1]);
163
                break;
164
 
165
        case 3: w3(0x48); r1();
166
                for (k=0;k<count/2;k++) w4w(pi_swab16(buf,k));
167
                break;
168
 
169
        case 4: w3(0x48); r1();
170
                for (k=0;k<count/4;k++) w4l(pi_swab32(buf,k));
171
                break;
172
 
173
 
174
        }
175
}
176
 
177
static void comm_log_adapter( PIA *pi, char * scratch, int verbose )
178
 
179
{       char    *mode_string[5] = {"4-bit","8-bit","EPP-8","EPP-16","EPP-32"};
180
 
181
        printk("%s: comm %s, DataStor Commuter at 0x%x, ",
182
                pi->device,COMM_VERSION,pi->port);
183
        printk("mode %d (%s), delay %d\n",pi->mode,
184
                mode_string[pi->mode],pi->delay);
185
 
186
}
187
 
188
static void comm_init_proto(PIA *pi)
189
 
190
{       MOD_INC_USE_COUNT;
191
}
192
 
193
static void comm_release_proto(PIA *pi)
194
 
195
{       MOD_DEC_USE_COUNT;
196
}
197
 
198
struct pi_protocol comm = {"comm",0,5,2,1,1,
199
                           comm_write_regr,
200
                           comm_read_regr,
201
                           comm_write_block,
202
                           comm_read_block,
203
                           comm_connect,
204
                           comm_disconnect,
205
                           0,
206
                           0,
207
                           0,
208
                           comm_log_adapter,
209
                           comm_init_proto,
210
                           comm_release_proto
211
                          };
212
 
213
 
214
#ifdef MODULE
215
 
216
int     init_module(void)
217
 
218
{       return pi_register( &comm ) - 1;
219
}
220
 
221
void    cleanup_module(void)
222
 
223
{       pi_unregister( &comm );
224
}
225
 
226
#endif
227
 
228
/* end of comm.c */

powered by: WebSVN 2.1.0

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