xref: /openbmc/linux/drivers/ata/pata_parport/ktti.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1ece68db9SDamien Le Moal // SPDX-License-Identifier: GPL-2.0-or-later
272f2b0b2SOndrej Zary /*
3ece68db9SDamien Le Moal  * (c) 1998  Grant R. Guenther <grant@torque.net>
4ece68db9SDamien Le Moal  *
5ece68db9SDamien Le Moal  * ktti.c is a low-level protocol driver for the KT Technology
6ece68db9SDamien Le Moal  * parallel port adapter.  This adapter is used in the "PHd"
7ece68db9SDamien Le Moal  * portable hard-drives.  As far as I can tell, this device
8ece68db9SDamien Le Moal  * supports 4-bit mode _only_.
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/types.h>
1672f2b0b2SOndrej Zary #include <linux/wait.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))
2172f2b0b2SOndrej Zary 
22ece68db9SDamien Le Moal /*
23ece68db9SDamien Le Moal  * cont = 0 - access the IDE register file
24ece68db9SDamien Le Moal  * cont = 1 - access the IDE command set
2572f2b0b2SOndrej Zary  */
2672f2b0b2SOndrej Zary static int cont_map[2] = { 0x10, 0x08 };
2772f2b0b2SOndrej Zary 
ktti_write_regr(struct pi_adapter * pi,int cont,int regr,int val)28882ff0caSOndrej Zary static void ktti_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
29ece68db9SDamien Le Moal {
30ece68db9SDamien Le Moal 	int r = regr + cont_map[cont];
3172f2b0b2SOndrej Zary 
3272f2b0b2SOndrej Zary 	w0(r); w2(0xb); w2(0xa); w2(3); w2(6);
3372f2b0b2SOndrej Zary 	w0(val); w2(3); w0(0); w2(6); w2(0xb);
3472f2b0b2SOndrej Zary }
3572f2b0b2SOndrej Zary 
ktti_read_regr(struct pi_adapter * pi,int cont,int regr)36882ff0caSOndrej Zary static int ktti_read_regr(struct pi_adapter *pi, int cont, int regr)
37ece68db9SDamien Le Moal {
38ece68db9SDamien Le Moal 	int a, b, r;
3972f2b0b2SOndrej Zary 
4072f2b0b2SOndrej Zary         r = regr + cont_map[cont];
4172f2b0b2SOndrej Zary 
4272f2b0b2SOndrej Zary 	w0(r); w2(0xb); w2(0xa); w2(9); w2(0xc); w2(9);
4372f2b0b2SOndrej Zary 	a = r1(); w2(0xc);  b = r1(); w2(9); w2(0xc); w2(9);
4472f2b0b2SOndrej Zary 	return j44(a, b);
4572f2b0b2SOndrej Zary }
4672f2b0b2SOndrej Zary 
ktti_read_block(struct pi_adapter * pi,char * buf,int count)47882ff0caSOndrej Zary static void ktti_read_block(struct pi_adapter *pi, char *buf, int count)
48ece68db9SDamien Le Moal {
49ece68db9SDamien Le Moal 	int k, a, b;
5072f2b0b2SOndrej Zary 
5172f2b0b2SOndrej Zary 	for (k = 0; k < count / 2; k++) {
5272f2b0b2SOndrej Zary 		w0(0x10); w2(0xb); w2(0xa); w2(9); w2(0xc); w2(9);
5372f2b0b2SOndrej Zary 		a = r1(); w2(0xc); b = r1(); w2(9);
5472f2b0b2SOndrej Zary 		buf[2*k] = j44(a, b);
5572f2b0b2SOndrej Zary 		a = r1(); w2(0xc); b = r1(); w2(9);
5672f2b0b2SOndrej Zary 		buf[2*k+1] = j44(a, b);
5772f2b0b2SOndrej Zary 	}
5872f2b0b2SOndrej Zary }
5972f2b0b2SOndrej Zary 
ktti_write_block(struct pi_adapter * pi,char * buf,int count)60882ff0caSOndrej Zary static void ktti_write_block(struct pi_adapter *pi, char *buf, int count)
61ece68db9SDamien Le Moal {
62ece68db9SDamien Le Moal 	int k;
6372f2b0b2SOndrej Zary 
6472f2b0b2SOndrej Zary 	for (k = 0; k < count / 2; k++) {
6572f2b0b2SOndrej Zary 		w0(0x10); w2(0xb); w2(0xa); w2(3); w2(6);
6672f2b0b2SOndrej Zary 		w0(buf[2 * k]); w2(3);
6772f2b0b2SOndrej Zary 		w0(buf[2 * k + 1]); w2(6);
6872f2b0b2SOndrej Zary 		w2(0xb);
6972f2b0b2SOndrej Zary 	}
7072f2b0b2SOndrej Zary }
7172f2b0b2SOndrej Zary 
ktti_connect(struct pi_adapter * pi)72882ff0caSOndrej Zary static void ktti_connect(struct pi_adapter *pi)
73ece68db9SDamien Le Moal {
74ece68db9SDamien Le Moal 	pi->saved_r0 = r0();
7572f2b0b2SOndrej Zary 	pi->saved_r2 = r2();
7672f2b0b2SOndrej Zary 	w2(0xb); w2(0xa); w0(0); w2(3); w2(6);
7772f2b0b2SOndrej Zary }
7872f2b0b2SOndrej Zary 
ktti_disconnect(struct pi_adapter * pi)79882ff0caSOndrej Zary static void ktti_disconnect(struct pi_adapter *pi)
80ece68db9SDamien Le Moal {
81ece68db9SDamien Le Moal 	w2(0xb); w2(0xa); w0(0xa0); w2(3); w2(4);
8272f2b0b2SOndrej Zary 	w0(pi->saved_r0);
8372f2b0b2SOndrej Zary 	w2(pi->saved_r2);
8472f2b0b2SOndrej Zary }
8572f2b0b2SOndrej Zary 
ktti_log_adapter(struct pi_adapter * pi)865b77db9cSOndrej Zary static void ktti_log_adapter(struct pi_adapter *pi)
87a4f2ff92SOndrej Zary {
88426eb3c5SOndrej Zary 	dev_info(&pi->dev, "KT adapter at 0x%x, delay %d\n",
89426eb3c5SOndrej Zary 		 pi->port, pi->delay);
9072f2b0b2SOndrej Zary }
9172f2b0b2SOndrej Zary 
9272f2b0b2SOndrej Zary static struct pi_protocol ktti = {
9372f2b0b2SOndrej Zary 	.owner		= THIS_MODULE,
9472f2b0b2SOndrej Zary 	.name		= "ktti",
9572f2b0b2SOndrej Zary 	.max_mode	= 1,
9672f2b0b2SOndrej Zary 	.epp_first	= 2,
9772f2b0b2SOndrej Zary 	.default_delay	= 1,
9872f2b0b2SOndrej Zary 	.max_units	= 1,
9972f2b0b2SOndrej Zary 	.write_regr	= ktti_write_regr,
10072f2b0b2SOndrej Zary 	.read_regr	= ktti_read_regr,
10172f2b0b2SOndrej Zary 	.write_block	= ktti_write_block,
10272f2b0b2SOndrej Zary 	.read_block	= ktti_read_block,
10372f2b0b2SOndrej Zary 	.connect	= ktti_connect,
10472f2b0b2SOndrej Zary 	.disconnect	= ktti_disconnect,
10572f2b0b2SOndrej Zary 	.log_adapter	= ktti_log_adapter,
10672f2b0b2SOndrej Zary };
10772f2b0b2SOndrej Zary 
10872f2b0b2SOndrej Zary MODULE_LICENSE("GPL");
109*cec148c2SDamien Le Moal MODULE_AUTHOR("Grant R. Guenther <grant@torque.net>");
110*cec148c2SDamien Le Moal MODULE_DESCRIPTION("KT Technology parallel port IDE adapter protocol driver");
1112c08ec0fSOndrej Zary module_pata_parport_driver(ktti);
112