/arch/m32r/kernel/io_oaks32r.c

https://bitbucket.org/evzijst/gittest · C · 251 lines · 195 code · 45 blank · 11 comment · 38 complexity · 8c479329d58aabbe0544c3d5007a60ff MD5 · raw file

  1. /*
  2. * linux/arch/m32r/kernel/io_oaks32r.c
  3. *
  4. * Typical I/O routines for OAKS32R board.
  5. *
  6. * Copyright (c) 2001-2004 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;
  75. if (port >= 0x300 && port < 0x320)
  76. v = _ne_inb(PORT2ADDR_NE(port));
  77. else
  78. v = *(volatile unsigned char *)PORT2ADDR(port);
  79. delay();
  80. return (v);
  81. }
  82. unsigned short _inw_p(unsigned long port)
  83. {
  84. unsigned short v;
  85. if (port >= 0x300 && port < 0x320)
  86. v = _ne_inw(PORT2ADDR_NE(port));
  87. else
  88. v = *(volatile unsigned short *)PORT2ADDR(port);
  89. delay();
  90. return (v);
  91. }
  92. unsigned long _inl_p(unsigned long port)
  93. {
  94. unsigned long v;
  95. v = *(volatile unsigned long *)PORT2ADDR(port);
  96. delay();
  97. return (v);
  98. }
  99. void _outb(unsigned char b, unsigned long port)
  100. {
  101. if (port >= 0x300 && port < 0x320)
  102. _ne_outb(b, PORT2ADDR_NE(port));
  103. else
  104. *(volatile unsigned char *)PORT2ADDR(port) = b;
  105. }
  106. void _outw(unsigned short w, unsigned long port)
  107. {
  108. if (port >= 0x300 && port < 0x320)
  109. _ne_outw(w, PORT2ADDR_NE(port));
  110. else
  111. *(volatile unsigned short *)PORT2ADDR(port) = w;
  112. }
  113. void _outl(unsigned long l, unsigned long port)
  114. {
  115. *(volatile unsigned long *)PORT2ADDR(port) = l;
  116. }
  117. void _outb_p(unsigned char b, unsigned long port)
  118. {
  119. if (port >= 0x300 && port < 0x320)
  120. _ne_outb(b, PORT2ADDR_NE(port));
  121. else
  122. *(volatile unsigned char *)PORT2ADDR(port) = b;
  123. delay();
  124. }
  125. void _outw_p(unsigned short w, unsigned long port)
  126. {
  127. if (port >= 0x300 && port < 0x320)
  128. _ne_outw(w, PORT2ADDR_NE(port));
  129. else
  130. *(volatile unsigned short *)PORT2ADDR(port) = w;
  131. delay();
  132. }
  133. void _outl_p(unsigned long l, unsigned long port)
  134. {
  135. *(volatile unsigned long *)PORT2ADDR(port) = l;
  136. delay();
  137. }
  138. void _insb(unsigned int port, void *addr, unsigned long count)
  139. {
  140. if (port >= 0x300 && port < 0x320)
  141. _ne_insb(PORT2ADDR_NE(port), addr, count);
  142. else {
  143. unsigned char *buf = addr;
  144. unsigned char *portp = PORT2ADDR(port);
  145. while (count--)
  146. *buf++ = *(volatile unsigned char *)portp;
  147. }
  148. }
  149. void _insw(unsigned int port, void *addr, unsigned long count)
  150. {
  151. unsigned short *buf = addr;
  152. unsigned short *portp;
  153. if (port >= 0x300 && port < 0x320) {
  154. portp = PORT2ADDR_NE(port);
  155. while (count--)
  156. *buf++ = _ne_inw(portp);
  157. } else {
  158. portp = PORT2ADDR(port);
  159. while (count--)
  160. *buf++ = *(volatile unsigned short *)portp;
  161. }
  162. }
  163. void _insl(unsigned int port, void *addr, unsigned long count)
  164. {
  165. unsigned long *buf = addr;
  166. unsigned long *portp;
  167. portp = PORT2ADDR(port);
  168. while (count--)
  169. *buf++ = *(volatile unsigned long *)portp;
  170. }
  171. void _outsb(unsigned int port, const void *addr, unsigned long count)
  172. {
  173. const unsigned char *buf = addr;
  174. unsigned char *portp;
  175. if (port >= 0x300 && port < 0x320) {
  176. portp = PORT2ADDR_NE(port);
  177. while (count--)
  178. _ne_outb(*buf++, portp);
  179. } else {
  180. portp = PORT2ADDR(port);
  181. while (count--)
  182. *(volatile unsigned char *)portp = *buf++;
  183. }
  184. }
  185. void _outsw(unsigned int port, const void *addr, unsigned long count)
  186. {
  187. const unsigned short *buf = addr;
  188. unsigned short *portp;
  189. if (port >= 0x300 && port < 0x320) {
  190. portp = PORT2ADDR_NE(port);
  191. while (count--)
  192. _ne_outw(*buf++, portp);
  193. } else {
  194. portp = PORT2ADDR(port);
  195. while (count--)
  196. *(volatile unsigned short *)portp = *buf++;
  197. }
  198. }
  199. void _outsl(unsigned int port, const void *addr, unsigned long count)
  200. {
  201. const unsigned long *buf = addr;
  202. unsigned char *portp;
  203. portp = PORT2ADDR(port);
  204. while (count--)
  205. *(volatile unsigned long *)portp = *buf++;
  206. }