io_mappi3.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. /*
  2. * linux/arch/m32r/kernel/io_mappi3.c
  3. *
  4. * Typical I/O routines for Mappi3 board.
  5. *
  6. * Copyright (c) 2001-2005 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_M32R_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. #if defined(CONFIG_IDE)
  32. static inline void *__port2addr_ata(unsigned long port)
  33. {
  34. static int dummy_reg;
  35. switch (port) {
  36. /* IDE0 CF */
  37. case 0x1f0: return (void *)0xb4002000;
  38. case 0x1f1: return (void *)0xb4012800;
  39. case 0x1f2: return (void *)0xb4012002;
  40. case 0x1f3: return (void *)0xb4012802;
  41. case 0x1f4: return (void *)0xb4012004;
  42. case 0x1f5: return (void *)0xb4012804;
  43. case 0x1f6: return (void *)0xb4012006;
  44. case 0x1f7: return (void *)0xb4012806;
  45. case 0x3f6: return (void *)0xb401200e;
  46. /* IDE1 IDE */
  47. case 0x170: return (void *)0xb4810000; /* Data 16bit */
  48. case 0x171: return (void *)0xb4810002; /* Features / Error */
  49. case 0x172: return (void *)0xb4810004; /* Sector count */
  50. case 0x173: return (void *)0xb4810006; /* Sector number */
  51. case 0x174: return (void *)0xb4810008; /* Cylinder low */
  52. case 0x175: return (void *)0xb481000a; /* Cylinder high */
  53. case 0x176: return (void *)0xb481000c; /* Device head */
  54. case 0x177: return (void *)0xb481000e; /* Command */
  55. case 0x376: return (void *)0xb480800c; /* Device control / Alt status */
  56. default: return (void *)&dummy_reg;
  57. }
  58. }
  59. #endif
  60. #define LAN_IOSTART 0xa0000300
  61. #define LAN_IOEND 0xa0000320
  62. static inline void *_port2addr_ne(unsigned long port)
  63. {
  64. return (void *)(port + 0x10000000);
  65. }
  66. static inline void *_port2addr_usb(unsigned long port)
  67. {
  68. return (void *)(port + NONCACHE_OFFSET + 0x12000000);
  69. }
  70. static inline void delay(void)
  71. {
  72. __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
  73. }
  74. /*
  75. * NIC I/O function
  76. */
  77. static inline unsigned char _ne_inb(void *portp)
  78. {
  79. return (unsigned char) *(volatile unsigned char *)portp;
  80. }
  81. static inline unsigned short _ne_inw(void *portp)
  82. {
  83. return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
  84. }
  85. static inline void _ne_insb(void *portp, void * addr, unsigned long count)
  86. {
  87. unsigned char *buf = addr;
  88. while (count--)
  89. *buf++ = *(volatile unsigned char *)portp;
  90. }
  91. static inline void _ne_outb(unsigned char b, void *portp)
  92. {
  93. *(volatile unsigned char *)portp = (unsigned char)b;
  94. }
  95. static inline void _ne_outw(unsigned short w, void *portp)
  96. {
  97. *(volatile unsigned short *)portp = cpu_to_le16(w);
  98. }
  99. unsigned char _inb(unsigned long port)
  100. {
  101. if (port >= LAN_IOSTART && port < LAN_IOEND)
  102. return _ne_inb(PORT2ADDR_NE(port));
  103. #if defined(CONFIG_IDE)
  104. else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
  105. ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
  106. return *(volatile unsigned char *)__port2addr_ata(port);
  107. }
  108. #endif
  109. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  110. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  111. unsigned char b;
  112. pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
  113. return b;
  114. } else
  115. #endif
  116. return *(volatile unsigned char *)PORT2ADDR(port);
  117. }
  118. unsigned short _inw(unsigned long port)
  119. {
  120. if (port >= LAN_IOSTART && port < LAN_IOEND)
  121. return _ne_inw(PORT2ADDR_NE(port));
  122. #if defined(CONFIG_IDE)
  123. else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
  124. ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
  125. return *(volatile unsigned short *)__port2addr_ata(port);
  126. }
  127. #endif
  128. #if defined(CONFIG_USB)
  129. else if (port >= 0x340 && port < 0x3a0)
  130. return *(volatile unsigned short *)PORT2ADDR_USB(port);
  131. #endif
  132. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  133. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  134. unsigned short w;
  135. pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
  136. return w;
  137. } else
  138. #endif
  139. return *(volatile unsigned short *)PORT2ADDR(port);
  140. }
  141. unsigned long _inl(unsigned long port)
  142. {
  143. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  144. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  145. unsigned long l;
  146. pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
  147. return l;
  148. } else
  149. #endif
  150. return *(volatile unsigned long *)PORT2ADDR(port);
  151. }
  152. unsigned char _inb_p(unsigned long port)
  153. {
  154. unsigned char v = _inb(port);
  155. delay();
  156. return (v);
  157. }
  158. unsigned short _inw_p(unsigned long port)
  159. {
  160. unsigned short v = _inw(port);
  161. delay();
  162. return (v);
  163. }
  164. unsigned long _inl_p(unsigned long port)
  165. {
  166. unsigned long v = _inl(port);
  167. delay();
  168. return (v);
  169. }
  170. void _outb(unsigned char b, unsigned long port)
  171. {
  172. if (port >= LAN_IOSTART && port < LAN_IOEND)
  173. _ne_outb(b, PORT2ADDR_NE(port));
  174. else
  175. #if defined(CONFIG_IDE)
  176. if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
  177. ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
  178. *(volatile unsigned char *)__port2addr_ata(port) = b;
  179. } else
  180. #endif
  181. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  182. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  183. pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
  184. } else
  185. #endif
  186. *(volatile unsigned char *)PORT2ADDR(port) = b;
  187. }
  188. void _outw(unsigned short w, unsigned long port)
  189. {
  190. if (port >= LAN_IOSTART && port < LAN_IOEND)
  191. _ne_outw(w, PORT2ADDR_NE(port));
  192. else
  193. #if defined(CONFIG_IDE)
  194. if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
  195. ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
  196. *(volatile unsigned short *)__port2addr_ata(port) = w;
  197. } else
  198. #endif
  199. #if defined(CONFIG_USB)
  200. if (port >= 0x340 && port < 0x3a0)
  201. *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
  202. else
  203. #endif
  204. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  205. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  206. pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
  207. } else
  208. #endif
  209. *(volatile unsigned short *)PORT2ADDR(port) = w;
  210. }
  211. void _outl(unsigned long l, unsigned long port)
  212. {
  213. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  214. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  215. pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
  216. } else
  217. #endif
  218. *(volatile unsigned long *)PORT2ADDR(port) = l;
  219. }
  220. void _outb_p(unsigned char b, unsigned long port)
  221. {
  222. _outb(b, port);
  223. delay();
  224. }
  225. void _outw_p(unsigned short w, unsigned long port)
  226. {
  227. _outw(w, port);
  228. delay();
  229. }
  230. void _outl_p(unsigned long l, unsigned long port)
  231. {
  232. _outl(l, port);
  233. delay();
  234. }
  235. void _insb(unsigned int port, void * addr, unsigned long count)
  236. {
  237. if (port >= LAN_IOSTART && port < LAN_IOEND)
  238. _ne_insb(PORT2ADDR_NE(port), addr, count);
  239. #if defined(CONFIG_IDE)
  240. else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
  241. ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
  242. unsigned char *buf = addr;
  243. unsigned char *portp = __port2addr_ata(port);
  244. while (count--)
  245. *buf++ = *(volatile unsigned char *)portp;
  246. }
  247. #endif
  248. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  249. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  250. pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
  251. count, 1);
  252. }
  253. #endif
  254. else {
  255. unsigned char *buf = addr;
  256. unsigned char *portp = PORT2ADDR(port);
  257. while (count--)
  258. *buf++ = *(volatile unsigned char *)portp;
  259. }
  260. }
  261. void _insw(unsigned int port, void * addr, unsigned long count)
  262. {
  263. unsigned short *buf = addr;
  264. unsigned short *portp;
  265. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  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. #if defined(CONFIG_IDE)
  275. } else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
  276. ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
  277. portp = __port2addr_ata(port);
  278. while (count--)
  279. *buf++ = *(volatile unsigned short *)portp;
  280. #endif
  281. } else {
  282. portp = PORT2ADDR(port);
  283. while (count--)
  284. *buf++ = *(volatile unsigned short *)portp;
  285. }
  286. }
  287. void _insl(unsigned int port, void * addr, unsigned long count)
  288. {
  289. unsigned long *buf = addr;
  290. unsigned long *portp;
  291. portp = PORT2ADDR(port);
  292. while (count--)
  293. *buf++ = *(volatile unsigned long *)portp;
  294. }
  295. void _outsb(unsigned int port, const void * addr, unsigned long count)
  296. {
  297. const unsigned char *buf = addr;
  298. unsigned char *portp;
  299. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  300. portp = PORT2ADDR_NE(port);
  301. while (count--)
  302. _ne_outb(*buf++, portp);
  303. #if defined(CONFIG_IDE)
  304. } else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
  305. ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
  306. portp = __port2addr_ata(port);
  307. while (count--)
  308. *(volatile unsigned char *)portp = *buf++;
  309. #endif
  310. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  311. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  312. pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
  313. count, 1);
  314. #endif
  315. } else {
  316. portp = PORT2ADDR(port);
  317. while (count--)
  318. *(volatile unsigned char *)portp = *buf++;
  319. }
  320. }
  321. void _outsw(unsigned int port, const void * addr, unsigned long count)
  322. {
  323. const 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. *(volatile unsigned short *)portp = *buf++;
  329. #if defined(CONFIG_IDE)
  330. } else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
  331. ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
  332. portp = __port2addr_ata(port);
  333. while (count--)
  334. *(volatile unsigned short *)portp = *buf++;
  335. #endif
  336. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  337. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  338. pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
  339. count, 1);
  340. #endif
  341. } else {
  342. portp = PORT2ADDR(port);
  343. while (count--)
  344. *(volatile unsigned short *)portp = *buf++;
  345. }
  346. }
  347. void _outsl(unsigned int port, const void * addr, unsigned long count)
  348. {
  349. const unsigned long *buf = addr;
  350. unsigned char *portp;
  351. portp = PORT2ADDR(port);
  352. while (count--)
  353. *(volatile unsigned long *)portp = *buf++;
  354. }