io_m32700ut.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*
  2. * linux/arch/m32r/kernel/io_m32700ut.c
  3. *
  4. * Typical I/O routines for M32700UT 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. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  35. static inline void *__port2addr_ata(unsigned long port)
  36. {
  37. static int dummy_reg;
  38. switch (port) {
  39. case 0x1f0: return (void *)0xac002000;
  40. case 0x1f1: return (void *)0xac012800;
  41. case 0x1f2: return (void *)0xac012002;
  42. case 0x1f3: return (void *)0xac012802;
  43. case 0x1f4: return (void *)0xac012004;
  44. case 0x1f5: return (void *)0xac012804;
  45. case 0x1f6: return (void *)0xac012006;
  46. case 0x1f7: return (void *)0xac012806;
  47. case 0x3f6: return (void *)0xac01200e;
  48. default: return (void *)&dummy_reg;
  49. }
  50. }
  51. #endif
  52. /*
  53. * M32700UT-LAN is located in the extended bus space
  54. * from 0x10000000 to 0x13ffffff on physical address.
  55. * The base address of LAN controller(LAN91C111) is 0x300.
  56. */
  57. #define LAN_IOSTART 0x300
  58. #define LAN_IOEND 0x320
  59. static inline void *_port2addr_ne(unsigned long port)
  60. {
  61. return (void *)(port + NONCACHE_OFFSET + 0x10000000);
  62. }
  63. static inline void *_port2addr_usb(unsigned long port)
  64. {
  65. return (void *)((port & 0x0f) + NONCACHE_OFFSET + 0x10303000);
  66. }
  67. static inline void delay(void)
  68. {
  69. __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
  70. }
  71. /*
  72. * NIC I/O function
  73. */
  74. #define PORT2ADDR_NE(port) _port2addr_ne(port)
  75. static inline unsigned char _ne_inb(void *portp)
  76. {
  77. return *(volatile unsigned char *)portp;
  78. }
  79. static inline unsigned short _ne_inw(void *portp)
  80. {
  81. return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
  82. }
  83. static inline void _ne_insb(void *portp, void *addr, unsigned long count)
  84. {
  85. unsigned char *buf = (unsigned char *)addr;
  86. while (count--)
  87. *buf++ = _ne_inb(portp);
  88. }
  89. static inline void _ne_outb(unsigned char b, void *portp)
  90. {
  91. *(volatile unsigned char *)portp = b;
  92. }
  93. static inline void _ne_outw(unsigned short w, void *portp)
  94. {
  95. *(volatile unsigned short *)portp = cpu_to_le16(w);
  96. }
  97. unsigned char _inb(unsigned long port)
  98. {
  99. if (port >= LAN_IOSTART && port < LAN_IOEND)
  100. return _ne_inb(PORT2ADDR_NE(port));
  101. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  102. else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  103. return *(volatile unsigned char *)__port2addr_ata(port);
  104. }
  105. #endif
  106. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  107. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  108. unsigned char b;
  109. pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
  110. return b;
  111. } else
  112. #endif
  113. return *(volatile unsigned char *)PORT2ADDR(port);
  114. }
  115. unsigned short _inw(unsigned long port)
  116. {
  117. if (port >= LAN_IOSTART && port < LAN_IOEND)
  118. return _ne_inw(PORT2ADDR_NE(port));
  119. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  120. else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  121. return *(volatile unsigned short *)__port2addr_ata(port);
  122. }
  123. #endif
  124. #if defined(CONFIG_USB)
  125. else if(port >= 0x340 && port < 0x3a0)
  126. return *(volatile unsigned short *)PORT2ADDR_USB(port);
  127. #endif
  128. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  129. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  130. unsigned short w;
  131. pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
  132. return w;
  133. } else
  134. #endif
  135. return *(volatile unsigned short *)PORT2ADDR(port);
  136. }
  137. unsigned long _inl(unsigned long port)
  138. {
  139. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  140. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  141. unsigned long l;
  142. pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
  143. return l;
  144. } else
  145. #endif
  146. return *(volatile unsigned long *)PORT2ADDR(port);
  147. }
  148. unsigned char _inb_p(unsigned long port)
  149. {
  150. unsigned char v = _inb(port);
  151. delay();
  152. return (v);
  153. }
  154. unsigned short _inw_p(unsigned long port)
  155. {
  156. unsigned short v = _inw(port);
  157. delay();
  158. return (v);
  159. }
  160. unsigned long _inl_p(unsigned long port)
  161. {
  162. unsigned long v = _inl(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_IDE) && !defined(CONFIG_M32R_CFC)
  172. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  173. *(volatile unsigned char *)__port2addr_ata(port) = b;
  174. } else
  175. #endif
  176. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  177. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  178. pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
  179. } else
  180. #endif
  181. *(volatile unsigned char *)PORT2ADDR(port) = b;
  182. }
  183. void _outw(unsigned short w, unsigned long port)
  184. {
  185. if (port >= LAN_IOSTART && port < LAN_IOEND)
  186. _ne_outw(w, PORT2ADDR_NE(port));
  187. else
  188. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  189. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  190. *(volatile unsigned short *)__port2addr_ata(port) = w;
  191. } else
  192. #endif
  193. #if defined(CONFIG_USB)
  194. if(port >= 0x340 && port < 0x3a0)
  195. *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
  196. else
  197. #endif
  198. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  199. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  200. pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
  201. } else
  202. #endif
  203. *(volatile unsigned short *)PORT2ADDR(port) = w;
  204. }
  205. void _outl(unsigned long l, unsigned long port)
  206. {
  207. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  208. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  209. pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
  210. } else
  211. #endif
  212. *(volatile unsigned long *)PORT2ADDR(port) = l;
  213. }
  214. void _outb_p(unsigned char b, unsigned long port)
  215. {
  216. _outb(b, port);
  217. delay();
  218. }
  219. void _outw_p(unsigned short w, unsigned long port)
  220. {
  221. _outw(w, port);
  222. delay();
  223. }
  224. void _outl_p(unsigned long l, unsigned long port)
  225. {
  226. _outl(l, port);
  227. delay();
  228. }
  229. void _insb(unsigned int port, void *addr, unsigned long count)
  230. {
  231. if (port >= LAN_IOSTART && port < LAN_IOEND)
  232. _ne_insb(PORT2ADDR_NE(port), addr, count);
  233. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  234. else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  235. unsigned char *buf = addr;
  236. unsigned char *portp = __port2addr_ata(port);
  237. while (count--)
  238. *buf++ = *(volatile unsigned char *)portp;
  239. }
  240. #endif
  241. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  242. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  243. pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
  244. count, 1);
  245. }
  246. #endif
  247. else {
  248. unsigned char *buf = addr;
  249. unsigned char *portp = PORT2ADDR(port);
  250. while (count--)
  251. *buf++ = *(volatile unsigned char *)portp;
  252. }
  253. }
  254. void _insw(unsigned int port, void *addr, unsigned long count)
  255. {
  256. unsigned short *buf = addr;
  257. unsigned short *portp;
  258. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  259. /*
  260. * This portion is only used by smc91111.c to read data
  261. * from the DATA_REG. Do not swap the data.
  262. */
  263. portp = PORT2ADDR_NE(port);
  264. while (count--)
  265. *buf++ = *(volatile unsigned short *)portp;
  266. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  267. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  268. pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
  269. count, 1);
  270. #endif
  271. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  272. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  273. portp = __port2addr_ata(port);
  274. while (count--)
  275. *buf++ = *(volatile unsigned short *)portp;
  276. #endif
  277. } else {
  278. portp = PORT2ADDR(port);
  279. while (count--)
  280. *buf++ = *(volatile unsigned short *)portp;
  281. }
  282. }
  283. void _insl(unsigned int port, void *addr, unsigned long count)
  284. {
  285. unsigned long *buf = addr;
  286. unsigned long *portp;
  287. portp = PORT2ADDR(port);
  288. while (count--)
  289. *buf++ = *(volatile unsigned long *)portp;
  290. }
  291. void _outsb(unsigned int port, const void *addr, unsigned long count)
  292. {
  293. const unsigned char *buf = addr;
  294. unsigned char *portp;
  295. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  296. portp = PORT2ADDR_NE(port);
  297. while (count--)
  298. _ne_outb(*buf++, portp);
  299. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  300. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  301. portp = __port2addr_ata(port);
  302. while (count--)
  303. *(volatile unsigned char *)portp = *buf++;
  304. #endif
  305. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  306. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  307. pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
  308. count, 1);
  309. #endif
  310. } else {
  311. portp = PORT2ADDR(port);
  312. while (count--)
  313. *(volatile unsigned char *)portp = *buf++;
  314. }
  315. }
  316. void _outsw(unsigned int port, const void *addr, unsigned long count)
  317. {
  318. const unsigned short *buf = addr;
  319. unsigned short *portp;
  320. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  321. /*
  322. * This portion is only used by smc91111.c to write data
  323. * into the DATA_REG. Do not swap the data.
  324. */
  325. portp = PORT2ADDR_NE(port);
  326. while (count--)
  327. *(volatile unsigned short *)portp = *buf++;
  328. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  329. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  330. portp = __port2addr_ata(port);
  331. while (count--)
  332. *(volatile unsigned short *)portp = *buf++;
  333. #endif
  334. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  335. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  336. pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
  337. count, 1);
  338. #endif
  339. } else {
  340. portp = PORT2ADDR(port);
  341. while (count--)
  342. *(volatile unsigned short *)portp = *buf++;
  343. }
  344. }
  345. void _outsl(unsigned int port, const void *addr, unsigned long count)
  346. {
  347. const unsigned long *buf = addr;
  348. unsigned char *portp;
  349. portp = PORT2ADDR(port);
  350. while (count--)
  351. *(volatile unsigned long *)portp = *buf++;
  352. }