io_opsput.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*
  2. * linux/arch/m32r/kernel/io_mappi.c
  3. *
  4. * Typical I/O routines for OPSPUT board.
  5. *
  6. * Copyright (c) 2001, 2002 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;
  123. if (port >= LAN_IOSTART && port < LAN_IOEND)
  124. v = _ne_inb(PORT2ADDR_NE(port));
  125. else
  126. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  127. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  128. unsigned char b;
  129. pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
  130. return b;
  131. } else
  132. #endif
  133. v = *(volatile unsigned char *)PORT2ADDR(port);
  134. delay();
  135. return (v);
  136. }
  137. unsigned short _inw_p(unsigned long port)
  138. {
  139. unsigned short v;
  140. if (port >= LAN_IOSTART && port < LAN_IOEND)
  141. v = _ne_inw(PORT2ADDR_NE(port));
  142. else
  143. #if defined(CONFIG_USB)
  144. if(port >= 0x340 && port < 0x3a0)
  145. return *(volatile unsigned short *)PORT2ADDR_USB(port);
  146. else
  147. #endif
  148. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  149. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  150. unsigned short w;
  151. pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
  152. return w;
  153. } else
  154. #endif
  155. v = *(volatile unsigned short *)PORT2ADDR(port);
  156. delay();
  157. return (v);
  158. }
  159. unsigned long _inl_p(unsigned long port)
  160. {
  161. unsigned long v;
  162. v = *(volatile unsigned long *)PORT2ADDR(port);
  163. delay();
  164. return (v);
  165. }
  166. void _outb(unsigned char b, unsigned long port)
  167. {
  168. if (port >= LAN_IOSTART && port < LAN_IOEND)
  169. _ne_outb(b, PORT2ADDR_NE(port));
  170. else
  171. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  172. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  173. pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
  174. } else
  175. #endif
  176. *(volatile unsigned char *)PORT2ADDR(port) = b;
  177. }
  178. void _outw(unsigned short w, unsigned long port)
  179. {
  180. if (port >= LAN_IOSTART && port < LAN_IOEND)
  181. _ne_outw(w, PORT2ADDR_NE(port));
  182. else
  183. #if defined(CONFIG_USB)
  184. if(port >= 0x340 && port < 0x3a0)
  185. *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
  186. else
  187. #endif
  188. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  189. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  190. pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
  191. } else
  192. #endif
  193. *(volatile unsigned short *)PORT2ADDR(port) = w;
  194. }
  195. void _outl(unsigned long l, unsigned long port)
  196. {
  197. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  198. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  199. pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
  200. } else
  201. #endif
  202. *(volatile unsigned long *)PORT2ADDR(port) = l;
  203. }
  204. void _outb_p(unsigned char b, unsigned long port)
  205. {
  206. if (port >= LAN_IOSTART && port < LAN_IOEND)
  207. _ne_outb(b, PORT2ADDR_NE(port));
  208. else
  209. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  210. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  211. pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
  212. } else
  213. #endif
  214. *(volatile unsigned char *)PORT2ADDR(port) = b;
  215. delay();
  216. }
  217. void _outw_p(unsigned short w, unsigned long port)
  218. {
  219. if (port >= LAN_IOSTART && port < LAN_IOEND)
  220. _ne_outw(w, PORT2ADDR_NE(port));
  221. else
  222. #if defined(CONFIG_USB)
  223. if(port >= 0x340 && port < 0x3a0)
  224. *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
  225. else
  226. #endif
  227. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  228. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  229. pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
  230. } else
  231. #endif
  232. *(volatile unsigned short *)PORT2ADDR(port) = w;
  233. delay();
  234. }
  235. void _outl_p(unsigned long l, unsigned long port)
  236. {
  237. *(volatile unsigned long *)PORT2ADDR(port) = l;
  238. delay();
  239. }
  240. void _insb(unsigned int port, void *addr, unsigned long count)
  241. {
  242. if (port >= LAN_IOSTART && port < LAN_IOEND)
  243. _ne_insb(PORT2ADDR_NE(port), addr, count);
  244. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  245. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  246. pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
  247. count, 1);
  248. }
  249. #endif
  250. else {
  251. unsigned char *buf = addr;
  252. unsigned char *portp = PORT2ADDR(port);
  253. while (count--)
  254. *buf++ = *(volatile unsigned char *)portp;
  255. }
  256. }
  257. void _insw(unsigned int port, void *addr, unsigned long count)
  258. {
  259. 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 read data
  264. * from the DATA_REG. Do not swap the data.
  265. */
  266. portp = PORT2ADDR_NE(port);
  267. while (count--)
  268. *buf++ = *(volatile unsigned short *)portp;
  269. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  270. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  271. pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
  272. count, 1);
  273. #endif
  274. } else {
  275. portp = PORT2ADDR(port);
  276. while (count--)
  277. *buf++ = *(volatile unsigned short *)portp;
  278. }
  279. }
  280. void _insl(unsigned int port, void *addr, unsigned long count)
  281. {
  282. unsigned long *buf = addr;
  283. unsigned long *portp;
  284. portp = PORT2ADDR(port);
  285. while (count--)
  286. *buf++ = *(volatile unsigned long *)portp;
  287. }
  288. void _outsb(unsigned int port, const void *addr, unsigned long count)
  289. {
  290. const unsigned char *buf = addr;
  291. unsigned char *portp;
  292. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  293. portp = PORT2ADDR_NE(port);
  294. while (count--)
  295. _ne_outb(*buf++, portp);
  296. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  297. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  298. pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
  299. count, 1);
  300. #endif
  301. } else {
  302. portp = PORT2ADDR(port);
  303. while (count--)
  304. *(volatile unsigned char *)portp = *buf++;
  305. }
  306. }
  307. void _outsw(unsigned int port, const void *addr, unsigned long count)
  308. {
  309. const unsigned short *buf = addr;
  310. unsigned short *portp;
  311. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  312. /*
  313. * This portion is only used by smc91111.c to write data
  314. * into the DATA_REG. Do not swap the data.
  315. */
  316. portp = PORT2ADDR_NE(port);
  317. while (count--)
  318. *(volatile unsigned short *)portp = *buf++;
  319. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  320. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  321. pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
  322. count, 1);
  323. #endif
  324. } else {
  325. portp = PORT2ADDR(port);
  326. while (count--)
  327. *(volatile unsigned short *)portp = *buf++;
  328. }
  329. }
  330. void _outsl(unsigned int port, const void *addr, unsigned long count)
  331. {
  332. const unsigned long *buf = addr;
  333. unsigned char *portp;
  334. portp = PORT2ADDR(port);
  335. while (count--)
  336. *(volatile unsigned long *)portp = *buf++;
  337. }