]>
Commit | Line | Data |
---|---|---|
630b64bc DLM |
1 | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | /* | |
3 | * (c) 1997-1998 Grant R. Guenther <grant@torque.net> | |
4 | * | |
5 | * comm.c is a low-level protocol driver for some older models of the DataStor | |
6 | * "Commuter" parallel to IDE adapter. Some of the parallel port devices | |
7 | * marketed by Arista currently use this adapter. | |
8 | */ | |
1da177e4 | 9 | |
1da177e4 LT |
10 | #include <linux/module.h> |
11 | #include <linux/init.h> | |
12 | #include <linux/delay.h> | |
13 | #include <linux/kernel.h> | |
14 | #include <linux/types.h> | |
15 | #include <linux/wait.h> | |
16 | #include <asm/io.h> | |
fe027ff9 | 17 | #include "pata_parport.h" |
1da177e4 | 18 | |
630b64bc DLM |
19 | /* |
20 | * mode codes: 0 nybble reads, 8-bit writes | |
21 | * 1 8-bit reads and writes | |
22 | * 2 8-bit EPP mode | |
23 | */ | |
1da177e4 | 24 | |
630b64bc | 25 | #define j44(a, b) (((a >> 3) & 0x0f) | ((b << 1) & 0xf0)) |
1da177e4 LT |
26 | |
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); | |
29 | ||
630b64bc DLM |
30 | /* |
31 | * cont = 0 - access the IDE register file | |
32 | * cont = 1 - access the IDE command set | |
33 | */ | |
1da177e4 LT |
34 | static int cont_map[2] = { 0x08, 0x10 }; |
35 | ||
882ff0ca | 36 | static int comm_read_regr(struct pi_adapter *pi, int cont, int regr) |
630b64bc DLM |
37 | { |
38 | int l, h, r; | |
1da177e4 LT |
39 | |
40 | r = regr + cont_map[cont]; | |
41 | ||
630b64bc DLM |
42 | switch (pi->mode) { |
43 | case 0: | |
44 | w0(r); P1; w0(0); | |
45 | w2(6); l = r1(); w0(0x80); h = r1(); w2(4); | |
46 | return j44(l, h); | |
1da177e4 | 47 | |
630b64bc DLM |
48 | case 1: |
49 | w0(r+0x20); P1; | |
50 | w0(0); w2(0x26); h = r0(); w2(4); | |
51 | return h; | |
1da177e4 LT |
52 | |
53 | case 2: | |
54 | case 3: | |
630b64bc DLM |
55 | case 4: |
56 | w3(r+0x20); (void)r1(); | |
57 | w2(0x24); h = r4(); w2(4); | |
58 | return h; | |
59 | } | |
1da177e4 | 60 | |
630b64bc DLM |
61 | return -1; |
62 | } | |
1da177e4 | 63 | |
882ff0ca | 64 | static void comm_write_regr(struct pi_adapter *pi, int cont, int regr, int val) |
630b64bc DLM |
65 | { |
66 | int r = regr + cont_map[cont]; | |
1da177e4 | 67 | |
630b64bc DLM |
68 | switch (pi->mode) { |
69 | case 0: | |
70 | case 1: | |
71 | w0(r); P1; w0(val); P2; | |
1da177e4 | 72 | break; |
1da177e4 LT |
73 | case 2: |
74 | case 3: | |
630b64bc DLM |
75 | case 4: |
76 | w3(r); (void)r1(); w4(val); | |
77 | break; | |
78 | } | |
1da177e4 LT |
79 | } |
80 | ||
882ff0ca | 81 | static void comm_connect(struct pi_adapter *pi) |
630b64bc DLM |
82 | { |
83 | pi->saved_r0 = r0(); | |
84 | pi->saved_r2 = r2(); | |
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); | |
1da177e4 LT |
90 | } |
91 | ||
882ff0ca | 92 | static void comm_disconnect(struct pi_adapter *pi) |
1da177e4 | 93 | |
630b64bc DLM |
94 | { |
95 | w2(0); w2(0); w2(0); w2(4); | |
1da177e4 | 96 | w0(pi->saved_r0); |
630b64bc DLM |
97 | w2(pi->saved_r2); |
98 | } | |
1da177e4 | 99 | |
882ff0ca | 100 | static void comm_read_block(struct pi_adapter *pi, char *buf, int count) |
630b64bc DLM |
101 | { |
102 | int i, l, h; | |
103 | ||
104 | switch (pi->mode) { | |
105 | case 0: | |
106 | w0(0x48); P1; | |
107 | for (i = 0; i < count; i++) { | |
108 | w0(0); w2(6); l = r1(); | |
109 | w0(0x80); h = r1(); w2(4); | |
110 | buf[i] = j44(l, h); | |
111 | } | |
112 | break; | |
113 | case 1: | |
114 | w0(0x68); P1; w0(0); | |
115 | for (i = 0; i < count; i++) { | |
116 | w2(0x26); | |
117 | buf[i] = r0(); | |
118 | w2(0x24); | |
119 | } | |
1da177e4 LT |
120 | w2(4); |
121 | break; | |
630b64bc DLM |
122 | case 2: |
123 | w3(0x68); (void)r1(); w2(0x24); | |
124 | for (i = 0; i < count; i++) | |
125 | buf[i] = r4(); | |
126 | w2(4); | |
127 | break; | |
128 | case 3: | |
129 | w3(0x68); (void)r1(); w2(0x24); | |
130 | for (i = 0; i < count / 2; i++) | |
131 | ((u16 *)buf)[i] = r4w(); | |
132 | w2(4); | |
133 | break; | |
134 | case 4: | |
135 | w3(0x68); (void)r1(); w2(0x24); | |
136 | for (i = 0; i < count / 4; i++) | |
137 | ((u32 *)buf)[i] = r4l(); | |
1da177e4 LT |
138 | w2(4); |
139 | break; | |
1da177e4 LT |
140 | } |
141 | } | |
142 | ||
143 | /* NB: Watch out for the byte swapped writes ! */ | |
882ff0ca | 144 | static void comm_write_block(struct pi_adapter *pi, char *buf, int count) |
630b64bc DLM |
145 | { |
146 | int k; | |
147 | ||
148 | switch (pi->mode) { | |
149 | case 0: | |
150 | case 1: | |
151 | w0(0x68); P1; | |
152 | for (k = 0; k < count; k++) { | |
153 | w2(5); | |
154 | w0(buf[k ^ 1]); | |
155 | w2(7); | |
156 | } | |
157 | w2(5); w2(4); | |
158 | break; | |
159 | case 2: | |
160 | w3(0x48); (void)r1(); | |
161 | for (k = 0; k < count; k++) | |
162 | w4(buf[k ^ 1]); | |
163 | break; | |
164 | case 3: | |
165 | w3(0x48); (void)r1(); | |
e02c625d OZ |
166 | for (k = 0; k < count / 2; k++) |
167 | w4w(swab16(((u16 *)buf)[k])); | |
630b64bc DLM |
168 | break; |
169 | case 4: | |
170 | w3(0x48); (void)r1(); | |
e02c625d OZ |
171 | for (k = 0; k < count / 4; k++) |
172 | w4l(swab16(((u16 *)buf)[2 * k]) | | |
173 | swab16(((u16 *)buf)[2 * k + 1]) << 16); | |
630b64bc | 174 | break; |
1da177e4 LT |
175 | } |
176 | } | |
177 | ||
5b77db9c | 178 | static void comm_log_adapter(struct pi_adapter *pi) |
1da177e4 | 179 | |
630b64bc | 180 | { char *mode_string[5] = { "4-bit", "8-bit", "EPP-8", "EPP-16", "EPP-32" }; |
1da177e4 | 181 | |
630b64bc DLM |
182 | dev_info(&pi->dev, |
183 | "DataStor Commuter at 0x%x, mode %d (%s), delay %d\n", | |
184 | pi->port, pi->mode, mode_string[pi->mode], pi->delay); | |
1da177e4 LT |
185 | } |
186 | ||
187 | static struct pi_protocol comm = { | |
188 | .owner = THIS_MODULE, | |
189 | .name = "comm", | |
190 | .max_mode = 5, | |
191 | .epp_first = 2, | |
192 | .default_delay = 1, | |
193 | .max_units = 1, | |
194 | .write_regr = comm_write_regr, | |
195 | .read_regr = comm_read_regr, | |
196 | .write_block = comm_write_block, | |
197 | .read_block = comm_read_block, | |
198 | .connect = comm_connect, | |
199 | .disconnect = comm_disconnect, | |
200 | .log_adapter = comm_log_adapter, | |
201 | }; | |
202 | ||
1da177e4 | 203 | MODULE_LICENSE("GPL"); |
cec148c2 DLM |
204 | MODULE_AUTHOR("Grant R. Guenther <grant@torque.net>"); |
205 | MODULE_DESCRIPTION("DataStor Commuter parallel port IDE adapter protocol driver"); | |
2c08ec0f | 206 | module_pata_parport_driver(comm); |