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
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>
27 /* mode codes: 0 nybble reads, 8-bit writes
28 1 8-bit reads and writes
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
)
47 r
= regr
+ cont_map
[cont
];
51 case 0: w0(r
); P1
; w0(0);
52 w2(6); l
= r1(); w0(0x80); h
= r1(); w2(4);
55 case 1: w0(r
+0x20); P1
;
56 w0(0); w2(0x26); h
= r0(); w2(4);
61 case 4: w3(r
+0x20); r1();
62 w2(0x24); h
= r4(); w2(4);
69 static void comm_write_regr( PIA
*pi
, int cont
, int regr
, int val
)
73 r
= regr
+ cont_map
[cont
];
78 case 1: w0(r
); P1
; w0(val
); P2
;
83 case 4: w3(r
); r1(); w4(val
);
88 static void comm_connect ( PIA
*pi
)
90 { pi
->saved_r0
= r0();
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);
106 static void comm_read_block( PIA
*pi
, char * buf
, int count
)
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);
120 case 1: w0(0x68); P1
; w0(0);
121 for(i
=0;i
<count
;i
++) {
122 w2(0x26); buf
[i
] = r0(); w2(0x24);
127 case 2: w3(0x68); r1(); w2(0x24);
128 for (i
=0;i
<count
;i
++) buf
[i
] = r4();
132 case 3: w3(0x68); r1(); w2(0x24);
133 for (i
=0;i
<count
/2;i
++) ((u16
*)buf
)[i
] = r4w();
137 case 4: w3(0x68); r1(); w2(0x24);
138 for (i
=0;i
<count
/4;i
++) ((u32
*)buf
)[i
] = r4l();
145 /* NB: Watch out for the byte swapped writes ! */
147 static void comm_write_block( PIA
*pi
, char * buf
, int count
)
154 case 1: w0(0x68); P1
;
155 for (k
=0;k
<count
;k
++) {
156 w2(5); w0(buf
[k
^1]); w2(7);
161 case 2: w3(0x48); r1();
162 for (k
=0;k
<count
;k
++) w4(buf
[k
^1]);
165 case 3: w3(0x48); r1();
166 for (k
=0;k
<count
/2;k
++) w4w(pi_swab16(buf
,k
));
169 case 4: w3(0x48); r1();
170 for (k
=0;k
<count
/4;k
++) w4l(pi_swab32(buf
,k
));
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
)
193 static void comm_release_proto(PIA
*pi
)
198 struct pi_protocol comm
= {"comm",0,5,2,1,1,
216 int init_module(void)
218 { return pi_register( &comm
) - 1;
221 void cleanup_module(void)
223 { pi_unregister( &comm
);