ktti.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. ktti.c (c) 1998 Grant R. Guenther <grant@torque.net>
  3. Under the terms of the GNU General Public License.
  4. ktti.c is a low-level protocol driver for the KT Technology
  5. parallel port adapter. This adapter is used in the "PHd"
  6. portable hard-drives. As far as I can tell, this device
  7. supports 4-bit mode _only_.
  8. */
  9. #define KTTI_VERSION "1.0"
  10. #include <linux/module.h>
  11. #include <linux/init.h>
  12. #include <linux/delay.h>
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/wait.h>
  16. #include <asm/io.h>
  17. #include "paride.h"
  18. #define j44(a,b) (((a>>4)&0x0f)|(b&0xf0))
  19. /* cont = 0 - access the IDE register file
  20. cont = 1 - access the IDE command set
  21. */
  22. static int cont_map[2] = { 0x10, 0x08 };
  23. static void ktti_write_regr( PIA *pi, int cont, int regr, int val)
  24. { int r;
  25. r = regr + cont_map[cont];
  26. w0(r); w2(0xb); w2(0xa); w2(3); w2(6);
  27. w0(val); w2(3); w0(0); w2(6); w2(0xb);
  28. }
  29. static int ktti_read_regr( PIA *pi, int cont, int regr )
  30. { int a, b, r;
  31. r = regr + cont_map[cont];
  32. w0(r); w2(0xb); w2(0xa); w2(9); w2(0xc); w2(9);
  33. a = r1(); w2(0xc); b = r1(); w2(9); w2(0xc); w2(9);
  34. return j44(a,b);
  35. }
  36. static void ktti_read_block( PIA *pi, char * buf, int count )
  37. { int k, a, b;
  38. for (k=0;k<count/2;k++) {
  39. w0(0x10); w2(0xb); w2(0xa); w2(9); w2(0xc); w2(9);
  40. a = r1(); w2(0xc); b = r1(); w2(9);
  41. buf[2*k] = j44(a,b);
  42. a = r1(); w2(0xc); b = r1(); w2(9);
  43. buf[2*k+1] = j44(a,b);
  44. }
  45. }
  46. static void ktti_write_block( PIA *pi, char * buf, int count )
  47. { int k;
  48. for (k=0;k<count/2;k++) {
  49. w0(0x10); w2(0xb); w2(0xa); w2(3); w2(6);
  50. w0(buf[2*k]); w2(3);
  51. w0(buf[2*k+1]); w2(6);
  52. w2(0xb);
  53. }
  54. }
  55. static void ktti_connect ( PIA *pi )
  56. { pi->saved_r0 = r0();
  57. pi->saved_r2 = r2();
  58. w2(0xb); w2(0xa); w0(0); w2(3); w2(6);
  59. }
  60. static void ktti_disconnect ( PIA *pi )
  61. { w2(0xb); w2(0xa); w0(0xa0); w2(3); w2(4);
  62. w0(pi->saved_r0);
  63. w2(pi->saved_r2);
  64. }
  65. static void ktti_log_adapter( PIA *pi, char * scratch, int verbose )
  66. { printk("%s: ktti %s, KT adapter at 0x%x, delay %d\n",
  67. pi->device,KTTI_VERSION,pi->port,pi->delay);
  68. }
  69. static struct pi_protocol ktti = {
  70. .owner = THIS_MODULE,
  71. .name = "ktti",
  72. .max_mode = 1,
  73. .epp_first = 2,
  74. .default_delay = 1,
  75. .max_units = 1,
  76. .write_regr = ktti_write_regr,
  77. .read_regr = ktti_read_regr,
  78. .write_block = ktti_write_block,
  79. .read_block = ktti_read_block,
  80. .connect = ktti_connect,
  81. .disconnect = ktti_disconnect,
  82. .log_adapter = ktti_log_adapter,
  83. };
  84. static int __init ktti_init(void)
  85. {
  86. return paride_register(&ktti);
  87. }
  88. static void __exit ktti_exit(void)
  89. {
  90. paride_unregister(&ktti);
  91. }
  92. MODULE_LICENSE("GPL");
  93. module_init(ktti_init)
  94. module_exit(ktti_exit)