1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * (c) 1998 Grant R. Guenther <grant@torque.net>
5 * friq.c is a low-level protocol driver for the Freecom "IQ"
6 * parallel port IDE adapter. Early versions of this adapter
7 * use the 'frpw' protocol.
9 * Freecom uses this adapter in a battery powered external
10 * CD-ROM drive. It is also used in LS-120 drives by
11 * Maxell and Panasonic, and other devices.
13 * The battery powered drive requires software support to
14 * control the power to the drive. This module enables the
15 * drive power when the high level driver (pcd) is loaded
16 * and disables it when the module is unloaded. Note, if
17 * the friq module is built in to the kernel, the power
18 * will never be switched off, so other means should be
19 * used to conserve battery power.
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/kernel.h>
26 #include <linux/types.h>
27 #include <linux/wait.h>
29 #include "pata_parport.h"
33 w2(4); w0(0xff); w0(0xff); w0(0x73); w0(0x73); \
34 w0(0xc9); w0(0xc9); w0(0x26); \
35 w0(0x26); w0(x); w0(x); \
38 #define j44(l, h) (((l >> 4) & 0x0f) | (h & 0xf0))
41 * cont = 0 - access the IDE register file
42 * cont = 1 - access the IDE command set
44 static int cont_map[2] = { 0x08, 0x10 };
46 static int friq_read_regr(struct pi_adapter *pi, int cont, int regr)
50 r = regr + cont_map[cont];
60 static void friq_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
62 int r = regr + cont_map[cont];
66 w2(5); w2(7); w2(5); w2(4);
69 static void friq_read_block_int(struct pi_adapter *pi, char *buf, int count, int regr)
76 for (k = 0; k < count; k++) {
87 for (k = 0; k < count; k++) {
92 w2(0xac); w2(0xa4); w2(4);
96 for (k = 0; k < count - 2; k++)
99 buf[count - 2] = r4();
100 buf[count - 1] = r4();
105 for (k = 0; k < count / 2 - 1; k++)
106 ((u16 *)buf)[k] = r4w();
108 buf[count - 2] = r4();
109 buf[count - 1] = r4();
114 for (k = 0; k < count / 4 - 1; k++)
115 ((u32 *)buf)[k] = r4l();
116 buf[count - 4] = r4();
117 buf[count - 3] = r4();
119 buf[count - 2] = r4();
120 buf[count - 1] = r4();
126 static void friq_read_block(struct pi_adapter *pi, char *buf, int count)
128 friq_read_block_int(pi, buf, count, 0x08);
131 static void friq_write_block(struct pi_adapter *pi, char *buf, int count)
139 for (k = 0; k < count; k++) {
147 for (k = 0; k < count; k++)
153 for (k = 0; k < count / 2; k++)
154 w4w(((u16 *)buf)[k]);
159 for (k = 0; k < count / 4; k++)
160 w4l(((u32 *)buf)[k]);
166 static void friq_connect(struct pi_adapter *pi)
173 static void friq_disconnect(struct pi_adapter *pi)
180 static int friq_test_proto(struct pi_adapter *pi)
187 w0(0xff); udelay(20); CMD(0x3d); /* turn the power on */
192 for (j = 0; j < 2; j++) {
193 friq_write_regr(pi, 0, 6, 0xa0 + j * 0x10);
194 for (k = 0; k < 256; k++) {
195 friq_write_regr(pi, 0, 2, k ^ 0xaa);
196 friq_write_regr(pi, 0, 3, k ^ 0x55);
197 if (friq_read_regr(pi, 0, 2) != (k ^ 0xaa))
204 friq_read_block_int(pi, scratch, 512, 0x10);
206 for (k = 0; k < 128; k++) {
213 "friq: port 0x%x, mode %d, test=(%d,%d,%d)\n",
214 pi->port, pi->mode, e[0], e[1], r);
216 return r || (e[0] && e[1]);
219 static void friq_log_adapter(struct pi_adapter *pi)
221 char *mode_string[6] = { "4-bit", "8-bit", "EPP-8", "EPP-16", "EPP-32"};
224 "Freecom IQ ASIC-2 adapter at 0x%x, mode %d (%s), delay %d\n",
225 pi->port, pi->mode, mode_string[pi->mode], pi->delay);
229 CMD(0x9e); /* disable sleep timer */
233 static void friq_release_proto(struct pi_adapter *pi)
235 if (pi->private) { /* turn off the power */
237 CMD(0x1d); CMD(0x1e);
243 static struct pi_protocol friq = {
244 .owner = THIS_MODULE,
250 .write_regr = friq_write_regr,
251 .read_regr = friq_read_regr,
252 .write_block = friq_write_block,
253 .read_block = friq_read_block,
254 .connect = friq_connect,
255 .disconnect = friq_disconnect,
256 .test_proto = friq_test_proto,
257 .log_adapter = friq_log_adapter,
258 .release_proto = friq_release_proto,
261 MODULE_LICENSE("GPL");
262 module_pata_parport_driver(friq);