1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * (c) 1997-1998 Grant R. Guenther <grant@torque.net>
5 * on26.c is a low-level protocol driver for the
6 * OnSpec 90c26 parallel to IDE adapter chip.
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/delay.h>
12 #include <linux/kernel.h>
13 #include <linux/types.h>
14 #include <linux/wait.h>
16 #include "pata_parport.h"
19 * mode codes: 0 nybble reads, 8-bit writes
20 * 1 8-bit reads and writes
26 #define j44(a, b) (((a >> 4) & 0x0f) | (b & 0xf0))
30 w2(5); w2(0xd); w2(5); w2(0xd); w2(5); w2(4); \
35 w2(5); 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 on26_read_regr(struct pi_adapter *pi, int cont, int regr)
47 r = (regr << 2) + 1 + cont;
51 w0(1); P1; w0(r); P2; w0(0); P1;
52 w2(6); a = r1(); w2(4);
53 w2(6); b = r1(); w2(4);
54 w2(6); w2(4); w2(6); w2(4);
57 w0(1); P1; w0(r); P2; w0(0); P1;
58 w2(0x26); a = r0(); w2(4); w2(0x26); w2(4);
63 w3(1); w3(1); w2(5); w4(r); w2(4);
64 w3(0); w3(0); w2(0x24); a = r4(); w2(4);
65 w2(0x24); (void)r4(); w2(4);
72 static void on26_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
74 int r = (regr << 2) + 1 + cont;
79 w0(1); P1; w0(r); P2; w0(0); P1;
80 w0(val); P2; w0(val); P2;
85 w3(1); w3(1); w2(5); w4(r); w2(4);
87 w2(5); w4(val); w2(4);
88 w2(5); w4(val); w2(4);
95 w0(0xfe); w0(0xaa); w0(0x55); w0(0); \
96 w0(0xff); w0(0x87); w0(0x78); w0(x); \
97 w2(4); w2(5); w2(4); w0(0xff); \
100 static void on26_connect(struct pi_adapter *pi)
113 w0(2); P1; w0(8); P2;
114 w0(2); P1; w0(x); P2;
117 static void on26_disconnect(struct pi_adapter *pi)
120 w3(4); w3(4); w3(4); w3(4);
122 w0(4); P1; w0(4); P1;
129 #define RESET_WAIT 200
132 static int on26_test_port(struct pi_adapter *pi)
134 int i, m, d, x = 0, y = 0;
148 w0(0xfe); w0(0xaa); w0(0x55); w0(0); w0(0xff);
149 i = ((r1() & 0xf0) << 4); w0(0x87);
150 i |= (r1() & 0xf0); w0(0x78);
151 w0(0x20); w2(4); w2(5);
152 i |= ((r1() & 0xf0) >> 4);
156 w0(2); P1; w0(0); P2;
157 w0(3); P1; w0(0); P2;
158 w0(2); P1; w0(8); P2; udelay(100);
159 w0(2); P1; w0(0xa); P2; udelay(100);
160 w0(2); P1; w0(8); P2; udelay(1000);
162 on26_write_regr(pi, 0, 6, 0xa0);
164 for (i = 0; i < RESET_WAIT; i++) {
165 on26_write_regr(pi, 0, 6, 0xa0);
166 x = on26_read_regr(pi, 0, 7);
167 on26_write_regr(pi, 0, 6, 0xb0);
168 y = on26_read_regr(pi, 0, 7);
169 if (!((x & 0x80) || (y & 0x80)))
176 "on26: Device reset failed (%x,%x)\n", x, y);
178 w0(4); P1; w0(4); P1;
191 static void on26_read_block(struct pi_adapter *pi, char *buf, int count)
197 w0(1); P1; w0(1); P2; w0(2); P1; w0(0x18); P2; w0(0); P1;
199 for (k = 0; k < count; k++) {
204 w0(2); P1; w0(8); P2;
207 w0(1); P1; w0(1); P2; w0(2); P1; w0(0x19); P2; w0(0); P1;
209 for (k = 0; k < count / 2; k++) {
210 w2(0x26); buf[2 * k] = r0();
211 w2(0x24); buf[2 * k + 1] = r0();
213 w0(2); P1; w0(9); P2;
216 w3(1); w3(1); w2(5); w4(1); w2(4);
217 w3(0); w3(0); w2(0x24);
219 for (k = 0; k < count; k++)
224 w3(1); w3(1); w2(5); w4(1); w2(4);
225 w3(0); w3(0); w2(0x24);
227 for (k = 0; k < count / 2; k++)
228 ((u16 *)buf)[k] = r4w();
232 w3(1); w3(1); w2(5); w4(1); w2(4);
233 w3(0); w3(0); w2(0x24);
235 for (k = 0; k < count / 4; k++)
236 ((u32 *)buf)[k] = r4l();
242 static void on26_write_block(struct pi_adapter *pi, char *buf, int count)
249 w0(1); P1; w0(1); P2;
250 w0(2); P1; w0(0x18 + pi->mode); P2; w0(0); P1;
252 for (k = 0; k < count / 2; k++) {
253 w2(5); w0(buf[2 * k]);
254 w2(7); w0(buf[2 * k + 1]);
257 w0(2); P1; w0(8 + pi->mode); P2;
260 w3(1); w3(1); w2(5); w4(1); w2(4);
261 w3(0); w3(0); w2(0xc5);
263 for (k = 0; k < count; k++)
268 w3(1); w3(1); w2(5); w4(1); w2(4);
269 w3(0); w3(0); w2(0xc5);
271 for (k = 0; k < count / 2; k++)
272 w4w(((u16 *)buf)[k]);
276 w3(1); w3(1); w2(5); w4(1); w2(4);
277 w3(0); w3(0); w2(0xc5);
279 for (k = 0; k < count / 4; k++)
280 w4l(((u32 *)buf)[k]);
286 static void on26_log_adapter(struct pi_adapter *pi)
288 char *mode_string[5] = { "4-bit", "8-bit", "EPP-8", "EPP-16", "EPP-32" };
291 "OnSpec 90c26 at 0x%x, mode %d (%s), delay %d\n",
292 pi->port, pi->mode, mode_string[pi->mode], pi->delay);
295 static struct pi_protocol on26 = {
296 .owner = THIS_MODULE,
302 .write_regr = on26_write_regr,
303 .read_regr = on26_read_regr,
304 .write_block = on26_write_block,
305 .read_block = on26_read_block,
306 .connect = on26_connect,
307 .disconnect = on26_disconnect,
308 .test_port = on26_test_port,
309 .log_adapter = on26_log_adapter,
312 MODULE_LICENSE("GPL");
313 MODULE_AUTHOR("Grant R. Guenther <grant@torque.net>");
314 MODULE_DESCRIPTION("Onspec 90c26 parallel port IDE adapter protocol driver");
315 module_pata_parport_driver(on26);