io_m32700ut.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /*
  2. * linux/arch/m32r/kernel/io_m32700ut.c
  3. *
  4. * Typical I/O routines for M32700UT 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. #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;
  151. if (port >= LAN_IOSTART && port < LAN_IOEND)
  152. v = _ne_inb(PORT2ADDR_NE(port));
  153. else
  154. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  155. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  156. return *(volatile unsigned char *)__port2addr_ata(port);
  157. } else
  158. #endif
  159. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  160. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  161. unsigned char b;
  162. pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
  163. return b;
  164. } else
  165. #endif
  166. v = *(volatile unsigned char *)PORT2ADDR(port);
  167. delay();
  168. return (v);
  169. }
  170. unsigned short _inw_p(unsigned long port)
  171. {
  172. unsigned short v;
  173. if (port >= LAN_IOSTART && port < LAN_IOEND)
  174. v = _ne_inw(PORT2ADDR_NE(port));
  175. else
  176. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  177. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  178. return *(volatile unsigned short *)__port2addr_ata(port);
  179. } else
  180. #endif
  181. #if defined(CONFIG_USB)
  182. if(port >= 0x340 && port < 0x3a0)
  183. return *(volatile unsigned short *)PORT2ADDR_USB(port);
  184. else
  185. #endif
  186. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  187. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  188. unsigned short w;
  189. pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
  190. return w;
  191. } else
  192. #endif
  193. v = *(volatile unsigned short *)PORT2ADDR(port);
  194. delay();
  195. return (v);
  196. }
  197. unsigned long _inl_p(unsigned long port)
  198. {
  199. unsigned long v;
  200. v = *(volatile unsigned long *)PORT2ADDR(port);
  201. delay();
  202. return (v);
  203. }
  204. void _outb(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_IDE) && !defined(CONFIG_M32R_CFC)
  210. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  211. *(volatile unsigned char *)__port2addr_ata(port) = b;
  212. } else
  213. #endif
  214. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  215. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  216. pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
  217. } else
  218. #endif
  219. *(volatile unsigned char *)PORT2ADDR(port) = b;
  220. }
  221. void _outw(unsigned short w, unsigned long port)
  222. {
  223. if (port >= LAN_IOSTART && port < LAN_IOEND)
  224. _ne_outw(w, PORT2ADDR_NE(port));
  225. else
  226. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  227. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  228. *(volatile unsigned short *)__port2addr_ata(port) = w;
  229. } else
  230. #endif
  231. #if defined(CONFIG_USB)
  232. if(port >= 0x340 && port < 0x3a0)
  233. *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
  234. else
  235. #endif
  236. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  237. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  238. pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
  239. } else
  240. #endif
  241. *(volatile unsigned short *)PORT2ADDR(port) = w;
  242. }
  243. void _outl(unsigned long l, unsigned long port)
  244. {
  245. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  246. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  247. pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
  248. } else
  249. #endif
  250. *(volatile unsigned long *)PORT2ADDR(port) = l;
  251. }
  252. void _outb_p(unsigned char b, unsigned long port)
  253. {
  254. if (port >= LAN_IOSTART && port < LAN_IOEND)
  255. _ne_outb(b, PORT2ADDR_NE(port));
  256. else
  257. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  258. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  259. *(volatile unsigned char *)__port2addr_ata(port) = b;
  260. } else
  261. #endif
  262. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  263. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  264. pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
  265. } else
  266. #endif
  267. *(volatile unsigned char *)PORT2ADDR(port) = b;
  268. delay();
  269. }
  270. void _outw_p(unsigned short w, unsigned long port)
  271. {
  272. if (port >= LAN_IOSTART && port < LAN_IOEND)
  273. _ne_outw(w, PORT2ADDR_NE(port));
  274. else
  275. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  276. if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  277. *(volatile unsigned short *)__port2addr_ata(port) = w;
  278. } else
  279. #endif
  280. #if defined(CONFIG_USB)
  281. if(port >= 0x340 && port < 0x3a0)
  282. *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
  283. else
  284. #endif
  285. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  286. if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  287. pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
  288. } else
  289. #endif
  290. *(volatile unsigned short *)PORT2ADDR(port) = w;
  291. delay();
  292. }
  293. void _outl_p(unsigned long l, unsigned long port)
  294. {
  295. *(volatile unsigned long *)PORT2ADDR(port) = l;
  296. delay();
  297. }
  298. void _insb(unsigned int port, void *addr, unsigned long count)
  299. {
  300. if (port >= LAN_IOSTART && port < LAN_IOEND)
  301. _ne_insb(PORT2ADDR_NE(port), addr, count);
  302. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  303. else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  304. unsigned char *buf = addr;
  305. unsigned char *portp = __port2addr_ata(port);
  306. while (count--)
  307. *buf++ = *(volatile unsigned char *)portp;
  308. }
  309. #endif
  310. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  311. else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  312. pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
  313. count, 1);
  314. }
  315. #endif
  316. else {
  317. unsigned char *buf = addr;
  318. unsigned char *portp = PORT2ADDR(port);
  319. while (count--)
  320. *buf++ = *(volatile unsigned char *)portp;
  321. }
  322. }
  323. void _insw(unsigned int port, void *addr, unsigned long count)
  324. {
  325. unsigned short *buf = addr;
  326. unsigned short *portp;
  327. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  328. /*
  329. * This portion is only used by smc91111.c to read data
  330. * from the DATA_REG. Do not swap the data.
  331. */
  332. portp = PORT2ADDR_NE(port);
  333. while (count--)
  334. *buf++ = *(volatile unsigned short *)portp;
  335. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  336. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  337. pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
  338. count, 1);
  339. #endif
  340. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  341. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  342. portp = __port2addr_ata(port);
  343. while (count--)
  344. *buf++ = *(volatile unsigned short *)portp;
  345. #endif
  346. } else {
  347. portp = PORT2ADDR(port);
  348. while (count--)
  349. *buf++ = *(volatile unsigned short *)portp;
  350. }
  351. }
  352. void _insl(unsigned int port, void *addr, unsigned long count)
  353. {
  354. unsigned long *buf = addr;
  355. unsigned long *portp;
  356. portp = PORT2ADDR(port);
  357. while (count--)
  358. *buf++ = *(volatile unsigned long *)portp;
  359. }
  360. void _outsb(unsigned int port, const void *addr, unsigned long count)
  361. {
  362. const unsigned char *buf = addr;
  363. unsigned char *portp;
  364. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  365. portp = PORT2ADDR_NE(port);
  366. while (count--)
  367. _ne_outb(*buf++, portp);
  368. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  369. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  370. portp = __port2addr_ata(port);
  371. while (count--)
  372. *(volatile unsigned char *)portp = *buf++;
  373. #endif
  374. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  375. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  376. pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
  377. count, 1);
  378. #endif
  379. } else {
  380. portp = PORT2ADDR(port);
  381. while (count--)
  382. *(volatile unsigned char *)portp = *buf++;
  383. }
  384. }
  385. void _outsw(unsigned int port, const void *addr, unsigned long count)
  386. {
  387. const unsigned short *buf = addr;
  388. unsigned short *portp;
  389. if (port >= LAN_IOSTART && port < LAN_IOEND) {
  390. /*
  391. * This portion is only used by smc91111.c to write data
  392. * into the DATA_REG. Do not swap the data.
  393. */
  394. portp = PORT2ADDR_NE(port);
  395. while (count--)
  396. *(volatile unsigned short *)portp = *buf++;
  397. #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
  398. } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
  399. portp = __port2addr_ata(port);
  400. while (count--)
  401. *(volatile unsigned short *)portp = *buf++;
  402. #endif
  403. #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
  404. } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
  405. pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
  406. count, 1);
  407. #endif
  408. } else {
  409. portp = PORT2ADDR(port);
  410. while (count--)
  411. *(volatile unsigned short *)portp = *buf++;
  412. }
  413. }
  414. void _outsl(unsigned int port, const void *addr, unsigned long count)
  415. {
  416. const unsigned long *buf = addr;
  417. unsigned char *portp;
  418. portp = PORT2ADDR(port);
  419. while (count--)
  420. *(volatile unsigned long *)portp = *buf++;
  421. }