xref: /openbmc/linux/drivers/ata/pata_parport/on20.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1012f2059SDamien Le Moal // SPDX-License-Identifier: GPL-2.0-or-later
272f2b0b2SOndrej Zary /*
3012f2059SDamien Le Moal  * (c) 1996-1998  Grant R. Guenther <grant@torque.net>
4012f2059SDamien Le Moal  *
5012f2059SDamien Le Moal  * on20.c is a low-level protocol driver for the
6012f2059SDamien Le Moal  * Onspec 90c20 parallel to IDE adapter.
772f2b0b2SOndrej Zary  */
872f2b0b2SOndrej Zary 
972f2b0b2SOndrej Zary #include <linux/module.h>
1072f2b0b2SOndrej Zary #include <linux/init.h>
1172f2b0b2SOndrej Zary #include <linux/delay.h>
1272f2b0b2SOndrej Zary #include <linux/kernel.h>
1372f2b0b2SOndrej Zary #include <linux/types.h>
1472f2b0b2SOndrej Zary #include <linux/wait.h>
1572f2b0b2SOndrej Zary #include <asm/io.h>
16fe027ff9SOndrej Zary #include "pata_parport.h"
1772f2b0b2SOndrej Zary 
18012f2059SDamien Le Moal #define op(f)					\
19012f2059SDamien Le Moal 	do {					\
20012f2059SDamien Le Moal 		w2(4); w0(f); w2(5); w2(0xd);	\
21012f2059SDamien Le Moal 		w2(5); w2(0xd); w2(5); w2(4);	\
22012f2059SDamien Le Moal 	} while (0)
23012f2059SDamien Le Moal 
24012f2059SDamien Le Moal #define vl(v)					\
25012f2059SDamien Le Moal 	do {					\
26012f2059SDamien Le Moal 		w2(4); w0(v); w2(5);		\
27012f2059SDamien Le Moal 		w2(7); w2(5); w2(4);		\
28012f2059SDamien Le Moal 	} while (0)
2972f2b0b2SOndrej Zary 
3072f2b0b2SOndrej Zary #define j44(a, b)	(((a >> 4) & 0x0f) | (b & 0xf0))
3172f2b0b2SOndrej Zary 
32012f2059SDamien Le Moal /*
33012f2059SDamien Le Moal  * cont = 0 - access the IDE register file
34012f2059SDamien Le Moal  * cont = 1 - access the IDE command set
3572f2b0b2SOndrej Zary  */
3672f2b0b2SOndrej Zary 
on20_read_regr(struct pi_adapter * pi,int cont,int regr)37882ff0caSOndrej Zary static int on20_read_regr(struct pi_adapter *pi, int cont, int regr)
38012f2059SDamien Le Moal {
39012f2059SDamien Le Moal 	int h, l, r;
4072f2b0b2SOndrej Zary 
4172f2b0b2SOndrej Zary 	r = (regr << 2) + 1 + cont;
4272f2b0b2SOndrej Zary 
4372f2b0b2SOndrej Zary 	op(1); vl(r); op(0);
4472f2b0b2SOndrej Zary 
4572f2b0b2SOndrej Zary 	switch (pi->mode) {
46012f2059SDamien Le Moal 	case 0:
47012f2059SDamien Le Moal 		w2(4); w2(6); l = r1();
4872f2b0b2SOndrej Zary 		w2(4); w2(6); h = r1();
4972f2b0b2SOndrej Zary 		w2(4); w2(6); w2(4); w2(6); w2(4);
5072f2b0b2SOndrej Zary 		return j44(l, h);
51012f2059SDamien Le Moal 	case 1:
52012f2059SDamien Le Moal 		w2(4); w2(0x26); r = r0();
5372f2b0b2SOndrej Zary 		w2(4); w2(0x26); w2(4);
5472f2b0b2SOndrej Zary 		return r;
5572f2b0b2SOndrej Zary 	}
56012f2059SDamien Le Moal 
5772f2b0b2SOndrej Zary 	return -1;
5872f2b0b2SOndrej Zary }
5972f2b0b2SOndrej Zary 
on20_write_regr(struct pi_adapter * pi,int cont,int regr,int val)60882ff0caSOndrej Zary static void on20_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
61012f2059SDamien Le Moal {
62012f2059SDamien Le Moal 	int r = (regr << 2) + 1 + cont;
6372f2b0b2SOndrej Zary 
6472f2b0b2SOndrej Zary 	op(1); vl(r);
6572f2b0b2SOndrej Zary 	op(0); vl(val);
6672f2b0b2SOndrej Zary 	op(0); vl(val);
6772f2b0b2SOndrej Zary }
6872f2b0b2SOndrej Zary 
on20_connect(struct pi_adapter * pi)69882ff0caSOndrej Zary static void on20_connect(struct pi_adapter *pi)
70012f2059SDamien Le Moal {
71012f2059SDamien Le Moal 	pi->saved_r0 = r0();
7272f2b0b2SOndrej Zary 	pi->saved_r2 = r2();
7372f2b0b2SOndrej Zary 
7472f2b0b2SOndrej Zary 	w2(4); w0(0); w2(0xc); w2(4); w2(6); w2(4); w2(6); w2(4);
75012f2059SDamien Le Moal 	if (pi->mode) {
76012f2059SDamien Le Moal 		op(2); vl(8); op(2); vl(9);
77012f2059SDamien Le Moal 	} else {
78012f2059SDamien Le Moal 		op(2); vl(0); op(2); vl(8);
79012f2059SDamien Le Moal 	}
8072f2b0b2SOndrej Zary }
8172f2b0b2SOndrej Zary 
on20_disconnect(struct pi_adapter * pi)82882ff0caSOndrej Zary static void on20_disconnect(struct pi_adapter *pi)
83012f2059SDamien Le Moal {
84012f2059SDamien Le Moal 	w2(4); w0(7); w2(4); w2(0xc); w2(4);
8572f2b0b2SOndrej Zary 	w0(pi->saved_r0);
8672f2b0b2SOndrej Zary 	w2(pi->saved_r2);
8772f2b0b2SOndrej Zary }
8872f2b0b2SOndrej Zary 
on20_read_block(struct pi_adapter * pi,char * buf,int count)89882ff0caSOndrej Zary static void on20_read_block(struct pi_adapter *pi, char *buf, int count)
90012f2059SDamien Le Moal {
91012f2059SDamien Le Moal 	int k, l, h;
9272f2b0b2SOndrej Zary 
9372f2b0b2SOndrej Zary 	op(1); vl(1); op(0);
9472f2b0b2SOndrej Zary 
95012f2059SDamien Le Moal 	for (k = 0; k < count; k++) {
9672f2b0b2SOndrej Zary 		if (pi->mode) {
9772f2b0b2SOndrej Zary 			w2(4); w2(0x26); buf[k] = r0();
9872f2b0b2SOndrej Zary 		} else {
9972f2b0b2SOndrej Zary 			w2(6); l = r1(); w2(4);
10072f2b0b2SOndrej Zary 			w2(6); h = r1(); w2(4);
10172f2b0b2SOndrej Zary 			buf[k] = j44(l, h);
10272f2b0b2SOndrej Zary 		}
103012f2059SDamien Le Moal 	}
10472f2b0b2SOndrej Zary 	w2(4);
10572f2b0b2SOndrej Zary }
10672f2b0b2SOndrej Zary 
on20_write_block(struct pi_adapter * pi,char * buf,int count)107882ff0caSOndrej Zary static void on20_write_block(struct pi_adapter *pi, char *buf, int count)
108012f2059SDamien Le Moal {
109012f2059SDamien Le Moal 	int k;
11072f2b0b2SOndrej Zary 
11172f2b0b2SOndrej Zary 	op(1); vl(1); op(0);
11272f2b0b2SOndrej Zary 
113012f2059SDamien Le Moal 	for (k = 0; k < count; k++) {
114012f2059SDamien Le Moal 		w2(5); w0(buf[k]); w2(7);
115012f2059SDamien Le Moal 	}
11672f2b0b2SOndrej Zary 	w2(4);
11772f2b0b2SOndrej Zary }
11872f2b0b2SOndrej Zary 
on20_log_adapter(struct pi_adapter * pi)1195b77db9cSOndrej Zary static void on20_log_adapter(struct pi_adapter *pi)
120012f2059SDamien Le Moal {
121012f2059SDamien Le Moal 	char *mode_string[2] = { "4-bit", "8-bit" };
12272f2b0b2SOndrej Zary 
123012f2059SDamien Le Moal 	dev_info(&pi->dev,
124012f2059SDamien Le Moal 		 "OnSpec 90c20 at 0x%x, mode %d (%s), delay %d\n",
125426eb3c5SOndrej Zary 		 pi->port, pi->mode, mode_string[pi->mode], pi->delay);
12672f2b0b2SOndrej Zary }
12772f2b0b2SOndrej Zary 
12872f2b0b2SOndrej Zary static struct pi_protocol on20 = {
12972f2b0b2SOndrej Zary 	.owner		= THIS_MODULE,
13072f2b0b2SOndrej Zary 	.name		= "on20",
13172f2b0b2SOndrej Zary 	.max_mode	= 2,
13272f2b0b2SOndrej Zary 	.epp_first	= 2,
13372f2b0b2SOndrej Zary 	.default_delay	= 1,
13472f2b0b2SOndrej Zary 	.max_units	= 1,
13572f2b0b2SOndrej Zary 	.write_regr	= on20_write_regr,
13672f2b0b2SOndrej Zary 	.read_regr	= on20_read_regr,
13772f2b0b2SOndrej Zary 	.write_block	= on20_write_block,
13872f2b0b2SOndrej Zary 	.read_block	= on20_read_block,
13972f2b0b2SOndrej Zary 	.connect	= on20_connect,
14072f2b0b2SOndrej Zary 	.disconnect	= on20_disconnect,
14172f2b0b2SOndrej Zary 	.log_adapter	= on20_log_adapter,
14272f2b0b2SOndrej Zary };
14372f2b0b2SOndrej Zary 
14472f2b0b2SOndrej Zary MODULE_LICENSE("GPL");
145*cec148c2SDamien Le Moal MODULE_AUTHOR("Grant R. Guenther <grant@torque.net>");
146*cec148c2SDamien Le Moal MODULE_DESCRIPTION("Onspec 90c20 parallel port IDE adapter protocol driver");
1472c08ec0fSOndrej Zary module_pata_parport_driver(on20);
148