2 comm.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU General 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
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 <linux/wait.h>
28 /* mode codes: 0 nybble reads, 8-bit writes
29 1 8-bit reads and writes
33 #define j44(a,b) (((a>>3)&0x0f)|((b<<1)&0xf0))
35 #define P1 w2(5);w2(0xd);w2(0xd);w2(5);w2(4);
36 #define P2 w2(5);w2(7);w2(7);w2(5);w2(4);
38 /* cont = 0 - access the IDE register file
39 cont = 1 - access the IDE command set
42 static int cont_map[2] = { 0x08, 0x10 };
44 static int comm_read_regr( PIA *pi, int cont, int regr )
48 r = regr + cont_map[cont];
52 case 0: w0(r); P1; w0(0);
53 w2(6); l = r1(); w0(0x80); h = r1(); w2(4);
56 case 1: w0(r+0x20); P1;
57 w0(0); w2(0x26); h = r0(); w2(4);
62 case 4: w3(r+0x20); r1();
63 w2(0x24); h = r4(); w2(4);
70 static void comm_write_regr( PIA *pi, int cont, int regr, int val )
74 r = regr + cont_map[cont];
79 case 1: w0(r); P1; w0(val); P2;
84 case 4: w3(r); r1(); w4(val);
89 static void comm_connect ( PIA *pi )
91 { pi->saved_r0 = r0();
93 w2(4); w0(0xff); w2(6);
94 w2(4); w0(0xaa); w2(6);
95 w2(4); w0(0x00); w2(6);
96 w2(4); w0(0x87); w2(6);
97 w2(4); w0(0xe0); w2(0xc); w2(0xc); w2(4);
100 static void comm_disconnect ( PIA *pi )
102 { w2(0); w2(0); w2(0); w2(4);
107 static void comm_read_block( PIA *pi, char * buf, int count )
113 case 0: w0(0x48); P1;
114 for(i=0;i<count;i++) {
115 w0(0); w2(6); l = r1();
116 w0(0x80); h = r1(); w2(4);
121 case 1: w0(0x68); P1; w0(0);
122 for(i=0;i<count;i++) {
123 w2(0x26); buf[i] = r0(); w2(0x24);
128 case 2: w3(0x68); r1(); w2(0x24);
129 for (i=0;i<count;i++) buf[i] = r4();
133 case 3: w3(0x68); r1(); w2(0x24);
134 for (i=0;i<count/2;i++) ((u16 *)buf)[i] = r4w();
138 case 4: w3(0x68); r1(); w2(0x24);
139 for (i=0;i<count/4;i++) ((u32 *)buf)[i] = r4l();
146 /* NB: Watch out for the byte swapped writes ! */
148 static void comm_write_block( PIA *pi, char * buf, int count )
155 case 1: w0(0x68); P1;
156 for (k=0;k<count;k++) {
157 w2(5); w0(buf[k^1]); w2(7);
162 case 2: w3(0x48); r1();
163 for (k=0;k<count;k++) w4(buf[k^1]);
166 case 3: w3(0x48); r1();
167 for (k=0;k<count/2;k++) w4w(pi_swab16(buf,k));
170 case 4: w3(0x48); r1();
171 for (k=0;k<count/4;k++) w4l(pi_swab32(buf,k));
178 static void comm_log_adapter( PIA *pi, char * scratch, int verbose )
180 { char *mode_string[5] = {"4-bit","8-bit","EPP-8","EPP-16","EPP-32"};
182 printk("%s: comm %s, DataStor Commuter at 0x%x, ",
183 pi->device,COMM_VERSION,pi->port);
184 printk("mode %d (%s), delay %d\n",pi->mode,
185 mode_string[pi->mode],pi->delay);
189 static void comm_init_proto(PIA *pi)
194 static void comm_release_proto(PIA *pi)
199 struct pi_protocol comm = {"comm",0,5,2,1,1,
217 int init_module(void)
219 { return pi_register( &comm ) - 1;
222 void cleanup_module(void)
224 { pi_unregister( &comm );
230 MODULE_LICENSE("GPL");