comm.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. comm.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
  3. Under the terms of the GNU General Public License.
  4. comm.c is a low-level protocol driver for some older models
  5. of the DataStor "Commuter" parallel to IDE adapter. Some of
  6. the parallel port devices marketed by Arista currently
  7. use this adapter.
  8. */
  9. /* Changes:
  10. 1.01 GRG 1998.05.05 init_proto, release_proto
  11. */
  12. #define COMM_VERSION "1.01"
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/delay.h>
  16. #include <linux/kernel.h>
  17. #include <linux/types.h>
  18. #include <linux/wait.h>
  19. #include <asm/io.h>
  20. #include "paride.h"
  21. /* mode codes: 0 nybble reads, 8-bit writes
  22. 1 8-bit reads and writes
  23. 2 8-bit EPP mode
  24. */
  25. #define j44(a,b) (((a>>3)&0x0f)|((b<<1)&0xf0))
  26. #define P1 w2(5);w2(0xd);w2(0xd);w2(5);w2(4);
  27. #define P2 w2(5);w2(7);w2(7);w2(5);w2(4);
  28. /* cont = 0 - access the IDE register file
  29. cont = 1 - access the IDE command set
  30. */
  31. static int cont_map[2] = { 0x08, 0x10 };
  32. static int comm_read_regr( PIA *pi, int cont, int regr )
  33. { int l, h, r;
  34. r = regr + cont_map[cont];
  35. switch (pi->mode) {
  36. case 0: w0(r); P1; w0(0);
  37. w2(6); l = r1(); w0(0x80); h = r1(); w2(4);
  38. return j44(l,h);
  39. case 1: w0(r+0x20); P1;
  40. w0(0); w2(0x26); h = r0(); w2(4);
  41. return h;
  42. case 2:
  43. case 3:
  44. case 4: w3(r+0x20); (void)r1();
  45. w2(0x24); h = r4(); w2(4);
  46. return h;
  47. }
  48. return -1;
  49. }
  50. static void comm_write_regr( PIA *pi, int cont, int regr, int val )
  51. { int r;
  52. r = regr + cont_map[cont];
  53. switch (pi->mode) {
  54. case 0:
  55. case 1: w0(r); P1; w0(val); P2;
  56. break;
  57. case 2:
  58. case 3:
  59. case 4: w3(r); (void)r1(); w4(val);
  60. break;
  61. }
  62. }
  63. static void comm_connect ( PIA *pi )
  64. { pi->saved_r0 = r0();
  65. pi->saved_r2 = r2();
  66. w2(4); w0(0xff); w2(6);
  67. w2(4); w0(0xaa); w2(6);
  68. w2(4); w0(0x00); w2(6);
  69. w2(4); w0(0x87); w2(6);
  70. w2(4); w0(0xe0); w2(0xc); w2(0xc); w2(4);
  71. }
  72. static void comm_disconnect ( PIA *pi )
  73. { w2(0); w2(0); w2(0); w2(4);
  74. w0(pi->saved_r0);
  75. w2(pi->saved_r2);
  76. }
  77. static void comm_read_block( PIA *pi, char * buf, int count )
  78. { int i, l, h;
  79. switch (pi->mode) {
  80. case 0: w0(0x48); P1;
  81. for(i=0;i<count;i++) {
  82. w0(0); w2(6); l = r1();
  83. w0(0x80); h = r1(); w2(4);
  84. buf[i] = j44(l,h);
  85. }
  86. break;
  87. case 1: w0(0x68); P1; w0(0);
  88. for(i=0;i<count;i++) {
  89. w2(0x26); buf[i] = r0(); w2(0x24);
  90. }
  91. w2(4);
  92. break;
  93. case 2: w3(0x68); (void)r1(); w2(0x24);
  94. for (i=0;i<count;i++) buf[i] = r4();
  95. w2(4);
  96. break;
  97. case 3: w3(0x68); (void)r1(); w2(0x24);
  98. for (i=0;i<count/2;i++) ((u16 *)buf)[i] = r4w();
  99. w2(4);
  100. break;
  101. case 4: w3(0x68); (void)r1(); w2(0x24);
  102. for (i=0;i<count/4;i++) ((u32 *)buf)[i] = r4l();
  103. w2(4);
  104. break;
  105. }
  106. }
  107. /* NB: Watch out for the byte swapped writes ! */
  108. static void comm_write_block( PIA *pi, char * buf, int count )
  109. { int k;
  110. switch (pi->mode) {
  111. case 0:
  112. case 1: w0(0x68); P1;
  113. for (k=0;k<count;k++) {
  114. w2(5); w0(buf[k^1]); w2(7);
  115. }
  116. w2(5); w2(4);
  117. break;
  118. case 2: w3(0x48); (void)r1();
  119. for (k=0;k<count;k++) w4(buf[k^1]);
  120. break;
  121. case 3: w3(0x48); (void)r1();
  122. for (k=0;k<count/2;k++) w4w(pi_swab16(buf,k));
  123. break;
  124. case 4: w3(0x48); (void)r1();
  125. for (k=0;k<count/4;k++) w4l(pi_swab32(buf,k));
  126. break;
  127. }
  128. }
  129. static void comm_log_adapter( PIA *pi, char * scratch, int verbose )
  130. { char *mode_string[5] = {"4-bit","8-bit","EPP-8","EPP-16","EPP-32"};
  131. printk("%s: comm %s, DataStor Commuter at 0x%x, ",
  132. pi->device,COMM_VERSION,pi->port);
  133. printk("mode %d (%s), delay %d\n",pi->mode,
  134. mode_string[pi->mode],pi->delay);
  135. }
  136. static struct pi_protocol comm = {
  137. .owner = THIS_MODULE,
  138. .name = "comm",
  139. .max_mode = 5,
  140. .epp_first = 2,
  141. .default_delay = 1,
  142. .max_units = 1,
  143. .write_regr = comm_write_regr,
  144. .read_regr = comm_read_regr,
  145. .write_block = comm_write_block,
  146. .read_block = comm_read_block,
  147. .connect = comm_connect,
  148. .disconnect = comm_disconnect,
  149. .log_adapter = comm_log_adapter,
  150. };
  151. static int __init comm_init(void)
  152. {
  153. return paride_register(&comm);
  154. }
  155. static void __exit comm_exit(void)
  156. {
  157. paride_unregister(&comm);
  158. }
  159. MODULE_LICENSE("GPL");
  160. module_init(comm_init)
  161. module_exit(comm_exit)