io_oaks32r.c 4.6 KB

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