io_opsput.c 8.2 KB

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