* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / block / paride / comm.c
blob99660e218c40d142131acfa58a7cc62a3f5613f6
1 /*
2 comm.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU public license.
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 */
11 /* Changes:
13 1.01 GRG 1998.05.05 init_proto, release_proto
17 #define COMM_VERSION "1.01"
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>
25 #include "paride.h"
27 /* mode codes: 0 nybble reads, 8-bit writes
28 1 8-bit reads and writes
29 2 8-bit EPP mode
32 #define j44(a,b) (((a>>3)&0x0f)|((b<<1)&0xf0))
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);
37 /* cont = 0 - access the IDE register file
38 cont = 1 - access the IDE command set
41 static int cont_map[2] = { 0x08, 0x10 };
43 static int comm_read_regr( PIA *pi, int cont, int regr )
45 { int l, h, r;
47 r = regr + cont_map[cont];
49 switch (pi->mode) {
51 case 0: w0(r); P1; w0(0);
52 w2(6); l = r1(); w0(0x80); h = r1(); w2(4);
53 return j44(l,h);
55 case 1: w0(r+0x20); P1;
56 w0(0); w2(0x26); h = r0(); w2(4);
57 return h;
59 case 2:
60 case 3:
61 case 4: w3(r+0x20); r1();
62 w2(0x24); h = r4(); w2(4);
63 return h;
66 return -1;
69 static void comm_write_regr( PIA *pi, int cont, int regr, int val )
71 { int r;
73 r = regr + cont_map[cont];
75 switch (pi->mode) {
77 case 0:
78 case 1: w0(r); P1; w0(val); P2;
79 break;
81 case 2:
82 case 3:
83 case 4: w3(r); r1(); w4(val);
84 break;
88 static void comm_connect ( PIA *pi )
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);
99 static void comm_disconnect ( PIA *pi )
101 { w2(0); w2(0); w2(0); w2(4);
102 w0(pi->saved_r0);
103 w2(pi->saved_r2);
106 static void comm_read_block( PIA *pi, char * buf, int count )
108 { int i, l, h;
110 switch (pi->mode) {
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);
118 break;
120 case 1: w0(0x68); P1; w0(0);
121 for(i=0;i<count;i++) {
122 w2(0x26); buf[i] = r0(); w2(0x24);
124 w2(4);
125 break;
127 case 2: w3(0x68); r1(); w2(0x24);
128 for (i=0;i<count;i++) buf[i] = r4();
129 w2(4);
130 break;
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;
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;
145 /* NB: Watch out for the byte swapped writes ! */
147 static void comm_write_block( PIA *pi, char * buf, int count )
149 { int k;
151 switch (pi->mode) {
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);
158 w2(5); w2(4);
159 break;
161 case 2: w3(0x48); r1();
162 for (k=0;k<count;k++) w4(buf[k^1]);
163 break;
165 case 3: w3(0x48); r1();
166 for (k=0;k<count/2;k++) w4w(pi_swab16(buf,k));
167 break;
169 case 4: w3(0x48); r1();
170 for (k=0;k<count/4;k++) w4l(pi_swab32(buf,k));
171 break;
177 static void comm_log_adapter( PIA *pi, char * scratch, int verbose )
179 { char *mode_string[5] = {"4-bit","8-bit","EPP-8","EPP-16","EPP-32"};
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);
188 static void comm_init_proto(PIA *pi)
190 { MOD_INC_USE_COUNT;
193 static void comm_release_proto(PIA *pi)
195 { MOD_DEC_USE_COUNT;
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,
208 comm_log_adapter,
209 comm_init_proto,
210 comm_release_proto
214 #ifdef MODULE
216 int init_module(void)
218 { return pi_register( &comm ) - 1;
221 void cleanup_module(void)
223 { pi_unregister( &comm );
226 #endif
228 /* end of comm.c */