io.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
  3. * Based largely on io_se.c.
  4. *
  5. * I/O routine for Renesas Technology sales RTS7751R2D.
  6. *
  7. * Initial version only to support LAN access; some
  8. * placeholder code from io_rts7751r2d.c left in with the
  9. * expectation of later SuperIO and PCMCIA access.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/types.h>
  13. #include <linux/pci.h>
  14. #include <linux/io.h>
  15. #include <asm/rts7751r2d.h>
  16. #include <asm/addrspace.h>
  17. /*
  18. * The 7751R RTS7751R2D uses the built-in PCI controller (PCIC)
  19. * of the 7751R processor, and has a SuperIO accessible via the PCI.
  20. * The board also includes a PCMCIA controller on its memory bus,
  21. * like the other Solution Engine boards.
  22. */
  23. static inline unsigned long port2adr(unsigned int port)
  24. {
  25. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  26. if (port == 0x3f6)
  27. return (PA_AREA5_IO + 0x80c);
  28. else
  29. return (PA_AREA5_IO + 0x1000 + ((port-0x1f0) << 1));
  30. else
  31. maybebadio((unsigned long)port);
  32. return port;
  33. }
  34. static inline unsigned long port88796l(unsigned int port, int flag)
  35. {
  36. unsigned long addr;
  37. if (flag)
  38. addr = PA_AX88796L + ((port - AX88796L_IO_BASE) << 1);
  39. else
  40. addr = PA_AX88796L + ((port - AX88796L_IO_BASE) << 1) + 0x1000;
  41. return addr;
  42. }
  43. /* The 7751R RTS7751R2D seems to have everything hooked */
  44. /* up pretty normally (nothing on high-bytes only...) so this */
  45. /* shouldn't be needed */
  46. static inline int shifted_port(unsigned long port)
  47. {
  48. /* For IDE registers, value is not shifted */
  49. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  50. return 0;
  51. else
  52. return 1;
  53. }
  54. #if defined(CONFIG_NE2000) || defined(CONFIG_NE2000_MODULE)
  55. #define CHECK_AX88796L_PORT(port) \
  56. ((port >= AX88796L_IO_BASE) && (port < (AX88796L_IO_BASE+0x20)))
  57. #else
  58. #define CHECK_AX88796L_PORT(port) (0)
  59. #endif
  60. /*
  61. * General outline: remap really low stuff [eventually] to SuperIO,
  62. * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
  63. * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
  64. * should be way beyond the window, and is used w/o translation for
  65. * compatibility.
  66. */
  67. unsigned char rts7751r2d_inb(unsigned long port)
  68. {
  69. if (CHECK_AX88796L_PORT(port))
  70. return (*(volatile unsigned short *)port88796l(port, 0)) & 0xff;
  71. else if (PXSEG(port))
  72. return *(volatile unsigned char *)port;
  73. else if (is_pci_ioaddr(port) || shifted_port(port))
  74. return *(volatile unsigned char *)pci_ioaddr(port);
  75. else
  76. return (*(volatile unsigned short *)port2adr(port) & 0xff);
  77. }
  78. unsigned char rts7751r2d_inb_p(unsigned long port)
  79. {
  80. unsigned char v;
  81. if (CHECK_AX88796L_PORT(port))
  82. v = (*(volatile unsigned short *)port88796l(port, 0)) & 0xff;
  83. else if (PXSEG(port))
  84. v = *(volatile unsigned char *)port;
  85. else if (is_pci_ioaddr(port) || shifted_port(port))
  86. v = *(volatile unsigned char *)pci_ioaddr(port);
  87. else
  88. v = (*(volatile unsigned short *)port2adr(port) & 0xff);
  89. ctrl_delay();
  90. return v;
  91. }
  92. unsigned short rts7751r2d_inw(unsigned long port)
  93. {
  94. if (CHECK_AX88796L_PORT(port))
  95. maybebadio(port);
  96. else if (PXSEG(port))
  97. return *(volatile unsigned short *)port;
  98. else if (is_pci_ioaddr(port) || shifted_port(port))
  99. return *(volatile unsigned short *)pci_ioaddr(port);
  100. else
  101. maybebadio(port);
  102. return 0;
  103. }
  104. unsigned int rts7751r2d_inl(unsigned long port)
  105. {
  106. if (CHECK_AX88796L_PORT(port))
  107. maybebadio(port);
  108. else if (PXSEG(port))
  109. return *(volatile unsigned long *)port;
  110. else if (is_pci_ioaddr(port) || shifted_port(port))
  111. return *(volatile unsigned long *)pci_ioaddr(port);
  112. else
  113. maybebadio(port);
  114. return 0;
  115. }
  116. void rts7751r2d_outb(unsigned char value, unsigned long port)
  117. {
  118. if (CHECK_AX88796L_PORT(port))
  119. *((volatile unsigned short *)port88796l(port, 0)) = value;
  120. else if (PXSEG(port))
  121. *(volatile unsigned char *)port = value;
  122. else if (is_pci_ioaddr(port) || shifted_port(port))
  123. *(volatile unsigned char *)pci_ioaddr(port) = value;
  124. else
  125. *(volatile unsigned short *)port2adr(port) = value;
  126. }
  127. void rts7751r2d_outb_p(unsigned char value, unsigned long port)
  128. {
  129. if (CHECK_AX88796L_PORT(port))
  130. *((volatile unsigned short *)port88796l(port, 0)) = value;
  131. else if (PXSEG(port))
  132. *(volatile unsigned char *)port = value;
  133. else if (is_pci_ioaddr(port) || shifted_port(port))
  134. *(volatile unsigned char *)pci_ioaddr(port) = value;
  135. else
  136. *(volatile unsigned short *)port2adr(port) = value;
  137. ctrl_delay();
  138. }
  139. void rts7751r2d_outw(unsigned short value, unsigned long port)
  140. {
  141. if (CHECK_AX88796L_PORT(port))
  142. maybebadio(port);
  143. else if (PXSEG(port))
  144. *(volatile unsigned short *)port = value;
  145. else if (is_pci_ioaddr(port) || shifted_port(port))
  146. *(volatile unsigned short *)pci_ioaddr(port) = value;
  147. else
  148. maybebadio(port);
  149. }
  150. void rts7751r2d_outl(unsigned int value, unsigned long port)
  151. {
  152. if (CHECK_AX88796L_PORT(port))
  153. maybebadio(port);
  154. else if (PXSEG(port))
  155. *(volatile unsigned long *)port = value;
  156. else if (is_pci_ioaddr(port) || shifted_port(port))
  157. *(volatile unsigned long *)pci_ioaddr(port) = value;
  158. else
  159. maybebadio(port);
  160. }
  161. void rts7751r2d_insb(unsigned long port, void *addr, unsigned long count)
  162. {
  163. unsigned long a = (unsigned long)addr;
  164. volatile __u8 *bp;
  165. volatile __u16 *p;
  166. if (CHECK_AX88796L_PORT(port)) {
  167. p = (volatile unsigned short *)port88796l(port, 0);
  168. while (count--)
  169. ctrl_outb(*p & 0xff, a++);
  170. } else if (PXSEG(port))
  171. while (count--)
  172. ctrl_outb(ctrl_inb(port), a++);
  173. else if (is_pci_ioaddr(port) || shifted_port(port)) {
  174. bp = (__u8 *)pci_ioaddr(port);
  175. while (count--)
  176. ctrl_outb(*bp, a++);
  177. } else {
  178. p = (volatile unsigned short *)port2adr(port);
  179. while (count--)
  180. ctrl_outb(*p & 0xff, a++);
  181. }
  182. }
  183. void rts7751r2d_insw(unsigned long port, void *addr, unsigned long count)
  184. {
  185. unsigned long a = (unsigned long)addr;
  186. volatile __u16 *p;
  187. if (CHECK_AX88796L_PORT(port))
  188. p = (volatile unsigned short *)port88796l(port, 1);
  189. else if (PXSEG(port))
  190. p = (volatile unsigned short *)port;
  191. else if (is_pci_ioaddr(port) || shifted_port(port))
  192. p = (volatile unsigned short *)pci_ioaddr(port);
  193. else
  194. p = (volatile unsigned short *)port2adr(port);
  195. while (count--)
  196. ctrl_outw(*p, a++);
  197. }
  198. void rts7751r2d_insl(unsigned long port, void *addr, unsigned long count)
  199. {
  200. if (CHECK_AX88796L_PORT(port))
  201. maybebadio(port);
  202. else if (is_pci_ioaddr(port) || shifted_port(port)) {
  203. unsigned long a = (unsigned long)addr;
  204. while (count--) {
  205. ctrl_outl(ctrl_inl(pci_ioaddr(port)), a);
  206. a += 4;
  207. }
  208. } else
  209. maybebadio(port);
  210. }
  211. void rts7751r2d_outsb(unsigned long port, const void *addr, unsigned long count)
  212. {
  213. unsigned long a = (unsigned long)addr;
  214. volatile __u8 *bp;
  215. volatile __u16 *p;
  216. if (CHECK_AX88796L_PORT(port)) {
  217. p = (volatile unsigned short *)port88796l(port, 0);
  218. while (count--)
  219. *p = ctrl_inb(a++);
  220. } else if (PXSEG(port))
  221. while (count--)
  222. ctrl_outb(a++, port);
  223. else if (is_pci_ioaddr(port) || shifted_port(port)) {
  224. bp = (__u8 *)pci_ioaddr(port);
  225. while (count--)
  226. *bp = ctrl_inb(a++);
  227. } else {
  228. p = (volatile unsigned short *)port2adr(port);
  229. while (count--)
  230. *p = ctrl_inb(a++);
  231. }
  232. }
  233. void rts7751r2d_outsw(unsigned long port, const void *addr, unsigned long count)
  234. {
  235. unsigned long a = (unsigned long)addr;
  236. volatile __u16 *p;
  237. if (CHECK_AX88796L_PORT(port))
  238. p = (volatile unsigned short *)port88796l(port, 1);
  239. else if (PXSEG(port))
  240. p = (volatile unsigned short *)port;
  241. else if (is_pci_ioaddr(port) || shifted_port(port))
  242. p = (volatile unsigned short *)pci_ioaddr(port);
  243. else
  244. p = (volatile unsigned short *)port2adr(port);
  245. while (count--) {
  246. ctrl_outw(*p, a);
  247. a += 2;
  248. }
  249. }
  250. void rts7751r2d_outsl(unsigned long port, const void *addr, unsigned long count)
  251. {
  252. if (CHECK_AX88796L_PORT(port))
  253. maybebadio(port);
  254. else if (is_pci_ioaddr(port) || shifted_port(port)) {
  255. unsigned long a = (unsigned long)addr;
  256. while (count--) {
  257. ctrl_outl(ctrl_inl(a), pci_ioaddr(port));
  258. a += 4;
  259. }
  260. } else
  261. maybebadio(port);
  262. }
  263. unsigned long rts7751r2d_isa_port2addr(unsigned long offset)
  264. {
  265. return port2adr(offset);
  266. }