io_mappi2.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. * linux/arch/m32r/kernel/io_mappi2.c
  3. *
  4. * Typical I/O routines for Mappi2 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. #include <asm/byteorder.h>
  14. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  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. extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
  20. extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
  21. extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
  22. extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
  23. #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
  24. #define PORT2ADDR(port) _port2addr(port)
  25. #define PORT2ADDR_NE(port) _port2addr_ne(port)
  26. #define PORT2ADDR_USB(port) _port2addr_usb(port)
  27. static inline void *_port2addr(unsigned long port)
  28. {
  29. return (void *)(port + NONCACHE_OFFSET);
  30. }
  31. #define LAN_IOSTART 0x300
  32. #define LAN_IOEND 0x320
  33. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  34. static inline void *__port2addr_ata(unsigned long port)
  35. {
  36. static int dummy_reg;
  37. switch (port) {
  38. case 0x1f0: return (void *)0xac002000;
  39. case 0x1f1: return (void *)0xac012800;
  40. case 0x1f2: return (void *)0xac012002;
  41. case 0x1f3: return (void *)0xac012802;
  42. case 0x1f4: return (void *)0xac012004;
  43. case 0x1f5: return (void *)0xac012804;
  44. case 0x1f6: return (void *)0xac012006;
  45. case 0x1f7: return (void *)0xac012806;
  46. case 0x3f6: return (void *)0xac01200e;
  47. default: return (void *)&dummy_reg;
  48. }
  49. }
  50. #endif
  51. #ifdef CONFIG_CHIP_OPSP
  52. static inline void *_port2addr_ne(unsigned long port)
  53. {
  54. return (void *)(port + NONCACHE_OFFSET + 0x10000000);
  55. }
  56. #else
  57. static inline void *_port2addr_ne(unsigned long port)
  58. {
  59. return (void *)(port + NONCACHE_OFFSET + 0x04000000);
  60. }
  61. #endif
  62. static inline void *_port2addr_usb(unsigned long port)
  63. {
  64. return (void *)(port + NONCACHE_OFFSET + 0x14000000);
  65. }
  66. static inline void delay(void)
  67. {
  68. __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
  69. }
  70. /*
  71. * NIC I/O function
  72. */
  73. static inline unsigned char _ne_inb(void *portp)
  74. {
  75. return (unsigned char) *(volatile unsigned char *)portp;
  76. }
  77. static inline unsigned short _ne_inw(void *portp)
  78. {
  79. return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
  80. }
  81. static inline void _ne_insb(void *portp, void * addr, unsigned long count)
  82. {
  83. unsigned char *buf = addr;
  84. while (count--)
  85. *buf++ = *(volatile unsigned char *)portp;
  86. }
  87. static inline void _ne_outb(unsigned char b, void *portp)
  88. {
  89. *(volatile unsigned char *)portp = (unsigned char)b;
  90. }
  91. static inline void _ne_outw(unsigned short w, void *portp)
  92. {
  93. *(volatile unsigned short *)portp = cpu_to_le16(w);
  94. }
  95. unsigned char _inb(unsigned long port)
  96. {
  97. if (port >= LAN_IOSTART && port < LAN_IOEND)
  98. return _ne_inb(PORT2ADDR_NE(port));
  99. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  100. else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  101. return *(volatile unsigned char *)__port2addr_ata(port);
  102. }
  103. #endif
  104. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  105. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  106. unsigned char b;
  107. pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
  108. return b;
  109. } else
  110. #endif
  111. return *(volatile unsigned char *)PORT2ADDR(port);
  112. }
  113. unsigned short _inw(unsigned long port)
  114. {
  115. if (port >= LAN_IOSTART && port < LAN_IOEND)
  116. return _ne_inw(PORT2ADDR_NE(port));
  117. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  118. else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  119. return *(volatile unsigned short *)__port2addr_ata(port);
  120. }
  121. #endif
  122. #if defined(CONFIG_USB)
  123. else if (port >= 0x340 && port < 0x3a0)
  124. return *(volatile unsigned short *)PORT2ADDR_USB(port);
  125. #endif
  126. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  127. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  128. unsigned short w;
  129. pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
  130. return w;
  131. } else
  132. #endif
  133. return *(volatile unsigned short *)PORT2ADDR(port);
  134. }
  135. unsigned long _inl(unsigned long port)
  136. {
  137. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  138. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  139. unsigned long l;
  140. pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
  141. return l;
  142. } else
  143. #endif
  144. return *(volatile unsigned long *)PORT2ADDR(port);
  145. }
  146. unsigned char _inb_p(unsigned long port)
  147. {
  148. unsigned char v = _inb(port);
  149. delay();
  150. return (v);
  151. }
  152. unsigned short _inw_p(unsigned long port)
  153. {
  154. unsigned short v = _inw(port);
  155. delay();
  156. return (v);
  157. }
  158. unsigned long _inl_p(unsigned long port)
  159. {
  160. unsigned long v = _inl(port);
  161. delay();
  162. return (v);
  163. }
  164. void _outb(unsigned char b, unsigned long port)
  165. {
  166. if (port >= LAN_IOSTART && port < LAN_IOEND)
  167. _ne_outb(b, PORT2ADDR_NE(port));
  168. else
  169. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  170. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  171. *(volatile unsigned char *)__port2addr_ata(port) = b;
  172. } else
  173. #endif
  174. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  175. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  176. pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
  177. } else
  178. #endif
  179. *(volatile unsigned char *)PORT2ADDR(port) = b;
  180. }
  181. void _outw(unsigned short w, unsigned long port)
  182. {
  183. if (port >= LAN_IOSTART && port < LAN_IOEND)
  184. _ne_outw(w, PORT2ADDR_NE(port));
  185. else
  186. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  187. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  188. *(volatile unsigned short *)__port2addr_ata(port) = w;
  189. } else
  190. #endif
  191. #if defined(CONFIG_USB)
  192. if (port >= 0x340 && port < 0x3a0)
  193. *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
  194. else
  195. #endif
  196. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  197. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  198. pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
  199. } else
  200. #endif
  201. *(volatile unsigned short *)PORT2ADDR(port) = w;
  202. }
  203. void _outl(unsigned long l, unsigned long port)
  204. {
  205. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  206. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  207. pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
  208. } else
  209. #endif
  210. *(volatile unsigned long *)PORT2ADDR(port) = l;
  211. }
  212. void _outb_p(unsigned char b, unsigned long port)
  213. {
  214. _outb(b, port);
  215. delay();
  216. }
  217. void _outw_p(unsigned short w, unsigned long port)
  218. {
  219. _outw(w, port);
  220. delay();
  221. }
  222. void _outl_p(unsigned long l, unsigned long port)
  223. {
  224. _outl(l, port);
  225. delay();
  226. }
  227. void _insb(unsigned int port, void * addr, unsigned long count)
  228. {
  229. if (port >= LAN_IOSTART && port < LAN_IOEND)
  230. _ne_insb(PORT2ADDR_NE(port), addr, count);
  231. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  232. else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  233. unsigned char *buf = addr;
  234. unsigned char *portp = __port2addr_ata(port);
  235. while (count--)
  236. *buf++ = *(volatile unsigned char *)portp;
  237. }
  238. #endif
  239. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  240. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  241. pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
  242. count, 1);
  243. }
  244. #endif
  245. else {
  246. unsigned char *buf = addr;
  247. unsigned char *portp = PORT2ADDR(port);
  248. while (count--)
  249. *buf++ = *(volatile unsigned char *)portp;
  250. }
  251. }
  252. void _insw(unsigned int port, void * addr, unsigned long count)
  253. {
  254. unsigned short *buf = addr;
  255. unsigned short *portp;
  256. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  257. portp = PORT2ADDR_NE(port);
  258. while (count--)
  259. *buf++ = *(volatile unsigned short *)portp;
  260. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  261. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  262. pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
  263. count, 1);
  264. #endif
  265. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  266. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  267. portp = __port2addr_ata(port);
  268. while (count--)
  269. *buf++ = *(volatile unsigned short *)portp;
  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 >= LAN_IOSTART && port < LAN_IOEND) {
  290. portp = PORT2ADDR_NE(port);
  291. while (count--)
  292. _ne_outb(*buf++, portp);
  293. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  294. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  295. portp = __port2addr_ata(port);
  296. while (count--)
  297. *(volatile unsigned char *)portp = *buf++;
  298. #endif
  299. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  300. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  301. pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
  302. count, 1);
  303. #endif
  304. } else {
  305. portp = PORT2ADDR(port);
  306. while (count--)
  307. *(volatile unsigned char *)portp = *buf++;
  308. }
  309. }
  310. void _outsw(unsigned int port, const void * addr, unsigned long count)
  311. {
  312. const unsigned short *buf = addr;
  313. unsigned short *portp;
  314. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  315. portp = PORT2ADDR_NE(port);
  316. while (count--)
  317. *(volatile unsigned short *)portp = *buf++;
  318. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  319. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  320. portp = __port2addr_ata(port);
  321. while (count--)
  322. *(volatile unsigned short *)portp = *buf++;
  323. #endif
  324. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  325. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  326. pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
  327. count, 1);
  328. #endif
  329. } else {
  330. portp = PORT2ADDR(port);
  331. while (count--)
  332. *(volatile unsigned short *)portp = *buf++;
  333. }
  334. }
  335. void _outsl(unsigned int port, const void * addr, unsigned long count)
  336. {
  337. const unsigned long *buf = addr;
  338. unsigned char *portp;
  339. portp = PORT2ADDR(port);
  340. while (count--)
  341. *(volatile unsigned long *)portp = *buf++;
  342. }