1 /* 2 ktti.c (c) 1998 Grant R. Guenther <grant@torque.net> 3 Under the terms of the GNU General Public License. 4 5 ktti.c is a low-level protocol driver for the KT Technology 6 parallel port adapter. This adapter is used in the "PHd" 7 portable hard-drives. As far as I can tell, this device 8 supports 4-bit mode _only_. 9 10 */ 11 12 #include <linux/module.h> 13 #include <linux/init.h> 14 #include <linux/delay.h> 15 #include <linux/kernel.h> 16 #include <linux/types.h> 17 #include <linux/wait.h> 18 #include <asm/io.h> 19 #include "pata_parport.h" 20 21 #define j44(a,b) (((a>>4)&0x0f)|(b&0xf0)) 22 23 /* cont = 0 - access the IDE register file 24 cont = 1 - access the IDE command set 25 */ 26 27 static int cont_map[2] = { 0x10, 0x08 }; 28 29 static void ktti_write_regr(struct pi_adapter *pi, int cont, int regr, int val) 30 31 { int r; 32 33 r = regr + cont_map[cont]; 34 35 w0(r); w2(0xb); w2(0xa); w2(3); w2(6); 36 w0(val); w2(3); w0(0); w2(6); w2(0xb); 37 } 38 39 static int ktti_read_regr(struct pi_adapter *pi, int cont, int regr) 40 41 { int a, b, r; 42 43 r = regr + cont_map[cont]; 44 45 w0(r); w2(0xb); w2(0xa); w2(9); w2(0xc); w2(9); 46 a = r1(); w2(0xc); b = r1(); w2(9); w2(0xc); w2(9); 47 return j44(a,b); 48 49 } 50 51 static void ktti_read_block(struct pi_adapter *pi, char *buf, int count) 52 53 { int k, a, b; 54 55 for (k=0;k<count/2;k++) { 56 w0(0x10); w2(0xb); w2(0xa); w2(9); w2(0xc); w2(9); 57 a = r1(); w2(0xc); b = r1(); w2(9); 58 buf[2*k] = j44(a,b); 59 a = r1(); w2(0xc); b = r1(); w2(9); 60 buf[2*k+1] = j44(a,b); 61 } 62 } 63 64 static void ktti_write_block(struct pi_adapter *pi, char *buf, int count) 65 66 { int k; 67 68 for (k=0;k<count/2;k++) { 69 w0(0x10); w2(0xb); w2(0xa); w2(3); w2(6); 70 w0(buf[2*k]); w2(3); 71 w0(buf[2*k+1]); w2(6); 72 w2(0xb); 73 } 74 } 75 76 static void ktti_connect(struct pi_adapter *pi) 77 78 { pi->saved_r0 = r0(); 79 pi->saved_r2 = r2(); 80 w2(0xb); w2(0xa); w0(0); w2(3); w2(6); 81 } 82 83 static void ktti_disconnect(struct pi_adapter *pi) 84 85 { w2(0xb); w2(0xa); w0(0xa0); w2(3); w2(4); 86 w0(pi->saved_r0); 87 w2(pi->saved_r2); 88 } 89 90 static void ktti_log_adapter(struct pi_adapter *pi) 91 92 { 93 dev_info(&pi->dev, "KT adapter at 0x%x, delay %d\n", 94 pi->port, pi->delay); 95 } 96 97 static struct pi_protocol ktti = { 98 .owner = THIS_MODULE, 99 .name = "ktti", 100 .max_mode = 1, 101 .epp_first = 2, 102 .default_delay = 1, 103 .max_units = 1, 104 .write_regr = ktti_write_regr, 105 .read_regr = ktti_read_regr, 106 .write_block = ktti_write_block, 107 .read_block = ktti_read_block, 108 .connect = ktti_connect, 109 .disconnect = ktti_disconnect, 110 .log_adapter = ktti_log_adapter, 111 }; 112 113 MODULE_LICENSE("GPL"); 114 module_pata_parport_driver(ktti); 115