Back to home page

OSCL-LXR

 
 

    


0001 /* 
0002     on20.c  (c) 1996-8  Grant R. Guenther <grant@torque.net>
0003                     Under the terms of the GNU General Public License.
0004 
0005         on20.c is a low-level protocol driver for the
0006         Onspec 90c20 parallel to IDE adapter. 
0007 */
0008 
0009 /* Changes:
0010 
0011         1.01    GRG 1998.05.06 init_proto, release_proto
0012 
0013 */
0014 
0015 #define ON20_VERSION    "1.01"
0016 
0017 #include <linux/module.h>
0018 #include <linux/init.h>
0019 #include <linux/delay.h>
0020 #include <linux/kernel.h>
0021 #include <linux/types.h>
0022 #include <linux/wait.h>
0023 #include <asm/io.h>
0024 
0025 #include "paride.h"
0026 
0027 #define op(f)   w2(4);w0(f);w2(5);w2(0xd);w2(5);w2(0xd);w2(5);w2(4);
0028 #define vl(v)   w2(4);w0(v);w2(5);w2(7);w2(5);w2(4);
0029 
0030 #define j44(a,b)  (((a>>4)&0x0f)|(b&0xf0))
0031 
0032 /* cont = 0 - access the IDE register file 
0033    cont = 1 - access the IDE command set 
0034 */
0035 
0036 static int on20_read_regr( PIA *pi, int cont, int regr )
0037 
0038 {   int h,l, r ;
0039 
0040         r = (regr<<2) + 1 + cont;
0041 
0042         op(1); vl(r); op(0);
0043 
0044     switch (pi->mode)  {
0045 
0046         case 0:  w2(4); w2(6); l = r1();
0047                  w2(4); w2(6); h = r1();
0048                  w2(4); w2(6); w2(4); w2(6); w2(4);
0049          return j44(l,h);
0050 
0051     case 1:  w2(4); w2(0x26); r = r0(); 
0052                  w2(4); w2(0x26); w2(4);
0053          return r;
0054 
0055     }
0056     return -1;
0057 }   
0058 
0059 static void on20_write_regr( PIA *pi, int cont, int regr, int val )
0060 
0061 {   int r;
0062 
0063     r = (regr<<2) + 1 + cont;
0064 
0065     op(1); vl(r); 
0066     op(0); vl(val); 
0067     op(0); vl(val);
0068 }
0069 
0070 static void on20_connect ( PIA *pi)
0071 
0072 {   pi->saved_r0 = r0();
0073         pi->saved_r2 = r2();
0074 
0075     w2(4);w0(0);w2(0xc);w2(4);w2(6);w2(4);w2(6);w2(4); 
0076     if (pi->mode) { op(2); vl(8); op(2); vl(9); }
0077            else   { op(2); vl(0); op(2); vl(8); }
0078 }
0079 
0080 static void on20_disconnect ( PIA *pi )
0081 
0082 {   w2(4);w0(7);w2(4);w2(0xc);w2(4);
0083         w0(pi->saved_r0);
0084         w2(pi->saved_r2);
0085 } 
0086 
0087 static void on20_read_block( PIA *pi, char * buf, int count )
0088 
0089 {   int     k, l, h; 
0090 
0091     op(1); vl(1); op(0);
0092 
0093     for (k=0;k<count;k++) 
0094         if (pi->mode) {
0095         w2(4); w2(0x26); buf[k] = r0();
0096         } else {
0097         w2(6); l = r1(); w2(4);
0098         w2(6); h = r1(); w2(4);
0099         buf[k] = j44(l,h);
0100         }
0101     w2(4);
0102 }
0103 
0104 static void on20_write_block(  PIA *pi, char * buf, int count )
0105 
0106 {   int k;
0107 
0108     op(1); vl(1); op(0);
0109 
0110     for (k=0;k<count;k++) { w2(5); w0(buf[k]); w2(7); }
0111     w2(4);
0112 }
0113 
0114 static void on20_log_adapter( PIA *pi, char * scratch, int verbose )
0115 
0116 {       char    *mode_string[2] = {"4-bit","8-bit"};
0117 
0118         printk("%s: on20 %s, OnSpec 90c20 at 0x%x, ",
0119                 pi->device,ON20_VERSION,pi->port);
0120         printk("mode %d (%s), delay %d\n",pi->mode,
0121         mode_string[pi->mode],pi->delay);
0122 
0123 }
0124 
0125 static struct pi_protocol on20 = {
0126     .owner      = THIS_MODULE,
0127     .name       = "on20",
0128     .max_mode   = 2,
0129     .epp_first  = 2,
0130     .default_delay  = 1,
0131     .max_units  = 1,
0132     .write_regr = on20_write_regr,
0133     .read_regr  = on20_read_regr,
0134     .write_block    = on20_write_block,
0135     .read_block = on20_read_block,
0136     .connect    = on20_connect,
0137     .disconnect = on20_disconnect,
0138     .log_adapter    = on20_log_adapter,
0139 };
0140 
0141 static int __init on20_init(void)
0142 {
0143     return paride_register(&on20);
0144 }
0145 
0146 static void __exit on20_exit(void)
0147 {
0148     paride_unregister(&on20);
0149 }
0150 
0151 MODULE_LICENSE("GPL");
0152 module_init(on20_init)
0153 module_exit(on20_exit)