aten.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. aten.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
  3. Under the terms of the GNU General Public License.
  4. aten.c is a low-level protocol driver for the ATEN EH-100
  5. parallel port adapter. The EH-100 supports 4-bit and 8-bit
  6. modes only. There is also an EH-132 which supports EPP mode
  7. transfers. The EH-132 is not yet supported.
  8. */
  9. /* Changes:
  10. 1.01 GRG 1998.05.05 init_proto, release_proto
  11. */
  12. #define ATEN_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/wait.h>
  18. #include <linux/types.h>
  19. #include <asm/io.h>
  20. #include "paride.h"
  21. #define j44(a,b) ((((a>>4)&0x0f)|(b&0xf0))^0x88)
  22. /* cont = 0 - access the IDE register file
  23. cont = 1 - access the IDE command set
  24. */
  25. static int cont_map[2] = { 0x08, 0x20 };
  26. static void aten_write_regr( PIA *pi, int cont, int regr, int val)
  27. { int r;
  28. r = regr + cont_map[cont] + 0x80;
  29. w0(r); w2(0xe); w2(6); w0(val); w2(7); w2(6); w2(0xc);
  30. }
  31. static int aten_read_regr( PIA *pi, int cont, int regr )
  32. { int a, b, r;
  33. r = regr + cont_map[cont] + 0x40;
  34. switch (pi->mode) {
  35. case 0: w0(r); w2(0xe); w2(6);
  36. w2(7); w2(6); w2(0);
  37. a = r1(); w0(0x10); b = r1(); w2(0xc);
  38. return j44(a,b);
  39. case 1: r |= 0x10;
  40. w0(r); w2(0xe); w2(6); w0(0xff);
  41. w2(0x27); w2(0x26); w2(0x20);
  42. a = r0();
  43. w2(0x26); w2(0xc);
  44. return a;
  45. }
  46. return -1;
  47. }
  48. static void aten_read_block( PIA *pi, char * buf, int count )
  49. { int k, a, b, c, d;
  50. switch (pi->mode) {
  51. case 0: w0(0x48); w2(0xe); w2(6);
  52. for (k=0;k<count/2;k++) {
  53. w2(7); w2(6); w2(2);
  54. a = r1(); w0(0x58); b = r1();
  55. w2(0); d = r1(); w0(0x48); c = r1();
  56. buf[2*k] = j44(c,d);
  57. buf[2*k+1] = j44(a,b);
  58. }
  59. w2(0xc);
  60. break;
  61. case 1: w0(0x58); w2(0xe); w2(6);
  62. for (k=0;k<count/2;k++) {
  63. w2(0x27); w2(0x26); w2(0x22);
  64. a = r0(); w2(0x20); b = r0();
  65. buf[2*k] = b; buf[2*k+1] = a;
  66. }
  67. w2(0x26); w2(0xc);
  68. break;
  69. }
  70. }
  71. static void aten_write_block( PIA *pi, char * buf, int count )
  72. { int k;
  73. w0(0x88); w2(0xe); w2(6);
  74. for (k=0;k<count/2;k++) {
  75. w0(buf[2*k+1]); w2(0xe); w2(6);
  76. w0(buf[2*k]); w2(7); w2(6);
  77. }
  78. w2(0xc);
  79. }
  80. static void aten_connect ( PIA *pi )
  81. { pi->saved_r0 = r0();
  82. pi->saved_r2 = r2();
  83. w2(0xc);
  84. }
  85. static void aten_disconnect ( PIA *pi )
  86. { w0(pi->saved_r0);
  87. w2(pi->saved_r2);
  88. }
  89. static void aten_log_adapter( PIA *pi, char * scratch, int verbose )
  90. { char *mode_string[2] = {"4-bit","8-bit"};
  91. printk("%s: aten %s, ATEN EH-100 at 0x%x, ",
  92. pi->device,ATEN_VERSION,pi->port);
  93. printk("mode %d (%s), delay %d\n",pi->mode,
  94. mode_string[pi->mode],pi->delay);
  95. }
  96. static struct pi_protocol aten = {
  97. .owner = THIS_MODULE,
  98. .name = "aten",
  99. .max_mode = 2,
  100. .epp_first = 2,
  101. .default_delay = 1,
  102. .max_units = 1,
  103. .write_regr = aten_write_regr,
  104. .read_regr = aten_read_regr,
  105. .write_block = aten_write_block,
  106. .read_block = aten_read_block,
  107. .connect = aten_connect,
  108. .disconnect = aten_disconnect,
  109. .log_adapter = aten_log_adapter,
  110. };
  111. static int __init aten_init(void)
  112. {
  113. return paride_register(&aten);
  114. }
  115. static void __exit aten_exit(void)
  116. {
  117. paride_unregister( &aten );
  118. }
  119. MODULE_LICENSE("GPL");
  120. module_init(aten_init)
  121. module_exit(aten_exit)