io_mappi3.c 9.8 KB

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