fit2.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. fit2.c (c) 1998 Grant R. Guenther <grant@torque.net>
  3. Under the terms of the GNU General Public License.
  4. fit2.c is a low-level protocol driver for the older version
  5. of the Fidelity International Technology parallel port adapter.
  6. This adapter is used in their TransDisk 2000 and older TransDisk
  7. 3000 portable hard-drives. As far as I can tell, this device
  8. supports 4-bit mode _only_.
  9. Newer models of the FIT products use an enhanced protocol.
  10. The "fit3" protocol module should support current drives.
  11. */
  12. #define FIT2_VERSION "1.0"
  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. #define j44(a,b) (((a>>4)&0x0f)|(b&0xf0))
  22. /* cont = 0 - access the IDE register file
  23. cont = 1 - access the IDE command set
  24. NB: The FIT adapter does not appear to use the control registers.
  25. So, we map ALT_STATUS to STATUS and NO-OP writes to the device
  26. control register - this means that IDE reset will not work on these
  27. devices.
  28. */
  29. static void fit2_write_regr( PIA *pi, int cont, int regr, int val)
  30. { if (cont == 1) return;
  31. w2(0xc); w0(regr); w2(4); w0(val); w2(5); w0(0); w2(4);
  32. }
  33. static int fit2_read_regr( PIA *pi, int cont, int regr )
  34. { int a, b, r;
  35. if (cont) {
  36. if (regr != 6) return 0xff;
  37. r = 7;
  38. } else r = regr + 0x10;
  39. w2(0xc); w0(r); w2(4); w2(5);
  40. w0(0); a = r1();
  41. w0(1); b = r1();
  42. w2(4);
  43. return j44(a,b);
  44. }
  45. static void fit2_read_block( PIA *pi, char * buf, int count )
  46. { int k, a, b, c, d;
  47. w2(0xc); w0(0x10);
  48. for (k=0;k<count/4;k++) {
  49. w2(4); w2(5);
  50. w0(0); a = r1(); w0(1); b = r1();
  51. w0(3); c = r1(); w0(2); d = r1();
  52. buf[4*k+0] = j44(a,b);
  53. buf[4*k+1] = j44(d,c);
  54. w2(4); w2(5);
  55. a = r1(); w0(3); b = r1();
  56. w0(1); c = r1(); w0(0); d = r1();
  57. buf[4*k+2] = j44(d,c);
  58. buf[4*k+3] = j44(a,b);
  59. }
  60. w2(4);
  61. }
  62. static void fit2_write_block( PIA *pi, char * buf, int count )
  63. { int k;
  64. w2(0xc); w0(0);
  65. for (k=0;k<count/2;k++) {
  66. w2(4); w0(buf[2*k]);
  67. w2(5); w0(buf[2*k+1]);
  68. }
  69. w2(4);
  70. }
  71. static void fit2_connect ( PIA *pi )
  72. { pi->saved_r0 = r0();
  73. pi->saved_r2 = r2();
  74. w2(0xcc);
  75. }
  76. static void fit2_disconnect ( PIA *pi )
  77. { w0(pi->saved_r0);
  78. w2(pi->saved_r2);
  79. }
  80. static void fit2_log_adapter( PIA *pi, char * scratch, int verbose )
  81. { printk("%s: fit2 %s, FIT 2000 adapter at 0x%x, delay %d\n",
  82. pi->device,FIT2_VERSION,pi->port,pi->delay);
  83. }
  84. static struct pi_protocol fit2 = {
  85. .owner = THIS_MODULE,
  86. .name = "fit2",
  87. .max_mode = 1,
  88. .epp_first = 2,
  89. .default_delay = 1,
  90. .max_units = 1,
  91. .write_regr = fit2_write_regr,
  92. .read_regr = fit2_read_regr,
  93. .write_block = fit2_write_block,
  94. .read_block = fit2_read_block,
  95. .connect = fit2_connect,
  96. .disconnect = fit2_disconnect,
  97. .log_adapter = fit2_log_adapter,
  98. };
  99. static int __init fit2_init(void)
  100. {
  101. return paride_register(&fit2);
  102. }
  103. static void __exit fit2_exit(void)
  104. {
  105. paride_unregister(&fit2);
  106. }
  107. MODULE_LICENSE("GPL");
  108. module_init(fit2_init)
  109. module_exit(fit2_exit)