io_mappi.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. * linux/arch/m32r/kernel/io_mappi.c
  3. *
  4. * Typical I/O routines for Mappi board.
  5. *
  6. * Copyright (c) 2001, 2002 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;
  113. if (port >= 0x300 && port < 0x320)
  114. v = _ne_inb(PORT2ADDR_NE(port));
  115. else
  116. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  117. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  118. unsigned char b;
  119. pcc_ioread(0, port, &b, sizeof(b), 1, 0);
  120. return b;
  121. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  122. unsigned char b;
  123. pcc_ioread(1, port, &b, sizeof(b), 1, 0);
  124. return b;
  125. } else
  126. #endif
  127. v = *(volatile unsigned char *)PORT2ADDR(port);
  128. delay();
  129. return (v);
  130. }
  131. unsigned short _inw_p(unsigned long port)
  132. {
  133. unsigned short v;
  134. if (port >= 0x300 && port < 0x320)
  135. v = _ne_inw(PORT2ADDR_NE(port));
  136. else
  137. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  138. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  139. unsigned short w;
  140. pcc_ioread(0, port, &w, sizeof(w), 1, 0);
  141. return w;
  142. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  143. unsigned short w;
  144. pcc_ioread(1, port, &w, sizeof(w), 1, 0);
  145. return w;
  146. } else
  147. #endif
  148. v = *(volatile unsigned short *)PORT2ADDR(port);
  149. delay();
  150. return (v);
  151. }
  152. unsigned long _inl_p(unsigned long port)
  153. {
  154. unsigned long v;
  155. v = *(volatile unsigned long *)PORT2ADDR(port);
  156. delay();
  157. return (v);
  158. }
  159. void _outb(unsigned char b, unsigned long port)
  160. {
  161. if (port >= 0x300 && port < 0x320)
  162. _ne_outb(b, PORT2ADDR_NE(port));
  163. else
  164. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  165. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  166. pcc_iowrite(0, port, &b, sizeof(b), 1, 0);
  167. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  168. pcc_iowrite(1, port, &b, sizeof(b), 1, 0);
  169. } else
  170. #endif
  171. *(volatile unsigned char *)PORT2ADDR(port) = b;
  172. }
  173. void _outw(unsigned short w, unsigned long port)
  174. {
  175. if (port >= 0x300 && port < 0x320)
  176. _ne_outw(w, PORT2ADDR_NE(port));
  177. else
  178. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  179. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  180. pcc_iowrite(0, port, &w, sizeof(w), 1, 0);
  181. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  182. pcc_iowrite(1, port, &w, sizeof(w), 1, 0);
  183. } else
  184. #endif
  185. *(volatile unsigned short *)PORT2ADDR(port) = w;
  186. }
  187. void _outl(unsigned long l, unsigned long port)
  188. {
  189. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  190. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  191. pcc_iowrite(0, port, &l, sizeof(l), 1, 0);
  192. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  193. pcc_iowrite(1, port, &l, sizeof(l), 1, 0);
  194. } else
  195. #endif
  196. *(volatile unsigned long *)PORT2ADDR(port) = l;
  197. }
  198. void _outb_p(unsigned char b, unsigned long port)
  199. {
  200. if (port >= 0x300 && port < 0x320)
  201. _ne_outb(b, PORT2ADDR_NE(port));
  202. else
  203. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  204. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  205. pcc_iowrite(0, port, &b, sizeof(b), 1, 0);
  206. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  207. pcc_iowrite(1, port, &b, sizeof(b), 1, 0);
  208. } else
  209. #endif
  210. *(volatile unsigned char *)PORT2ADDR(port) = b;
  211. delay();
  212. }
  213. void _outw_p(unsigned short w, unsigned long port)
  214. {
  215. if (port >= 0x300 && port < 0x320)
  216. _ne_outw(w, PORT2ADDR_NE(port));
  217. else
  218. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  219. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  220. pcc_iowrite(0, port, &w, sizeof(w), 1, 0);
  221. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  222. pcc_iowrite(1, port, &w, sizeof(w), 1, 0);
  223. } else
  224. #endif
  225. *(volatile unsigned short *)PORT2ADDR(port) = w;
  226. delay();
  227. }
  228. void _outl_p(unsigned long l, unsigned long port)
  229. {
  230. *(volatile unsigned long *)PORT2ADDR(port) = l;
  231. delay();
  232. }
  233. void _insb(unsigned int port, void *addr, unsigned long count)
  234. {
  235. unsigned short *buf = addr;
  236. unsigned short *portp;
  237. if (port >= 0x300 && port < 0x320){
  238. portp = PORT2ADDR_NE(port);
  239. while (count--)
  240. *buf++ = *(volatile unsigned char *)portp;
  241. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  242. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  243. pcc_ioread(0, port, (void *)addr, sizeof(unsigned char),
  244. count, 1);
  245. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  246. pcc_ioread(1, port, (void *)addr, sizeof(unsigned char),
  247. count, 1);
  248. #endif
  249. } else {
  250. portp = PORT2ADDR(port);
  251. while (count--)
  252. *buf++ = *(volatile unsigned char *)portp;
  253. }
  254. }
  255. void _insw(unsigned int port, void *addr, unsigned long count)
  256. {
  257. unsigned short *buf = addr;
  258. unsigned short *portp;
  259. if (port >= 0x300 && port < 0x320) {
  260. portp = PORT2ADDR_NE(port);
  261. while (count--)
  262. *buf++ = _ne_inw(portp);
  263. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  264. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  265. pcc_ioread(0, port, (void *)addr, sizeof(unsigned short),
  266. count, 1);
  267. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  268. pcc_ioread(1, port, (void *)addr, sizeof(unsigned short),
  269. count, 1);
  270. #endif
  271. } else {
  272. portp = PORT2ADDR(port);
  273. while (count--)
  274. *buf++ = *(volatile unsigned short *)portp;
  275. }
  276. }
  277. void _insl(unsigned int port, void *addr, unsigned long count)
  278. {
  279. unsigned long *buf = addr;
  280. unsigned long *portp;
  281. portp = PORT2ADDR(port);
  282. while (count--)
  283. *buf++ = *(volatile unsigned long *)portp;
  284. }
  285. void _outsb(unsigned int port, const void *addr, unsigned long count)
  286. {
  287. const unsigned char *buf = addr;
  288. unsigned char *portp;
  289. if (port >= 0x300 && port < 0x320) {
  290. portp = PORT2ADDR_NE(port);
  291. while (count--)
  292. _ne_outb(*buf++, portp);
  293. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  294. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  295. pcc_iowrite(0, port, (void *)addr, sizeof(unsigned char),
  296. count, 1);
  297. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  298. pcc_iowrite(1, port, (void *)addr, sizeof(unsigned char),
  299. count, 1);
  300. #endif
  301. } else {
  302. portp = PORT2ADDR(port);
  303. while (count--)
  304. *(volatile unsigned char *)portp = *buf++;
  305. }
  306. }
  307. void _outsw(unsigned int port, const void *addr, unsigned long count)
  308. {
  309. const unsigned short *buf = addr;
  310. unsigned short *portp;
  311. if (port >= 0x300 && port < 0x320) {
  312. portp = PORT2ADDR_NE(port);
  313. while (count--)
  314. _ne_outw(*buf++, portp);
  315. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
  316. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  317. pcc_iowrite(0, port, (void *)addr, sizeof(unsigned short),
  318. count, 1);
  319. } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
  320. pcc_iowrite(1, port, (void *)addr, sizeof(unsigned short),
  321. count, 1);
  322. #endif
  323. } else {
  324. portp = PORT2ADDR(port);
  325. while (count--)
  326. *(volatile unsigned short *)portp = *buf++;
  327. }
  328. }
  329. void _outsl(unsigned int port, const void *addr, unsigned long count)
  330. {
  331. const unsigned long *buf = addr;
  332. unsigned char *portp;
  333. portp = PORT2ADDR(port);
  334. while (count--)
  335. *(volatile unsigned long *)portp = *buf++;
  336. }