1 // SPDX-License-Identifier: GPL-2.0-or-later
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)
94 w2(0); w2(0); w2(0); w2(4);
99 static void comm_read_block(struct pi_adapter *pi, char *buf, int count)
106 for (i = 0; i < count; i++) {
107 w0(0); w2(6); l = r1();
108 w0(0x80); h = r1(); w2(4);
114 for (i = 0; i < count; i++) {
122 w3(0x68); (void)r1(); w2(0x24);
123 for (i = 0; i < count; i++)
128 w3(0x68); (void)r1(); w2(0x24);
129 for (i = 0; i < count / 2; i++)
130 ((u16 *)buf)[i] = r4w();
134 w3(0x68); (void)r1(); w2(0x24);
135 for (i = 0; i < count / 4; i++)
136 ((u32 *)buf)[i] = r4l();
142 /* NB: Watch out for the byte swapped writes ! */
143 static void comm_write_block(struct pi_adapter *pi, char *buf, int count)
151 for (k = 0; k < count; k++) {
159 w3(0x48); (void)r1();
160 for (k = 0; k < count; k++)
164 w3(0x48); (void)r1();
165 for (k = 0; k < count / 2; k++)
166 w4w(swab16(((u16 *)buf)[k]));
169 w3(0x48); (void)r1();
170 for (k = 0; k < count / 4; k++)
171 w4l(swab16(((u16 *)buf)[2 * k]) |
172 swab16(((u16 *)buf)[2 * k + 1]) << 16);
177 static void comm_log_adapter(struct pi_adapter *pi)
179 char *mode_string[5] = { "4-bit", "8-bit", "EPP-8", "EPP-16", "EPP-32" };
182 "DataStor Commuter at 0x%x, mode %d (%s), delay %d\n",
183 pi->port, pi->mode, mode_string[pi->mode], pi->delay);
186 static struct pi_protocol comm = {
187 .owner = THIS_MODULE,
193 .write_regr = comm_write_regr,
194 .read_regr = comm_read_regr,
195 .write_block = comm_write_block,
196 .read_block = comm_read_block,
197 .connect = comm_connect,
198 .disconnect = comm_disconnect,
199 .log_adapter = comm_log_adapter,
202 MODULE_LICENSE("GPL");
204 MODULE_DESCRIPTION("DataStor Commuter parallel port IDE adapter protocol driver");
205 module_pata_parport_driver(comm);