io.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (C) 2000 Kazumoto Kojima
  3. *
  4. * I/O routine for Hitachi SolutionEngine.
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/types.h>
  8. #include <asm/io.h>
  9. #include <mach-se/mach/se.h>
  10. /* MS7750 requires special versions of in*, out* routines, since
  11. PC-like io ports are located at upper half byte of 16-bit word which
  12. can be accessed only with 16-bit wide. */
  13. static inline volatile __u16 *
  14. port2adr(unsigned int port)
  15. {
  16. if (port & 0xff000000)
  17. return ( volatile __u16 *) port;
  18. if (port >= 0x2000)
  19. return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
  20. else if (port >= 0x1000)
  21. return (volatile __u16 *) (PA_83902 + (port << 1));
  22. else
  23. return (volatile __u16 *) (PA_SUPERIO + (port << 1));
  24. }
  25. static inline int
  26. shifted_port(unsigned long port)
  27. {
  28. /* For IDE registers, value is not shifted */
  29. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  30. return 0;
  31. else
  32. return 1;
  33. }
  34. unsigned char se_inb(unsigned long port)
  35. {
  36. if (shifted_port(port))
  37. return (*port2adr(port) >> 8);
  38. else
  39. return (*port2adr(port))&0xff;
  40. }
  41. unsigned char se_inb_p(unsigned long port)
  42. {
  43. unsigned long v;
  44. if (shifted_port(port))
  45. v = (*port2adr(port) >> 8);
  46. else
  47. v = (*port2adr(port))&0xff;
  48. ctrl_delay();
  49. return v;
  50. }
  51. unsigned short se_inw(unsigned long port)
  52. {
  53. if (port >= 0x2000)
  54. return *port2adr(port);
  55. else
  56. maybebadio(port);
  57. return 0;
  58. }
  59. unsigned int se_inl(unsigned long port)
  60. {
  61. maybebadio(port);
  62. return 0;
  63. }
  64. void se_outb(unsigned char value, unsigned long port)
  65. {
  66. if (shifted_port(port))
  67. *(port2adr(port)) = value << 8;
  68. else
  69. *(port2adr(port)) = value;
  70. }
  71. void se_outb_p(unsigned char value, unsigned long port)
  72. {
  73. if (shifted_port(port))
  74. *(port2adr(port)) = value << 8;
  75. else
  76. *(port2adr(port)) = value;
  77. ctrl_delay();
  78. }
  79. void se_outw(unsigned short value, unsigned long port)
  80. {
  81. if (port >= 0x2000)
  82. *port2adr(port) = value;
  83. else
  84. maybebadio(port);
  85. }
  86. void se_outl(unsigned int value, unsigned long port)
  87. {
  88. maybebadio(port);
  89. }
  90. void se_insb(unsigned long port, void *addr, unsigned long count)
  91. {
  92. volatile __u16 *p = port2adr(port);
  93. __u8 *ap = addr;
  94. if (shifted_port(port)) {
  95. while (count--)
  96. *ap++ = *p >> 8;
  97. } else {
  98. while (count--)
  99. *ap++ = *p;
  100. }
  101. }
  102. void se_insw(unsigned long port, void *addr, unsigned long count)
  103. {
  104. volatile __u16 *p = port2adr(port);
  105. __u16 *ap = addr;
  106. while (count--)
  107. *ap++ = *p;
  108. }
  109. void se_insl(unsigned long port, void *addr, unsigned long count)
  110. {
  111. maybebadio(port);
  112. }
  113. void se_outsb(unsigned long port, const void *addr, unsigned long count)
  114. {
  115. volatile __u16 *p = port2adr(port);
  116. const __u8 *ap = addr;
  117. if (shifted_port(port)) {
  118. while (count--)
  119. *p = *ap++ << 8;
  120. } else {
  121. while (count--)
  122. *p = *ap++;
  123. }
  124. }
  125. void se_outsw(unsigned long port, const void *addr, unsigned long count)
  126. {
  127. volatile __u16 *p = port2adr(port);
  128. const __u16 *ap = addr;
  129. while (count--)
  130. *p = *ap++;
  131. }
  132. void se_outsl(unsigned long port, const void *addr, unsigned long count)
  133. {
  134. maybebadio(port);
  135. }