io_opsput.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * linux/arch/m32r/kernel/io_opsput.c
  3. *
  4. * Typical I/O routines for OPSPUT board.
  5. *
  6. * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
  7. * Hitoshi Yamamoto, Takeo Takahashi
  8. *
  9. * This file is subject to the terms and conditions of the GNU General
  10. * Public License. See the file "COPYING" in the main directory of this
  11. * archive for more details.
  12. */
  13. #include <asm/m32r.h>
  14. #include <asm/page.h>
  15. #include <asm/io.h>
  16. #include <asm/byteorder.h>
  17. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  18. #include <linux/types.h>
  19. #define M32R_PCC_IOMAP_SIZE 0x1000
  20. #define M32R_PCC_IOSTART0 0x1000
  21. #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
  22. extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
  23. extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
  24. extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
  25. extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
  26. #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
  27. #define PORT2ADDR(port) _port2addr(port)
  28. #define PORT2ADDR_USB(port) _port2addr_usb(port)
  29. static inline void *_port2addr(unsigned long port)
  30. {
  31. return (void *)(port | NONCACHE_OFFSET);
  32. }
  33. /*
  34. * OPSPUT-LAN is located in the extended bus space
  35. * from 0x10000000 to 0x13ffffff on physical address.
  36. * The base address of LAN controller(LAN91C111) is 0x300.
  37. */
  38. #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
  39. #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
  40. static inline void *_port2addr_ne(unsigned long port)
  41. {
  42. return (void *)(port + 0x10000000);
  43. }
  44. static inline void *_port2addr_usb(unsigned long port)
  45. {
  46. return (void *)((port & 0x0f) + NONCACHE_OFFSET + 0x10303000);
  47. }
  48. static inline void delay(void)
  49. {
  50. __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
  51. }
  52. /*
  53. * NIC I/O function
  54. */
  55. #define PORT2ADDR_NE(port) _port2addr_ne(port)
  56. static inline unsigned char _ne_inb(void *portp)
  57. {
  58. return *(volatile unsigned char *)portp;
  59. }
  60. static inline unsigned short _ne_inw(void *portp)
  61. {
  62. return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
  63. }
  64. static inline void _ne_insb(void *portp, void *addr, unsigned long count)
  65. {
  66. unsigned char *buf = (unsigned char *)addr;
  67. while (count--)
  68. *buf++ = _ne_inb(portp);
  69. }
  70. static inline void _ne_outb(unsigned char b, void *portp)
  71. {
  72. *(volatile unsigned char *)portp = b;
  73. }
  74. static inline void _ne_outw(unsigned short w, void *portp)
  75. {
  76. *(volatile unsigned short *)portp = cpu_to_le16(w);
  77. }
  78. unsigned char _inb(unsigned long port)
  79. {
  80. if (port >= LAN_IOSTART && port < LAN_IOEND)
  81. return _ne_inb(PORT2ADDR_NE(port));
  82. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  83. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  84. unsigned char b;
  85. pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
  86. return b;
  87. } else
  88. #endif
  89. return *(volatile unsigned char *)PORT2ADDR(port);
  90. }
  91. unsigned short _inw(unsigned long port)
  92. {
  93. if (port >= LAN_IOSTART && port < LAN_IOEND)
  94. return _ne_inw(PORT2ADDR_NE(port));
  95. #if defined(CONFIG_USB)
  96. else if(port >= 0x340 && port < 0x3a0)
  97. return *(volatile unsigned short *)PORT2ADDR_USB(port);
  98. #endif
  99. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  100. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  101. unsigned short w;
  102. pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
  103. return w;
  104. } else
  105. #endif
  106. return *(volatile unsigned short *)PORT2ADDR(port);
  107. }
  108. unsigned long _inl(unsigned long port)
  109. {
  110. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  111. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  112. unsigned long l;
  113. pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
  114. return l;
  115. } else
  116. #endif
  117. return *(volatile unsigned long *)PORT2ADDR(port);
  118. }
  119. unsigned char _inb_p(unsigned long port)
  120. {
  121. unsigned char v = _inb(port);
  122. delay();
  123. return (v);
  124. }
  125. unsigned short _inw_p(unsigned long port)
  126. {
  127. unsigned short v = _inw(port);
  128. delay();
  129. return (v);
  130. }
  131. unsigned long _inl_p(unsigned long port)
  132. {
  133. unsigned long v = _inl(port);
  134. delay();
  135. return (v);
  136. }
  137. void _outb(unsigned char b, unsigned long port)
  138. {
  139. if (port >= LAN_IOSTART && port < LAN_IOEND)
  140. _ne_outb(b, PORT2ADDR_NE(port));
  141. else
  142. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  143. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  144. pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
  145. } else
  146. #endif
  147. *(volatile unsigned char *)PORT2ADDR(port) = b;
  148. }
  149. void _outw(unsigned short w, unsigned long port)
  150. {
  151. if (port >= LAN_IOSTART && port < LAN_IOEND)
  152. _ne_outw(w, PORT2ADDR_NE(port));
  153. else
  154. #if defined(CONFIG_USB)
  155. if(port >= 0x340 && port < 0x3a0)
  156. *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
  157. else
  158. #endif
  159. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  160. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  161. pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
  162. } else
  163. #endif
  164. *(volatile unsigned short *)PORT2ADDR(port) = w;
  165. }
  166. void _outl(unsigned long l, unsigned long port)
  167. {
  168. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  169. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  170. pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
  171. } else
  172. #endif
  173. *(volatile unsigned long *)PORT2ADDR(port) = l;
  174. }
  175. void _outb_p(unsigned char b, unsigned long port)
  176. {
  177. _outb(b, port);
  178. delay();
  179. }
  180. void _outw_p(unsigned short w, unsigned long port)
  181. {
  182. _outw(w, port);
  183. delay();
  184. }
  185. void _outl_p(unsigned long l, unsigned long port)
  186. {
  187. _outl(l, port);
  188. delay();
  189. }
  190. void _insb(unsigned int port, void *addr, unsigned long count)
  191. {
  192. if (port >= LAN_IOSTART && port < LAN_IOEND)
  193. _ne_insb(PORT2ADDR_NE(port), addr, count);
  194. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  195. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  196. pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
  197. count, 1);
  198. }
  199. #endif
  200. else {
  201. unsigned char *buf = addr;
  202. unsigned char *portp = PORT2ADDR(port);
  203. while (count--)
  204. *buf++ = *(volatile unsigned char *)portp;
  205. }
  206. }
  207. void _insw(unsigned int port, void *addr, unsigned long count)
  208. {
  209. unsigned short *buf = addr;
  210. unsigned short *portp;
  211. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  212. /*
  213. * This portion is only used by smc91111.c to read data
  214. * from the DATA_REG. Do not swap the data.
  215. */
  216. portp = PORT2ADDR_NE(port);
  217. while (count--)
  218. *buf++ = *(volatile unsigned short *)portp;
  219. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  220. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  221. pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
  222. count, 1);
  223. #endif
  224. } else {
  225. portp = PORT2ADDR(port);
  226. while (count--)
  227. *buf++ = *(volatile unsigned short *)portp;
  228. }
  229. }
  230. void _insl(unsigned int port, void *addr, unsigned long count)
  231. {
  232. unsigned long *buf = addr;
  233. unsigned long *portp;
  234. portp = PORT2ADDR(port);
  235. while (count--)
  236. *buf++ = *(volatile unsigned long *)portp;
  237. }
  238. void _outsb(unsigned int port, const void *addr, unsigned long count)
  239. {
  240. const unsigned char *buf = addr;
  241. unsigned char *portp;
  242. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  243. portp = PORT2ADDR_NE(port);
  244. while (count--)
  245. _ne_outb(*buf++, portp);
  246. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  247. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  248. pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
  249. count, 1);
  250. #endif
  251. } else {
  252. portp = PORT2ADDR(port);
  253. while (count--)
  254. *(volatile unsigned char *)portp = *buf++;
  255. }
  256. }
  257. void _outsw(unsigned int port, const void *addr, unsigned long count)
  258. {
  259. const unsigned short *buf = addr;
  260. unsigned short *portp;
  261. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  262. /*
  263. * This portion is only used by smc91111.c to write data
  264. * into the DATA_REG. Do not swap the data.
  265. */
  266. portp = PORT2ADDR_NE(port);
  267. while (count--)
  268. *(volatile unsigned short *)portp = *buf++;
  269. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  270. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  271. pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
  272. count, 1);
  273. #endif
  274. } else {
  275. portp = PORT2ADDR(port);
  276. while (count--)
  277. *(volatile unsigned short *)portp = *buf++;
  278. }
  279. }
  280. void _outsl(unsigned int port, const void *addr, unsigned long count)
  281. {
  282. const unsigned long *buf = addr;
  283. unsigned char *portp;
  284. portp = PORT2ADDR(port);
  285. while (count--)
  286. *(volatile unsigned long *)portp = *buf++;
  287. }