xref: /openbmc/linux/drivers/ata/pata_parport/aten.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1ab0695eeSDamien Le Moal // SPDX-License-Identifier: GPL-2.0-or-later
272f2b0b2SOndrej Zary /*
3ab0695eeSDamien Le Moal  * (c) 1997-8  Grant R. Guenther <grant@torque.net>
4ab0695eeSDamien Le Moal  *
5ab0695eeSDamien Le Moal  * aten.c is a low-level protocol driver for the ATEN EH-100
6ab0695eeSDamien Le Moal  * parallel port adapter.  The EH-100 supports 4-bit and 8-bit
7ab0695eeSDamien Le Moal  * modes only.  There is also an EH-132 which supports EPP mode
8ab0695eeSDamien Le Moal  * transfers.  The EH-132 is not yet supported.
972f2b0b2SOndrej Zary  */
1072f2b0b2SOndrej Zary 
1172f2b0b2SOndrej Zary #include <linux/module.h>
1272f2b0b2SOndrej Zary #include <linux/init.h>
1372f2b0b2SOndrej Zary #include <linux/delay.h>
1472f2b0b2SOndrej Zary #include <linux/kernel.h>
1572f2b0b2SOndrej Zary #include <linux/wait.h>
1672f2b0b2SOndrej Zary #include <linux/types.h>
1772f2b0b2SOndrej Zary #include <asm/io.h>
18fe027ff9SOndrej Zary #include "pata_parport.h"
1972f2b0b2SOndrej Zary 
2072f2b0b2SOndrej Zary #define j44(a,b)                ((((a>>4)&0x0f)|(b&0xf0))^0x88)
2172f2b0b2SOndrej Zary 
22ab0695eeSDamien Le Moal /*
23ab0695eeSDamien Le Moal  * cont = 0 - access the IDE register file
24ab0695eeSDamien Le Moal  * cont = 1 - access the IDE command set
2572f2b0b2SOndrej Zary  */
2672f2b0b2SOndrej Zary static int  cont_map[2] = { 0x08, 0x20 };
2772f2b0b2SOndrej Zary 
aten_write_regr(struct pi_adapter * pi,int cont,int regr,int val)28882ff0caSOndrej Zary static void aten_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
29ab0695eeSDamien Le Moal {
30ab0695eeSDamien Le Moal 	int r = regr + cont_map[cont] + 0x80;
3172f2b0b2SOndrej Zary 
3272f2b0b2SOndrej Zary 	w0(r); w2(0xe); w2(6); w0(val); w2(7); w2(6); w2(0xc);
3372f2b0b2SOndrej Zary }
3472f2b0b2SOndrej Zary 
aten_read_regr(struct pi_adapter * pi,int cont,int regr)35882ff0caSOndrej Zary static int aten_read_regr(struct pi_adapter *pi, int cont, int regr)
36ab0695eeSDamien Le Moal {
37ab0695eeSDamien Le Moal 	int  a, b, r;
3872f2b0b2SOndrej Zary 
3972f2b0b2SOndrej Zary 	r = regr + cont_map[cont] + 0x40;
4072f2b0b2SOndrej Zary 
4172f2b0b2SOndrej Zary 	switch (pi->mode) {
4272f2b0b2SOndrej Zary 
43ab0695eeSDamien Le Moal 	case 0:
44ab0695eeSDamien Le Moal 		w0(r); w2(0xe); w2(6);
4572f2b0b2SOndrej Zary 		w2(7); w2(6); w2(0);
4672f2b0b2SOndrej Zary 		a = r1(); w0(0x10); b = r1(); w2(0xc);
4772f2b0b2SOndrej Zary 		return j44(a,b);
4872f2b0b2SOndrej Zary 
49ab0695eeSDamien Le Moal 	case 1:
50ab0695eeSDamien Le Moal 		r |= 0x10;
5172f2b0b2SOndrej Zary 		w0(r); w2(0xe); w2(6); w0(0xff);
5272f2b0b2SOndrej Zary 		w2(0x27); w2(0x26); w2(0x20);
5372f2b0b2SOndrej Zary 		a = r0();
5472f2b0b2SOndrej Zary 		w2(0x26); w2(0xc);
5572f2b0b2SOndrej Zary 		return a;
5672f2b0b2SOndrej Zary 	}
5772f2b0b2SOndrej Zary 	return -1;
5872f2b0b2SOndrej Zary }
5972f2b0b2SOndrej Zary 
aten_read_block(struct pi_adapter * pi,char * buf,int count)60882ff0caSOndrej Zary static void aten_read_block(struct pi_adapter *pi, char *buf, int count)
61ab0695eeSDamien Le Moal {
62ab0695eeSDamien Le Moal 	int  k, a, b, c, d;
6372f2b0b2SOndrej Zary 
6472f2b0b2SOndrej Zary 	switch (pi->mode) {
6572f2b0b2SOndrej Zary 
66ab0695eeSDamien Le Moal 	case 0:
67ab0695eeSDamien Le Moal 		w0(0x48); w2(0xe); w2(6);
6872f2b0b2SOndrej Zary 		for (k = 0; k < count / 2; k++) {
6972f2b0b2SOndrej Zary 			w2(7); w2(6); w2(2);
7072f2b0b2SOndrej Zary 			a = r1(); w0(0x58); b = r1();
7172f2b0b2SOndrej Zary 			w2(0); d = r1(); w0(0x48); c = r1();
7272f2b0b2SOndrej Zary 			buf[2 * k] = j44(c, d);
7372f2b0b2SOndrej Zary 			buf[2 * k + 1] = j44(a, b);
7472f2b0b2SOndrej Zary 		}
7572f2b0b2SOndrej Zary 		w2(0xc);
7672f2b0b2SOndrej Zary 		break;
7772f2b0b2SOndrej Zary 
78ab0695eeSDamien Le Moal 	case 1:
79ab0695eeSDamien Le Moal 		w0(0x58); w2(0xe); w2(6);
8072f2b0b2SOndrej Zary 		for (k = 0; k < count / 2; k++) {
8172f2b0b2SOndrej Zary 			w2(0x27); w2(0x26); w2(0x22);
8272f2b0b2SOndrej Zary 			a = r0(); w2(0x20); b = r0();
83ab0695eeSDamien Le Moal 			buf[2 * k] = b;
84ab0695eeSDamien Le Moal 			buf[2 * k + 1] = a;
8572f2b0b2SOndrej Zary 		}
8672f2b0b2SOndrej Zary 		w2(0x26); w2(0xc);
8772f2b0b2SOndrej Zary 		break;
8872f2b0b2SOndrej Zary 	}
8972f2b0b2SOndrej Zary }
9072f2b0b2SOndrej Zary 
aten_write_block(struct pi_adapter * pi,char * buf,int count)91882ff0caSOndrej Zary static void aten_write_block(struct pi_adapter *pi, char *buf, int count)
92ab0695eeSDamien Le Moal {
93ab0695eeSDamien Le Moal 	int k;
9472f2b0b2SOndrej Zary 
9572f2b0b2SOndrej Zary 	w0(0x88); w2(0xe); w2(6);
9672f2b0b2SOndrej Zary 	for (k = 0; k < count / 2; k++) {
9772f2b0b2SOndrej Zary 		w0(buf[2 * k + 1]); w2(0xe); w2(6);
9872f2b0b2SOndrej Zary 		w0(buf[2 * k]); w2(7); w2(6);
9972f2b0b2SOndrej Zary 	}
10072f2b0b2SOndrej Zary 	w2(0xc);
10172f2b0b2SOndrej Zary }
10272f2b0b2SOndrej Zary 
aten_connect(struct pi_adapter * pi)103882ff0caSOndrej Zary static void aten_connect(struct pi_adapter *pi)
104ab0695eeSDamien Le Moal {
105ab0695eeSDamien Le Moal 	pi->saved_r0 = r0();
10672f2b0b2SOndrej Zary 	pi->saved_r2 = r2();
10772f2b0b2SOndrej Zary 	w2(0xc);
10872f2b0b2SOndrej Zary }
10972f2b0b2SOndrej Zary 
aten_disconnect(struct pi_adapter * pi)110882ff0caSOndrej Zary static void aten_disconnect(struct pi_adapter *pi)
111ab0695eeSDamien Le Moal {
112ab0695eeSDamien Le Moal 	w0(pi->saved_r0);
11372f2b0b2SOndrej Zary 	w2(pi->saved_r2);
11472f2b0b2SOndrej Zary }
11572f2b0b2SOndrej Zary 
aten_log_adapter(struct pi_adapter * pi)1165b77db9cSOndrej Zary static void aten_log_adapter(struct pi_adapter *pi)
117ab0695eeSDamien Le Moal {
118ab0695eeSDamien Le Moal 	char *mode_string[2] = { "4-bit", "8-bit" };
11972f2b0b2SOndrej Zary 
120ab0695eeSDamien Le Moal 	dev_info(&pi->dev,
121ab0695eeSDamien Le Moal 		 "ATEN EH-100 at 0x%x, mode %d (%s), delay %d\n",
122426eb3c5SOndrej Zary 		 pi->port, pi->mode, mode_string[pi->mode], pi->delay);
12372f2b0b2SOndrej Zary }
12472f2b0b2SOndrej Zary 
12572f2b0b2SOndrej Zary static struct pi_protocol aten = {
12672f2b0b2SOndrej Zary 	.owner		= THIS_MODULE,
12772f2b0b2SOndrej Zary 	.name		= "aten",
12872f2b0b2SOndrej Zary 	.max_mode	= 2,
12972f2b0b2SOndrej Zary 	.epp_first	= 2,
13072f2b0b2SOndrej Zary 	.default_delay	= 1,
13172f2b0b2SOndrej Zary 	.max_units	= 1,
13272f2b0b2SOndrej Zary 	.write_regr	= aten_write_regr,
13372f2b0b2SOndrej Zary 	.read_regr	= aten_read_regr,
13472f2b0b2SOndrej Zary 	.write_block	= aten_write_block,
13572f2b0b2SOndrej Zary 	.read_block	= aten_read_block,
13672f2b0b2SOndrej Zary 	.connect	= aten_connect,
13772f2b0b2SOndrej Zary 	.disconnect	= aten_disconnect,
13872f2b0b2SOndrej Zary 	.log_adapter	= aten_log_adapter,
13972f2b0b2SOndrej Zary };
14072f2b0b2SOndrej Zary 
14172f2b0b2SOndrej Zary MODULE_LICENSE("GPL");
142*cec148c2SDamien Le Moal MODULE_AUTHOR("Grant R. Guenther <grant@torque.net>");
143*cec148c2SDamien Le Moal MODULE_DESCRIPTION("ATEN EH-100 parallel port IDE adapter protocol driver");
1442c08ec0fSOndrej Zary module_pata_parport_driver(aten);
145