io.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * linux/arch/m32r/platforms/oaks32r/io.c
  3. *
  4. * Typical I/O routines for OAKS32R board.
  5. *
  6. * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
  7. * Hitoshi Yamamoto, Mamoru Sakugawa
  8. */
  9. #include <asm/m32r.h>
  10. #include <asm/page.h>
  11. #include <asm/io.h>
  12. #define PORT2ADDR(port) _port2addr(port)
  13. static inline void *_port2addr(unsigned long port)
  14. {
  15. return (void *)(port | NONCACHE_OFFSET);
  16. }
  17. static inline void *_port2addr_ne(unsigned long port)
  18. {
  19. return (void *)((port<<1) + NONCACHE_OFFSET + 0x02000000);
  20. }
  21. static inline void delay(void)
  22. {
  23. __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
  24. }
  25. /*
  26. * NIC I/O function
  27. */
  28. #define PORT2ADDR_NE(port) _port2addr_ne(port)
  29. static inline unsigned char _ne_inb(void *portp)
  30. {
  31. return *(volatile unsigned char *)(portp+1);
  32. }
  33. static inline unsigned short _ne_inw(void *portp)
  34. {
  35. unsigned short tmp;
  36. tmp = *(unsigned short *)(portp) & 0xff;
  37. tmp |= *(unsigned short *)(portp+2) << 8;
  38. return tmp;
  39. }
  40. static inline void _ne_insb(void *portp, void *addr, unsigned long count)
  41. {
  42. unsigned char *buf = addr;
  43. while (count--)
  44. *buf++ = *(volatile unsigned char *)(portp+1);
  45. }
  46. static inline void _ne_outb(unsigned char b, void *portp)
  47. {
  48. *(volatile unsigned char *)(portp+1) = b;
  49. }
  50. static inline void _ne_outw(unsigned short w, void *portp)
  51. {
  52. *(volatile unsigned short *)portp = (w >> 8);
  53. *(volatile unsigned short *)(portp+2) = (w & 0xff);
  54. }
  55. unsigned char _inb(unsigned long port)
  56. {
  57. if (port >= 0x300 && port < 0x320)
  58. return _ne_inb(PORT2ADDR_NE(port));
  59. return *(volatile unsigned char *)PORT2ADDR(port);
  60. }
  61. unsigned short _inw(unsigned long port)
  62. {
  63. if (port >= 0x300 && port < 0x320)
  64. return _ne_inw(PORT2ADDR_NE(port));
  65. return *(volatile unsigned short *)PORT2ADDR(port);
  66. }
  67. unsigned long _inl(unsigned long port)
  68. {
  69. return *(volatile unsigned long *)PORT2ADDR(port);
  70. }
  71. unsigned char _inb_p(unsigned long port)
  72. {
  73. unsigned char v = _inb(port);
  74. delay();
  75. return (v);
  76. }
  77. unsigned short _inw_p(unsigned long port)
  78. {
  79. unsigned short v = _inw(port);
  80. delay();
  81. return (v);
  82. }
  83. unsigned long _inl_p(unsigned long port)
  84. {
  85. unsigned long v = _inl(port);
  86. delay();
  87. return (v);
  88. }
  89. void _outb(unsigned char b, unsigned long port)
  90. {
  91. if (port >= 0x300 && port < 0x320)
  92. _ne_outb(b, PORT2ADDR_NE(port));
  93. else
  94. *(volatile unsigned char *)PORT2ADDR(port) = b;
  95. }
  96. void _outw(unsigned short w, unsigned long port)
  97. {
  98. if (port >= 0x300 && port < 0x320)
  99. _ne_outw(w, PORT2ADDR_NE(port));
  100. else
  101. *(volatile unsigned short *)PORT2ADDR(port) = w;
  102. }
  103. void _outl(unsigned long l, unsigned long port)
  104. {
  105. *(volatile unsigned long *)PORT2ADDR(port) = l;
  106. }
  107. void _outb_p(unsigned char b, unsigned long port)
  108. {
  109. _outb(b, port);
  110. delay();
  111. }
  112. void _outw_p(unsigned short w, unsigned long port)
  113. {
  114. _outw(w, port);
  115. delay();
  116. }
  117. void _outl_p(unsigned long l, unsigned long port)
  118. {
  119. _outl(l, port);
  120. delay();
  121. }
  122. void _insb(unsigned int port, void *addr, unsigned long count)
  123. {
  124. if (port >= 0x300 && port < 0x320)
  125. _ne_insb(PORT2ADDR_NE(port), addr, count);
  126. else {
  127. unsigned char *buf = addr;
  128. unsigned char *portp = PORT2ADDR(port);
  129. while (count--)
  130. *buf++ = *(volatile unsigned char *)portp;
  131. }
  132. }
  133. void _insw(unsigned int port, void *addr, unsigned long count)
  134. {
  135. unsigned short *buf = addr;
  136. unsigned short *portp;
  137. if (port >= 0x300 && port < 0x320) {
  138. portp = PORT2ADDR_NE(port);
  139. while (count--)
  140. *buf++ = _ne_inw(portp);
  141. } else {
  142. portp = PORT2ADDR(port);
  143. while (count--)
  144. *buf++ = *(volatile unsigned short *)portp;
  145. }
  146. }
  147. void _insl(unsigned int port, void *addr, unsigned long count)
  148. {
  149. unsigned long *buf = addr;
  150. unsigned long *portp;
  151. portp = PORT2ADDR(port);
  152. while (count--)
  153. *buf++ = *(volatile unsigned long *)portp;
  154. }
  155. void _outsb(unsigned int port, const void *addr, unsigned long count)
  156. {
  157. const unsigned char *buf = addr;
  158. unsigned char *portp;
  159. if (port >= 0x300 && port < 0x320) {
  160. portp = PORT2ADDR_NE(port);
  161. while (count--)
  162. _ne_outb(*buf++, portp);
  163. } else {
  164. portp = PORT2ADDR(port);
  165. while (count--)
  166. *(volatile unsigned char *)portp = *buf++;
  167. }
  168. }
  169. void _outsw(unsigned int port, const void *addr, unsigned long count)
  170. {
  171. const unsigned short *buf = addr;
  172. unsigned short *portp;
  173. if (port >= 0x300 && port < 0x320) {
  174. portp = PORT2ADDR_NE(port);
  175. while (count--)
  176. _ne_outw(*buf++, portp);
  177. } else {
  178. portp = PORT2ADDR(port);
  179. while (count--)
  180. *(volatile unsigned short *)portp = *buf++;
  181. }
  182. }
  183. void _outsl(unsigned int port, const void *addr, unsigned long count)
  184. {
  185. const unsigned long *buf = addr;
  186. unsigned char *portp;
  187. portp = PORT2ADDR(port);
  188. while (count--)
  189. *(volatile unsigned long *)portp = *buf++;
  190. }