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/init.h>
21 #include <linux/delay.h>
22 #include <linux/kernel.h>
23 #include <linux/types.h>
24 #include <linux/wait.h>
29 /* mode codes: 0 nybble reads, 8-bit writes
30 1 8-bit reads and writes
34 #define j44(a,b) (((a>>3)&0x0f)|((b<<1)&0xf0))
36 #define P1 w2(5);w2(0xd);w2(0xd);w2(5);w2(4);
37 #define P2 w2(5);w2(7);w2(7);w2(5);w2(4);
39 /* cont = 0 - access the IDE register file
40 cont = 1 - access the IDE command set
43 static int cont_map
[2] = { 0x08, 0x10 };
45 static int comm_read_regr( PIA
*pi
, int cont
, int regr
)
49 r
= regr
+ cont_map
[cont
];
53 case 0: w0(r
); P1
; w0(0);
54 w2(6); l
= r1(); w0(0x80); h
= r1(); w2(4);
57 case 1: w0(r
+0x20); P1
;
58 w0(0); w2(0x26); h
= r0(); w2(4);
63 case 4: w3(r
+0x20); (void)r1();
64 w2(0x24); h
= r4(); w2(4);
71 static void comm_write_regr( PIA
*pi
, int cont
, int regr
, int val
)
75 r
= regr
+ cont_map
[cont
];
80 case 1: w0(r
); P1
; w0(val
); P2
;
85 case 4: w3(r
); (void)r1(); w4(val
);
90 static void comm_connect ( PIA
*pi
)
92 { pi
->saved_r0
= r0();
94 w2(4); w0(0xff); w2(6);
95 w2(4); w0(0xaa); w2(6);
96 w2(4); w0(0x00); w2(6);
97 w2(4); w0(0x87); w2(6);
98 w2(4); w0(0xe0); w2(0xc); w2(0xc); w2(4);
101 static void comm_disconnect ( PIA
*pi
)
103 { w2(0); w2(0); w2(0); w2(4);
108 static void comm_read_block( PIA
*pi
, char * buf
, int count
)
114 case 0: w0(0x48); P1
;
115 for(i
=0;i
<count
;i
++) {
116 w0(0); w2(6); l
= r1();
117 w0(0x80); h
= r1(); w2(4);
122 case 1: w0(0x68); P1
; w0(0);
123 for(i
=0;i
<count
;i
++) {
124 w2(0x26); buf
[i
] = r0(); w2(0x24);
129 case 2: w3(0x68); (void)r1(); w2(0x24);
130 for (i
=0;i
<count
;i
++) buf
[i
] = r4();
134 case 3: w3(0x68); (void)r1(); w2(0x24);
135 for (i
=0;i
<count
/2;i
++) ((u16
*)buf
)[i
] = r4w();
139 case 4: w3(0x68); (void)r1(); w2(0x24);
140 for (i
=0;i
<count
/4;i
++) ((u32
*)buf
)[i
] = r4l();
147 /* NB: Watch out for the byte swapped writes ! */
149 static void comm_write_block( PIA
*pi
, char * buf
, int count
)
156 case 1: w0(0x68); P1
;
157 for (k
=0;k
<count
;k
++) {
158 w2(5); w0(buf
[k
^1]); w2(7);
163 case 2: w3(0x48); (void)r1();
164 for (k
=0;k
<count
;k
++) w4(buf
[k
^1]);
167 case 3: w3(0x48); (void)r1();
168 for (k
=0;k
<count
/2;k
++) w4w(pi_swab16(buf
,k
));
171 case 4: w3(0x48); (void)r1();
172 for (k
=0;k
<count
/4;k
++) w4l(pi_swab32(buf
,k
));
179 static void comm_log_adapter( PIA
*pi
, char * scratch
, int verbose
)
181 { char *mode_string
[5] = {"4-bit","8-bit","EPP-8","EPP-16","EPP-32"};
183 printk("%s: comm %s, DataStor Commuter at 0x%x, ",
184 pi
->device
,COMM_VERSION
,pi
->port
);
185 printk("mode %d (%s), delay %d\n",pi
->mode
,
186 mode_string
[pi
->mode
],pi
->delay
);
190 static struct pi_protocol comm
= {
191 .owner
= THIS_MODULE
,
197 .write_regr
= comm_write_regr
,
198 .read_regr
= comm_read_regr
,
199 .write_block
= comm_write_block
,
200 .read_block
= comm_read_block
,
201 .connect
= comm_connect
,
202 .disconnect
= comm_disconnect
,
203 .log_adapter
= comm_log_adapter
,
206 static int __init
comm_init(void)
208 return pi_register(&comm
)-1;
211 static void __exit
comm_exit(void)
213 pi_unregister(&comm
);
216 MODULE_LICENSE("GPL");
217 module_init(comm_init
)
218 module_exit(comm_exit
)