Back to home page

OSCL-LXR

 
 

    


0001 /* 
0002         ktti.c        (c) 1998  Grant R. Guenther <grant@torque.net>
0003                           Under the terms of the GNU General Public License.
0004 
0005     ktti.c is a low-level protocol driver for the KT Technology
0006     parallel port adapter.  This adapter is used in the "PHd" 
0007         portable hard-drives.  As far as I can tell, this device
0008     supports 4-bit mode _only_.  
0009 
0010 */
0011 
0012 #define KTTI_VERSION      "1.0"
0013 
0014 #include <linux/module.h>
0015 #include <linux/init.h>
0016 #include <linux/delay.h>
0017 #include <linux/kernel.h>
0018 #include <linux/types.h>
0019 #include <linux/wait.h>
0020 #include <asm/io.h>
0021 
0022 #include "paride.h"
0023 
0024 #define j44(a,b)                (((a>>4)&0x0f)|(b&0xf0))
0025 
0026 /* cont = 0 - access the IDE register file 
0027    cont = 1 - access the IDE command set 
0028 */
0029 
0030 static int  cont_map[2] = { 0x10, 0x08 };
0031 
0032 static void  ktti_write_regr( PIA *pi, int cont, int regr, int val)
0033 
0034 {   int r;
0035 
0036     r = regr + cont_map[cont];
0037 
0038     w0(r); w2(0xb); w2(0xa); w2(3); w2(6); 
0039     w0(val); w2(3); w0(0); w2(6); w2(0xb);
0040 }
0041 
0042 static int ktti_read_regr( PIA *pi, int cont, int regr )
0043 
0044 {   int  a, b, r;
0045 
0046         r = regr + cont_map[cont];
0047 
0048         w0(r); w2(0xb); w2(0xa); w2(9); w2(0xc); w2(9); 
0049     a = r1(); w2(0xc);  b = r1(); w2(9); w2(0xc); w2(9);
0050     return j44(a,b);
0051 
0052 }
0053 
0054 static void ktti_read_block( PIA *pi, char * buf, int count )
0055 
0056 {   int  k, a, b;
0057 
0058     for (k=0;k<count/2;k++) {
0059         w0(0x10); w2(0xb); w2(0xa); w2(9); w2(0xc); w2(9);
0060         a = r1(); w2(0xc); b = r1(); w2(9);
0061         buf[2*k] = j44(a,b);
0062         a = r1(); w2(0xc); b = r1(); w2(9);
0063         buf[2*k+1] = j44(a,b);
0064     }
0065 }
0066 
0067 static void ktti_write_block( PIA *pi, char * buf, int count )
0068 
0069 {   int k;
0070 
0071     for (k=0;k<count/2;k++) {
0072         w0(0x10); w2(0xb); w2(0xa); w2(3); w2(6);
0073         w0(buf[2*k]); w2(3);
0074         w0(buf[2*k+1]); w2(6);
0075         w2(0xb);
0076     }
0077 }
0078 
0079 static void ktti_connect ( PIA *pi  )
0080 
0081 {       pi->saved_r0 = r0();
0082         pi->saved_r2 = r2();
0083     w2(0xb); w2(0xa); w0(0); w2(3); w2(6);  
0084 }
0085 
0086 static void ktti_disconnect ( PIA *pi )
0087 
0088 {       w2(0xb); w2(0xa); w0(0xa0); w2(3); w2(4);
0089     w0(pi->saved_r0);
0090         w2(pi->saved_r2);
0091 } 
0092 
0093 static void ktti_log_adapter( PIA *pi, char * scratch, int verbose )
0094 
0095 {       printk("%s: ktti %s, KT adapter at 0x%x, delay %d\n",
0096                 pi->device,KTTI_VERSION,pi->port,pi->delay);
0097 
0098 }
0099 
0100 static struct pi_protocol ktti = {
0101     .owner      = THIS_MODULE,
0102     .name       = "ktti",
0103     .max_mode   = 1,
0104     .epp_first  = 2,
0105     .default_delay  = 1,
0106     .max_units  = 1,
0107     .write_regr = ktti_write_regr,
0108     .read_regr  = ktti_read_regr,
0109     .write_block    = ktti_write_block,
0110     .read_block = ktti_read_block,
0111     .connect    = ktti_connect,
0112     .disconnect = ktti_disconnect,
0113     .log_adapter    = ktti_log_adapter,
0114 };
0115 
0116 static int __init ktti_init(void)
0117 {
0118     return paride_register(&ktti);
0119 }
0120 
0121 static void __exit ktti_exit(void)
0122 {
0123     paride_unregister(&ktti);
0124 }
0125 
0126 MODULE_LICENSE("GPL");
0127 module_init(ktti_init)
0128 module_exit(ktti_exit)