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#define KTTI_VERSION "1.0" 13 14#include <linux/module.h> 15#include <linux/delay.h> 16#include <linux/kernel.h> 17#include <linux/types.h> 18#include <linux/wait.h> 19#include <asm/io.h> 20 21#include "paride.h" 22 23#define j44(a,b) (((a>>4)&0x0f)|(b&0xf0)) 24 25/* cont = 0 - access the IDE register file 26 cont = 1 - access the IDE command set 27*/ 28 29static int cont_map[2] = { 0x10, 0x08 }; 30 31static void ktti_write_regr( PIA *pi, int cont, int regr, int val) 32 33{ int r; 34 35 r = regr + cont_map[cont]; 36 37 w0(r); w2(0xb); w2(0xa); w2(3); w2(6); 38 w0(val); w2(3); w0(0); w2(6); w2(0xb); 39} 40 41static int ktti_read_regr( PIA *pi, int cont, int regr ) 42 43{ int a, b, r; 44 45 r = regr + cont_map[cont]; 46 47 w0(r); w2(0xb); w2(0xa); w2(9); w2(0xc); w2(9); 48 a = r1(); w2(0xc); b = r1(); w2(9); w2(0xc); w2(9); 49 return j44(a,b); 50 51} 52 53static void ktti_read_block( PIA *pi, char * buf, int count ) 54 55{ int k, a, b; 56 57 for (k=0;k<count/2;k++) { 58 w0(0x10); w2(0xb); w2(0xa); w2(9); w2(0xc); w2(9); 59 a = r1(); w2(0xc); b = r1(); w2(9); 60 buf[2*k] = j44(a,b); 61 a = r1(); w2(0xc); b = r1(); w2(9); 62 buf[2*k+1] = j44(a,b); 63 } 64} 65 66static void ktti_write_block( PIA *pi, char * buf, int count ) 67 68{ int k; 69 70 for (k=0;k<count/2;k++) { 71 w0(0x10); w2(0xb); w2(0xa); w2(3); w2(6); 72 w0(buf[2*k]); w2(3); 73 w0(buf[2*k+1]); w2(6); 74 w2(0xb); 75 } 76} 77 78static void ktti_connect ( PIA *pi ) 79 80{ pi->saved_r0 = r0(); 81 pi->saved_r2 = r2(); 82 w2(0xb); w2(0xa); w0(0); w2(3); w2(6); 83} 84 85static void ktti_disconnect ( PIA *pi ) 86 87{ w2(0xb); w2(0xa); w0(0xa0); w2(3); w2(4); 88 w0(pi->saved_r0); 89 w2(pi->saved_r2); 90} 91 92static void ktti_log_adapter( PIA *pi, char * scratch, int verbose ) 93 94{ printk("%s: ktti %s, KT adapter at 0x%x, delay %d\n", 95 pi->device,KTTI_VERSION,pi->port,pi->delay); 96 97} 98 99static void ktti_init_proto( PIA *pi) 100 101{ MOD_INC_USE_COUNT; 102} 103 104static void ktti_release_proto( PIA *pi) 105 106{ MOD_DEC_USE_COUNT; 107} 108 109struct pi_protocol ktti = {"ktti",0,1,2,1,1, 110 ktti_write_regr, 111 ktti_read_regr, 112 ktti_write_block, 113 ktti_read_block, 114 ktti_connect, 115 ktti_disconnect, 116 0, 117 0, 118 0, 119 ktti_log_adapter, 120 ktti_init_proto, 121 ktti_release_proto 122 }; 123 124 125#ifdef MODULE 126 127int init_module(void) 128 129{ return pi_register( &ktti ) - 1; 130} 131 132void cleanup_module(void) 133 134{ pi_unregister( &ktti ); 135} 136 137#endif 138 139/* end of ktti.c */ 140MODULE_LICENSE("GPL"); 141