1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * (c) 1997-1998 Grant R. Guenther <grant@torque.net>
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.
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>
17 #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);
31 * cont = 0 - access the IDE register file
32 * 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];
45 w2(6); l = r1(); w0(0x80); h = r1(); w2(4);
50 w0(0); w2(0x26); h = r0(); w2(4);
56 w3(r+0x20); (void)r1();
57 w2(0x24); h = r4(); w2(4);
64 static void comm_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
66 int r = regr + cont_map[cont];
71 w0(r); P1; w0(val); P2;
76 w3(r); (void)r1(); w4(val);
81 static void comm_connect(struct pi_adapter *pi)
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)
95 w2(0); w2(0); w2(0); w2(4);
100 static void comm_read_block(struct pi_adapter *pi, char *buf, int count)
107 for (i = 0; i < count; i++) {
108 w0(0); w2(6); l = r1();
109 w0(0x80); h = r1(); w2(4);
115 for (i = 0; i < count; i++) {
123 w3(0x68); (void)r1(); w2(0x24);
124 for (i = 0; i < count; i++)
129 w3(0x68); (void)r1(); w2(0x24);
130 for (i = 0; i < count / 2; i++)
131 ((u16 *)buf)[i] = r4w();
135 w3(0x68); (void)r1(); w2(0x24);
136 for (i = 0; i < count / 4; i++)
137 ((u32 *)buf)[i] = r4l();
143 /* NB: Watch out for the byte swapped writes ! */
144 static void comm_write_block(struct pi_adapter *pi, char *buf, int count)
152 for (k = 0; k < count; k++) {
160 w3(0x48); (void)r1();
161 for (k = 0; k < count; k++)
165 w3(0x48); (void)r1();
166 for (k = 0; k < count / 2; k++)
167 w4w(swab16(((u16 *)buf)[k]));
170 w3(0x48); (void)r1();
171 for (k = 0; k < count / 4; k++)
172 w4l(swab16(((u16 *)buf)[2 * k]) |
173 swab16(((u16 *)buf)[2 * k + 1]) << 16);
178 static void comm_log_adapter(struct pi_adapter *pi)
180 { char *mode_string[5] = { "4-bit", "8-bit", "EPP-8", "EPP-16", "EPP-32" };
183 "DataStor Commuter at 0x%x, mode %d (%s), delay %d\n",
184 pi->port, pi->mode, mode_string[pi->mode], pi->delay);
187 static struct pi_protocol comm = {
188 .owner = THIS_MODULE,
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,
203 MODULE_LICENSE("GPL");
204 MODULE_AUTHOR("Grant R. Guenther <grant@torque.net>");
205 MODULE_DESCRIPTION("DataStor Commuter parallel port IDE adapter protocol driver");
206 module_pata_parport_driver(comm);