io_m32104ut.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * linux/arch/m32r/kernel/io_m32104ut.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 <linux/config.h>
  11. #include <asm/m32r.h>
  12. #include <asm/page.h>
  13. #include <asm/io.h>
  14. #include <asm/byteorder.h>
  15. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  16. #include <linux/types.h>
  17. #define M32R_PCC_IOMAP_SIZE 0x1000
  18. #define M32R_PCC_IOSTART0 0x1000
  19. #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
  20. extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
  21. extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
  22. extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
  23. extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
  24. #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
  25. #define PORT2ADDR(port) _port2addr(port)
  26. static inline void *_port2addr(unsigned long port)
  27. {
  28. return (void *)(port | NONCACHE_OFFSET);
  29. }
  30. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  31. static inline void *__port2addr_ata(unsigned long port)
  32. {
  33. static int dummy_reg;
  34. switch (port) {
  35. case 0x1f0: return (void *)(0x0c002000 | NONCACHE_OFFSET);
  36. case 0x1f1: return (void *)(0x0c012800 | NONCACHE_OFFSET);
  37. case 0x1f2: return (void *)(0x0c012002 | NONCACHE_OFFSET);
  38. case 0x1f3: return (void *)(0x0c012802 | NONCACHE_OFFSET);
  39. case 0x1f4: return (void *)(0x0c012004 | NONCACHE_OFFSET);
  40. case 0x1f5: return (void *)(0x0c012804 | NONCACHE_OFFSET);
  41. case 0x1f6: return (void *)(0x0c012006 | NONCACHE_OFFSET);
  42. case 0x1f7: return (void *)(0x0c012806 | NONCACHE_OFFSET);
  43. case 0x3f6: return (void *)(0x0c01200e | NONCACHE_OFFSET);
  44. default: return (void *)&dummy_reg;
  45. }
  46. }
  47. #endif
  48. /*
  49. * M32104T-LAN is located in the extended bus space
  50. * from 0x01000000 to 0x01ffffff on physical address.
  51. * The base address of LAN controller(LAN91C111) is 0x300.
  52. */
  53. #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
  54. #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
  55. static inline void *_port2addr_ne(unsigned long port)
  56. {
  57. return (void *)(port + NONCACHE_OFFSET + 0x01000000);
  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. #define PORT2ADDR_NE(port) _port2addr_ne(port)
  67. static inline unsigned char _ne_inb(void *portp)
  68. {
  69. return *(volatile unsigned char *)portp;
  70. }
  71. static inline unsigned short _ne_inw(void *portp)
  72. {
  73. return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
  74. }
  75. static inline void _ne_insb(void *portp, void *addr, unsigned long count)
  76. {
  77. unsigned char *buf = (unsigned char *)addr;
  78. while (count--)
  79. *buf++ = _ne_inb(portp);
  80. }
  81. static inline void _ne_outb(unsigned char b, void *portp)
  82. {
  83. *(volatile unsigned char *)portp = b;
  84. }
  85. static inline void _ne_outw(unsigned short w, void *portp)
  86. {
  87. *(volatile unsigned short *)portp = cpu_to_le16(w);
  88. }
  89. unsigned char _inb(unsigned long port)
  90. {
  91. if (port >= LAN_IOSTART && port < LAN_IOEND)
  92. return _ne_inb(PORT2ADDR_NE(port));
  93. return *(volatile unsigned char *)PORT2ADDR(port);
  94. }
  95. unsigned short _inw(unsigned long port)
  96. {
  97. if (port >= LAN_IOSTART && port < LAN_IOEND)
  98. return _ne_inw(PORT2ADDR_NE(port));
  99. return *(volatile unsigned short *)PORT2ADDR(port);
  100. }
  101. unsigned long _inl(unsigned long port)
  102. {
  103. return *(volatile unsigned long *)PORT2ADDR(port);
  104. }
  105. unsigned char _inb_p(unsigned long port)
  106. {
  107. unsigned char v = _inb(port);
  108. delay();
  109. return (v);
  110. }
  111. unsigned short _inw_p(unsigned long port)
  112. {
  113. unsigned short v = _inw(port);
  114. delay();
  115. return (v);
  116. }
  117. unsigned long _inl_p(unsigned long port)
  118. {
  119. unsigned long v = _inl(port);
  120. delay();
  121. return (v);
  122. }
  123. void _outb(unsigned char b, unsigned long port)
  124. {
  125. if (port >= LAN_IOSTART && port < LAN_IOEND)
  126. _ne_outb(b, PORT2ADDR_NE(port));
  127. else
  128. *(volatile unsigned char *)PORT2ADDR(port) = b;
  129. }
  130. void _outw(unsigned short w, unsigned long port)
  131. {
  132. if (port >= LAN_IOSTART && port < LAN_IOEND)
  133. _ne_outw(w, PORT2ADDR_NE(port));
  134. else
  135. *(volatile unsigned short *)PORT2ADDR(port) = w;
  136. }
  137. void _outl(unsigned long l, unsigned long port)
  138. {
  139. *(volatile unsigned long *)PORT2ADDR(port) = l;
  140. }
  141. void _outb_p(unsigned char b, unsigned long port)
  142. {
  143. _outb(b, port);
  144. delay();
  145. }
  146. void _outw_p(unsigned short w, unsigned long port)
  147. {
  148. _outw(w, port);
  149. delay();
  150. }
  151. void _outl_p(unsigned long l, unsigned long port)
  152. {
  153. _outl(l, port);
  154. delay();
  155. }
  156. void _insb(unsigned int port, void *addr, unsigned long count)
  157. {
  158. if (port >= LAN_IOSTART && port < LAN_IOEND)
  159. _ne_insb(PORT2ADDR_NE(port), addr, count);
  160. else {
  161. unsigned char *buf = addr;
  162. unsigned char *portp = PORT2ADDR(port);
  163. while (count--)
  164. *buf++ = *(volatile unsigned char *)portp;
  165. }
  166. }
  167. void _insw(unsigned int port, void *addr, unsigned long count)
  168. {
  169. unsigned short *buf = addr;
  170. unsigned short *portp;
  171. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  172. /*
  173. * This portion is only used by smc91111.c to read data
  174. * from the DATA_REG. Do not swap the data.
  175. */
  176. portp = PORT2ADDR_NE(port);
  177. while (count--)
  178. *buf++ = *(volatile unsigned short *)portp;
  179. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  180. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  181. pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
  182. count, 1);
  183. #endif
  184. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  185. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  186. portp = __port2addr_ata(port);
  187. while (count--)
  188. *buf++ = *(volatile unsigned short *)portp;
  189. #endif
  190. } else {
  191. portp = PORT2ADDR(port);
  192. while (count--)
  193. *buf++ = *(volatile unsigned short *)portp;
  194. }
  195. }
  196. void _insl(unsigned int port, void *addr, unsigned long count)
  197. {
  198. unsigned long *buf = addr;
  199. unsigned long *portp;
  200. portp = PORT2ADDR(port);
  201. while (count--)
  202. *buf++ = *(volatile unsigned long *)portp;
  203. }
  204. void _outsb(unsigned int port, const void *addr, unsigned long count)
  205. {
  206. const unsigned char *buf = addr;
  207. unsigned char *portp;
  208. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  209. portp = PORT2ADDR_NE(port);
  210. while (count--)
  211. _ne_outb(*buf++, portp);
  212. } else {
  213. portp = PORT2ADDR(port);
  214. while (count--)
  215. *(volatile unsigned char *)portp = *buf++;
  216. }
  217. }
  218. void _outsw(unsigned int port, const void *addr, unsigned long count)
  219. {
  220. const unsigned short *buf = addr;
  221. unsigned short *portp;
  222. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  223. /*
  224. * This portion is only used by smc91111.c to write data
  225. * into the DATA_REG. Do not swap the data.
  226. */
  227. portp = PORT2ADDR_NE(port);
  228. while (count--)
  229. *(volatile unsigned short *)portp = *buf++;
  230. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  231. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  232. portp = __port2addr_ata(port);
  233. while (count--)
  234. *(volatile unsigned short *)portp = *buf++;
  235. #endif
  236. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  237. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  238. pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
  239. count, 1);
  240. #endif
  241. } else {
  242. portp = PORT2ADDR(port);
  243. while (count--)
  244. *(volatile unsigned short *)portp = *buf++;
  245. }
  246. }
  247. void _outsl(unsigned int port, const void *addr, unsigned long count)
  248. {
  249. const unsigned long *buf = addr;
  250. unsigned char *portp;
  251. portp = PORT2ADDR(port);
  252. while (count--)
  253. *(volatile unsigned long *)portp = *buf++;
  254. }