io_mappi3.c 11 KB

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