1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * (c) 1997-1998 Grant R. Guenther <grant@torque.net>
5 * dstr.c is a low-level protocol driver for the DataStor EP2000 parallel
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 >> 3) & 0x07) | ((~a >> 4) & 0x08) | \
27 ((b << 1) & 0x70) | ((~b) & 0x80))
29 #define P1 w2(5);w2(0xd);w2(5);w2(4);
30 #define P2 w2(5);w2(7);w2(5);w2(4);
31 #define P3 w2(6);w2(4);w2(6);w2(4);
34 * cont = 0 - access the IDE register file
35 * cont = 1 - access the IDE command set
37 static int cont_map
[2] = { 0x20, 0x40 };
39 static int dstr_read_regr(struct pi_adapter
*pi
, int cont
, int regr
)
43 r
= regr
+ cont_map
[cont
];
54 w2(6); a
= r1(); w2(4); w2(6); b
= r1(); w2(4);
57 w0(0); w2(0x26); a
= r0(); w2(4);
62 w2(0x24); a
= r4(); w2(4);
69 static void dstr_write_regr(struct pi_adapter
*pi
, int cont
, int regr
, int val
)
71 int r
= regr
+ cont_map
[cont
];
83 w0(val
); w2(5); w2(7); w2(5); w2(4);
95 w0(0xff); w2(0xc); w2(4); \
96 w0(0xaa); w0(0x55); w0(0); w0(0xff); \
98 w0(x); w2(5); w2(4); \
101 static void dstr_connect(struct pi_adapter
*pi
)
105 w2(4); CCP(0xe0); w0(0xff);
108 static void dstr_disconnect(struct pi_adapter
*pi
)
115 static void dstr_read_block(struct pi_adapter
*pi
, char *buf
, int count
)
124 P2
; w0(0x82); P1
; P3
; w0(0x20); P1
;
128 for (k
= 0; k
< count
; k
++) {
129 w2(6); a
= r1(); w2(4);
130 w2(6); b
= r1(); w2(4);
136 for (k
= 0; k
< count
; k
++) {
145 for (k
= 0; k
< count
; k
++)
151 for (k
= 0; k
< count
/ 2; k
++)
152 ((u16
*)buf
)[k
] = r4w();
157 for (k
= 0; k
< count
/ 4; k
++)
158 ((u32
*)buf
)[k
] = r4l();
164 static void dstr_write_block(struct pi_adapter
*pi
, char *buf
, int count
)
173 P2
; w0(0x82); P1
; P3
; w0(0x20); P1
;
178 for (k
= 0; k
< count
; k
++) {
187 for (k
= 0; k
< count
; k
++)
193 for (k
= 0; k
< count
/ 2; k
++)
194 w4w(((u16
*)buf
)[k
]);
199 for (k
= 0; k
< count
/ 4; k
++)
200 w4l(((u32
*)buf
)[k
]);
206 static void dstr_log_adapter(struct pi_adapter
*pi
)
209 char *mode_string
[5] = { "4-bit", "8-bit", "EPP-8", "EPP-16", "EPP-32" };
212 "DataStor EP2000 at 0x%x, mode %d (%s), delay %d\n",
213 pi
->port
, pi
->mode
, mode_string
[pi
->mode
], pi
->delay
);
216 static struct pi_protocol dstr
= {
217 .owner
= THIS_MODULE
,
223 .write_regr
= dstr_write_regr
,
224 .read_regr
= dstr_read_regr
,
225 .write_block
= dstr_write_block
,
226 .read_block
= dstr_read_block
,
227 .connect
= dstr_connect
,
228 .disconnect
= dstr_disconnect
,
229 .log_adapter
= dstr_log_adapter
,
232 MODULE_LICENSE("GPL");
233 MODULE_AUTHOR("Grant R. Guenther <grant@torque.net>");
234 MODULE_DESCRIPTION("DataStor EP2000 parallel port IDE adapter protocol driver");
235 module_pata_parport_driver(dstr
);