/arch/m32r/kernel/io_mappi2.c

https://bitbucket.org/evzijst/gittest · C · 461 lines · 400 code · 50 blank · 11 comment · 168 complexity · 34533eed0ddc69c63e94fe891c95fd38 MD5 · raw file

  1. /*
  2. * linux/arch/m32r/kernel/io_mappi2.c
  3. *
  4. * Typical I/O routines for Mappi2 board.
  5. *
  6. * Copyright (c) 2001-2003 Hiroyuki Kondo, Hirokazu Takata,
  7. * Hitoshi Yamamoto, Mamoru Sakugawa
  8. */
  9. #include <linux/config.h>
  10. #include <asm/m32r.h>
  11. #include <asm/page.h>
  12. #include <asm/io.h>
  13. #include <asm/byteorder.h>
  14. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  15. #include <linux/types.h>
  16. #define M32R_PCC_IOMAP_SIZE 0x1000
  17. #define M32R_PCC_IOSTART0 0x1000
  18. #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
  19. extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
  20. extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
  21. extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
  22. extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
  23. #endif /* CONFIG_PCMCIA && CONFIG_MAPPI2_CFC */
  24. #define PORT2ADDR(port) _port2addr(port)
  25. #define PORT2ADDR_NE(port) _port2addr_ne(port)
  26. #define PORT2ADDR_USB(port) _port2addr_usb(port)
  27. static inline void *_port2addr(unsigned long port)
  28. {
  29. return (void *)(port + NONCACHE_OFFSET);
  30. }
  31. #define LAN_IOSTART 0x300
  32. #define LAN_IOEND 0x320
  33. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  34. static inline void *__port2addr_ata(unsigned long port)
  35. {
  36. static int dummy_reg;
  37. switch (port) {
  38. case 0x1f0: return (void *)0xac002000;
  39. case 0x1f1: return (void *)0xac012800;
  40. case 0x1f2: return (void *)0xac012002;
  41. case 0x1f3: return (void *)0xac012802;
  42. case 0x1f4: return (void *)0xac012004;
  43. case 0x1f5: return (void *)0xac012804;
  44. case 0x1f6: return (void *)0xac012006;
  45. case 0x1f7: return (void *)0xac012806;
  46. case 0x3f6: return (void *)0xac01200e;
  47. default: return (void *)&dummy_reg;
  48. }
  49. }
  50. #endif
  51. #ifdef CONFIG_CHIP_OPSP
  52. static inline void *_port2addr_ne(unsigned long port)
  53. {
  54. return (void *)(port + NONCACHE_OFFSET + 0x10000000);
  55. }
  56. #else
  57. static inline void *_port2addr_ne(unsigned long port)
  58. {
  59. return (void *)(port + NONCACHE_OFFSET + 0x04000000);
  60. }
  61. #endif
  62. static inline void *_port2addr_usb(unsigned long port)
  63. {
  64. return (void *)(port + NONCACHE_OFFSET + 0x14000000);
  65. }
  66. static inline void delay(void)
  67. {
  68. __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
  69. }
  70. /*
  71. * NIC I/O function
  72. */
  73. static inline unsigned char _ne_inb(void *portp)
  74. {
  75. return (unsigned char) *(volatile unsigned char *)portp;
  76. }
  77. static inline unsigned short _ne_inw(void *portp)
  78. {
  79. return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
  80. }
  81. static inline void _ne_insb(void *portp, void * addr, unsigned long count)
  82. {
  83. unsigned char *buf = addr;
  84. while (count--)
  85. *buf++ = *(volatile unsigned char *)portp;
  86. }
  87. static inline void _ne_outb(unsigned char b, void *portp)
  88. {
  89. *(volatile unsigned char *)portp = (unsigned char)b;
  90. }
  91. static inline void _ne_outw(unsigned short w, void *portp)
  92. {
  93. *(volatile unsigned short *)portp = cpu_to_le16(w);
  94. }
  95. unsigned char _inb(unsigned long port)
  96. {
  97. if (port >= LAN_IOSTART && port < LAN_IOEND)
  98. return _ne_inb(PORT2ADDR_NE(port));
  99. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  100. else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  101. return *(volatile unsigned char *)__port2addr_ata(port);
  102. }
  103. #endif
  104. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  105. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  106. unsigned char b;
  107. pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
  108. return b;
  109. } else
  110. #endif
  111. return *(volatile unsigned char *)PORT2ADDR(port);
  112. }
  113. unsigned short _inw(unsigned long port)
  114. {
  115. if (port >= LAN_IOSTART && port < LAN_IOEND)
  116. return _ne_inw(PORT2ADDR_NE(port));
  117. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  118. else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  119. return *(volatile unsigned short *)__port2addr_ata(port);
  120. }
  121. #endif
  122. #if defined(CONFIG_USB)
  123. else if (port >= 0x340 && port < 0x3a0)
  124. return *(volatile unsigned short *)PORT2ADDR_USB(port);
  125. #endif
  126. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  127. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  128. unsigned short w;
  129. pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
  130. return w;
  131. } else
  132. #endif
  133. return *(volatile unsigned short *)PORT2ADDR(port);
  134. }
  135. unsigned long _inl(unsigned long port)
  136. {
  137. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  138. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  139. unsigned long l;
  140. pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
  141. return l;
  142. } else
  143. #endif
  144. return *(volatile unsigned long *)PORT2ADDR(port);
  145. }
  146. unsigned char _inb_p(unsigned long port)
  147. {
  148. unsigned char v;
  149. if (port >= LAN_IOSTART && port < LAN_IOEND)
  150. v = _ne_inb(PORT2ADDR_NE(port));
  151. else
  152. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  153. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  154. return *(volatile unsigned char *)__port2addr_ata(port);
  155. } else
  156. #endif
  157. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  158. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  159. unsigned char b;
  160. pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
  161. return b;
  162. } else
  163. #endif
  164. v = *(volatile unsigned char *)PORT2ADDR(port);
  165. delay();
  166. return (v);
  167. }
  168. unsigned short _inw_p(unsigned long port)
  169. {
  170. unsigned short v;
  171. if (port >= LAN_IOSTART && port < LAN_IOEND)
  172. v = _ne_inw(PORT2ADDR_NE(port));
  173. else
  174. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  175. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  176. return *(volatile unsigned short *)__port2addr_ata(port);
  177. } else
  178. #endif
  179. #if defined(CONFIG_USB)
  180. if (port >= 0x340 && port < 0x3a0)
  181. v = *(volatile unsigned short *)PORT2ADDR_USB(port);
  182. else
  183. #endif
  184. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  185. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  186. unsigned short w;
  187. pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
  188. return w;
  189. } else
  190. #endif
  191. v = *(volatile unsigned short *)PORT2ADDR(port);
  192. delay();
  193. return (v);
  194. }
  195. unsigned long _inl_p(unsigned long port)
  196. {
  197. unsigned long v;
  198. v = *(volatile unsigned long *)PORT2ADDR(port);
  199. delay();
  200. return (v);
  201. }
  202. void _outb(unsigned char b, unsigned long port)
  203. {
  204. if (port >= LAN_IOSTART && port < LAN_IOEND)
  205. _ne_outb(b, PORT2ADDR_NE(port));
  206. else
  207. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  208. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  209. *(volatile unsigned char *)__port2addr_ata(port) = b;
  210. } else
  211. #endif
  212. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  213. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  214. pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
  215. } else
  216. #endif
  217. *(volatile unsigned char *)PORT2ADDR(port) = b;
  218. }
  219. void _outw(unsigned short w, unsigned long port)
  220. {
  221. if (port >= LAN_IOSTART && port < LAN_IOEND)
  222. _ne_outw(w, PORT2ADDR_NE(port));
  223. else
  224. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  225. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  226. *(volatile unsigned short *)__port2addr_ata(port) = w;
  227. } else
  228. #endif
  229. #if defined(CONFIG_USB)
  230. if (port >= 0x340 && port < 0x3a0)
  231. *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
  232. else
  233. #endif
  234. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  235. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  236. pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
  237. } else
  238. #endif
  239. *(volatile unsigned short *)PORT2ADDR(port) = w;
  240. }
  241. void _outl(unsigned long l, unsigned long port)
  242. {
  243. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  244. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  245. pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
  246. } else
  247. #endif
  248. *(volatile unsigned long *)PORT2ADDR(port) = l;
  249. }
  250. void _outb_p(unsigned char b, unsigned long port)
  251. {
  252. if (port >= LAN_IOSTART && port < LAN_IOEND)
  253. _ne_outb(b, PORT2ADDR_NE(port));
  254. else
  255. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  256. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  257. *(volatile unsigned char *)__port2addr_ata(port) = b;
  258. } else
  259. #endif
  260. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  261. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  262. pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
  263. } else
  264. #endif
  265. *(volatile unsigned char *)PORT2ADDR(port) = b;
  266. delay();
  267. }
  268. void _outw_p(unsigned short w, unsigned long port)
  269. {
  270. if (port >= LAN_IOSTART && port < LAN_IOEND)
  271. _ne_outw(w, PORT2ADDR_NE(port));
  272. else
  273. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  274. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  275. *(volatile unsigned short *)__port2addr_ata(port) = w;
  276. } else
  277. #endif
  278. #if defined(CONFIG_USB)
  279. if (port >= 0x340 && port < 0x3a0)
  280. *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
  281. else
  282. #endif
  283. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  284. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  285. pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
  286. } else
  287. #endif
  288. *(volatile unsigned short *)PORT2ADDR(port) = w;
  289. delay();
  290. }
  291. void _outl_p(unsigned long l, unsigned long port)
  292. {
  293. *(volatile unsigned long *)PORT2ADDR(port) = l;
  294. delay();
  295. }
  296. void _insb(unsigned int port, void * addr, unsigned long count)
  297. {
  298. if (port >= LAN_IOSTART && port < LAN_IOEND)
  299. _ne_insb(PORT2ADDR_NE(port), addr, count);
  300. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  301. else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  302. unsigned char *buf = addr;
  303. unsigned char *portp = __port2addr_ata(port);
  304. while (count--)
  305. *buf++ = *(volatile unsigned char *)portp;
  306. }
  307. #endif
  308. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  309. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  310. pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
  311. count, 1);
  312. }
  313. #endif
  314. else {
  315. unsigned char *buf = addr;
  316. unsigned char *portp = PORT2ADDR(port);
  317. while (count--)
  318. *buf++ = *(volatile unsigned char *)portp;
  319. }
  320. }
  321. void _insw(unsigned int port, void * addr, unsigned long count)
  322. {
  323. unsigned short *buf = addr;
  324. unsigned short *portp;
  325. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  326. portp = PORT2ADDR_NE(port);
  327. while (count--)
  328. *buf++ = *(volatile unsigned short *)portp;
  329. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  330. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  331. pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
  332. count, 1);
  333. #endif
  334. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  335. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  336. portp = __port2addr_ata(port);
  337. while (count--)
  338. *buf++ = *(volatile unsigned short *)portp;
  339. #endif
  340. } else {
  341. portp = PORT2ADDR(port);
  342. while (count--)
  343. *buf++ = *(volatile unsigned short *)portp;
  344. }
  345. }
  346. void _insl(unsigned int port, void * addr, unsigned long count)
  347. {
  348. unsigned long *buf = addr;
  349. unsigned long *portp;
  350. portp = PORT2ADDR(port);
  351. while (count--)
  352. *buf++ = *(volatile unsigned long *)portp;
  353. }
  354. void _outsb(unsigned int port, const void * addr, unsigned long count)
  355. {
  356. const unsigned char *buf = addr;
  357. unsigned char *portp;
  358. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  359. portp = PORT2ADDR_NE(port);
  360. while (count--)
  361. _ne_outb(*buf++, portp);
  362. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  363. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  364. portp = __port2addr_ata(port);
  365. while (count--)
  366. *(volatile unsigned char *)portp = *buf++;
  367. #endif
  368. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  369. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  370. pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
  371. count, 1);
  372. #endif
  373. } else {
  374. portp = PORT2ADDR(port);
  375. while (count--)
  376. *(volatile unsigned char *)portp = *buf++;
  377. }
  378. }
  379. void _outsw(unsigned int port, const void * addr, unsigned long count)
  380. {
  381. const unsigned short *buf = addr;
  382. unsigned short *portp;
  383. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  384. portp = PORT2ADDR_NE(port);
  385. while (count--)
  386. *(volatile unsigned short *)portp = *buf++;
  387. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  388. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  389. portp = __port2addr_ata(port);
  390. while (count--)
  391. *(volatile unsigned short *)portp = *buf++;
  392. #endif
  393. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  394. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  395. pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
  396. count, 1);
  397. #endif
  398. } else {
  399. portp = PORT2ADDR(port);
  400. while (count--)
  401. *(volatile unsigned short *)portp = *buf++;
  402. }
  403. }
  404. void _outsl(unsigned int port, const void * addr, unsigned long count)
  405. {
  406. const unsigned long *buf = addr;
  407. unsigned char *portp;
  408. portp = PORT2ADDR(port);
  409. while (count--)
  410. *(volatile unsigned long *)portp = *buf++;
  411. }