xref: /openbmc/linux/drivers/ata/pata_parport/fit3.c (revision 8182d7a3f1b8982c0136dca82a846ea375a4d6e9)
16b427116SDamien Le Moal // SPDX-License-Identifier: GPL-2.0-or-later
272f2b0b2SOndrej Zary /*
36b427116SDamien Le Moal  * (c) 1998  Grant R. Guenther <grant@torque.net>
46b427116SDamien Le Moal  *
56b427116SDamien Le Moal  * fit3.c is a low-level protocol driver for newer models
66b427116SDamien Le Moal  * of the Fidelity International Technology parallel port adapter.
76b427116SDamien Le Moal  * This adapter is used in their TransDisk 3000 portable
86b427116SDamien Le Moal  * hard-drives, as well as CD-ROM, PD-CD and other devices.
96b427116SDamien Le Moal  *
106b427116SDamien Le Moal  * The TD-2000 and certain older devices use a different protocol.
116b427116SDamien Le Moal  * Try the fit2 protocol module with them.
1272f2b0b2SOndrej Zary  */
1372f2b0b2SOndrej Zary 
1472f2b0b2SOndrej Zary #include <linux/module.h>
1572f2b0b2SOndrej Zary #include <linux/init.h>
1672f2b0b2SOndrej Zary #include <linux/delay.h>
1772f2b0b2SOndrej Zary #include <linux/kernel.h>
1872f2b0b2SOndrej Zary #include <linux/types.h>
1972f2b0b2SOndrej Zary #include <linux/wait.h>
2072f2b0b2SOndrej Zary #include <asm/io.h>
21fe027ff9SOndrej Zary #include "pata_parport.h"
2272f2b0b2SOndrej Zary 
2372f2b0b2SOndrej Zary #define j44(a, b)	(((a >> 3) & 0x0f) | ((b << 1) & 0xf0))
2472f2b0b2SOndrej Zary 
256b427116SDamien Le Moal #define w7(byte)	out_p(7, byte)
2672f2b0b2SOndrej Zary #define r7()		(in_p(7) & 0xff)
2772f2b0b2SOndrej Zary 
286b427116SDamien Le Moal /*
296b427116SDamien Le Moal  * cont = 0 - access the IDE register file
306b427116SDamien Le Moal  * cont = 1 - access the IDE command set
3172f2b0b2SOndrej Zary  */
3272f2b0b2SOndrej Zary 
fit3_write_regr(struct pi_adapter * pi,int cont,int regr,int val)33882ff0caSOndrej Zary static void fit3_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
346b427116SDamien Le Moal {
35*0c1e81d0SOndrej Zary 	regr += cont << 3;
3672f2b0b2SOndrej Zary 
3772f2b0b2SOndrej Zary 	switch (pi->mode) {
3872f2b0b2SOndrej Zary 	case 0:
396b427116SDamien Le Moal 	case 1:
406b427116SDamien Le Moal 		w2(0xc); w0(regr); w2(0x8); w2(0xc);
4172f2b0b2SOndrej Zary 		w0(val); w2(0xd);
4272f2b0b2SOndrej Zary 		w0(0);   w2(0xc);
4372f2b0b2SOndrej Zary 		break;
446b427116SDamien Le Moal 	case 2:
456b427116SDamien Le Moal 		w2(0xc); w0(regr); w2(0x8); w2(0xc);
4672f2b0b2SOndrej Zary 		w4(val); w4(0);
4772f2b0b2SOndrej Zary 		w2(0xc);
4872f2b0b2SOndrej Zary 		break;
4972f2b0b2SOndrej Zary 	}
5072f2b0b2SOndrej Zary }
5172f2b0b2SOndrej Zary 
fit3_read_regr(struct pi_adapter * pi,int cont,int regr)52882ff0caSOndrej Zary static int fit3_read_regr(struct pi_adapter *pi, int cont, int regr)
536b427116SDamien Le Moal {
546b427116SDamien Le Moal 	int  a, b;
5572f2b0b2SOndrej Zary 
56*0c1e81d0SOndrej Zary 	regr += cont << 3;
5772f2b0b2SOndrej Zary 
5872f2b0b2SOndrej Zary 	switch (pi->mode) {
596b427116SDamien Le Moal 	case 0:
606b427116SDamien Le Moal 		w2(0xc); w0(regr + 0x10); w2(0x8); w2(0xc);
6172f2b0b2SOndrej Zary 		w2(0xd); a = r1();
6272f2b0b2SOndrej Zary 		w2(0xf); b = r1();
6372f2b0b2SOndrej Zary 		w2(0xc);
6472f2b0b2SOndrej Zary 		return j44(a, b);
656b427116SDamien Le Moal 	case 1:
666b427116SDamien Le Moal 		w2(0xc); w0(regr + 0x90); w2(0x8); w2(0xc);
6772f2b0b2SOndrej Zary 		w2(0xec); w2(0xee); w2(0xef); a = r0();
6872f2b0b2SOndrej Zary 		w2(0xc);
6972f2b0b2SOndrej Zary 		return a;
706b427116SDamien Le Moal 	case 2:
716b427116SDamien Le Moal 		w2(0xc); w0(regr + 0x90); w2(0x8); w2(0xc);
7272f2b0b2SOndrej Zary 		w2(0xec);
7372f2b0b2SOndrej Zary 		a = r4(); b = r4();
7472f2b0b2SOndrej Zary 		w2(0xc);
7572f2b0b2SOndrej Zary 		return a;
7672f2b0b2SOndrej Zary 	}
7772f2b0b2SOndrej Zary 
786b427116SDamien Le Moal 	return -1;
7972f2b0b2SOndrej Zary }
8072f2b0b2SOndrej Zary 
fit3_read_block(struct pi_adapter * pi,char * buf,int count)81882ff0caSOndrej Zary static void fit3_read_block(struct pi_adapter *pi, char *buf, int count)
826b427116SDamien Le Moal {
836b427116SDamien Le Moal 	int  k, a, b, c, d;
8472f2b0b2SOndrej Zary 
8572f2b0b2SOndrej Zary 	switch (pi->mode) {
866b427116SDamien Le Moal 	case 0:
876b427116SDamien Le Moal 		w2(0xc); w0(0x10); w2(0x8); w2(0xc);
8872f2b0b2SOndrej Zary 		for (k = 0; k < count / 2; k++) {
8972f2b0b2SOndrej Zary 			w2(0xd); a = r1();
9072f2b0b2SOndrej Zary 			w2(0xf); b = r1();
9172f2b0b2SOndrej Zary 			w2(0xc); c = r1();
9272f2b0b2SOndrej Zary 			w2(0xe); d = r1();
9372f2b0b2SOndrej Zary 			buf[2 * k] = j44(a, b);
9472f2b0b2SOndrej Zary 			buf[2 * k + 1] = j44(c, d);
9572f2b0b2SOndrej Zary 		}
9672f2b0b2SOndrej Zary 		w2(0xc);
9772f2b0b2SOndrej Zary 		break;
986b427116SDamien Le Moal 	case 1:
996b427116SDamien Le Moal 		w2(0xc); w0(0x90); w2(0x8); w2(0xc);
10072f2b0b2SOndrej Zary 		w2(0xec); w2(0xee);
10172f2b0b2SOndrej Zary 		for (k = 0; k < count / 2; k++) {
10272f2b0b2SOndrej Zary 			w2(0xef); a = r0();
10372f2b0b2SOndrej Zary 			w2(0xee); b = r0();
10472f2b0b2SOndrej Zary 			buf[2 * k] = a;
10572f2b0b2SOndrej Zary 			buf[2 * k + 1] = b;
10672f2b0b2SOndrej Zary 		}
10772f2b0b2SOndrej Zary 		w2(0xec);
10872f2b0b2SOndrej Zary 		w2(0xc);
10972f2b0b2SOndrej Zary 		break;
1106b427116SDamien Le Moal 	case 2:
1116b427116SDamien Le Moal 		w2(0xc); w0(0x90); w2(0x8); w2(0xc);
11272f2b0b2SOndrej Zary 		w2(0xec);
1136b427116SDamien Le Moal 		for (k = 0; k < count; k++)
1146b427116SDamien Le Moal 			buf[k] = r4();
11572f2b0b2SOndrej Zary 		w2(0xc);
11672f2b0b2SOndrej Zary 		break;
11772f2b0b2SOndrej Zary 	}
11872f2b0b2SOndrej Zary }
11972f2b0b2SOndrej Zary 
fit3_write_block(struct pi_adapter * pi,char * buf,int count)120882ff0caSOndrej Zary static void fit3_write_block(struct pi_adapter *pi, char *buf, int count)
1216b427116SDamien Le Moal {
1226b427116SDamien Le Moal 	int k;
12372f2b0b2SOndrej Zary 
12472f2b0b2SOndrej Zary 	switch (pi->mode) {
12572f2b0b2SOndrej Zary 	case 0:
1266b427116SDamien Le Moal 	case 1:
1276b427116SDamien Le Moal 		w2(0xc); w0(0); w2(0x8); w2(0xc);
12872f2b0b2SOndrej Zary 		for (k = 0; k < count / 2; k++) {
12972f2b0b2SOndrej Zary 			w0(buf[2 * k]); w2(0xd);
13072f2b0b2SOndrej Zary 			w0(buf[2 * k + 1]); w2(0xc);
13172f2b0b2SOndrej Zary 		}
13272f2b0b2SOndrej Zary 		break;
1336b427116SDamien Le Moal 	case 2:
1346b427116SDamien Le Moal 		w2(0xc); w0(0); w2(0x8); w2(0xc);
1356b427116SDamien Le Moal 		for (k = 0; k < count; k++)
1366b427116SDamien Le Moal 			w4(buf[k]);
13772f2b0b2SOndrej Zary 		w2(0xc);
13872f2b0b2SOndrej Zary 		break;
13972f2b0b2SOndrej Zary 	}
14072f2b0b2SOndrej Zary }
14172f2b0b2SOndrej Zary 
fit3_connect(struct pi_adapter * pi)142882ff0caSOndrej Zary static void fit3_connect(struct pi_adapter *pi)
1436b427116SDamien Le Moal {
1446b427116SDamien Le Moal 	pi->saved_r0 = r0();
14572f2b0b2SOndrej Zary 	pi->saved_r2 = r2();
14672f2b0b2SOndrej Zary 	w2(0xc); w0(0); w2(0xa);
14772f2b0b2SOndrej Zary 	if (pi->mode == 2) {
1486b427116SDamien Le Moal 		w2(0xc); w0(0x9);
1496b427116SDamien Le Moal 		w2(0x8); w2(0xc);
15072f2b0b2SOndrej Zary 	}
15172f2b0b2SOndrej Zary }
15272f2b0b2SOndrej Zary 
fit3_disconnect(struct pi_adapter * pi)153882ff0caSOndrej Zary static void fit3_disconnect(struct pi_adapter *pi)
1546b427116SDamien Le Moal {
1556b427116SDamien Le Moal 	w2(0xc); w0(0xa); w2(0x8); w2(0xc);
15672f2b0b2SOndrej Zary 	w0(pi->saved_r0);
15772f2b0b2SOndrej Zary 	w2(pi->saved_r2);
15872f2b0b2SOndrej Zary }
15972f2b0b2SOndrej Zary 
fit3_log_adapter(struct pi_adapter * pi)1605b77db9cSOndrej Zary static void fit3_log_adapter(struct pi_adapter *pi)
1616b427116SDamien Le Moal {
1626b427116SDamien Le Moal 	char *mode_string[3] = { "4-bit", "8-bit", "EPP"};
16372f2b0b2SOndrej Zary 
1646b427116SDamien Le Moal 	dev_info(&pi->dev,
1656b427116SDamien Le Moal 		 "FIT 3000 adapter at 0x%x, mode %d (%s), delay %d\n",
166426eb3c5SOndrej Zary 		 pi->port, pi->mode, mode_string[pi->mode], pi->delay);
16772f2b0b2SOndrej Zary }
16872f2b0b2SOndrej Zary 
16972f2b0b2SOndrej Zary static struct pi_protocol fit3 = {
17072f2b0b2SOndrej Zary 	.owner		= THIS_MODULE,
17172f2b0b2SOndrej Zary 	.name		= "fit3",
17272f2b0b2SOndrej Zary 	.max_mode	= 3,
17372f2b0b2SOndrej Zary 	.epp_first	= 2,
17472f2b0b2SOndrej Zary 	.default_delay	= 1,
17572f2b0b2SOndrej Zary 	.max_units	= 1,
17672f2b0b2SOndrej Zary 	.write_regr	= fit3_write_regr,
17772f2b0b2SOndrej Zary 	.read_regr	= fit3_read_regr,
17872f2b0b2SOndrej Zary 	.write_block	= fit3_write_block,
17972f2b0b2SOndrej Zary 	.read_block	= fit3_read_block,
18072f2b0b2SOndrej Zary 	.connect	= fit3_connect,
18172f2b0b2SOndrej Zary 	.disconnect	= fit3_disconnect,
18272f2b0b2SOndrej Zary 	.log_adapter	= fit3_log_adapter,
18372f2b0b2SOndrej Zary };
18472f2b0b2SOndrej Zary 
18572f2b0b2SOndrej Zary MODULE_LICENSE("GPL");
186cec148c2SDamien Le Moal MODULE_AUTHOR("Grant R. Guenther <grant@torque.net>");
187cec148c2SDamien Le Moal MODULE_DESCRIPTION("Fidelity International Technology parallel port IDE adapter"
188cec148c2SDamien Le Moal 		   "(newer models) protocol driver");
1892c08ec0fSOndrej Zary module_pata_parport_driver(fit3);
190