Back to home page

OSCL-LXR

 
 

    


0001 /* 
0002         dstr.c    (c) 1997-8  Grant R. Guenther <grant@torque.net>
0003                               Under the terms of the GNU General Public License.
0004 
0005         dstr.c is a low-level protocol driver for the 
0006         DataStor EP2000 parallel to IDE adapter chip.
0007 
0008 */
0009 
0010 /* Changes:
0011 
0012         1.01    GRG 1998.05.06 init_proto, release_proto
0013 
0014 */
0015 
0016 #define DSTR_VERSION      "1.01"
0017 
0018 #include <linux/module.h>
0019 #include <linux/init.h>
0020 #include <linux/delay.h>
0021 #include <linux/kernel.h>
0022 #include <linux/types.h>
0023 #include <linux/wait.h>
0024 #include <asm/io.h>
0025 
0026 #include "paride.h"
0027 
0028 /* mode codes:  0  nybble reads, 8-bit writes
0029                 1  8-bit reads and writes
0030                 2  8-bit EPP mode
0031         3  EPP-16
0032         4  EPP-32
0033 */
0034 
0035 #define j44(a,b)  (((a>>3)&0x07)|((~a>>4)&0x08)|((b<<1)&0x70)|((~b)&0x80))
0036 
0037 #define P1  w2(5);w2(0xd);w2(5);w2(4);
0038 #define P2  w2(5);w2(7);w2(5);w2(4);
0039 #define P3      w2(6);w2(4);w2(6);w2(4);
0040 
0041 /* cont = 0 - access the IDE register file 
0042    cont = 1 - access the IDE command set 
0043 */
0044 
0045 static int  cont_map[2] = { 0x20, 0x40 };
0046 
0047 static int dstr_read_regr( PIA *pi, int cont, int regr )
0048 
0049 {       int     a, b, r;
0050 
0051         r = regr + cont_map[cont];
0052 
0053     w0(0x81); P1;
0054     if (pi->mode) { w0(0x11); } else { w0(1); }
0055     P2; w0(r); P1;
0056 
0057         switch (pi->mode)  {
0058 
0059         case 0: w2(6); a = r1(); w2(4); w2(6); b = r1(); w2(4);
0060                 return j44(a,b);
0061 
0062         case 1: w0(0); w2(0x26); a = r0(); w2(4);
0063                 return a;
0064 
0065     case 2:
0066     case 3:
0067         case 4: w2(0x24); a = r4(); w2(4);
0068                 return a;
0069 
0070         }
0071         return -1;
0072 }       
0073 
0074 static void dstr_write_regr(  PIA *pi, int cont, int regr, int val )
0075 
0076 {       int  r;
0077 
0078         r = regr + cont_map[cont];
0079 
0080     w0(0x81); P1; 
0081     if (pi->mode >= 2) { w0(0x11); } else { w0(1); }
0082     P2; w0(r); P1;
0083     
0084         switch (pi->mode)  {
0085 
0086         case 0:
0087         case 1: w0(val); w2(5); w2(7); w2(5); w2(4);
0088         break;
0089 
0090     case 2:
0091     case 3:
0092         case 4: w4(val); 
0093                 break;
0094         }
0095 }
0096 
0097 #define  CCP(x)  w0(0xff);w2(0xc);w2(4);\
0098          w0(0xaa);w0(0x55);w0(0);w0(0xff);w0(0x87);w0(0x78);\
0099          w0(x);w2(5);w2(4);
0100 
0101 static void dstr_connect ( PIA *pi  )
0102 
0103 {       pi->saved_r0 = r0();
0104         pi->saved_r2 = r2();
0105         w2(4); CCP(0xe0); w0(0xff);
0106 }
0107 
0108 static void dstr_disconnect ( PIA *pi )
0109 
0110 {       CCP(0x30);
0111         w0(pi->saved_r0);
0112         w2(pi->saved_r2);
0113 } 
0114 
0115 static void dstr_read_block( PIA *pi, char * buf, int count )
0116 
0117 {       int     k, a, b;
0118 
0119         w0(0x81); P1;
0120         if (pi->mode) { w0(0x19); } else { w0(9); }
0121     P2; w0(0x82); P1; P3; w0(0x20); P1;
0122 
0123         switch (pi->mode) {
0124 
0125         case 0: for (k=0;k<count;k++) {
0126                         w2(6); a = r1(); w2(4);
0127                         w2(6); b = r1(); w2(4);
0128                         buf[k] = j44(a,b);
0129                 } 
0130                 break;
0131 
0132         case 1: w0(0);
0133                 for (k=0;k<count;k++) {
0134                         w2(0x26); buf[k] = r0(); w2(0x24);
0135                 }
0136                 w2(4);
0137                 break;
0138 
0139         case 2: w2(0x24); 
0140                 for (k=0;k<count;k++) buf[k] = r4();
0141                 w2(4);
0142                 break;
0143 
0144         case 3: w2(0x24); 
0145                 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
0146                 w2(4);
0147                 break;
0148 
0149         case 4: w2(0x24); 
0150                 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
0151                 w2(4);
0152                 break;
0153 
0154         }
0155 }
0156 
0157 static void dstr_write_block( PIA *pi, char * buf, int count )
0158 
0159 {       int k;
0160 
0161         w0(0x81); P1;
0162         if (pi->mode) { w0(0x19); } else { w0(9); }
0163         P2; w0(0x82); P1; P3; w0(0x20); P1;
0164 
0165         switch (pi->mode) {
0166 
0167         case 0:
0168         case 1: for (k=0;k<count;k++) {
0169                         w2(5); w0(buf[k]); w2(7);
0170                 }
0171                 w2(5); w2(4);
0172                 break;
0173 
0174         case 2: w2(0xc5);
0175                 for (k=0;k<count;k++) w4(buf[k]);
0176         w2(0xc4);
0177                 break;
0178 
0179         case 3: w2(0xc5);
0180                 for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
0181                 w2(0xc4);
0182                 break;
0183 
0184         case 4: w2(0xc5);
0185                 for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
0186                 w2(0xc4);
0187                 break;
0188 
0189         }
0190 }
0191 
0192 
0193 static void dstr_log_adapter( PIA *pi, char * scratch, int verbose )
0194 
0195 {       char    *mode_string[5] = {"4-bit","8-bit","EPP-8",
0196                    "EPP-16","EPP-32"};
0197 
0198         printk("%s: dstr %s, DataStor EP2000 at 0x%x, ",
0199                 pi->device,DSTR_VERSION,pi->port);
0200         printk("mode %d (%s), delay %d\n",pi->mode,
0201         mode_string[pi->mode],pi->delay);
0202 
0203 }
0204 
0205 static struct pi_protocol dstr = {
0206     .owner      = THIS_MODULE,
0207     .name       = "dstr",
0208     .max_mode   = 5,
0209     .epp_first  = 2,
0210     .default_delay  = 1,
0211     .max_units  = 1,
0212     .write_regr = dstr_write_regr,
0213     .read_regr  = dstr_read_regr,
0214     .write_block    = dstr_write_block,
0215     .read_block = dstr_read_block,
0216     .connect    = dstr_connect,
0217     .disconnect = dstr_disconnect,
0218     .log_adapter    = dstr_log_adapter,
0219 };
0220 
0221 static int __init dstr_init(void)
0222 {
0223     return paride_register(&dstr);
0224 }
0225 
0226 static void __exit dstr_exit(void)
0227 {
0228     paride_unregister(&dstr);
0229 }
0230 
0231 MODULE_LICENSE("GPL");
0232 module_init(dstr_init)
0233 module_exit(dstr_exit)