io.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * linux/arch/m32r/platforms/m32104ut/io.c
  3. *
  4. * Typical I/O routines for M32104UT board.
  5. *
  6. * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
  7. * Hitoshi Yamamoto, Mamoru Sakugawa,
  8. * Naoto Sugai, Hayato Fujiwara
  9. */
  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. static inline void *_port2addr(unsigned long port)
  26. {
  27. return (void *)(port | NONCACHE_OFFSET);
  28. }
  29. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  30. static inline void *__port2addr_ata(unsigned long port)
  31. {
  32. static int dummy_reg;
  33. switch (port) {
  34. case 0x1f0: return (void *)(0x0c002000 | NONCACHE_OFFSET);
  35. case 0x1f1: return (void *)(0x0c012800 | NONCACHE_OFFSET);
  36. case 0x1f2: return (void *)(0x0c012002 | NONCACHE_OFFSET);
  37. case 0x1f3: return (void *)(0x0c012802 | NONCACHE_OFFSET);
  38. case 0x1f4: return (void *)(0x0c012004 | NONCACHE_OFFSET);
  39. case 0x1f5: return (void *)(0x0c012804 | NONCACHE_OFFSET);
  40. case 0x1f6: return (void *)(0x0c012006 | NONCACHE_OFFSET);
  41. case 0x1f7: return (void *)(0x0c012806 | NONCACHE_OFFSET);
  42. case 0x3f6: return (void *)(0x0c01200e | NONCACHE_OFFSET);
  43. default: return (void *)&dummy_reg;
  44. }
  45. }
  46. #endif
  47. /*
  48. * M32104T-LAN is located in the extended bus space
  49. * from 0x01000000 to 0x01ffffff on physical address.
  50. * The base address of LAN controller(LAN91C111) is 0x300.
  51. */
  52. #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
  53. #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
  54. static inline void *_port2addr_ne(unsigned long port)
  55. {
  56. return (void *)(port + NONCACHE_OFFSET + 0x01000000);
  57. }
  58. static inline void delay(void)
  59. {
  60. __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
  61. }
  62. /*
  63. * NIC I/O function
  64. */
  65. #define PORT2ADDR_NE(port) _port2addr_ne(port)
  66. static inline unsigned char _ne_inb(void *portp)
  67. {
  68. return *(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 = (unsigned char *)addr;
  77. while (count--)
  78. *buf++ = _ne_inb(portp);
  79. }
  80. static inline void _ne_outb(unsigned char b, void *portp)
  81. {
  82. *(volatile unsigned char *)portp = 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. return *(volatile unsigned char *)PORT2ADDR(port);
  93. }
  94. unsigned short _inw(unsigned long port)
  95. {
  96. if (port >= LAN_IOSTART && port < LAN_IOEND)
  97. return _ne_inw(PORT2ADDR_NE(port));
  98. return *(volatile unsigned short *)PORT2ADDR(port);
  99. }
  100. unsigned long _inl(unsigned long port)
  101. {
  102. return *(volatile unsigned long *)PORT2ADDR(port);
  103. }
  104. unsigned char _inb_p(unsigned long port)
  105. {
  106. unsigned char v = _inb(port);
  107. delay();
  108. return (v);
  109. }
  110. unsigned short _inw_p(unsigned long port)
  111. {
  112. unsigned short v = _inw(port);
  113. delay();
  114. return (v);
  115. }
  116. unsigned long _inl_p(unsigned long port)
  117. {
  118. unsigned long v = _inl(port);
  119. delay();
  120. return (v);
  121. }
  122. void _outb(unsigned char b, unsigned long port)
  123. {
  124. if (port >= LAN_IOSTART && port < LAN_IOEND)
  125. _ne_outb(b, PORT2ADDR_NE(port));
  126. else
  127. *(volatile unsigned char *)PORT2ADDR(port) = b;
  128. }
  129. void _outw(unsigned short w, unsigned long port)
  130. {
  131. if (port >= LAN_IOSTART && port < LAN_IOEND)
  132. _ne_outw(w, PORT2ADDR_NE(port));
  133. else
  134. *(volatile unsigned short *)PORT2ADDR(port) = w;
  135. }
  136. void _outl(unsigned long l, unsigned long port)
  137. {
  138. *(volatile unsigned long *)PORT2ADDR(port) = l;
  139. }
  140. void _outb_p(unsigned char b, unsigned long port)
  141. {
  142. _outb(b, port);
  143. delay();
  144. }
  145. void _outw_p(unsigned short w, unsigned long port)
  146. {
  147. _outw(w, port);
  148. delay();
  149. }
  150. void _outl_p(unsigned long l, unsigned long port)
  151. {
  152. _outl(l, port);
  153. delay();
  154. }
  155. void _insb(unsigned int port, void *addr, unsigned long count)
  156. {
  157. if (port >= LAN_IOSTART && port < LAN_IOEND)
  158. _ne_insb(PORT2ADDR_NE(port), addr, count);
  159. else {
  160. unsigned char *buf = addr;
  161. unsigned char *portp = PORT2ADDR(port);
  162. while (count--)
  163. *buf++ = *(volatile unsigned char *)portp;
  164. }
  165. }
  166. void _insw(unsigned int port, void *addr, unsigned long count)
  167. {
  168. unsigned short *buf = addr;
  169. unsigned short *portp;
  170. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  171. /*
  172. * This portion is only used by smc91111.c to read data
  173. * from the DATA_REG. Do not swap the data.
  174. */
  175. portp = PORT2ADDR_NE(port);
  176. while (count--)
  177. *buf++ = *(volatile unsigned short *)portp;
  178. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  179. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  180. pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
  181. count, 1);
  182. #endif
  183. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  184. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  185. portp = __port2addr_ata(port);
  186. while (count--)
  187. *buf++ = *(volatile unsigned short *)portp;
  188. #endif
  189. } else {
  190. portp = PORT2ADDR(port);
  191. while (count--)
  192. *buf++ = *(volatile unsigned short *)portp;
  193. }
  194. }
  195. void _insl(unsigned int port, void *addr, unsigned long count)
  196. {
  197. unsigned long *buf = addr;
  198. unsigned long *portp;
  199. portp = PORT2ADDR(port);
  200. while (count--)
  201. *buf++ = *(volatile unsigned long *)portp;
  202. }
  203. void _outsb(unsigned int port, const void *addr, unsigned long count)
  204. {
  205. const unsigned char *buf = addr;
  206. unsigned char *portp;
  207. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  208. portp = PORT2ADDR_NE(port);
  209. while (count--)
  210. _ne_outb(*buf++, portp);
  211. } else {
  212. portp = PORT2ADDR(port);
  213. while (count--)
  214. *(volatile unsigned char *)portp = *buf++;
  215. }
  216. }
  217. void _outsw(unsigned int port, const void *addr, unsigned long count)
  218. {
  219. const unsigned short *buf = addr;
  220. unsigned short *portp;
  221. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  222. /*
  223. * This portion is only used by smc91111.c to write data
  224. * into the DATA_REG. Do not swap the data.
  225. */
  226. portp = PORT2ADDR_NE(port);
  227. while (count--)
  228. *(volatile unsigned short *)portp = *buf++;
  229. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  230. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  231. portp = __port2addr_ata(port);
  232. while (count--)
  233. *(volatile unsigned short *)portp = *buf++;
  234. #endif
  235. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  236. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  237. pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
  238. count, 1);
  239. #endif
  240. } else {
  241. portp = PORT2ADDR(port);
  242. while (count--)
  243. *(volatile unsigned short *)portp = *buf++;
  244. }
  245. }
  246. void _outsl(unsigned int port, const void *addr, unsigned long count)
  247. {
  248. const unsigned long *buf = addr;
  249. unsigned char *portp;
  250. portp = PORT2ADDR(port);
  251. while (count--)
  252. *(volatile unsigned long *)portp = *buf++;
  253. }