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
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/delay.h>
14 #include <linux/kernel.h>
15 #include <linux/types.h>
16 #include <linux/wait.h>
18 #include "pata_parport.h"
20 /* mode codes: 0 nybble reads, 8-bit writes
21 1 8-bit reads and writes
25 #define j44(a,b) (((a>>3)&0x0f)|((b<<1)&0xf0))
27 #define P1 w2(5);w2(0xd);w2(0xd);w2(5);w2(4);
28 #define P2 w2(5);w2(7);w2(7);w2(5);w2(4);
30 /* cont = 0 - access the IDE register file
31 cont = 1 - access the IDE command set
34 static int cont_map[2] = { 0x08, 0x10 };
36 static int comm_read_regr(struct pi_adapter *pi, int cont, int regr)
40 r = regr + cont_map[cont];
44 case 0: w0(r); P1; w0(0);
45 w2(6); l = r1(); w0(0x80); h = r1(); w2(4);
48 case 1: w0(r+0x20); P1;
49 w0(0); w2(0x26); h = r0(); w2(4);
54 case 4: w3(r+0x20); (void)r1();
55 w2(0x24); h = r4(); w2(4);
62 static void comm_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
66 r = regr + cont_map[cont];
71 case 1: w0(r); P1; w0(val); P2;
76 case 4: w3(r); (void)r1(); w4(val);
81 static void comm_connect(struct pi_adapter *pi)
83 { pi->saved_r0 = r0();
85 w2(4); w0(0xff); w2(6);
86 w2(4); w0(0xaa); w2(6);
87 w2(4); w0(0x00); w2(6);
88 w2(4); w0(0x87); w2(6);
89 w2(4); w0(0xe0); w2(0xc); w2(0xc); w2(4);
92 static void comm_disconnect(struct pi_adapter *pi)
94 { w2(0); w2(0); w2(0); w2(4);
99 static void comm_read_block(struct pi_adapter *pi, char *buf, int count)
105 case 0: w0(0x48); P1;
106 for(i=0;i<count;i++) {
107 w0(0); w2(6); l = r1();
108 w0(0x80); h = r1(); w2(4);
113 case 1: w0(0x68); P1; w0(0);
114 for(i=0;i<count;i++) {
115 w2(0x26); buf[i] = r0(); w2(0x24);
120 case 2: w3(0x68); (void)r1(); w2(0x24);
121 for (i=0;i<count;i++) buf[i] = r4();
125 case 3: w3(0x68); (void)r1(); w2(0x24);
126 for (i=0;i<count/2;i++) ((u16 *)buf)[i] = r4w();
130 case 4: w3(0x68); (void)r1(); w2(0x24);
131 for (i=0;i<count/4;i++) ((u32 *)buf)[i] = r4l();
138 /* NB: Watch out for the byte swapped writes ! */
140 static void comm_write_block(struct pi_adapter *pi, char *buf, int count)
147 case 1: w0(0x68); P1;
148 for (k=0;k<count;k++) {
149 w2(5); w0(buf[k^1]); w2(7);
154 case 2: w3(0x48); (void)r1();
155 for (k=0;k<count;k++) w4(buf[k^1]);
158 case 3: w3(0x48); (void)r1();
159 for (k = 0; k < count / 2; k++)
160 w4w(swab16(((u16 *)buf)[k]));
163 case 4: w3(0x48); (void)r1();
164 for (k = 0; k < count / 4; k++)
165 w4l(swab16(((u16 *)buf)[2 * k]) |
166 swab16(((u16 *)buf)[2 * k + 1]) << 16);
173 static void comm_log_adapter(struct pi_adapter *pi)
175 { char *mode_string[5] = {"4-bit","8-bit","EPP-8","EPP-16","EPP-32"};
177 dev_info(&pi->dev, "DataStor Commuter at 0x%x, mode %d (%s), delay %d\n",
178 pi->port, pi->mode, mode_string[pi->mode], pi->delay);
181 static struct pi_protocol comm = {
182 .owner = THIS_MODULE,
188 .write_regr = comm_write_regr,
189 .read_regr = comm_read_regr,
190 .write_block = comm_write_block,
191 .read_block = comm_read_block,
192 .connect = comm_connect,
193 .disconnect = comm_disconnect,
194 .log_adapter = comm_log_adapter,
197 MODULE_LICENSE("GPL");
198 module_pata_parport_driver(comm);