io.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. * linux/arch/m32r/platforms/mappi/io.c
  3. *
  4. * Typical I/O routines for Mappi board.
  5. *
  6. * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
  7. * Hitoshi Yamamoto
  8. */
  9. #include <asm/m32r.h>
  10. #include <asm/page.h>
  11. #include <asm/io.h>
  12. #include <asm/byteorder.h>
  13. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  14. #include <linux/types.h>
  15. #define M32R_PCC_IOMAP_SIZE 0x1000
  16. #define M32R_PCC_IOSTART0 0x1000
  17. #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
  18. #define M32R_PCC_IOSTART1 0x2000
  19. #define M32R_PCC_IOEND1 (M32R_PCC_IOSTART1 + M32R_PCC_IOMAP_SIZE - 1)
  20. extern void pcc_ioread(int, unsigned long, void *, size_t, size_t, int);
  21. extern void pcc_iowrite(int, unsigned long, void *, size_t, size_t, int);
  22. #endif /* CONFIG_PCMCIA && CONFIG_M32R_PCC */
  23. #define PORT2ADDR(port) _port2addr(port)
  24. static inline void *_port2addr(unsigned long port)
  25. {
  26. return (void *)(port | NONCACHE_OFFSET);
  27. }
  28. static inline void *_port2addr_ne(unsigned long port)
  29. {
  30. return (void *)((port<<1) + NONCACHE_OFFSET + 0x0C000000);
  31. }
  32. static inline void delay(void)
  33. {
  34. __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
  35. }
  36. /*
  37. * NIC I/O function
  38. */
  39. #define PORT2ADDR_NE(port) _port2addr_ne(port)
  40. static inline unsigned char _ne_inb(void *portp)
  41. {
  42. return (unsigned char) *(volatile unsigned short *)portp;
  43. }
  44. static inline unsigned short _ne_inw(void *portp)
  45. {
  46. unsigned short tmp;
  47. tmp = *(volatile unsigned short *)portp;
  48. return le16_to_cpu(tmp);
  49. }
  50. static inline void _ne_outb(unsigned char b, void *portp)
  51. {
  52. *(volatile unsigned short *)portp = (unsigned short)b;
  53. }
  54. static inline void _ne_outw(unsigned short w, void *portp)
  55. {
  56. *(volatile unsigned short *)portp = cpu_to_le16(w);
  57. }
  58. unsigned char _inb(unsigned long port)
  59. {
  60. if (port >= 0x300 && port < 0x320)
  61. return _ne_inb(PORT2ADDR_NE(port));
  62. else
  63. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  64. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  65. unsigned char b;
  66. pcc_ioread(0, port, &b, sizeof(b), 1, 0);
  67. return b;
  68. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  69. unsigned char b;
  70. pcc_ioread(1, port, &b, sizeof(b), 1, 0);
  71. return b;
  72. } else
  73. #endif
  74. return *(volatile unsigned char *)PORT2ADDR(port);
  75. }
  76. unsigned short _inw(unsigned long port)
  77. {
  78. if (port >= 0x300 && port < 0x320)
  79. return _ne_inw(PORT2ADDR_NE(port));
  80. else
  81. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  82. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  83. unsigned short w;
  84. pcc_ioread(0, port, &w, sizeof(w), 1, 0);
  85. return w;
  86. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  87. unsigned short w;
  88. pcc_ioread(1, port, &w, sizeof(w), 1, 0);
  89. return w;
  90. } else
  91. #endif
  92. return *(volatile unsigned short *)PORT2ADDR(port);
  93. }
  94. unsigned long _inl(unsigned long port)
  95. {
  96. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  97. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  98. unsigned long l;
  99. pcc_ioread(0, port, &l, sizeof(l), 1, 0);
  100. return l;
  101. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  102. unsigned short l;
  103. pcc_ioread(1, port, &l, sizeof(l), 1, 0);
  104. return l;
  105. } else
  106. #endif
  107. return *(volatile unsigned long *)PORT2ADDR(port);
  108. }
  109. unsigned char _inb_p(unsigned long port)
  110. {
  111. unsigned char v = _inb(port);
  112. delay();
  113. return (v);
  114. }
  115. unsigned short _inw_p(unsigned long port)
  116. {
  117. unsigned short v = _inw(port);
  118. delay();
  119. return (v);
  120. }
  121. unsigned long _inl_p(unsigned long port)
  122. {
  123. unsigned long v = _inl(port);
  124. delay();
  125. return (v);
  126. }
  127. void _outb(unsigned char b, unsigned long port)
  128. {
  129. if (port >= 0x300 && port < 0x320)
  130. _ne_outb(b, PORT2ADDR_NE(port));
  131. else
  132. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  133. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  134. pcc_iowrite(0, port, &b, sizeof(b), 1, 0);
  135. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  136. pcc_iowrite(1, port, &b, sizeof(b), 1, 0);
  137. } else
  138. #endif
  139. *(volatile unsigned char *)PORT2ADDR(port) = b;
  140. }
  141. void _outw(unsigned short w, unsigned long port)
  142. {
  143. if (port >= 0x300 && port < 0x320)
  144. _ne_outw(w, PORT2ADDR_NE(port));
  145. else
  146. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  147. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  148. pcc_iowrite(0, port, &w, sizeof(w), 1, 0);
  149. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  150. pcc_iowrite(1, port, &w, sizeof(w), 1, 0);
  151. } else
  152. #endif
  153. *(volatile unsigned short *)PORT2ADDR(port) = w;
  154. }
  155. void _outl(unsigned long l, unsigned long port)
  156. {
  157. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  158. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  159. pcc_iowrite(0, port, &l, sizeof(l), 1, 0);
  160. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  161. pcc_iowrite(1, port, &l, sizeof(l), 1, 0);
  162. } else
  163. #endif
  164. *(volatile unsigned long *)PORT2ADDR(port) = l;
  165. }
  166. void _outb_p(unsigned char b, unsigned long port)
  167. {
  168. _outb(b, port);
  169. delay();
  170. }
  171. void _outw_p(unsigned short w, unsigned long port)
  172. {
  173. _outw(w, port);
  174. delay();
  175. }
  176. void _outl_p(unsigned long l, unsigned long port)
  177. {
  178. _outl(l, port);
  179. delay();
  180. }
  181. void _insb(unsigned int port, void *addr, unsigned long count)
  182. {
  183. unsigned short *buf = addr;
  184. unsigned short *portp;
  185. if (port >= 0x300 && port < 0x320){
  186. portp = PORT2ADDR_NE(port);
  187. while (count--)
  188. *buf++ = *(volatile unsigned char *)portp;
  189. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  190. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  191. pcc_ioread(0, port, (void *)addr, sizeof(unsigned char),
  192. count, 1);
  193. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  194. pcc_ioread(1, port, (void *)addr, sizeof(unsigned char),
  195. count, 1);
  196. #endif
  197. } else {
  198. portp = PORT2ADDR(port);
  199. while (count--)
  200. *buf++ = *(volatile unsigned char *)portp;
  201. }
  202. }
  203. void _insw(unsigned int port, void *addr, unsigned long count)
  204. {
  205. unsigned short *buf = addr;
  206. unsigned short *portp;
  207. if (port >= 0x300 && port < 0x320) {
  208. portp = PORT2ADDR_NE(port);
  209. while (count--)
  210. *buf++ = _ne_inw(portp);
  211. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  212. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  213. pcc_ioread(0, port, (void *)addr, sizeof(unsigned short),
  214. count, 1);
  215. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  216. pcc_ioread(1, port, (void *)addr, sizeof(unsigned short),
  217. count, 1);
  218. #endif
  219. } else {
  220. portp = PORT2ADDR(port);
  221. while (count--)
  222. *buf++ = *(volatile unsigned short *)portp;
  223. }
  224. }
  225. void _insl(unsigned int port, void *addr, unsigned long count)
  226. {
  227. unsigned long *buf = addr;
  228. unsigned long *portp;
  229. portp = PORT2ADDR(port);
  230. while (count--)
  231. *buf++ = *(volatile unsigned long *)portp;
  232. }
  233. void _outsb(unsigned int port, const void *addr, unsigned long count)
  234. {
  235. const unsigned char *buf = addr;
  236. unsigned char *portp;
  237. if (port >= 0x300 && port < 0x320) {
  238. portp = PORT2ADDR_NE(port);
  239. while (count--)
  240. _ne_outb(*buf++, portp);
  241. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  242. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  243. pcc_iowrite(0, port, (void *)addr, sizeof(unsigned char),
  244. count, 1);
  245. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  246. pcc_iowrite(1, port, (void *)addr, sizeof(unsigned char),
  247. count, 1);
  248. #endif
  249. } else {
  250. portp = PORT2ADDR(port);
  251. while (count--)
  252. *(volatile unsigned char *)portp = *buf++;
  253. }
  254. }
  255. void _outsw(unsigned int port, const void *addr, unsigned long count)
  256. {
  257. const unsigned short *buf = addr;
  258. unsigned short *portp;
  259. if (port >= 0x300 && port < 0x320) {
  260. portp = PORT2ADDR_NE(port);
  261. while (count--)
  262. _ne_outw(*buf++, portp);
  263. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  264. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  265. pcc_iowrite(0, port, (void *)addr, sizeof(unsigned short),
  266. count, 1);
  267. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  268. pcc_iowrite(1, port, (void *)addr, sizeof(unsigned short),
  269. count, 1);
  270. #endif
  271. } else {
  272. portp = PORT2ADDR(port);
  273. while (count--)
  274. *(volatile unsigned short *)portp = *buf++;
  275. }
  276. }
  277. void _outsl(unsigned int port, const void *addr, unsigned long count)
  278. {
  279. const unsigned long *buf = addr;
  280. unsigned char *portp;
  281. portp = PORT2ADDR(port);
  282. while (count--)
  283. *(volatile unsigned long *)portp = *buf++;
  284. }