18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci        fit2.c        (c) 1998  Grant R. Guenther <grant@torque.net>
38c2ecf20Sopenharmony_ci                          Under the terms of the GNU General Public License.
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci	fit2.c is a low-level protocol driver for the older version
68c2ecf20Sopenharmony_ci        of the Fidelity International Technology parallel port adapter.
78c2ecf20Sopenharmony_ci	This adapter is used in their TransDisk 2000 and older TransDisk
88c2ecf20Sopenharmony_ci	3000 portable hard-drives.  As far as I can tell, this device
98c2ecf20Sopenharmony_ci	supports 4-bit mode _only_.
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci	Newer models of the FIT products use an enhanced protocol.
128c2ecf20Sopenharmony_ci	The "fit3" protocol module should support current drives.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci*/
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define FIT2_VERSION      "1.0"
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <linux/module.h>
198c2ecf20Sopenharmony_ci#include <linux/init.h>
208c2ecf20Sopenharmony_ci#include <linux/delay.h>
218c2ecf20Sopenharmony_ci#include <linux/kernel.h>
228c2ecf20Sopenharmony_ci#include <linux/types.h>
238c2ecf20Sopenharmony_ci#include <linux/wait.h>
248c2ecf20Sopenharmony_ci#include <asm/io.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include "paride.h"
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define j44(a,b)                (((a>>4)&0x0f)|(b&0xf0))
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* cont = 0 - access the IDE register file
318c2ecf20Sopenharmony_ci   cont = 1 - access the IDE command set
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ciNB:  The FIT adapter does not appear to use the control registers.
348c2ecf20Sopenharmony_ciSo, we map ALT_STATUS to STATUS and NO-OP writes to the device
358c2ecf20Sopenharmony_cicontrol register - this means that IDE reset will not work on these
368c2ecf20Sopenharmony_cidevices.
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci*/
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic void  fit2_write_regr( PIA *pi, int cont, int regr, int val)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci{	if (cont == 1) return;
438c2ecf20Sopenharmony_ci	w2(0xc); w0(regr); w2(4); w0(val); w2(5); w0(0); w2(4);
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic int fit2_read_regr( PIA *pi, int cont, int regr )
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci{	int  a, b, r;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	if (cont) {
518c2ecf20Sopenharmony_ci	  if (regr != 6) return 0xff;
528c2ecf20Sopenharmony_ci	  r = 7;
538c2ecf20Sopenharmony_ci	} else r = regr + 0x10;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	w2(0xc); w0(r); w2(4); w2(5);
568c2ecf20Sopenharmony_ci	         w0(0); a = r1();
578c2ecf20Sopenharmony_ci	         w0(1); b = r1();
588c2ecf20Sopenharmony_ci	w2(4);
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	return j44(a,b);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistatic void fit2_read_block( PIA *pi, char * buf, int count )
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci{	int  k, a, b, c, d;
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	w2(0xc); w0(0x10);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	for (k=0;k<count/4;k++) {
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci		w2(4); w2(5);
738c2ecf20Sopenharmony_ci		w0(0); a = r1(); w0(1); b = r1();
748c2ecf20Sopenharmony_ci		w0(3); c = r1(); w0(2); d = r1();
758c2ecf20Sopenharmony_ci		buf[4*k+0] = j44(a,b);
768c2ecf20Sopenharmony_ci		buf[4*k+1] = j44(d,c);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci                w2(4); w2(5);
798c2ecf20Sopenharmony_ci                       a = r1(); w0(3); b = r1();
808c2ecf20Sopenharmony_ci                w0(1); c = r1(); w0(0); d = r1();
818c2ecf20Sopenharmony_ci                buf[4*k+2] = j44(d,c);
828c2ecf20Sopenharmony_ci                buf[4*k+3] = j44(a,b);
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	}
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	w2(4);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistatic void fit2_write_block( PIA *pi, char * buf, int count )
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci{	int k;
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	w2(0xc); w0(0);
968c2ecf20Sopenharmony_ci	for (k=0;k<count/2;k++) {
978c2ecf20Sopenharmony_ci		w2(4); w0(buf[2*k]);
988c2ecf20Sopenharmony_ci		w2(5); w0(buf[2*k+1]);
998c2ecf20Sopenharmony_ci	}
1008c2ecf20Sopenharmony_ci	w2(4);
1018c2ecf20Sopenharmony_ci}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistatic void fit2_connect ( PIA *pi  )
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci{       pi->saved_r0 = r0();
1068c2ecf20Sopenharmony_ci        pi->saved_r2 = r2();
1078c2ecf20Sopenharmony_ci	w2(0xcc);
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistatic void fit2_disconnect ( PIA *pi )
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci{       w0(pi->saved_r0);
1138c2ecf20Sopenharmony_ci        w2(pi->saved_r2);
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic void fit2_log_adapter( PIA *pi, char * scratch, int verbose )
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci{       printk("%s: fit2 %s, FIT 2000 adapter at 0x%x, delay %d\n",
1198c2ecf20Sopenharmony_ci                pi->device,FIT2_VERSION,pi->port,pi->delay);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_cistatic struct pi_protocol fit2 = {
1248c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,
1258c2ecf20Sopenharmony_ci	.name		= "fit2",
1268c2ecf20Sopenharmony_ci	.max_mode	= 1,
1278c2ecf20Sopenharmony_ci	.epp_first	= 2,
1288c2ecf20Sopenharmony_ci	.default_delay	= 1,
1298c2ecf20Sopenharmony_ci	.max_units	= 1,
1308c2ecf20Sopenharmony_ci	.write_regr	= fit2_write_regr,
1318c2ecf20Sopenharmony_ci	.read_regr	= fit2_read_regr,
1328c2ecf20Sopenharmony_ci	.write_block	= fit2_write_block,
1338c2ecf20Sopenharmony_ci	.read_block	= fit2_read_block,
1348c2ecf20Sopenharmony_ci	.connect	= fit2_connect,
1358c2ecf20Sopenharmony_ci	.disconnect	= fit2_disconnect,
1368c2ecf20Sopenharmony_ci	.log_adapter	= fit2_log_adapter,
1378c2ecf20Sopenharmony_ci};
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_cistatic int __init fit2_init(void)
1408c2ecf20Sopenharmony_ci{
1418c2ecf20Sopenharmony_ci	return paride_register(&fit2);
1428c2ecf20Sopenharmony_ci}
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cistatic void __exit fit2_exit(void)
1458c2ecf20Sopenharmony_ci{
1468c2ecf20Sopenharmony_ci	paride_unregister(&fit2);
1478c2ecf20Sopenharmony_ci}
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
1508c2ecf20Sopenharmony_cimodule_init(fit2_init)
1518c2ecf20Sopenharmony_cimodule_exit(fit2_exit)
152