xref: /linux/drivers/ata/pata_parport/aten.c (revision 52990390f91c1c39ca742fc8f390b29891d95127)
1 /*
2         aten.c  (c) 1997-8  Grant R. Guenther <grant@torque.net>
3                             Under the terms of the GNU General Public License.
4 
5 	aten.c is a low-level protocol driver for the ATEN EH-100
6 	parallel port adapter.  The EH-100 supports 4-bit and 8-bit
7         modes only.  There is also an EH-132 which supports EPP mode
8         transfers.  The EH-132 is not yet supported.
9 
10 */
11 
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/delay.h>
15 #include <linux/kernel.h>
16 #include <linux/wait.h>
17 #include <linux/types.h>
18 #include <asm/io.h>
19 #include "pata_parport.h"
20 
21 #define j44(a,b)                ((((a>>4)&0x0f)|(b&0xf0))^0x88)
22 
23 /* cont = 0 - access the IDE register file
24    cont = 1 - access the IDE command set
25 */
26 
27 static int  cont_map[2] = { 0x08, 0x20 };
28 
29 static void aten_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
30 
31 {	int r;
32 
33 	r = regr + cont_map[cont] + 0x80;
34 
35 	w0(r); w2(0xe); w2(6); w0(val); w2(7); w2(6); w2(0xc);
36 }
37 
38 static int aten_read_regr(struct pi_adapter *pi, int cont, int regr)
39 
40 {	int  a, b, r;
41 
42         r = regr + cont_map[cont] + 0x40;
43 
44 	switch (pi->mode) {
45 
46         case 0: w0(r); w2(0xe); w2(6);
47 		w2(7); w2(6); w2(0);
48 		a = r1(); w0(0x10); b = r1(); w2(0xc);
49 		return j44(a,b);
50 
51         case 1: r |= 0x10;
52 		w0(r); w2(0xe); w2(6); w0(0xff);
53 		w2(0x27); w2(0x26); w2(0x20);
54 		a = r0();
55 		w2(0x26); w2(0xc);
56 		return a;
57 	}
58 	return -1;
59 }
60 
61 static void aten_read_block(struct pi_adapter *pi, char *buf, int count)
62 
63 {	int  k, a, b, c, d;
64 
65 	switch (pi->mode) {
66 
67 	case 0:	w0(0x48); w2(0xe); w2(6);
68 		for (k=0;k<count/2;k++) {
69 			w2(7); w2(6); w2(2);
70 			a = r1(); w0(0x58); b = r1();
71 			w2(0); d = r1(); w0(0x48); c = r1();
72 			buf[2*k] = j44(c,d);
73 			buf[2*k+1] = j44(a,b);
74 		}
75 		w2(0xc);
76 		break;
77 
78 	case 1: w0(0x58); w2(0xe); w2(6);
79 		for (k=0;k<count/2;k++) {
80 			w2(0x27); w2(0x26); w2(0x22);
81 			a = r0(); w2(0x20); b = r0();
82 			buf[2*k] = b; buf[2*k+1] = a;
83 		}
84 		w2(0x26); w2(0xc);
85 		break;
86 	}
87 }
88 
89 static void aten_write_block(struct pi_adapter *pi, char *buf, int count)
90 
91 {	int k;
92 
93 	w0(0x88); w2(0xe); w2(6);
94 	for (k=0;k<count/2;k++) {
95 		w0(buf[2*k+1]); w2(0xe); w2(6);
96 		w0(buf[2*k]); w2(7); w2(6);
97 	}
98 	w2(0xc);
99 }
100 
101 static void aten_connect(struct pi_adapter *pi)
102 
103 {       pi->saved_r0 = r0();
104         pi->saved_r2 = r2();
105 	w2(0xc);
106 }
107 
108 static void aten_disconnect(struct pi_adapter *pi)
109 
110 {       w0(pi->saved_r0);
111         w2(pi->saved_r2);
112 }
113 
114 static void aten_log_adapter(struct pi_adapter *pi)
115 
116 {       char    *mode_string[2] = {"4-bit","8-bit"};
117 
118 	dev_info(&pi->dev, "ATEN EH-100 at 0x%x, mode %d (%s), delay %d\n",
119 		pi->port, pi->mode, mode_string[pi->mode], pi->delay);
120 }
121 
122 static struct pi_protocol aten = {
123 	.owner		= THIS_MODULE,
124 	.name		= "aten",
125 	.max_mode	= 2,
126 	.epp_first	= 2,
127 	.default_delay	= 1,
128 	.max_units	= 1,
129 	.write_regr	= aten_write_regr,
130 	.read_regr	= aten_read_regr,
131 	.write_block	= aten_write_block,
132 	.read_block	= aten_read_block,
133 	.connect	= aten_connect,
134 	.disconnect	= aten_disconnect,
135 	.log_adapter	= aten_log_adapter,
136 };
137 
138 MODULE_LICENSE("GPL");
139 module_pata_parport_driver(aten);
140