dstr.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. dstr.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
  3. Under the terms of the GNU General Public License.
  4. dstr.c is a low-level protocol driver for the
  5. DataStor EP2000 parallel to IDE adapter chip.
  6. */
  7. /* Changes:
  8. 1.01 GRG 1998.05.06 init_proto, release_proto
  9. */
  10. #define DSTR_VERSION "1.01"
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/delay.h>
  14. #include <linux/kernel.h>
  15. #include <linux/types.h>
  16. #include <linux/wait.h>
  17. #include <asm/io.h>
  18. #include "paride.h"
  19. /* mode codes: 0 nybble reads, 8-bit writes
  20. 1 8-bit reads and writes
  21. 2 8-bit EPP mode
  22. 3 EPP-16
  23. 4 EPP-32
  24. */
  25. #define j44(a,b) (((a>>3)&0x07)|((~a>>4)&0x08)|((b<<1)&0x70)|((~b)&0x80))
  26. #define P1 w2(5);w2(0xd);w2(5);w2(4);
  27. #define P2 w2(5);w2(7);w2(5);w2(4);
  28. #define P3 w2(6);w2(4);w2(6);w2(4);
  29. /* cont = 0 - access the IDE register file
  30. cont = 1 - access the IDE command set
  31. */
  32. static int cont_map[2] = { 0x20, 0x40 };
  33. static int dstr_read_regr( PIA *pi, int cont, int regr )
  34. { int a, b, r;
  35. r = regr + cont_map[cont];
  36. w0(0x81); P1;
  37. if (pi->mode) { w0(0x11); } else { w0(1); }
  38. P2; w0(r); P1;
  39. switch (pi->mode) {
  40. case 0: w2(6); a = r1(); w2(4); w2(6); b = r1(); w2(4);
  41. return j44(a,b);
  42. case 1: w0(0); w2(0x26); a = r0(); w2(4);
  43. return a;
  44. case 2:
  45. case 3:
  46. case 4: w2(0x24); a = r4(); w2(4);
  47. return a;
  48. }
  49. return -1;
  50. }
  51. static void dstr_write_regr( PIA *pi, int cont, int regr, int val )
  52. { int r;
  53. r = regr + cont_map[cont];
  54. w0(0x81); P1;
  55. if (pi->mode >= 2) { w0(0x11); } else { w0(1); }
  56. P2; w0(r); P1;
  57. switch (pi->mode) {
  58. case 0:
  59. case 1: w0(val); w2(5); w2(7); w2(5); w2(4);
  60. break;
  61. case 2:
  62. case 3:
  63. case 4: w4(val);
  64. break;
  65. }
  66. }
  67. #define CCP(x) w0(0xff);w2(0xc);w2(4);\
  68. w0(0xaa);w0(0x55);w0(0);w0(0xff);w0(0x87);w0(0x78);\
  69. w0(x);w2(5);w2(4);
  70. static void dstr_connect ( PIA *pi )
  71. { pi->saved_r0 = r0();
  72. pi->saved_r2 = r2();
  73. w2(4); CCP(0xe0); w0(0xff);
  74. }
  75. static void dstr_disconnect ( PIA *pi )
  76. { CCP(0x30);
  77. w0(pi->saved_r0);
  78. w2(pi->saved_r2);
  79. }
  80. static void dstr_read_block( PIA *pi, char * buf, int count )
  81. { int k, a, b;
  82. w0(0x81); P1;
  83. if (pi->mode) { w0(0x19); } else { w0(9); }
  84. P2; w0(0x82); P1; P3; w0(0x20); P1;
  85. switch (pi->mode) {
  86. case 0: for (k=0;k<count;k++) {
  87. w2(6); a = r1(); w2(4);
  88. w2(6); b = r1(); w2(4);
  89. buf[k] = j44(a,b);
  90. }
  91. break;
  92. case 1: w0(0);
  93. for (k=0;k<count;k++) {
  94. w2(0x26); buf[k] = r0(); w2(0x24);
  95. }
  96. w2(4);
  97. break;
  98. case 2: w2(0x24);
  99. for (k=0;k<count;k++) buf[k] = r4();
  100. w2(4);
  101. break;
  102. case 3: w2(0x24);
  103. for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
  104. w2(4);
  105. break;
  106. case 4: w2(0x24);
  107. for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
  108. w2(4);
  109. break;
  110. }
  111. }
  112. static void dstr_write_block( PIA *pi, char * buf, int count )
  113. { int k;
  114. w0(0x81); P1;
  115. if (pi->mode) { w0(0x19); } else { w0(9); }
  116. P2; w0(0x82); P1; P3; w0(0x20); P1;
  117. switch (pi->mode) {
  118. case 0:
  119. case 1: for (k=0;k<count;k++) {
  120. w2(5); w0(buf[k]); w2(7);
  121. }
  122. w2(5); w2(4);
  123. break;
  124. case 2: w2(0xc5);
  125. for (k=0;k<count;k++) w4(buf[k]);
  126. w2(0xc4);
  127. break;
  128. case 3: w2(0xc5);
  129. for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
  130. w2(0xc4);
  131. break;
  132. case 4: w2(0xc5);
  133. for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
  134. w2(0xc4);
  135. break;
  136. }
  137. }
  138. static void dstr_log_adapter( PIA *pi, char * scratch, int verbose )
  139. { char *mode_string[5] = {"4-bit","8-bit","EPP-8",
  140. "EPP-16","EPP-32"};
  141. printk("%s: dstr %s, DataStor EP2000 at 0x%x, ",
  142. pi->device,DSTR_VERSION,pi->port);
  143. printk("mode %d (%s), delay %d\n",pi->mode,
  144. mode_string[pi->mode],pi->delay);
  145. }
  146. static struct pi_protocol dstr = {
  147. .owner = THIS_MODULE,
  148. .name = "dstr",
  149. .max_mode = 5,
  150. .epp_first = 2,
  151. .default_delay = 1,
  152. .max_units = 1,
  153. .write_regr = dstr_write_regr,
  154. .read_regr = dstr_read_regr,
  155. .write_block = dstr_write_block,
  156. .read_block = dstr_read_block,
  157. .connect = dstr_connect,
  158. .disconnect = dstr_disconnect,
  159. .log_adapter = dstr_log_adapter,
  160. };
  161. static int __init dstr_init(void)
  162. {
  163. return paride_register(&dstr);
  164. }
  165. static void __exit dstr_exit(void)
  166. {
  167. paride_unregister(&dstr);
  168. }
  169. MODULE_LICENSE("GPL");
  170. module_init(dstr_init)
  171. module_exit(dstr_exit)