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