kbic.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:7k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.         kbic.c    (c) 1997-8  Grant R. Guenther <grant@torque.net>
  3.                               Under the terms of the GNU General Public License.
  4.         This is a low-level driver for the KBIC-951A and KBIC-971A
  5.         parallel to IDE adapter chips from KingByte Information Systems.
  6. The chips are almost identical, however, the wakeup code 
  7. required for the 971A interferes with the correct operation of
  8.         the 951A, so this driver registers itself twice, once for
  9. each chip.
  10. */
  11. /* Changes:
  12.         1.01    GRG 1998.05.06 init_proto, release_proto
  13. */
  14. #define KBIC_VERSION      "1.01"
  15. #include <linux/module.h>
  16. #include <linux/delay.h>
  17. #include <linux/kernel.h>
  18. #include <linux/types.h>
  19. #include <linux/wait.h>
  20. #include <asm/io.h>
  21. #include "paride.h"
  22. #define r12w() (delay_p,inw(pi->port+1)&0xffff) 
  23. #define j44(a,b)                ((((a>>4)&0x0f)|(b&0xf0))^0x88)
  24. #define j53(w)                  (((w>>3)&0x1f)|((w>>4)&0xe0))
  25. /* cont = 0 - access the IDE register file 
  26.    cont = 1 - access the IDE command set 
  27. */
  28. static int  cont_map[2] = { 0x80, 0x40 };
  29. static int kbic_read_regr( PIA *pi, int cont, int regr )
  30. {       int     a, b, s;
  31.         s = cont_map[cont];
  32. switch (pi->mode) {
  33. case 0: w0(regr|0x18|s); w2(4); w2(6); w2(4); w2(1); w0(8);
  34.         a = r1(); w0(0x28); b = r1(); w2(4);
  35. return j44(a,b);
  36. case 1: w0(regr|0x38|s); w2(4); w2(6); w2(4); w2(5); w0(8);
  37. a = r12w(); w2(4);
  38. return j53(a);
  39. case 2: w0(regr|0x08|s); w2(4); w2(6); w2(4); w2(0xa5); w2(0xa1);
  40. a = r0(); w2(4);
  41.         return a;
  42. case 3:
  43. case 4:
  44. case 5: w0(0x20|s); w2(4); w2(6); w2(4); w3(regr);
  45. a = r4(); b = r4(); w2(4); w2(0); w2(4);
  46. return a;
  47. }
  48. return -1;
  49. }       
  50. static void  kbic_write_regr( PIA *pi, int cont, int regr, int val)
  51. {       int  s;
  52.         s = cont_map[cont];
  53.         switch (pi->mode) {
  54. case 0: 
  55.         case 1:
  56. case 2: w0(regr|0x10|s); w2(4); w2(6); w2(4); 
  57. w0(val); w2(5); w2(4);
  58. break;
  59. case 3:
  60. case 4:
  61. case 5: w0(0x20|s); w2(4); w2(6); w2(4); w3(regr);
  62. w4(val); w4(val);
  63. w2(4); w2(0); w2(4);
  64.                 break;
  65. }
  66. }
  67. static void k951_connect ( PIA *pi  )
  68. {  pi->saved_r0 = r0();
  69.         pi->saved_r2 = r2();
  70.         w2(4); 
  71. }
  72. static void k951_disconnect ( PIA *pi )
  73. {       w0(pi->saved_r0);
  74.         w2(pi->saved_r2);
  75. }
  76. #define CCP(x) w2(0xc4);w0(0xaa);w0(0x55);w0(0);w0(0xff);w0(0x87);
  77. w0(0x78);w0(x);w2(0xc5);w2(0xc4);w0(0xff);
  78. static void k971_connect ( PIA *pi  )
  79. {  pi->saved_r0 = r0();
  80.         pi->saved_r2 = r2();
  81. CCP(0x20);
  82.         w2(4); 
  83. }
  84. static void k971_disconnect ( PIA *pi )
  85. {       CCP(0x30);
  86. w0(pi->saved_r0);
  87.         w2(pi->saved_r2);
  88. }
  89. /* counts must be congruent to 0 MOD 4, but all known applications
  90.    have this property.
  91. */
  92. static void kbic_read_block( PIA *pi, char * buf, int count )
  93. {       int     k, a, b;
  94.         switch (pi->mode) {
  95.         case 0: w0(0x98); w2(4); w2(6); w2(4);
  96.                 for (k=0;k<count/2;k++) {
  97. w2(1); w0(8);    a = r1();
  98.        w0(0x28); b = r1();
  99. buf[2*k]   = j44(a,b);
  100. w2(5);           b = r1();
  101.        w0(8);    a = r1();
  102. buf[2*k+1] = j44(a,b);
  103. w2(4);
  104.                 } 
  105.                 break;
  106.         case 1: w0(0xb8); w2(4); w2(6); w2(4); 
  107.                 for (k=0;k<count/4;k++) {
  108.                         w0(0xb8); 
  109. w2(4); w2(5); 
  110.                         w0(8);    buf[4*k]   = j53(r12w());
  111. w0(0xb8); buf[4*k+1] = j53(r12w());
  112. w2(4); w2(5);
  113.           buf[4*k+3] = j53(r12w());
  114. w0(8);    buf[4*k+2] = j53(r12w());
  115.                 }
  116.                 w2(4);
  117.                 break;
  118.         case 2: w0(0x88); w2(4); w2(6); w2(4);
  119.                 for (k=0;k<count/2;k++) {
  120.                         w2(0xa0); w2(0xa1); buf[2*k] = r0();
  121.                         w2(0xa5); buf[2*k+1] = r0();
  122.                 }
  123.                 w2(4);
  124.                 break;
  125.         case 3: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
  126.                 for (k=0;k<count;k++) buf[k] = r4();
  127.                 w2(4); w2(0); w2(4);
  128.                 break;
  129. case 4: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
  130.                 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
  131.                 w2(4); w2(0); w2(4);
  132.                 break;
  133.         case 5: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
  134.                 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
  135.                 w2(4); w2(0); w2(4);
  136.                 break;
  137.         }
  138. }
  139. static void kbic_write_block( PIA *pi, char * buf, int count )
  140. {       int     k;
  141.         switch (pi->mode) {
  142.         case 0:
  143.         case 1:
  144.         case 2: w0(0x90); w2(4); w2(6); w2(4); 
  145. for(k=0;k<count/2;k++) {
  146. w0(buf[2*k+1]); w2(0); w2(4); 
  147. w0(buf[2*k]);   w2(5); w2(4); 
  148. }
  149. break;
  150.         case 3: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
  151. for(k=0;k<count/2;k++) {
  152. w4(buf[2*k+1]); 
  153.                         w4(buf[2*k]);
  154.                 }
  155. w2(4); w2(0); w2(4);
  156. break;
  157. case 4: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
  158.                 for(k=0;k<count/2;k++) w4w(pi_swab16(buf,k));
  159.                 w2(4); w2(0); w2(4);
  160.                 break;
  161.         case 5: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
  162.                 for(k=0;k<count/4;k++) w4l(pi_swab32(buf,k));
  163.                 w2(4); w2(0); w2(4);
  164.                 break;
  165.         }
  166. }
  167. static void kbic_log_adapter( PIA *pi, char * scratch, 
  168.       int verbose, char * chip )
  169. {       char    *mode_string[6] = {"4-bit","5/3","8-bit",
  170.    "EPP-8","EPP_16","EPP-32"};
  171.         printk("%s: kbic %s, KingByte %s at 0x%x, ",
  172.                 pi->device,KBIC_VERSION,chip,pi->port);
  173.         printk("mode %d (%s), delay %dn",pi->mode,
  174. mode_string[pi->mode],pi->delay);
  175. }
  176. static void k951_log_adapter( PIA *pi, char * scratch, int verbose )
  177. { kbic_log_adapter(pi,scratch,verbose,"KBIC-951A");
  178. }
  179. static void k971_log_adapter( PIA *pi, char * scratch, int verbose )
  180. {       kbic_log_adapter(pi,scratch,verbose,"KBIC-971A");
  181. }
  182. static void kbic_init_proto( PIA *pi)
  183. {       MOD_INC_USE_COUNT;
  184. }
  185. static void kbic_release_proto( PIA *pi)
  186. {       MOD_DEC_USE_COUNT;
  187. }
  188. struct pi_protocol k951 = {"k951",0,6,3,1,1,
  189.                            kbic_write_regr,
  190.                            kbic_read_regr,
  191.                            kbic_write_block,
  192.                            kbic_read_block,
  193.                            k951_connect,
  194.                            k951_disconnect,
  195.                            0,
  196.                            0,
  197.                            0,
  198.                            k951_log_adapter,
  199.                            kbic_init_proto,
  200.                            kbic_release_proto
  201.      };
  202. struct pi_protocol k971 = {"k971",0,6,3,1,1,
  203.                            kbic_write_regr,
  204.                            kbic_read_regr,
  205.                            kbic_write_block,
  206.                            kbic_read_block,
  207.                            k971_connect,
  208.                            k971_disconnect,
  209.                            0,
  210.                            0,
  211.                            0,
  212.                            k971_log_adapter,
  213.                            kbic_init_proto,
  214.                            kbic_release_proto
  215.                           };
  216. #ifdef MODULE
  217. int     init_module(void)
  218. {       int s5,s7;
  219. s5 = pi_register(&k951);
  220. s7 = pi_register(&k971);
  221. return (s5 || s7) - 1;
  222. }
  223. void    cleanup_module(void)
  224. {       pi_unregister( &k951 );
  225. pi_unregister( &k971 );
  226. }
  227. #endif
  228. /* end of kbic.c */
  229. MODULE_LICENSE("GPL");