io_mappi.c 8.2 KB

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